Repository: ambari Updated Branches: refs/heads/trunk 05f0b402f -> 0f7dee0b4
AMBARI-7405 Slider View: Error when creating new app not shown to user. (atkach) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/0f7dee0b Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/0f7dee0b Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/0f7dee0b Branch: refs/heads/trunk Commit: 0f7dee0b4582e277604ab8866dcc9711f3b8643a Parents: 05f0b40 Author: atkach <atk...@hortonworks.com> Authored: Fri Sep 19 15:59:18 2014 +0300 Committer: atkach <atk...@hortonworks.com> Committed: Fri Sep 19 15:59:18 2014 +0300 ---------------------------------------------------------------------- .../createAppWizard/step4_controller.js | 10 +-- .../ui/app/controllers/slider_app_controller.js | 2 +- .../src/main/resources/ui/app/helpers/ajax.js | 14 +++- .../ui/app/mixins/ajax_error_handler.js | 84 ++++++++++++++++++++ .../resources/ui/app/styles/application.less | 6 ++ .../ui/app/templates/common/ajax_error.hbs | 24 ++++++ .../src/main/resources/ui/app/translations.js | 9 ++- 7 files changed, 137 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/0f7dee0b/contrib/views/slider/src/main/resources/ui/app/controllers/createAppWizard/step4_controller.js ---------------------------------------------------------------------- diff --git a/contrib/views/slider/src/main/resources/ui/app/controllers/createAppWizard/step4_controller.js b/contrib/views/slider/src/main/resources/ui/app/controllers/createAppWizard/step4_controller.js index e703c27..6454938 100644 --- a/contrib/views/slider/src/main/resources/ui/app/controllers/createAppWizard/step4_controller.js +++ b/contrib/views/slider/src/main/resources/ui/app/controllers/createAppWizard/step4_controller.js @@ -16,7 +16,7 @@ * limitations under the License. */ -App.CreateAppWizardStep4Controller = Ember.ObjectController.extend({ +App.CreateAppWizardStep4Controller = Ember.ObjectController.extend(App.AjaxErrorHandler, { needs: "createAppWizard", @@ -95,15 +95,15 @@ App.CreateAppWizardStep4Controller = Ember.ObjectController.extend({ typeConfigs: app.get('configs') } }, - complete: 'sendAppDataToServerCompleteCallback' + success: 'sendAppDataToServerSuccessCallback' }); }, /** - * Complete-callback for "create new app"-request - * @method sendAppDataToServerCompleteCallback + * Success-callback for "create new app"-request + * @method sendAppDataToServerSuccessCallback */ - sendAppDataToServerCompleteCallback: function() { + sendAppDataToServerSuccessCallback: function() { this.get('appWizardController').hidePopup(); }, http://git-wip-us.apache.org/repos/asf/ambari/blob/0f7dee0b/contrib/views/slider/src/main/resources/ui/app/controllers/slider_app_controller.js ---------------------------------------------------------------------- diff --git a/contrib/views/slider/src/main/resources/ui/app/controllers/slider_app_controller.js b/contrib/views/slider/src/main/resources/ui/app/controllers/slider_app_controller.js index d1bfccf..b2effa0 100644 --- a/contrib/views/slider/src/main/resources/ui/app/controllers/slider_app_controller.js +++ b/contrib/views/slider/src/main/resources/ui/app/controllers/slider_app_controller.js @@ -16,7 +16,7 @@ * limitations under the License. */ -App.SliderAppController = Ember.ObjectController.extend({ +App.SliderAppController = Ember.ObjectController.extend(App.AjaxErrorHandler, { /** * List of Slider App tabs http://git-wip-us.apache.org/repos/asf/ambari/blob/0f7dee0b/contrib/views/slider/src/main/resources/ui/app/helpers/ajax.js ---------------------------------------------------------------------- diff --git a/contrib/views/slider/src/main/resources/ui/app/helpers/ajax.js b/contrib/views/slider/src/main/resources/ui/app/helpers/ajax.js index ba7fbce..ea01d82 100644 --- a/contrib/views/slider/src/main/resources/ui/app/helpers/ajax.js +++ b/contrib/views/slider/src/main/resources/ui/app/helpers/ajax.js @@ -132,7 +132,8 @@ var urls = { format: function (data) { return { type: 'POST', - data: JSON.stringify(data.data) + data: JSON.stringify(data.data), + showErrorPopup: true } } }, @@ -142,7 +143,8 @@ var urls = { mock: '', format: function () { return { - method: 'DELETE' + method: 'DELETE', + showErrorPopup: true } } }, @@ -156,7 +158,8 @@ var urls = { format: function (data) { return { method: 'PUT', - data: JSON.stringify(data.data) + data: JSON.stringify(data.data), + showErrorPopup: true } } }, @@ -169,7 +172,8 @@ var urls = { format: function (data) { return { method: 'PUT', - data: JSON.stringify(data.data) + data: JSON.stringify(data.data), + showErrorPopup: true } } }, @@ -320,6 +324,8 @@ var ajax = Em.Object.extend({ opt.error = function (request, ajaxOptions, error) { if (config.error) { config.sender[config.error](request, ajaxOptions, error, opt, params); + } else { + config.sender.defaultErrorHandler.call(config.sender, request, opt.url, opt.type, opt.showErrorPopup); } }; http://git-wip-us.apache.org/repos/asf/ambari/blob/0f7dee0b/contrib/views/slider/src/main/resources/ui/app/mixins/ajax_error_handler.js ---------------------------------------------------------------------- diff --git a/contrib/views/slider/src/main/resources/ui/app/mixins/ajax_error_handler.js b/contrib/views/slider/src/main/resources/ui/app/mixins/ajax_error_handler.js new file mode 100644 index 0000000..8eecb02 --- /dev/null +++ b/contrib/views/slider/src/main/resources/ui/app/mixins/ajax_error_handler.js @@ -0,0 +1,84 @@ +/** + * 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. + */ + +/** + * Attach default error handler on error of Ajax calls + * To correct work should be mixed with Controller or View instance + * Example: + * <code> + * var obj = Ember.Controller.extend(App.AjaxErrorHandler, { + * callToServer: function() { + * App.ajax.send(config); + * } + * }); + * if ajax config doesn't have error handler then the default hanlder will be established + * </code> + * @type {Ember.Mixin} + */ +App.AjaxErrorHandler = Ember.Mixin.create({ + /** + * flag to indicate whether popup with ajax already opened to avoid popup overlaying + */ + errorPopupShown: false, + /** + * defaultErrorHandler function is referred from App.ajax.send function + * @jqXHR {jqXHR Object} + * @url {string} + * @method {String} Http method + * @showErrorPopup {boolean} + */ + defaultErrorHandler: function (jqXHR, url, method, showErrorPopup) { + method = method || 'GET'; + var context = this.get('isController') ? this : (this.get('isView') && this.get('controller')); + try { + var json = $.parseJSON(jqXHR.responseText); + var message = json.message; + } catch (err) { + } + + if (!context) { + console.warn('WARN: App.AjaxErrorHandler should be used only for views and controllers'); + return; + } + if (showErrorPopup && !this.get('errorPopupShown')) { + Bootstrap.ModalManager.open( + "ajax-error-modal", + Em.I18n.t('common.error'), + Ember.View.extend({ + classNames: ['api-error'], + templateName: 'common/ajax_error', + api: Em.I18n.t('ajax.apiInfo').format(method, url), + statusCode: Em.I18n.t('ajax.statusCode').format(jqXHR.status), + message: message, + showMessage: !!message + }), + [ + Ember.Object.create({title: Em.I18n.t('ok'), clicked: "errorPopupClose", dismiss: 'modal'}) + ], + context + ); + this.set('errorPopupShown', true); + } + }, + actions: { + + errorPopupClose: function () { + this.set('errorPopupShown', false); + } + } +}); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ambari/blob/0f7dee0b/contrib/views/slider/src/main/resources/ui/app/styles/application.less ---------------------------------------------------------------------- diff --git a/contrib/views/slider/src/main/resources/ui/app/styles/application.less b/contrib/views/slider/src/main/resources/ui/app/styles/application.less index 7497b6e..f8bded3 100644 --- a/contrib/views/slider/src/main/resources/ui/app/styles/application.less +++ b/contrib/views/slider/src/main/resources/ui/app/styles/application.less @@ -877,3 +877,9 @@ a { filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#f7f7f7', endColorstr='#ffffff',GradientType=1 ); } } + +.api-error { + max-height: 403px; + word-wrap: break-word; + overflow: auto; +} http://git-wip-us.apache.org/repos/asf/ambari/blob/0f7dee0b/contrib/views/slider/src/main/resources/ui/app/templates/common/ajax_error.hbs ---------------------------------------------------------------------- diff --git a/contrib/views/slider/src/main/resources/ui/app/templates/common/ajax_error.hbs b/contrib/views/slider/src/main/resources/ui/app/templates/common/ajax_error.hbs new file mode 100644 index 0000000..dd2b6f1 --- /dev/null +++ b/contrib/views/slider/src/main/resources/ui/app/templates/common/ajax_error.hbs @@ -0,0 +1,24 @@ +{{! +* 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. +}} + +<span class="text-danger">{{view.statusCode}}</span> <span> {{view.api}}</span> +{{#if view.showMessage}} + <br /> + <br /> + <pre><strong>{{t ajax.errorMessage}}: </strong><span class="text-danger">{{view.message}}</span></pre> +{{/if}} http://git-wip-us.apache.org/repos/asf/ambari/blob/0f7dee0b/contrib/views/slider/src/main/resources/ui/app/translations.js ---------------------------------------------------------------------- diff --git a/contrib/views/slider/src/main/resources/ui/app/translations.js b/contrib/views/slider/src/main/resources/ui/app/translations.js index 4336ddc..b3bfa14 100644 --- a/contrib/views/slider/src/main/resources/ui/app/translations.js +++ b/contrib/views/slider/src/main/resources/ui/app/translations.js @@ -50,7 +50,8 @@ Em.I18n.translations = { 'alerts': 'Alerts', 'key': 'Key', 'remove': 'Remove', - 'send': 'Send' + 'send': 'Send', + 'error': 'Error' }, 'error.config_is_empty': 'Config <strong>{0}</strong> should not be empty', @@ -113,5 +114,9 @@ Em.I18n.translations = { 'wizard.step3.error': 'Only \"key\":\"value\" format allowed.', 'wizard.step4.name': 'Deploy', 'wizard.step4.appName': 'App Name', - 'wizard.step4.appType': 'App Type' + 'wizard.step4.appType': 'App Type', + + 'ajax.errorMessage': 'Error message', + 'ajax.apiInfo': 'received on {0} method for API: {1}', + 'ajax.statusCode': '{0} status code' };