Pārlūkot izejas kodu

HUE-4530 [indexer] Progress bar on indexing

Enrico Berti 9 gadi atpakaļ
vecāks
revīzija
9df36a6

+ 5 - 5
desktop/core/src/desktop/static/desktop/css/wizard.css

@@ -67,13 +67,13 @@
   color: #0F9D56;
 }
 
-.step-indicator .incomplete .step {
-  border-color: #ff3b30;
-  color: #ff3b30;
+.step-indicator .error .step {
+  border-color: #d6616b;
+  color: #d6616b;
 }
 
-.step-indicator .incomplete .caption {
-  color: #ff3b30;
+.step-indicator .error .caption {
+  color: #d6616b;
 }
 
 .step-indicator .active.complete .step {

+ 50 - 8
desktop/libs/indexer/src/indexer/templates/indexer.mako

@@ -71,6 +71,10 @@ ${ assist.assistPanel() }
     margin-bottom: 5px;
     margin-left: 10px;
   }
+
+  .right-panel {
+    overflow-x: hidden;
+  }
 </style>
 
 <script src="${ static('desktop/js/jquery.hiveautocomplete.js') }" type="text/javascript" charset="utf-8"></script>
@@ -186,13 +190,21 @@ ${ assist.assistPanel() }
         </div>
         <div class="caption">${ _('Tweak it') }</div>
       </li>
-      <li data-bind="css: { 'inactive': currentStep() < 3, 'active': currentStep() == 3 }, click: function() { currentStep(3) }">
+      <li data-bind="css: { 'inactive': currentStep() < 3, 'active': currentStep() == 3, 'error': createWizard.indexingError, 'complete': createWizard.indexingSuccess }, click: function() { currentStep(3) }">
         <div class="step">
           <!-- ko if: createWizard.isIndexing -->
             <span class="fa fa-spinner fa-spin"></span>
           <!-- /ko -->
           <!-- ko ifnot: createWizard.isIndexing -->
+            <!-- ko if: !createWizard.indexingError() && !createWizard.indexingSuccess() -->
             3
+            <!-- /ko -->
+            <!-- ko if: createWizard.indexingError -->
+              <span class="fa fa-exclamation-triangle"></span>
+            <!-- /ko -->
+            <!-- ko if: createWizard.indexingSuccess -->
+              <span class="fa fa-check"></span>
+            <!-- /ko -->
           <!-- /ko -->
         </div>
         <div class="caption">${ _('Index it!') }</div>
@@ -318,12 +330,12 @@ ${ assist.assistPanel() }
     <!-- /ko -->
 
     <div data-bind="visible: createWizard.jobId">
-      <a href="javascript:void(0)" class="btn btn-success" data-bind="attr: {href: '/oozie/list_oozie_workflow/' + createWizard.jobId() }" target="_blank" title="${ _('Open') }">
-        ${_('Oozie Status')}
-      </a>
-      <a href="javascript:void(0)" class="btn btn-success" data-bind="attr: {href: '${ url('notebook:editor') }?editor=' + createWizard.editorId() }" target="_blank" title="${ _('Open') }">
-        ${_('View indexing status')}
-      </a>
+##       <a href="javascript:void(0)" class="btn btn-success" data-bind="attr: {href: '/oozie/list_oozie_workflow/' + createWizard.jobId() }" target="_blank" title="${ _('Open') }">
+##         ${_('Oozie Status')}
+##       </a>
+##       <a href="javascript:void(0)" class="btn btn-success" data-bind="attr: {href: '${ url('notebook:editor') }?editor=' + createWizard.editorId() }" target="_blank" title="${ _('Open') }">
+##         ${_('View indexing status')}
+##       </a>
 
       ${ _('View collection') } <a href="javascript:void(0)" data-bind="attr: {href: '${ url("indexer:collections") }' +'#edit/' + createWizard.fileFormat().name() }, text: createWizard.fileFormat().name" target="_blank"></a>
     </div>
@@ -429,6 +441,20 @@ ${ assist.assistPanel() }
   <!--/ko -->
 </script>
 
+<script type="text/html" id="notebook-progress">
+  <!-- ko with: selectedNotebook  -->
+    <!-- ko foreach: snippets  -->
+      <div class="progress-snippet progress active" data-bind="css: {
+        'progress-starting': progress() == 0 && status() == 'running',
+        'progress-warning': progress() > 0 && progress() < 100,
+        'progress-success': progress() == 100,
+        'progress-danger': progress() == 0 && errors().length > 0}" style="background-color: #FFF; width: 100%; height: 4px">
+        <div class="bar" data-bind="style: {'width': (errors().length > 0 ? 100 : Math.max(2,progress())) + '%'}"></div>
+      </div>
+    <!-- /ko -->
+  <!-- /ko -->
+</script>
+
 
 <script type="text/javascript" charset="utf-8">
 
@@ -757,6 +783,8 @@ ${ assist.assistPanel() }
       };
 
       self.isIndexing = ko.observable(false);
+      self.indexingError = ko.observable(false);
+      self.indexingSuccess = ko.observable(false);
       self.indexFile = function () {
         if (!self.readyToIndex()) return;
 
@@ -770,6 +798,7 @@ ${ assist.assistPanel() }
           self.showCreate(true);
           self.jobId(resp.handle.id);
           self.editorId(resp.history_id);
+          $('#notebook').html($('#notebook-progress').html());
           self.editorVM = new EditorViewModel(resp.history_uuid, '', {
             user: '${ user.username }',
             userId: ${ user.id },
@@ -782,7 +811,20 @@ ${ assist.assistPanel() }
           });
           ko.cleanNode($("#notebook")[0]);
           ko.applyBindings(self.editorVM, $("#notebook")[0]);
-          self.editorVM.openNotebook(resp.history_uuid);
+          self.editorVM.openNotebook(resp.history_uuid, null, true, function(){
+            self.editorVM.selectedNotebook().snippets()[0].progress.subscribe(function(val){
+              if (val == 100){
+                self.isIndexing(false);
+                self.indexingSuccess(true);
+              }
+            });
+            self.editorVM.selectedNotebook().snippets()[0].status.subscribe(function(val){
+              if (val == 'failed'){
+                self.isIndexing(false);
+                self.indexingError(true);
+              }
+            });
+          });
           viewModel.isLoading(false);
         }).fail(function (xhr, textStatus, errorThrown) {
           $(document).trigger("error", xhr.responseText);

+ 7 - 2
desktop/libs/notebook/src/notebook/static/notebook/js/notebook.ko.js

@@ -2075,7 +2075,7 @@
       huePubSub.publish('check.job.browser');
     };
 
-    self.openNotebook = function (uuid, queryTab) {
+    self.openNotebook = function (uuid, queryTab, skipUrlChange, callback) {
       $.get('/desktop/api2/doc/', {
         uuid: uuid,
         data: true,
@@ -2086,7 +2086,12 @@
           data.data.can_write = data.user_perms.can_write;
           var notebook = data.data;
           self.loadNotebook(notebook, queryTab);
-          hueUtils.changeURL('/notebook/editor?editor=' + data.document.id);
+          if (typeof skipUrlChange === 'undefined'){
+            hueUtils.changeURL('/notebook/editor?editor=' + data.document.id);
+          }
+          if (typeof callback !== 'undefined'){
+            callback();
+          }
         }
         else {
           $(document).trigger("error", data.message);