From 767cdc1f6f6a63ce997fc9476911e2c361f9d402 Mon Sep 17 00:00:00 2001 From: LukePulverenti Date: Wed, 20 Feb 2013 20:33:05 -0500 Subject: Pushing missing changes --- .../Html/scripts/ScheduledTasksPage.js | 170 +++++++++++++++++++++ 1 file changed, 170 insertions(+) create mode 100644 MediaBrowser.WebDashboard/Html/scripts/ScheduledTasksPage.js (limited to 'MediaBrowser.WebDashboard/Html/scripts/ScheduledTasksPage.js') diff --git a/MediaBrowser.WebDashboard/Html/scripts/ScheduledTasksPage.js b/MediaBrowser.WebDashboard/Html/scripts/ScheduledTasksPage.js new file mode 100644 index 000000000..d822db722 --- /dev/null +++ b/MediaBrowser.WebDashboard/Html/scripts/ScheduledTasksPage.js @@ -0,0 +1,170 @@ +var ScheduledTasksPage = { + + onPageShow: function () { + + Dashboard.showLoadingMsg(); + + ScheduledTasksPage.reloadList(true); + + $(document).on("websocketmessage", ScheduledTasksPage.onWebSocketMessage).on("websocketopen", ScheduledTasksPage.onWebSocketConnectionChange).on("websocketerror", ScheduledTasksPage.onWebSocketConnectionChange).on("websocketclose", ScheduledTasksPage.onWebSocketConnectionChange); + }, + + onPageHide: function () { + $(document).off("websocketmessage", ScheduledTasksPage.onWebSocketMessage).off("websocketopen", ScheduledTasksPage.onWebSocketConnectionChange).off("websocketerror", ScheduledTasksPage.onWebSocketConnectionChange).off("websocketclose", ScheduledTasksPage.onWebSocketConnectionChange); + ScheduledTasksPage.stopInterval(); + }, + + startInterval: function () { + + if (Dashboard.isWebSocketOpen()) { + Dashboard.sendWebSocketMessage("ScheduledTasksInfoStart", "1500,1500"); + } + }, + + stopInterval: function () { + + if (Dashboard.isWebSocketOpen()) { + Dashboard.sendWebSocketMessage("ScheduledTasksInfoStop"); + } + }, + + onWebSocketMessage: function (e, msg) { + + if (msg.MessageType == "ScheduledTasksInfo") { + ScheduledTasksPage.populateList(msg.Data); + } + }, + + onWebSocketConnectionChange: function() { + ScheduledTasksPage.reloadList(true); + }, + + reloadList: function (updateInterval) { + + if (updateInterval) { + ScheduledTasksPage.stopInterval(); + } + + ApiClient.getScheduledTasks().done(function (tasks) { + ScheduledTasksPage.populateList(tasks); + Dashboard.hideLoadingMsg(); + + if (updateInterval) { + ScheduledTasksPage.startInterval(); + } + + }); + }, + + populateList: function (tasks) { + + tasks = tasks.sort(function (a, b) { + + a = a.Category + " " + a.Name; + b = b.Category + " " + b.Name; + + if (a == b) { + return 0; + } + + if (a < b) { + return -1; + } + + return 1; + }); + + var page = $($.mobile.activePage); + + var html = ""; + + var currentCategory; + + for (var i = 0, length = tasks.length; i < length; i++) { + + var task = tasks[i]; + + if (task.Category != currentCategory) { + currentCategory = task.Category; + + html += "
  • " + currentCategory + "
  • "; + } + + html += "
  • "; + + html += ""; + + html += "

    " + task.Name + "

    "; + + if (task.State == "Idle") { + + if (task.LastExecutionResult) { + + var text = "Last run " + humane_date(task.LastExecutionResult.EndTimeUtc) + ', taking ' + humane_elapsed(task.LastExecutionResult.StartTimeUtc, task.LastExecutionResult.EndTimeUtc); + + if (task.LastExecutionResult.Status == "Failed") { + text += " (failed)"; + } + else if (task.LastExecutionResult.Status == "Cancelled") { + text += " (cancelled)"; + } + else if (task.LastExecutionResult.Status == "Aborted") { + text += " (Aborted by server shutdown)"; + } + + html += "

    " + text + "

    "; + } + + html += "
    Start"; + } + else if (task.State == "Running") { + + var progress = task.CurrentProgress || { PercentComplete: 0 }; + progress = Math.round(progress.PercentComplete); + + html += '

    '; + html += '' + progress + '%'; + html += ''; + + html += "" + progress + "%"; + html += '

    '; + + html += "Stop"; + + } else { + + html += "

    Stopping

    "; + html += "Start"; + } + + html += ""; + + html += "
  • "; + } + + $('#ulScheduledTasks', page).html(html).listview('refresh'); + }, + + startTask: function (id) { + + Dashboard.showLoadingMsg(); + + ApiClient.startScheduledTask(id).done(function (result) { + + ScheduledTasksPage.reloadList(); + }); + + }, + + stopTask: function (id) { + + Dashboard.showLoadingMsg(); + + ApiClient.stopScheduledTask(id).done(function (result) { + + ScheduledTasksPage.reloadList(); + }); + } +}; + +$(document).on('pageshow', "#scheduledTasksPage", ScheduledTasksPage.onPageShow).on('pagehide', "#scheduledTasksPage", ScheduledTasksPage.onPageHide); \ No newline at end of file -- cgit v1.2.3