From 07d6d245d16755772fab427625a8996085368097 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 16 Mar 2014 15:39:58 -0400 Subject: [PATCH] added refresh buttons to guide and tv pages --- dashboard-ui/library.html | 8 ++ dashboard-ui/livetvstatus.html | 8 ++ dashboard-ui/scripts/dashboardpage.js | 11 ++- dashboard-ui/scripts/livetvstatus.js | 92 +++++++++++++++++++- dashboard-ui/scripts/medialibrarypage.js | 102 ++++++++++++++++++++++- 5 files changed, 216 insertions(+), 5 deletions(-) diff --git a/dashboard-ui/library.html b/dashboard-ui/library.html index 7276ad89f3..c79186293d 100644 --- a/dashboard-ui/library.html +++ b/dashboard-ui/library.html @@ -21,6 +21,14 @@

+ +
+
+ + +
Last Result:
+
+ diff --git a/dashboard-ui/livetvstatus.html b/dashboard-ui/livetvstatus.html index 305ad0300f..d8370ef02a 100644 --- a/dashboard-ui/livetvstatus.html +++ b/dashboard-ui/livetvstatus.html @@ -23,6 +23,14 @@

Status:

Version:

+
+ +
+ + +
Last Result:
+
+

Tuners

diff --git a/dashboard-ui/scripts/dashboardpage.js b/dashboard-ui/scripts/dashboardpage.js index 297f6a4cd0..8d652db365 100644 --- a/dashboard-ui/scripts/dashboardpage.js +++ b/dashboard-ui/scripts/dashboardpage.js @@ -372,16 +372,21 @@ html += '

'; - html += task.Name; + html += task.Name+"
"; if (task.State == "Running") { var progress = (task.CurrentProgressPercentage || 0).toFixed(1); - html += ' - ' + progress + '%'; + + html += ''; + html += '' + progress + '%'; + html += ''; + + html += "" + progress + "%"; html += ''; } else if (task.State == "Cancelling") { - html += ' - Stopping'; + html += 'Stopping'; } html += '

