소스 검색

HUE-1795 [core] Update window title on every page with a progress bar

Introduced jHueTitleUpdater
Added functionality to Pig, JB and Oozie
Enrico Berti 12 년 전
부모
커밋
e947a693b8

+ 7 - 0
apps/jobbrowser/src/jobbrowser/templates/job.mako

@@ -450,23 +450,30 @@ $(document).ready(function () {
     }
     $("#killJobContainer").html(killCell);
     $("#jobStatus").html('<span class="label ' + getStatusClass(job.status) + '">' + (job.isRetired && !job.isMR2 ? '<i class="fa fa-briefcase fa fa-white" title="${ _('Retired') }"></i> ' : '') + job.status + '</span>');
+    var _title = "";
     if (job.desiredMaps > 0) {
       $("#jobMaps").html((job.isRetired ? '${_('N/A')}' : '<div class="progress" style="width:100px" title="' + (job.isMR2 ? job.mapsPercentComplete : job.finishedMaps + '/' + job.desiredMaps) + '"><div class="bar-label">' + job.mapsPercentComplete + '%</div><div class="' + 'bar ' + getStatusClass(job.status, "bar-") + '" style="margin-top:-20px;width:' + job.mapsPercentComplete + '%"></div></div>'));
+      _title += "M " + job.mapsPercentComplete + "%";
     }
     else {
       $("#jobMaps").html('${_('N/A')}');
     }
     if (job.desiredReduces > 0) {
       $("#jobReduces").html((job.isRetired ? '${_('N/A')}' : '<div class="progress" style="width:100px" title="' + (job.isMR2 ? job.reducesPercentComplete : job.finishedReduces + '/' + job.desiredReduces) + '"><div class="bar-label">' + job.reducesPercentComplete + '%</div><div class="' + 'bar ' + getStatusClass(job.status, "bar-") + '" style="margin-top:-20px;width:' + job.reducesPercentComplete + '%"></div></div>'));
+      _title += " R " + job.reducesPercentComplete + "%";;
     }
     else {
       $("#jobReduces").html('${_('N/A')}');
     }
+    if (_title != ""){
+      $.jHueTitleUpdater.set(_title);
+    }
     $("#jobDuration").html('<span title="' + emptyStringIfNull(job.durationMs) + '">' + (job.isRetired ? '${_('N/A')}' : emptyStringIfNull(job.durationFormatted)) + '</span>');
 
     if (['RUNNING', 'PREP', 'WAITING', 'SUSPENDED', 'PREPSUSPENDED', 'PREPPAUSED', 'PAUSED'].indexOf(job.status.toUpperCase()) == -1) {
       window.clearInterval(_runningInterval);
       removeFailedTasksFromRecent();
+      $.jHueTitleUpdater.reset();
     }
   }
 

+ 4 - 1
apps/oozie/src/oozie/templates/dashboard/list_oozie_bundle.mako

@@ -437,6 +437,8 @@ ${ layout.menubar(section='bundles', dashboard=True) }
 
         $("#status span").attr("class", "label").addClass(getStatusClass(data.status)).text(data.status);
 
