Repository: ambari Updated Branches: refs/heads/trunk 0e772bef5 -> b9d82cf98
AMBARI-11339 Dashboards: hiding a widget from the dashboard causes the page to jump and widgets to reload (jarring). (atkach) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/b9d82cf9 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/b9d82cf9 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/b9d82cf9 Branch: refs/heads/trunk Commit: b9d82cf98f762d2d279555f6238444a1abf0375e Parents: 0e772be Author: Andrii Tkach <[email protected]> Authored: Fri May 22 16:12:07 2015 +0300 Committer: Andrii Tkach <[email protected]> Committed: Fri May 22 18:49:03 2015 +0300 ---------------------------------------------------------------------- .../controllers/main/service/info/summary.js | 25 +++++++++++-- .../main/service/info/summary_test.js | 39 ++++++++++++++++++++ 2 files changed, 60 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/b9d82cf9/ambari-web/app/controllers/main/service/info/summary.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/controllers/main/service/info/summary.js b/ambari-web/app/controllers/main/service/info/summary.js index 69e6328..c4d56f3 100644 --- a/ambari-web/app/controllers/main/service/info/summary.js +++ b/ambari-web/app/controllers/main/service/info/summary.js @@ -484,7 +484,7 @@ App.MainServiceInfoSummaryController = Em.Controller.extend(App.WidgetSectionMix hideWidget: function (event) { var widgetToHide = event.context; var activeLayout = this.get('activeWidgetLayout'); - var widgetIds = activeLayout.get('widgets').map(function(widget) { + var widgetIds = activeLayout.get('widgets').map(function (widget) { return { "id": widget.get("id") } @@ -496,8 +496,8 @@ App.MainServiceInfoSummaryController = Em.Controller.extend(App.WidgetSectionMix "layout_name": activeLayout.get("layoutName"), "scope": activeLayout.get("scope"), "section_name": activeLayout.get("sectionName"), - "widgets": widgetIds.filter(function(widget) { - return widget.id != widgetToHide.id; + "widgets": widgetIds.filter(function (widget) { + return widget.id !== widgetToHide.id; }) } }; @@ -510,12 +510,29 @@ App.MainServiceInfoSummaryController = Em.Controller.extend(App.WidgetSectionMix layoutId: activeLayout.get("id"), data: data }, - success: 'updateActiveLayout' + success: 'hideWidgetSuccessCallback' }); }, /** + * @param {object|null} data + * @param {object} opt + * @param {object} params + */ + hideWidgetSuccessCallback: function (data, opt, params) { + params.data.WidgetLayoutInfo.widgets = params.data.WidgetLayoutInfo.widgets.map(function (widget) { + return { + WidgetInfo: { + id: widget.id + } + } + }); + App.widgetLayoutMapper.map({items: [params.data]}); + this.propertyDidChange('widgets'); + }, + + /** * update current active widget layout */ updateActiveLayout: function () { http://git-wip-us.apache.org/repos/asf/ambari/blob/b9d82cf9/ambari-web/test/controllers/main/service/info/summary_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/controllers/main/service/info/summary_test.js b/ambari-web/test/controllers/main/service/info/summary_test.js index 1e49be7..a15979f 100644 --- a/ambari-web/test/controllers/main/service/info/summary_test.js +++ b/ambari-web/test/controllers/main/service/info/summary_test.js @@ -292,4 +292,43 @@ describe('App.MainServiceInfoSummaryController', function () { }); + describe("#hideWidgetSuccessCallback()", function () { + beforeEach(function () { + sinon.stub(App.widgetLayoutMapper, 'map'); + sinon.stub(controller, 'propertyDidChange'); + }); + afterEach(function () { + App.widgetLayoutMapper.map.restore(); + controller.propertyDidChange.restore(); + }); + it("", function () { + var params = { + data: { + WidgetLayoutInfo: { + widgets: [ + { + id: 1 + } + ] + } + } + }; + controller.hideWidgetSuccessCallback({}, {}, params); + expect(App.widgetLayoutMapper.map.calledWith({ + items: [{ + WidgetLayoutInfo: { + widgets: [ + { + WidgetInfo: { + id: 1 + } + } + ] + } + }] + })).to.be.true; + expect(controller.propertyDidChange.calledWith('widgets')).to.be.true; + }); + }); + }); \ No newline at end of file