'; diff --git a/dashboard-ui/scripts/livetvstatus.js b/dashboard-ui/scripts/livetvstatus.js index e68ca9e66e..434efc966b 100644 --- a/dashboard-ui/scripts/livetvstatus.js +++ b/dashboard-ui/scripts/livetvstatus.js @@ -157,12 +157,102 @@ }); } - $(document).on('pageshow', "#liveTvStatusPage", function () { + function pollTasks(page) { + + ApiClient.getScheduledTasks().done(function (tasks) { + + updateTasks(page, tasks); + }); + + } + + function updateTasks(page, tasks) { + + $('.refreshGuidePanel', page).removeClass('hide'); + + var task = tasks.filter(function (t) { + + return t.Name == 'Refresh Guide'; + + })[0]; + + $('.btnRefreshGuide', page).buttonEnabled(task.State == 'Idle').attr('data-taskid', task.Id); + + var progress = (task.CurrentProgressPercentage || 0).toFixed(1); + $('.refreshGuideProgress', page).val(progress); + var lastResult = task.LastExecutionResult ? task.LastExecutionResult.Status : ''; + + if (lastResult == "Failed") { + $('.lastRefreshGuideResult', page).html('(failed)'); + } + else if (lastResult == "Cancelled") { + $('.lastRefreshGuideResult', page).html('(cancelled)'); + } + else if (lastResult == "Aborted") { + $('.lastRefreshGuideResult', page).html('(Aborted by server shutdown)'); + } else { + $('.lastRefreshGuideResult', page).html(lastResult); + } + } + + function onWebSocketMessage(e, msg) { + + if (msg.MessageType == "ScheduledTasksInfo") { + + var tasks = msg.Data; + + var page = $.mobile.activePage; + + updateTasks(page, tasks); + } + } + + $(document).on('pageinit', "#liveTvStatusPage", function () { var page = this; + $('.btnRefreshGuide', page).on('click', function () { + + var button = this; + var id = button.getAttribute('data-taskid'); + + ApiClient.startScheduledTask(id).done(function () { + + pollTasks(page); + }); + + }); + + }).on('pageshow', "#liveTvStatusPage", function () { + + var page = this; + + $('.refreshGuidePanel', page).addClass('hide'); + reload(page); + pollTasks(page); + + if (ApiClient.isWebSocketOpen()) { + ApiClient.sendWebSocketMessage("ScheduledTasksInfoStart", "1500,1500"); + } + + $(ApiClient).on("websocketmessage", onWebSocketMessage).on('websocketopen', function () { + + if (ApiClient.isWebSocketOpen()) { + ApiClient.sendWebSocketMessage("ScheduledTasksInfoStart", "1500,1500"); + } + }); + + }).on('pagehide', "#liveTvStatusPage", function () { + + var page = this; + + if (ApiClient.isWebSocketOpen()) { + ApiClient.sendWebSocketMessage("ScheduledTasksInfoStop"); + } + + $(ApiClient).off("websocketmessage", onWebSocketMessage); }); })(jQuery, document, window); diff --git a/dashboard-ui/scripts/medialibrarypage.js b/dashboard-ui/scripts/medialibrarypage.js index 0ebff6a68f..0a13a900b7 100644 --- a/dashboard-ui/scripts/medialibrarypage.js +++ b/dashboard-ui/scripts/medialibrarypage.js @@ -326,4 +326,104 @@ } }; -$(document).on('pageshow', ".mediaLibraryPage", MediaLibraryPage.onPageShow); \ No newline at end of file +$(document).on('pageshow', ".mediaLibraryPage", MediaLibraryPage.onPageShow); + +(function ($, document, window) { + + function pollTasks(page) { + + ApiClient.getScheduledTasks().done(function (tasks) { + + updateTasks(page, tasks); + }); + + } + + function updateTasks(page, tasks) { + + $('.refreshLibraryPanel', page).removeClass('hide'); + + var task = tasks.filter(function (t) { + + return t.Name == 'Scan media library'; + + })[0]; + + $('.btnRefresh', page).buttonEnabled(task.State == 'Idle').attr('data-taskid', task.Id); + + var progress = (task.CurrentProgressPercentage || 0).toFixed(1); + $('.refreshProgress', page).val(progress); + var lastResult = task.LastExecutionResult ? task.LastExecutionResult.Status : ''; + + if (lastResult == "Failed") { + $('.lastRefreshResult', page).html('(failed)'); + } + else if (lastResult == "Cancelled") { + $('.lastRefreshResult', page).html('(cancelled)'); + } + else if (lastResult == "Aborted") { + $('.lastRefreshResult', page).html('(Aborted by server shutdown)'); + } else { + $('.lastRefreshResult', page).html(lastResult); + } + } + + function onWebSocketMessage(e, msg) { + + if (msg.MessageType == "ScheduledTasksInfo") { + + var tasks = msg.Data; + + var page = $.mobile.activePage; + + updateTasks(page, tasks); + } + } + + $(document).on('pageinit', "#mediaLibraryPage", function () { + + var page = this; + + $('.btnRefresh', page).on('click', function () { + + var button = this; + var id = button.getAttribute('data-taskid'); + + ApiClient.startScheduledTask(id).done(function () { + + pollTasks(page); + }); + + }); + + }).on('pageshow', "#mediaLibraryPage", function () { + + var page = this; + + $('.refreshLibraryPanel', page).addClass('hide'); + + pollTasks(page); + + if (ApiClient.isWebSocketOpen()) { + ApiClient.sendWebSocketMessage("ScheduledTasksInfoStart", "1500,1500"); + } + + $(ApiClient).on("websocketmessage", onWebSocketMessage).on('websocketopen', function () { + + if (ApiClient.isWebSocketOpen()) { + ApiClient.sendWebSocketMessage("ScheduledTasksInfoStart", "1500,1500"); + } + }); + + }).on('pagehide', "#mediaLibraryPage", function () { + + var page = this; + + if (ApiClient.isWebSocketOpen()) { + ApiClient.sendWebSocketMessage("ScheduledTasksInfoStop"); + } + + $(ApiClient).off("websocketmessage", onWebSocketMessage); + }); + +})(jQuery, document, window);