Repository: ambari Updated Branches: refs/heads/trunk 56ff1abdb -> 1eaf6a9e9
AMBARI-6847. After second canceling of background operation was opened error (Max Shepel via alexantonenko) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/1eaf6a9e Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/1eaf6a9e Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/1eaf6a9e Branch: refs/heads/trunk Commit: 1eaf6a9e92d5620cf7c7952a100e9dc243b6b576 Parents: 56ff1ab Author: Alex Antonenko <[email protected]> Authored: Wed Aug 13 18:26:29 2014 +0300 Committer: Alex Antonenko <[email protected]> Committed: Wed Aug 13 18:27:00 2014 +0300 ---------------------------------------------------------------------- .../templates/common/host_progress_popup.hbs | 2 +- ambari-web/app/utils/host_progress_popup.js | 42 ++++++++++++++++---- .../test/utils/host_progress_popup_test.js | 26 ++++++++---- 3 files changed, 55 insertions(+), 15 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/1eaf6a9e/ambari-web/app/templates/common/host_progress_popup.hbs ---------------------------------------------------------------------- diff --git a/ambari-web/app/templates/common/host_progress_popup.hbs b/ambari-web/app/templates/common/host_progress_popup.hbs index 939177a..b5df61d 100644 --- a/ambari-web/app/templates/common/host_progress_popup.hbs +++ b/ambari-web/app/templates/common/host_progress_popup.hbs @@ -46,7 +46,7 @@ <div class="operation-name-icon-wrap"> <i {{bindAttr class=":service-status servicesInfo.status servicesInfo.icon"}}></i> {{#if App.supports.abortRequests}} - <i {{action abortRequest servicesInfo}} {{translateAttr title="hostPopup.bgop.abortRequest.title"}} class="abort-icon icon-remove-circle hidden"></i> + <i {{action abortRequest servicesInfo}} {{translateAttr title="hostPopup.bgop.abortRequest.title"}} {{bindAttr class="servicesInfo.abortClassName servicesInfo.abortable:abortable :abort-icon :icon-remove-circle :hidden"}}></i> {{/if}} <a href="#"> {{servicesInfo.name}} http://git-wip-us.apache.org/repos/asf/ambari/blob/1eaf6a9e/ambari-web/app/utils/host_progress_popup.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/utils/host_progress_popup.js b/ambari-web/app/utils/host_progress_popup.js index 0da534d..25b0899 100644 --- a/ambari-web/app/utils/host_progress_popup.js +++ b/ambari-web/app/utils/host_progress_popup.js @@ -68,6 +68,12 @@ App.HostPopup = Em.Object.create({ isPopup: null, /** + * List of aborted requests + * @type {Array} + */ + abortedRequests: [], + + /** * Entering point of this component * @param {String} serviceName * @param {Object} controller @@ -264,8 +270,9 @@ App.HostPopup = Em.Object.create({ this.set("servicesInfo", null); this.get("inputData").forEach(function (service) { var status = statuses[service.status] || pendingStatus; + var id = service.id; var newService = Ember.Object.create({ - id: service.id, + id: id, displayName: service.displayName, progress: service.progress, status: App.format.taskStatus(status[0]), @@ -281,8 +288,19 @@ App.HostPopup = Em.Object.create({ sourceRequestScheduleId: service.get('sourceRequestScheduleId'), contextCommand: service.get('contextCommand') }); + if (App.get('supports.abortRequests')) { + var abortable = !Em.keys(statuses).contains(service.status) || service.status == 'IN_PROGRESS'; + if (!abortable) { + var abortedRequests = this.get('abortedRequests'); + this.set('abortedRequests', abortedRequests.without(id)); + } + newService.setProperties({ + abortable: abortable, + abortClassName: 'abort' + id + }); + } allNewServices.push(newService); - }); + }, this); self.set('servicesInfo', allNewServices); this.setBackgroundOperationHeader(isServiceListHidden); } @@ -482,10 +500,16 @@ App.HostPopup = Em.Object.create({ if (App.get('supports.abortRequests')) { $(document).on({ mouseenter: function () { - if ($(this).find('.service-status').hasClass(App.format.taskStatus('IN_PROGRESS')) || $(this).find('.service-status').hasClass(App.format.taskStatus('PENDING'))) { - App.tooltip($('.abort-icon')); - $(this).find('.service-status').addClass('hidden'); - $(this).find('.abort-icon').removeClass('hidden'); + var statusIcon = $(this).find('.service-status'); + var abortIcon = $(this).find('.abort-icon.abortable'); + if (abortIcon.length > 0) { + var id = parseInt(abortIcon.attr('class').split(' ')[0].match(/\d+/)[0]); + var abortedRequests = self.get('abortedRequests'); + if (!(abortedRequests && abortedRequests.contains(id))) { + App.tooltip($('.abort-icon')); + statusIcon.addClass('hidden'); + abortIcon.removeClass('hidden'); + } } }, mouseleave: function () { @@ -1014,6 +1038,8 @@ App.HostPopup = Em.Object.create({ var requestName = event.context.get('name'); var self = this; App.showConfirmationPopup(function () { + var requestId = event.context.get('id'); + self.get('controller.abortedRequests').push(requestId); App.ajax.send({ name: 'background_operations.abort_request', sender: self, @@ -1038,7 +1064,9 @@ App.HostPopup = Em.Object.create({ /** * Method called on unsuccessful sending request to abort operation */ - abortRequestErrorCallback: function (xhr, textStatus, error, opt) { + abortRequestErrorCallback: function (xhr, textStatus, error, opt, data) { + var abortedRequests = this.get('controller.abortedRequests'); + this.set('controller.abortedRequests', abortedRequests.without(data.requestId)); App.ajax.defaultErrorHandler(xhr, opt.url, 'PUT', xhr.status); }, http://git-wip-us.apache.org/repos/asf/ambari/blob/1eaf6a9e/ambari-web/test/utils/host_progress_popup_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/utils/host_progress_popup_test.js b/ambari-web/test/utils/host_progress_popup_test.js index 3a9caa2..b8bc177 100644 --- a/ambari-web/test/utils/host_progress_popup_test.js +++ b/ambari-web/test/utils/host_progress_popup_test.js @@ -373,28 +373,40 @@ describe('App.HostPopup', function () { }); describe('#abortRequestErrorCallback', function () { + var popup = App.HostPopup.createPopup(); beforeEach(function () { sinon.stub(App.ajax, 'get', function(k) { if (k === 'modalPopup') return null; return Em.get(App, k); }); - App.HostPopup.createPopup(); sinon.spy(App.ModalPopup, 'show'); + sinon.stub(popup, 'get', function(k) { + if (k === 'abortedRequests') return [0]; + return Em.get(popup, k); + }); + popup.get('bodyClass').create().abortRequestErrorCallback({ + responseText: { + message: 'message' + }, + status: 404 + }, 'status', 'error', { + url: 'url' + }, { + requestId: 0 + }); }); afterEach(function () { App.HostPopup.get('isPopup').hide(); App.ModalPopup.show.restore(); + popup.get.restore(); App.ajax.get.restore(); }); it('should open popup', function () { - App.HostPopup.get('isPopup.bodyClass').create().abortRequestErrorCallback({ - responseText: { - message: 'message' - }, - status: 404 - }, 'url', 'PUT', 404); expect(App.ModalPopup.show.calledOnce).to.be.true; }); + it('should remove current request id from abortedRequests', function () { + expect(App.HostPopup.get('abortedRequests')).to.be.empty; + }); }); });
