[PATCH 0/5] List pending debug reports to all users

Today only the user who started the debug report creation is able to get the view of a pending debug report. But while switching tabs, this information is lost. This patch set gets the pending debug reports by filtering running tasks by target_uri=^/debugreports and list them among to the exinting debug reports. That way all users will get the same view of which debug reports are being generated. Aline Manera (5): Add function to get pending tasks according to filter Add common function to track Task Add function to list all pending debug reports List pending debug reports while loading report grid Only disable report buttons when the selected report is pending ui/js/src/kimchi.api.js | 34 ++++++++++++------- ui/js/src/kimchi.host.js | 65 ++++++++++++++++++++++++++++++++----- ui/js/src/kimchi.report_add_main.js | 42 ++---------------------- 3 files changed, 83 insertions(+), 58 deletions(-) -- 1.9.3

A Task is always associated to a resource and it can be identified by the target_uri parameter. That way we can properly get tasks related to a specific resource type. Example: GET /tasks?target_uri=^/debugreports will return all the tasks associated to a debug report. Signed-off-by: Aline Manera <alinefm@linux.vnet.ibm.com> --- ui/js/src/kimchi.api.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ui/js/src/kimchi.api.js b/ui/js/src/kimchi.api.js index 5fc456d..6f12455 100644 --- a/ui/js/src/kimchi.api.js +++ b/ui/js/src/kimchi.api.js @@ -533,6 +533,18 @@ var kimchi = { }); }, + getTasksByFilter : function(filter, suc, err, sync) { + kimchi.requestJSON({ + url : kimchi.url + 'tasks?' + filter, + type : 'GET', + contentType : 'application/json', + dataType : 'json', + async : !sync, + success : suc, + error : err + }); + }, + login : function(settings, suc, err) { $.ajax({ url : "/login", -- 1.9.3

Track a task is a common funtionality used on UI to idenitfy if the operation has finished or not. So create a common function to do it and reuse whenever is needed. Signed-off-by: Aline Manera <alinefm@linux.vnet.ibm.com> --- ui/js/src/kimchi.api.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/ui/js/src/kimchi.api.js b/ui/js/src/kimchi.api.js index 6f12455..681f573 100644 --- a/ui/js/src/kimchi.api.js +++ b/ui/js/src/kimchi.api.js @@ -21,6 +21,8 @@ var kimchi = { widget: {}, + trackingTasks: [], + /** * A wrapper of jQuery.ajax function to allow custom bindings. * @@ -681,19 +683,15 @@ var kimchi = { }); }, - createReport: function(settings, suc, err, progress) { - var taskID = -1; + trackTask : function(taskID, suc, err, progress) { var onTaskResponse = function(result) { var taskStatus = result['status']; switch(taskStatus) { case 'running': - if(kimchi.stopTrackingReport === true) { - return; - } progress && progress(result); setTimeout(function() { - trackTask(); - }, 200); + kimchi.trackTask(taskID, suc, err, progress); + }, 2000); break; case 'finished': suc(result); @@ -706,13 +704,15 @@ var kimchi = { } }; - var trackTask = function() { - kimchi.getTask(taskID, onTaskResponse, err); - }; + kimchi.getTask(taskID, onTaskResponse, err); + if(kimchi.trackingTasks.indexOf(taskID) < 0) + kimchi.trackingTasks.push(taskID); + }, + createReport: function(settings, suc, err, progress) { var onResponse = function(data) { taskID = data['id']; - trackTask(); + kimchi.trackTask(taskID, suc, err, progress); }; kimchi.requestJSON({ -- 1.9.3

Only the user who has started the debug report creation was able to get the view of a pending debug report. But while switching tabs, this information was lost. To fix this behavior and also let all users get the same view, the pending debug reports must be listed while loading the report grid. In order to do that, create a function to return all the pending debug reports. Signed-off-by: Aline Manera <alinefm@linux.vnet.ibm.com> --- ui/js/src/kimchi.host.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/ui/js/src/kimchi.host.js b/ui/js/src/kimchi.host.js index b2e08b8..526ce5d 100644 --- a/ui/js/src/kimchi.host.js +++ b/ui/js/src/kimchi.host.js @@ -380,6 +380,39 @@ kimchi.host_main = function() { }); }; + var getPendingReports = function() { + var reports = [] + var filter = 'status=running&target_uri=' + encodeURIComponent('^/debugreports/*') + + kimchi.getTasksByFilter(filter, function(tasks) { + for(var i = 0; i < tasks.length; i++) { + reportName = tasks[i].target_uri.replace(/^\/debugreports\//, '') || i18n['KCHDR6012M']; + reports.push({'name': reportName, 'time': i18n['KCHDR6007M']}) + + if(kimchi.trackingTasks.indexOf(tasks[i].id) >= 0) { + continue; + } + + kimchi.trackTask(tasks[i].id, function(result) { + kimchi.topic('kimchi/debugReportAdded').publish(); + }, function(result) { + // Error message from Async Task status + if (result['message']) { + var errText = result['message']; + } + // Error message from standard kimchi exception + else { + var errText = result['responseJSON']['reason']; + } + result && kimchi.message.error(errText); + kimchi.topic('kimchi/debugReportAdded').publish(); + }, null); + } + }, null, true); + + return reports; + }; + var listDebugReports = function() { kimchi.listReports(function(reports) { $('#debug-report-section').removeClass('hidden'); -- 1.9.3

While loading the report grid, the pending debug reports will be listed in addition to the existing debug reports. It will let all users get the same view of which debug reports are being generated and also prevent losing information while switching tabs. Signed-off-by: Aline Manera <alinefm@linux.vnet.ibm.com> --- ui/js/src/kimchi.host.js | 32 ++++++++++++++++++++++++-------- ui/js/src/kimchi.report_add_main.js | 20 ++------------------ 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/ui/js/src/kimchi.host.js b/ui/js/src/kimchi.host.js index 526ce5d..45708d7 100644 --- a/ui/js/src/kimchi.host.js +++ b/ui/js/src/kimchi.host.js @@ -302,11 +302,7 @@ kimchi.host_main = function() { id: reportGridID + '-generate-button', label: i18n['KCHDR6006M'], onClick: function(event) { - kimchi.window.open('report-add.html', { - close: function() { - kimchi.stopTrackingReport = true; - } - }); + kimchi.window.open('report-add.html'); } }, { id: reportGridID + '-rename-button', @@ -364,7 +360,18 @@ kimchi.host_main = function() { } }], onRowSelected: function(row) { - enableReportButtons(true); + var report = reportGrid.getSelected(); + // Only enable report buttons if the selected line is not a + // pending report + if (report['time'] == i18n['KCHDR6007M']) { + var gridElement = $('#'+ reportGridID); + var row = $('tr:contains(' + report['name'] + ')', gridElement); + enableReportButtons(false); + row.attr('class', ''); + } + else { + enableReportButtons(true); + } }, frozenFields: [], fields: [{ @@ -415,17 +422,26 @@ kimchi.host_main = function() { var listDebugReports = function() { kimchi.listReports(function(reports) { + pendingReports = getPendingReports(); + allReports = pendingReports.concat(reports); $('#debug-report-section').removeClass('hidden'); // Row selection will be cleared so disable buttons here enableReportButtons(false); if(reportGrid) { - reportGrid.setData(reports); + reportGrid.setData(allReports); } else { - initReportGrid(reports); + initReportGrid(allReports); } + + // Set id-debug-img to pending reports + // It will display a loading icon + var gridElement = $('#' + reportGridID); + $.each($('td:contains(' + i18n['KCHDR6007M'] + ')', gridElement), function(index, row) { + $(row).attr('id', 'id-debug-img'); + }); }, function(error) { if(error['status'] == 403) { $('#debug-report-section').addClass('hidden'); diff --git a/ui/js/src/kimchi.report_add_main.js b/ui/js/src/kimchi.report_add_main.js index 8d67c8b..62d0d79 100644 --- a/ui/js/src/kimchi.report_add_main.js +++ b/ui/js/src/kimchi.report_add_main.js @@ -54,17 +54,7 @@ kimchi.report_add_main = function() { } taskAccepted = true; kimchi.window.close(); - var reportName = nameTextbox.val() || i18n['KCHDR6012M']; - $('.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>' - ); + kimchi.topic('kimchi/debugReportAdded').publish(); }; disableToolbarButtons(); @@ -73,13 +63,7 @@ kimchi.report_add_main = function() { .on('click', disableToolbarButtons); kimchi.createReport(formData, function(result) { onTaskAccepted(); - $('.grid-body-view table tr:first-child', '#' + reportGridID).remove(); - $('.grid-body table tr', '#' + reportGridID) - .off('click', disableToolbarButtons); - generateButton.prop('disabled', false); - kimchi.topic('kimchi/debugReportAdded').publish({ - result: result - }); + kimchi.topic('kimchi/debugReportAdded').publish(); }, function(result) { // Error message from Async Task status if (result['message']) { -- 1.9.3

The actions buttons must be disable only if the selected debug report is pending. Otherwise, the user should be able to rename/remove/download an existing debug report while another one is being generated. Signed-off-by: Aline Manera <alinefm@linux.vnet.ibm.com> --- ui/js/src/kimchi.report_add_main.js | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/ui/js/src/kimchi.report_add_main.js b/ui/js/src/kimchi.report_add_main.js index 62d0d79..9a7df2c 100644 --- a/ui/js/src/kimchi.report_add_main.js +++ b/ui/js/src/kimchi.report_add_main.js @@ -17,25 +17,11 @@ */ 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; @@ -57,10 +43,6 @@ kimchi.report_add_main = function() { kimchi.topic('kimchi/debugReportAdded').publish(); }; - disableToolbarButtons(); - submitButton.prop('disabled', true); - $('.grid-body table tr', '#' + reportGridID) - .on('click', disableToolbarButtons); kimchi.createReport(formData, function(result) { onTaskAccepted(); kimchi.topic('kimchi/debugReportAdded').publish(); @@ -74,12 +56,10 @@ kimchi.report_add_main = function() { var errText = result['responseJSON']['reason']; } result && kimchi.message.error(errText); + taskAccepted && $('.grid-body-view table tr:first-child', '#' + reportGridID).remove(); - $('.grid-body table tr', '#' + reportGridID) - .off('click', disableToolbarButtons); - generateButton.prop('disabled', false); submitButton.prop('disabled', false); nameTextbox.select(); }, onTaskAccepted); -- 1.9.3

Reviewed-by: Crístian Viana <vianac@linux.vnet.ibm.com> On 08-09-2014 00:07, Aline Manera wrote:
Today only the user who started the debug report creation is able to get the view of a pending debug report. But while switching tabs, this information is lost.
This patch set gets the pending debug reports by filtering running tasks by target_uri=^/debugreports and list them among to the exinting debug reports. That way all users will get the same view of which debug reports are being generated.
Aline Manera (5): Add function to get pending tasks according to filter Add common function to track Task Add function to list all pending debug reports List pending debug reports while loading report grid Only disable report buttons when the selected report is pending
ui/js/src/kimchi.api.js | 34 ++++++++++++------- ui/js/src/kimchi.host.js | 65 ++++++++++++++++++++++++++++++++----- ui/js/src/kimchi.report_add_main.js | 42 ++---------------------- 3 files changed, 83 insertions(+), 58 deletions(-)
participants (2)
-
Aline Manera
-
Crístian Viana