+        $.jHueTitleUpdater.set(data.progress + "%");
+
         if (data.id && (data.status == "KILLED" || data.status == "SUCCEEDED" ||  data.status == "DONEWITHERROR" || data.status == "FAILED")) {
           $("#kill-btn").hide();
           if (data.status != "KILLED" ) {
@@ -449,6 +451,7 @@ ${ layout.menubar(section='bundles', dashboard=True) }
 
         if (data.id && (data.status == "RUNNING" || data.status == "RUNNINGWITHERROR")){
           $("#suspend-btn").show();
+          $.jHueTitleUpdater.reset();
         } else {
           $("#suspend-btn").hide();
         }
@@ -460,7 +463,7 @@ ${ layout.menubar(section='bundles', dashboard=True) }
           $("#resume-btn").hide();
         }
 
-        $("#progress .bar").text(data.progress+"%").css("width", data.progress+"%").attr("class", "bar "+getStatusClass(data.status, "bar-"));
+        $("#progress .bar").text(data.progress + "%").css("width", data.progress + "%").attr("class", "bar " + getStatusClass(data.status, "bar-"));
 
         var _logsEl = $("#log pre");
         var newLines = data.log.split("\n").slice(_logsEl.text().split("\n").length);

+ 4 - 1
apps/oozie/src/oozie/templates/dashboard/list_oozie_coordinator.mako

@@ -434,6 +434,8 @@ ${ layout.menubar(section='coordinators', dashboard=True) }
 
         $("#status span").attr("class", "label").addClass(getStatusClass(data.status)).text(data.status);
 
+        $.jHueTitleUpdater.set(data.progress + "%");
+
         if (data.id && data.status != "RUNNING" && data.status != "SUSPENDED" && data.status != "KILLED" && data.status != "FAILED"){
           $("#kill-btn").hide();
           $("#rerun-btn").show();
@@ -448,11 +450,12 @@ ${ layout.menubar(section='coordinators', dashboard=True) }
         if (data.id && (data.status == "SUSPENDED" || data.status == "SUSPENDEDWITHERROR" || data.status == "SUSPENDEDWITHERROR"
             || data.status == "PREPSUSPENDED")){
           $("#resume-btn").show();
+          $.jHueTitleUpdater.reset();
         } else {
           $("#resume-btn").hide();
         }
 
-        $("#progress .bar").text(data.progress+"%").css("width", data.progress+"%").attr("class", "bar "+getStatusClass(data.status, "bar-"));
+        $("#progress .bar").text(data.progress + "%").css("width", data.progress + "%").attr("class", "bar " + getStatusClass(data.status, "bar-"));
 
         var _logsEl = $("#log pre");
         var newLines = data.log.split("\n").slice(_logsEl.text().split("\n").length);

+ 5 - 1
apps/oozie/src/oozie/templates/dashboard/list_oozie_workflow.mako

@@ -492,6 +492,8 @@ ${ layout.menubar(section='workflows', dashboard=True) }
 
         $("#status span").attr("class", "label").addClass(getStatusClass(data.status)).text(data.status);
 
+        $.jHueTitleUpdater.set(data.progress + "%");
+
         if (data.id && data.status == "SUSPENDED"){
           $("#resume-btn").show();
         } else {
@@ -507,9 +509,11 @@ ${ layout.menubar(section='workflows', dashboard=True) }
         if (data.id && data.status != "RUNNING" && data.status != "SUSPENDED"){
           $("#kill-btn").hide();
           $("#rerun-btn").show();
+          $.jHueTitleUpdater.reset();
         }
 
-        $("#progress .bar").text(data.progress+"%").css("width", data.progress+"%").attr("class", "bar " + getStatusClass(data.status, "bar-"));
+        $("#progress .bar").text(data.progress + "%").css("width", data.progress + "%").attr("class", "bar " + getStatusClass(data.status, "bar-"));
+
         $("#graph").html(data.graph);
 
         var _logsEl = $("#log pre");

+ 8 - 0
apps/pig/src/pig/templates/app.mako

@@ -1097,10 +1097,12 @@ ${ commonheader(None, "pig", user) | n,unicode }
 
     $(document).on("showDashboard", function () {
       routie("dashboard");
+      $.jHueTitleUpdater.reset();
     });
 
     $(document).on("showScripts", function () {
       routie("scripts");
+      $.jHueTitleUpdater.reset();
     });
 
     $(document).on("scriptsRefreshed", function () {
@@ -1120,6 +1122,7 @@ ${ commonheader(None, "pig", user) | n,unicode }
 
     $(document).on("stopLogsRefresh", function () {
       window.clearInterval(logsRefreshInterval);
+      $.jHueTitleUpdater.reset();
     });
 
     $(document).on("clearLogs", function () {
@@ -1203,16 +1206,21 @@ ${ commonheader(None, "pig", user) | n,unicode }
           }
           if (data.workflow && data.workflow.isRunning) {
             viewModel.currentScript().actions(data.workflow.actions);
+            if (data.workflow.actions != null && data.workflow.actions.length > 0) {
+              $.jHueTitleUpdater.set(data.workflow.actions[data.workflow.actions.length-1].progress + "%");
+            }
           }
           else {
             viewModel.currentScript().actions(data.workflow.actions);
             viewModel.currentScript().isRunning(false);
             $(document).trigger("stopLogsRefresh");
+            $.jHueTitleUpdater.reset();
           }
         });
       }
       else {
         $(document).trigger("stopLogsRefresh");
+        $.jHueTitleUpdater.reset();
       }
     }
 

+ 1 - 0
desktop/core/src/desktop/templates/common_header.mako

@@ -125,6 +125,7 @@ from django.utils.translation import ugettext as _
   <script src="/static/js/jquery.alert.js"></script>
   <script src="/static/js/jquery.rowselector.js"></script>
   <script src="/static/js/jquery.notify.js"></script>
+  <script src="/static/js/jquery.titleupdater.js"></script>
   <script src="/static/js/jquery.tablescroller.js"></script>
   <script src="/static/js/jquery.tableextender.js"></script>
   <script src="/static/js/jquery.scrollup.js"></script>

+ 65 - 0
desktop/core/static/js/jquery.titleupdater.js

@@ -0,0 +1,65 @@
+// Licensed to Cloudera, Inc. under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  Cloudera, Inc. licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+/*
+ * jHue title updater plugin
+ *
+ */
+;
+(function ($, window, document, undefined) {
+
+  var pluginName = "jHueTitleUpdater",
+    defaults = {
+      message: "",
+      reset: false
+    };
+
+  function Plugin(options) {
+    this.options = $.extend({}, defaults, options);
+    this._defaults = defaults;
+    this._name = pluginName;
+    this.updateStatusBar();
+  }
+
+  Plugin.prototype.setOptions = function (options) {
+    this.options = $.extend({}, defaults, options);
+  };
+
+  Plugin.prototype.updateStatusBar = function () {
+    var _this = this;
+    if (_this.options.reset && $(document).data("jHueTitleUpdaterOriginal") != null) {
+      document.title = $(document).data("jHueTitleUpdaterOriginal");
+      $(document).data("jHueTitleUpdaterOriginal", null);
+    }
+    else if (_this.options.message != "") {
+      if ($(document).data("jHueTitleUpdaterOriginal") == null) {
+        $(document).data("jHueTitleUpdaterOriginal", document.title);
+      }
+      document.title = _this.options.message + " - " + $(document).data("jHueTitleUpdaterOriginal");
+    }
+  };
+
+  $[pluginName] = function () {
+  };
+
+  $[pluginName].reset = function () {
+    new Plugin({ reset: true});
+  };
+
+  $[pluginName].set = function (message) {
+    new Plugin({ message: message});
+  };
+
+})(jQuery, window, document);