[Kimchi-devel] [PATCH v4 3/4] Implement the package manager monitor frontend

Jose Ricardo Ziviani joserz at linux.vnet.ibm.com
Wed Oct 7 16:25:40 UTC 2015


 - Whenever Kimchi host tab is displayed this client will check if the package
   manager is running, if so the logfile will be displayed in the Package Update
   progress window.

Signed-off-by: Jose Ricardo Ziviani <joserz at linux.vnet.ibm.com>
---
 src/wok/plugins/kimchi/ui/js/src/kimchi.api.js  | 39 +++++++++++++++++++++++++
 src/wok/plugins/kimchi/ui/js/src/kimchi.host.js | 29 ++++++++++++++++++
 src/wok/plugins/kimchi/ui/pages/i18n.json.tmpl  |  2 ++
 3 files changed, 70 insertions(+)

diff --git a/src/wok/plugins/kimchi/ui/js/src/kimchi.api.js b/src/wok/plugins/kimchi/ui/js/src/kimchi.api.js
index c82d040..a16c95e 100644
--- a/src/wok/plugins/kimchi/ui/js/src/kimchi.api.js
+++ b/src/wok/plugins/kimchi/ui/js/src/kimchi.api.js
@@ -884,6 +884,45 @@ var kimchi = {
         });
     },
 
+    softwareUpdateProgress : function(suc, err, progress) {
+        var taskID = -1;
+        var onResponse = function(data) {
+            taskID = data['id'];
+            trackTask();
+        };
+
+        var trackTask = function() {
+            kimchi.getTask(taskID, onTaskResponse, err);
+        };
+
+        var onTaskResponse = function(result) {
+            var taskStatus = result['status'];
+            switch(taskStatus) {
+            case 'running':
+                progress && progress(result);
+                setTimeout(function() {
+                    trackTask();
+                }, 1000);
+                break;
+            case 'finished':
+            case 'failed':
+                suc(result);
+                break;
+            default:
+                break;
+            }
+        };
+
+        wok.requestJSON({
+            url : 'plugins/kimchi/host/swupdateprogress',
+            type : "GET",
+            contentType : "application/json",
+            dataType : "json",
+            success : onResponse,
+            error : err
+        });
+    },
+
     updateSoftware : function(suc, err, progress) {
         var taskID = -1;
         var onResponse = function(data) {
diff --git a/src/wok/plugins/kimchi/ui/js/src/kimchi.host.js b/src/wok/plugins/kimchi/ui/js/src/kimchi.host.js
index c3765dc..8d2517a 100644
--- a/src/wok/plugins/kimchi/ui/js/src/kimchi.host.js
+++ b/src/wok/plugins/kimchi/ui/js/src/kimchi.host.js
@@ -258,6 +258,24 @@ kimchi.host_main = function() {
         });
     };
 
+    var startSoftwareUpdateProgress = function() {
+        var progressArea = $('#' + progressAreaID)[0];
+        $('#software-updates-progress-container').removeClass('hidden');
+        $(progressArea).text('');
+        !wok.isElementInViewport(progressArea) &&
+            progressArea.scrollIntoView();
+
+        kimchi.softwareUpdateProgress(function(result) {
+            reloadProgressArea(result);
+            wok.topic('kimchi/softwareUpdated').publish({
+                result: result
+            });
+            wok.message.warn(i18n['KCHUPD6010M']);
+        }, function(error) {
+            wok.message.error(i18n['KCHUPD6011M']);
+        }, reloadProgressArea);
+    };
+
     var listSoftwareUpdates = function(gridCallback) {
         kimchi.listSoftwareUpdates(function(softwareUpdates) {
             if($.isFunction(gridCallback)) {
@@ -276,6 +294,17 @@ kimchi.host_main = function() {
             $(updateButton).prop('disabled', softwareUpdates.length === 0);
         }, function(error) {
             var message = error && error['responseJSON'] && error['responseJSON']['reason'];
+
+            // cannot get the list of packages because there is another
+            // package manager instance running, so follow that instance updates
+            if (message.indexOf("KCHPKGUPD0005E") !== -1) {
+                startSoftwareUpdateProgress();
+                if($.isFunction(gridCallback)) {
+                    gridCallback([]);
+                }
+                return;
+            }
+
             if($.isFunction(gridCallback)) {
                 gridCallback([]);
             }
diff --git a/src/wok/plugins/kimchi/ui/pages/i18n.json.tmpl b/src/wok/plugins/kimchi/ui/pages/i18n.json.tmpl
index cd320e0..64045a9 100644
--- a/src/wok/plugins/kimchi/ui/pages/i18n.json.tmpl
+++ b/src/wok/plugins/kimchi/ui/pages/i18n.json.tmpl
@@ -103,6 +103,8 @@
     "KCHUPD6007M": "$_("Updating...")",
     "KCHUPD6008M": "$_("Failed to retrieve packages update information.")",
     "KCHUPD6009M": "$_("Failed to update package(s).")",
+    "KCHUPD6010M": "$_("The package manager job is done.")",
+    "KCHUPD6011M": "$_("Failed to read the package manager logfile.")",
 
 
     "KCHDR6001M": "$_("Debug report will be removed permanently and can't be recovered. Do you want to continue?")",
-- 
1.9.1




More information about the Kimchi-devel mailing list