From 4f2ce200aa316ed3e0a4bf166bbab3b2beadc9c4 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 17 Aug 2016 01:29:05 -0400 Subject: [PATCH] update sync display --- .../indicators/indicators.css | 13 +- .../indicators/indicators.js | 2 +- .../components/syncjoblist/syncjoblist.js | 286 +++++++++++++++++- dashboard-ui/mysync.html | 11 +- dashboard-ui/scripts/mysync.js | 58 +++- dashboard-ui/scripts/plugincatalogpage.js | 4 +- dashboard-ui/scripts/site.js | 1 + dashboard-ui/scripts/syncactivity.js | 6 +- 8 files changed, 354 insertions(+), 27 deletions(-) diff --git a/dashboard-ui/bower_components/emby-webcomponents/indicators/indicators.css b/dashboard-ui/bower_components/emby-webcomponents/indicators/indicators.css index 7bdfd68d4..51f6aceff 100644 --- a/dashboard-ui/bower_components/emby-webcomponents/indicators/indicators.css +++ b/dashboard-ui/bower_components/emby-webcomponents/indicators/indicators.css @@ -72,14 +72,5 @@ } .fullSyncIndicator { - color: #673AB7; - padding: 0; - border: 4px solid #673AB7; - background: #fff; - width: auto; - height: auto; -} - -.fullSyncIndicatorIcon { - margin: -3px; -} + background: rgba(82,181,75,1); +} \ No newline at end of file diff --git a/dashboard-ui/bower_components/emby-webcomponents/indicators/indicators.js b/dashboard-ui/bower_components/emby-webcomponents/indicators/indicators.js index d5556bdbf..5f64c1790 100644 --- a/dashboard-ui/bower_components/emby-webcomponents/indicators/indicators.js +++ b/dashboard-ui/bower_components/emby-webcomponents/indicators/indicators.js @@ -111,7 +111,7 @@ define(['css!./indicators.css', 'material-icons'], function () { function getSyncIndicator(item) { if (item.SyncPercent == 100) { - return '
offline_pin
'; + return '
file_download
'; } else if (item.SyncPercent != null) { return '
file_download
'; } diff --git a/dashboard-ui/components/syncjoblist/syncjoblist.js b/dashboard-ui/components/syncjoblist/syncjoblist.js index 3fc451f14..5acaa0c44 100644 --- a/dashboard-ui/components/syncjoblist/syncjoblist.js +++ b/dashboard-ui/components/syncjoblist/syncjoblist.js @@ -1,11 +1,187 @@ -define(['serverNotifications', 'events', 'loading', 'connectionManager'], function (serverNotifications, events, loading, connectionManager) { +define(['serverNotifications', 'events', 'loading', 'connectionManager', 'imageLoader', 'dom', 'globalize', 'listViewStyle'], function (serverNotifications, events, loading, connectionManager, imageLoader, dom, globalize) { function onSyncJobsUpdated(e, apiClient, data) { + var listInstance = this; + renderList(listInstance, data); } - function renderList(listInstance, items) { + function refreshList(listInstance, jobs) { + for (var i = 0, length = jobs.length; i < length; i++) { + var job = jobs[i]; + refreshJob(listInstance, job); + } + } + + function cancelJob(listInstance, id) { + + require(['confirm'], function (confirm) { + + var msg = listInstance.options.isLocalSync ? +globalize.translate('ConfirmRemoveDownload') : +globalize.translate('CancelSyncJobConfirmation'); + + confirm(msg).then(function () { + + loading.show(); + var apiClient = getApiClient(listInstance); + + apiClient.ajax({ + + url: apiClient.getUrl('Sync/Jobs/' + id), + type: 'DELETE' + + }).then(function () { + + fetchData(listInstance); + }); + }); + }); + } + + function refreshJob(listInstance, job) { + + var listItem = listInstance.options.element.querySelector('.listItem[data-id=\'' + job.Id + '\']'); + + if (!listItem) { + return; + } + + var progress = job.Progress || 0; + var statusIcon = listItem.querySelector('.statusIcon'); + + if (progress === 0) { + statusIcon.innerHTML = 'file_download'; + statusIcon.classList.add('md-icon'); + statusIcon.classList.remove('status-text-icon'); + statusIcon.classList.add('zeroProgressStatus'); + } else if (progress >= 100) { + statusIcon.innerHTML = 'file_download'; + statusIcon.classList.add('md-icon'); + statusIcon.classList.remove('status-text-icon'); + statusIcon.classList.remove('zeroProgressStatus'); + } else { + statusIcon.classList.remove('md-icon'); + statusIcon.classList.remove('zeroProgressStatus'); + statusIcon.classList.add('status-text-icon'); + statusIcon.innerHTML = (Math.round(progress)) + '%'; + } + } + + function getSyncJobHtml(listInstance, job) { + + var html = ''; + + html += '
'; + + var progress = job.Progress || 0; + + if (progress === 0) { + html += 'file_download'; + } else if (progress >= 100) { + html += 'file_download'; + } else { + html += '' + (Math.round(progress)) + '%'; + } + + var textLines = []; + + if (job.ParentName) { + textLines.push(job.ParentName); + } + + textLines.push(job.Name); + + if (job.ItemCount == 1) { + textLines.push(globalize.translate('ValueItemCount', job.ItemCount)); + } else { + textLines.push(globalize.translate('ValueItemCountPlural', job.ItemCount)); + } + + if (textLines >= 3) { + html += '
'; + } else { + html += '
'; + } + + for (var i = 0, length = textLines.length; i < length; i++) { + + if (i == 0) { + html += '

'; + html += textLines[i]; + html += '

'; + } else { + html += '
'; + html += textLines[i]; + html += '
'; + } + } + + html += '
'; + + html += ''; + + html += '
'; + + return html; + } + + function renderList(listInstance, jobs) { + + if ((new Date().getTime() - listInstance.lastDataLoad) < 60000) { + refreshList(listInstance, jobs); + return; + } + + listInstance.lastDataLoad = new Date().getTime(); + + var html = ''; + var lastTargetName = ''; + + var showTargetName = !listInstance.options.isLocalSync; + + var hasOpenSection = false; + + for (var i = 0, length = jobs.length; i < length; i++) { + + var job = jobs[i]; + if (showTargetName) { + var targetName = job.TargetName || 'Unknown'; + + if (targetName != lastTargetName) { + + if (lastTargetName) { + html += '
'; + html += '
'; + html += '
'; + html += '
'; + hasOpenSection = false; + } + + lastTargetName = targetName; + + html += '
'; + + html += '
' + targetName + '
'; + + html += '
'; + html += '
'; + hasOpenSection = true; + } + } + + html += getSyncJobHtml(listInstance, job); + } + + if (hasOpenSection) { + html += '
'; + } + + var elem = listInstance.options.element; + elem.innerHTML = html; + + imageLoader.lazyChildren(elem); } function fetchData(listInstance) { @@ -14,7 +190,7 @@ loading.show(); var options = {}; - var apiClient = connectionManager.getApiClient(listInstance.options.serverId); + var apiClient = getApiClient(listInstance); if (listInstance.options.userId) { options.UserId = listInstance.options.userId; @@ -31,6 +207,98 @@ }); } + function startListening(listInstance) { + + var startParams = "0,1500"; + + var apiClient = getApiClient(listInstance); + + if (listInstance.options.userId) { + startParams += "," + listInstance.options.userId; + } + if (listInstance.options.isLocalSync) { + startParams += "," + apiClient.deviceId(); + } + + if (apiClient.isWebSocketOpen()) { + apiClient.sendWebSocketMessage("SyncJobsStart", startParams); + } + } + + function stopListening(listInstance) { + + var apiClient = getApiClient(listInstance); + if (apiClient.isWebSocketOpen()) { + apiClient.sendWebSocketMessage("SyncJobsStop", ""); + } + } + + function getApiClient(listInstance) { + return connectionManager.getApiClient(listInstance.options.serverId); + } + + function showJobMenu(listInstance, elem) { + + var item = dom.parentWithClass(elem, 'listItem'); + var jobId = item.getAttribute('data-id'); + var status = item.getAttribute('data-status'); + + var menuItems = []; + + if (status == 'Cancelled') { + menuItems.push({ + name: globalize.translate('ButtonDelete'), + id: 'delete' + }); + } else { + menuItems.push({ + name: globalize.translate('ButtonCancelSyncJob'), + id: 'cancel' + }); + } + + require(['actionsheet'], function (actionsheet) { + + actionsheet.show({ + items: menuItems, + positionTo: elem, + callback: function (id) { + + switch (id) { + + case 'delete': + cancelJob(listInstance, jobId); + break; + case 'cancel': + cancelJob(listInstance, jobId); + break; + default: + break; + } + } + }); + + }); + } + + function onElementClick(e) { + + var listInstance = this; + + var btnJobMenu = dom.parentWithClass(e.target, 'btnJobMenu'); + if (btnJobMenu) { + showJobMenu(this, btnJobMenu); + return; + } + + var listItem = dom.parentWithClass(e.target, 'listItem'); + if (listItem) { + var jobId = listItem.getAttribute('data-id'); + // edit job + events.trigger(listInstance, 'jobedit', [jobId, listInstance.options.serverId]); + } + } + function syncJobList(options) { this.options = options; @@ -38,15 +306,27 @@ this.onSyncJobsUpdatedHandler = null; events.on(serverNotifications, 'SyncJobs', onSyncJobsUpdatedHandler); + var onClickHandler = onElementClick.bind(this); + options.element.addEventListener('click', onClickHandler); + this.onClickHandler = onClickHandler; + fetchData(this); + startListening(this); } syncJobList.prototype.destroy = function () { + + stopListening(this); + this.options = null; var onSyncJobsUpdatedHandler = this.onSyncJobsUpdatedHandler; this.onSyncJobsUpdatedHandler = null; events.off(serverNotifications, 'SyncJobs', onSyncJobsUpdatedHandler); + + var onClickHandler = this.onClickHandler; + this.onClickHandler = null; + options.element.removeEventListener('click', onClickHandler); }; return syncJobList; diff --git a/dashboard-ui/mysync.html b/dashboard-ui/mysync.html index 84dce4272..bde3b84ea 100644 --- a/dashboard-ui/mysync.html +++ b/dashboard-ui/mysync.html @@ -1,8 +1,17 @@ 
+
-