AMBARI-13785. JS errors on leaving pages with graphs before they're loaded
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/ac8147b6 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/ac8147b6 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/ac8147b6 Branch: refs/heads/trunk Commit: ac8147b6c9786da067b068ded9c87865ba711547 Parents: 47ab142 Author: Alex Antonenko <hiv...@gmail.com> Authored: Mon Nov 9 15:28:30 2015 +0200 Committer: Alex Antonenko <hiv...@gmail.com> Committed: Mon Nov 9 19:06:19 2015 +0200 ---------------------------------------------------------------------- ambari-web/app/assets/test/tests.js | 1 + ambari-web/app/utils/ember_reopen.js | 12 +++ .../app/views/common/chart/linear_time.js | 15 ++-- ambari-web/test/utils/ember_reopen_test.js | 81 ++++++++++++++++++++ 4 files changed, 103 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/ac8147b6/ambari-web/app/assets/test/tests.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/assets/test/tests.js b/ambari-web/app/assets/test/tests.js index 71c69db..7e3c83d 100644 --- a/ambari-web/app/assets/test/tests.js +++ b/ambari-web/app/assets/test/tests.js @@ -169,6 +169,7 @@ var files = [ 'test/utils/data_manipulation_test', 'test/utils/config_test', 'test/utils/db_test', + 'test/utils/ember_reopen_test', 'test/utils/form_field_test', 'test/utils/host_progress_popup_test', 'test/utils/misc_test', http://git-wip-us.apache.org/repos/asf/ambari/blob/ac8147b6/ambari-web/app/utils/ember_reopen.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/utils/ember_reopen.js b/ambari-web/app/utils/ember_reopen.js index b1bcdcf..4f3f1dd 100644 --- a/ambari-web/app/utils/ember_reopen.js +++ b/ambari-web/app/utils/ember_reopen.js @@ -199,6 +199,18 @@ Em.View.reopen({ } else { console.debug('Calling set on destroyed view'); } + }, + + /** + * overwritten setProperties method of Ember.View to avoid uncaught errors + * when trying to set multiple properties of destroyed view + */ + setProperties: function(hash){ + if(!this.get('isDestroyed') && !this.get('isDestroying')){ + this._super(hash); + } else { + console.debug('Calling setProperties on destroyed view'); + } } }); http://git-wip-us.apache.org/repos/asf/ambari/blob/ac8147b6/ambari-web/app/views/common/chart/linear_time.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/views/common/chart/linear_time.js b/ambari-web/app/views/common/chart/linear_time.js index a6bd9a4..efea946 100644 --- a/ambari-web/app/views/common/chart/linear_time.js +++ b/ambari-web/app/views/common/chart/linear_time.js @@ -299,12 +299,15 @@ App.ChartLinearTimeView = Ember.View.extend(App.ExportMetricsMixin, { setExportTooltip: function () { if (this.get('isReady')) { Em.run.next(this, function () { - this.$('.corner-icon').on('mouseover', function () { - $(this).closest("[rel='ZoomInTooltip']").trigger('mouseleave'); - }); - App.tooltip(this.$('.corner-icon > .icon-save'), { - title: Em.I18n.t('common.export') - }); + var icon = this.$('.corner-icon'); + if (icon) { + icon.on('mouseover', function () { + $(this).closest("[rel='ZoomInTooltip']").trigger('mouseleave'); + }); + App.tooltip(icon.children('.icon-save'), { + title: Em.I18n.t('common.export') + }); + } }); } }.observes('isReady'), http://git-wip-us.apache.org/repos/asf/ambari/blob/ac8147b6/ambari-web/test/utils/ember_reopen_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/utils/ember_reopen_test.js b/ambari-web/test/utils/ember_reopen_test.js new file mode 100644 index 0000000..eda5e81 --- /dev/null +++ b/ambari-web/test/utils/ember_reopen_test.js @@ -0,0 +1,81 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +require('utils/ember_reopen'); + +describe('Ember functionality extension', function () { + + describe('#Em.View', function () { + + var view, + cases = [ + { + result: { + p0: 'v3', + p1: 'v4', + p2: 'v5' + }, + title: 'active view' + }, + { + result: { + p0: 'v0', + p1: 'v1', + p2: 'v2' + }, + propertyToSet: 'isDestroyed', + title: 'destroyed view' + }, + { + result: { + p0: 'v0', + p1: 'v1', + p2: 'v2' + }, + propertyToSet: 'isDestroying', + title: 'view being destroyed' + } + ]; + + beforeEach(function () { + view = Em.View.create({ + isDestroyed: false, + isDestroying: false, + p0: 'v0', + p1: 'v1', + p2: 'v2' + }); + }); + + cases.forEach(function (item) { + it(item.title, function () { + if (item.propertyToSet) { + view.set(item.propertyToSet, true); + } + view.set('p0', 'v3'); + view.setProperties({ + p1: 'v4', + p2: 'v5' + }); + expect(view.getProperties(['p0', 'p1', 'p2'])).to.eql(item.result); + }); + }); + + }); + +});