[Kimchi-devel] [PATCH] Enhancement:Enable operations when generating a debug report

Wen Wang wenwang at linux.vnet.ibm.com
Tue Jun 24 10:38:27 UTC 2014


From: Wen Wang <wenwang at linux.vnet.ibm.com>

1) Enabled remove and download button when generating a debug report
2) Fixed the bug when changing tabs or refreshing generate indicator
disappears.

Signed-off-by: Wen Wang <wenwang at linux.vnet.ibm.com>
---
 ui/js/src/kimchi.grid.js            |    7 ++++
 ui/js/src/kimchi.host.js            |   67 +++++++++++++++++++++++++++++++++-
 ui/js/src/kimchi.report_add_main.js |   36 ++++++-------------
 3 files changed, 83 insertions(+), 27 deletions(-)

diff --git a/ui/js/src/kimchi.grid.js b/ui/js/src/kimchi.grid.js
index 2c70969..615d469 100644
--- a/ui/js/src/kimchi.grid.js
+++ b/ui/js/src/kimchi.grid.js
@@ -234,6 +234,12 @@ kimchi.widget.Grid.prototype = (function() {
             : null;
     };
 
+    var getSelectedAbove = function() {
+        return this.selectedIndex >= 0
+            ? this.data[this.selectedIndex - 1]
+            : null;
+    };
+
     var startResizing = function(container, event) {
         var grid = event.data.grid;
         kimchi.widget.Grid.beingResized = grid;
@@ -520,6 +526,7 @@ kimchi.widget.Grid.prototype = (function() {
         createDOM: createDOM,
         setData: setData,
         getSelected: getSelected,
+        getSelectedAbove:getSelectedAbove,
         reload: reload,
         destroy: destroy
     };
diff --git a/ui/js/src/kimchi.host.js b/ui/js/src/kimchi.host.js
index f3de831..c3d0eef 100644
--- a/ui/js/src/kimchi.host.js
+++ b/ui/js/src/kimchi.host.js
@@ -310,7 +310,13 @@ kimchi.host_main = function() {
                 label: i18n['KCHDR6009M'],
                 disabled: true,
                 onClick: function(event) {
-                    var report = reportGrid.getSelected();
+                    var report = null;
+                    if ($('.grid-body-view table tbody tr:first-child td:last-child',
+                            '#' + reportGridID).attr('id') === 'id-debug-img') {
+                        report = reportGrid.getSelectedAbove();
+                    } else {
+                        report = reportGrid.getSelected();
+                    }
                     if(!report) {
                         return;
                     }
@@ -341,7 +347,13 @@ kimchi.host_main = function() {
                 label: i18n['KCHDR6010M'],
                 disabled: true,
                 onClick: function(event) {
-                    var report = reportGrid.getSelected();
+                    var report = null;
+                    if ($('.grid-body-view table tbody tr:first-child td:last-child',
+                            '#' + reportGridID).attr('id') === 'id-debug-img') {
+                        report = reportGrid.getSelectedAbove();
+                    } else {
+                        report = reportGrid.getSelected();
+                    }
                     if(!report) {
                         return;
                     }
@@ -383,6 +395,28 @@ kimchi.host_main = function() {
             else {
                 initReportGrid(reports);
             }
+            var taskID = sessionStorage.getItem('sessionDebugReportID')
+            var reportName = sessionStorage.getItem('sessionDebugReportName');
+            if (taskID != null) {
+                kimchi.getTask(taskID, function(result) {
+                    var taskStatus = result['status'];
+                    if (taskStatus === 'running') {
+                        $('.grid-body-view table tbody', '#' + reportGridID).prepend(
+                            '<tr>' +
+                                '<td>' +
+                                    '<div class="cell-text-wrapper">' + reportName + '</div>' +
+                                '</td>' +
+                                '<td id ="id-debug-img">' +
+                                    '<div class="cell-text-wrapper">' + i18n['KCHDR6007M'] + '</div>' +
+                                '</td>' +
+                            '</tr>'
+                        );
+                        $('#' + reportGridID + '-generate-button').prop('disabled', true);
+                    } else {
+                        $('#' + reportGridID + '-generate-button').prop('disabled', false);
+                    }
+                }, '');
+            }
         }, function(error) {
             if(error['status'] == 403) {
                 $('#debug-report-section').addClass('hidden');
@@ -473,6 +507,35 @@ kimchi.host_main = function() {
                     .subscribe(listDebugReports);
             }
         });
+        var taskID = sessionStorage.getItem('sessionDebugReportID');
+        if (taskID != null) {
+            var isRunning =false;
+            var trackTask = function() {
+                kimchi.getTask(taskID, function(result) {
+                    var taskStatus = result['status'];
+                    switch(taskStatus) {
+                    case 'running':
+                        if(kimchi.stopTrackingReport === true) {
+                            return;
+                        }
+                        setTimeout(function() {
+                            trackTask();
+                        }, 200);
+                        break;
+                    case 'finished':
+                        listDebugReports();
+                        isRunning = true;
+                        break;
+                    default:
+                        break;
+                    }
+                }, '');
+            }
+            if (!isRunning)
+            {
+               trackTask();
+            }
+        }
     };
 
     kimchi.getHost(function(data) {
diff --git a/ui/js/src/kimchi.report_add_main.js b/ui/js/src/kimchi.report_add_main.js
index 43484f5..3fdaa9d 100644
--- a/ui/js/src/kimchi.report_add_main.js
+++ b/ui/js/src/kimchi.report_add_main.js
@@ -17,25 +17,10 @@
  */
 kimchi.report_add_main = function() {
     var reportGridID = 'available-reports-grid';
-    var generateButton = $('#' + reportGridID + '-generate-button');
     var addReportForm = $('#form-report-add');
     var submitButton = $('#button-report-add');
     var nameTextbox = $('input[name="name"]', addReportForm);
     nameTextbox.select();
-
-    /*
-     * FIXME:
-     *   Currently, all buttons will be disabled when a report is being
-     * generated. Though operations on existing debug reports shouldn't
-     * be affected when a new one is being generated, and it's expected
-     * to enable Rename/Remove/Download Buttons whenever users click an
-     * existing report row in the grid.
-     */
-    var disableToolbarButtons = function(event, toEnable) {
-        $('#' + reportGridID + ' .grid-toolbar button')
-            .prop('disabled', !toEnable);
-    };
-
     var submitForm = function(event) {
         if(submitButton.prop('disabled')) {
             return false;
@@ -48,15 +33,14 @@ kimchi.report_add_main = function() {
         }
         var formData = addReportForm.serializeObject();
         var taskAccepted = false;
-        disableToolbarButtons();
+        $('#' + reportGridID + '-generate-button').prop('disabled', true);
         submitButton.prop('disabled', true);
-        $('.grid-body table tr', '#' + reportGridID)
-            .on('click', disableToolbarButtons);
         kimchi.createReport(formData, function(result) {
-            $('.grid-body-view table tr:first-child', '#' + reportGridID).remove();
-            $('.grid-body table tr', '#' + reportGridID)
-                .off('click', disableToolbarButtons);
-            generateButton.prop('disabled', false);
+            $('.grid-body-view table tr:first-child',
+                '#' + reportGridID).remove();
+            $('#' + reportGridID + '-generate-button').prop('disabled', false);
+            sessionStorage.removeItem('sessionDebugReportID');
+            sessionStorage.removeItem('sessionDebugReportName');
             kimchi.topic('kimchi/debugReportAdded').publish({
                 result: result
             });
@@ -73,10 +57,10 @@ kimchi.report_add_main = function() {
             taskAccepted &&
                 $('.grid-body-view table tr:first-child',
                     '#' + reportGridID).remove();
-            $('.grid-body table tr', '#' + reportGridID)
-                .off('click', disableToolbarButtons);
-            generateButton.prop('disabled', false);
+            $('#' + reportGridID + '-generate-button').prop('disabled', false);
             submitButton.prop('disabled', false);
+            sessionStorage.removeItem('sessionDebugReportID');
+            sessionStorage.removeItem('sessionDebugReportName');
             nameTextbox.select();
         }, function(result) {
             if(taskAccepted) {
@@ -85,6 +69,8 @@ kimchi.report_add_main = function() {
             taskAccepted = true;
             kimchi.window.close();
             var reportName = nameTextbox.val() || i18n['KCHDR6012M'];
+            sessionStorage.setItem('sessionDebugReportName',reportName);
+            sessionStorage.setItem('sessionDebugReportID',result['id']);
             $('.grid-body-view table tbody', '#' + reportGridID).prepend(
                 '<tr>' +
                     '<td>' +
-- 
1.7.1




More information about the Kimchi-devel mailing list