Repository: ambari Updated Branches: refs/heads/trunk b4753afd1 -> 7b7f0c92b
AMBARI-8456. Alerts UI: Invalid property names in alerts code and some misc changes (onechiporenko) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/7b7f0c92 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/7b7f0c92 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/7b7f0c92 Branch: refs/heads/trunk Commit: 7b7f0c92bc84e92e51775700ad87904c39d4cef6 Parents: b4753af Author: Oleg Nechiporenko <onechipore...@apache.org> Authored: Wed Nov 26 17:59:19 2014 +0200 Committer: Oleg Nechiporenko <onechipore...@apache.org> Committed: Wed Nov 26 17:59:19 2014 +0200 ---------------------------------------------------------------------- ambari-web/app/assets/test/tests.js | 2 + .../main/alert_definitions_controller.js | 57 ++++----- .../alert_definitions_actions_controller.js | 33 +++-- .../alerts/definition_configs_controller.js | 18 ++- .../alerts/definition_details_controller.js | 26 +++- .../alerts/manage_alert_groups_controller.js | 4 +- .../manage_alert_notifications_controller.js | 22 +++- ambari-web/app/models/alert_definition.js | 4 +- .../app/templates/common/alerts_popup.hbs | 36 +++--- .../main/alerts/alert_definitions_actions.hbs | 2 +- .../main/alerts/manage_alert_groups_popup.hbs | 4 +- .../alerts/manage_alert_notifications_popup.hbs | 4 +- .../main/alerts/manage_alert_groups_view.js | 114 ++++++++++++------ .../alerts/manage_alert_notifications_view.js | 42 ++++--- .../main/alert_definitions_controller_test.js | 32 +++++ ambari-web/test/models/alert_definition_test.js | 51 ++++++++ .../alerts/manage_alert_groups_view_test.js | 92 ++++++++++++++ .../manage_alert_notifications_view_test.js | 119 +++++++++++++++++++ 18 files changed, 541 insertions(+), 121 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/7b7f0c92/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 6ab35fe..da05db2 100644 --- a/ambari-web/app/assets/test/tests.js +++ b/ambari-web/app/assets/test/tests.js @@ -157,6 +157,8 @@ var files = ['test/init_model_test', 'test/views/common/configs/config_history_flow_test', 'test/views/main/dashboard_test', 'test/views/main/menu_test', + 'test/views/main/alerts/manage_alert_groups_view_test', + 'test/views/main/alerts/manage_alert_notifications_view_test', 'test/views/main/admin/stack_version/stack_version_details_test', 'test/views/main/admin/upgrade_version_box_view_test', 'test/views/main/dashboard/config_history_view_test', http://git-wip-us.apache.org/repos/asf/ambari/blob/7b7f0c92/ambari-web/app/controllers/main/alert_definitions_controller.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/controllers/main/alert_definitions_controller.js b/ambari-web/app/controllers/main/alert_definitions_controller.js index fa1d8e0..6bf486f 100644 --- a/ambari-web/app/controllers/main/alert_definitions_controller.js +++ b/ambari-web/app/controllers/main/alert_definitions_controller.js @@ -49,6 +49,7 @@ App.MainAlertDefinitionsController = Em.ArrayController.extend({ * Enable/disable alertDefinition confirmation popup * @param {object} event * @method toggleState + * @return {App.ModalPopup} */ toggleState: function(event) { var alertDefinition = event.context; @@ -83,21 +84,25 @@ App.MainAlertDefinitionsController = Em.ArrayController.extend({ }, /** - * alerts number to show up on top-nav bar: number of critical/warning alerts + * Alerts number to show up on top-nav bar: number of critical/warning alerts + * @type {number} */ allAlertsCount: function () { return this.get('content').filterProperty('isCriticalOrWarning').get('length'); }.property('content.@each.isCriticalOrWarning'), /** - * if critical alerts exist, if true, the alert badge should be red. + * If critical alerts exist, if true, the alert badge should be red. + * @type {boolean} */ isCriticalAlerts: function () { return this.get('content').someProperty('isCritical'); }.property('content.@each.isCritical'), /** - * calcuale critical/warning count for each service, to show up the label on services menu + * Calculate critical/warning count for each service, to show up the label on services menu + * @method getCriticalAlertsCountForService + * @return {number} */ getCriticalAlertsCountForService: function(service) { var alertsForService = this.get('content').filterProperty('service', service); @@ -105,60 +110,58 @@ App.MainAlertDefinitionsController = Em.ArrayController.extend({ }, /** - * Onclick handler for alerts number located right to bg ops number + * Onclick handler for alerts number located right to bg ops number (see application.hbs) + * @method showPopup + * @return {App.ModalPopup} */ - showPopup: function(){ + showPopup: function() { + var self = this; + return App.ModalPopup.show({ + header: Em.I18n.t('alerts.fastAccess.popup.header').format(self.get('allAlertsCount')), + classNames: ['sixty-percent-width-modal', 'alerts-popup'], + secondary: null, + isHideBodyScroll: true, - closeModelPopup: function () { - this.hide(); - }, - onPrimary: function () { - this.closeModelPopup(); - }, - onClose: function () { - this.closeModelPopup(); - }, - - bodyClass: App.TableView.extend({ + + bodyClass: Em.View.extend({ + templateName: require('templates/common/alerts_popup'), + controller: self, - contents: function () { + content: function () { // show crit/warn alerts only. return this.get('controller.content').filterProperty('isCriticalOrWarning'); }.property('controller.content.@each.isCriticalOrWarning'), isLoaded: function () { - return this.get('controller.content.length'); + return !!this.get('controller.content.length'); }.property('controller.content.length'), isAlertEmptyList: function () { - return !this.get('contents.length'); - }.property('contents.length'), + return !this.get('content.length'); + }.property('content.length'), gotoAlertDetails: function (event) { - this.get('parentView').closeModelPopup(); + this.get('parentView').hide(); App.router.transitionTo('main.alerts.alertDetails', event.context); }, gotoService: function (event) { - this.get('parentView').closeModelPopup(); + this.get('parentView').hide(); App.router.transitionTo('main.services.service', event.context); }, showMore: function () { - this.get('parentView').closeModelPopup(); + this.get('parentView').hide(); App.router.transitionTo('main.alerts.index'); - }, + } - totalCount: function () { - return this.get('contents.length'); - }.property('contents.length') }) }) } http://git-wip-us.apache.org/repos/asf/ambari/blob/7b7f0c92/ambari-web/app/controllers/main/alerts/alert_definitions_actions_controller.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/controllers/main/alerts/alert_definitions_actions_controller.js b/ambari-web/app/controllers/main/alerts/alert_definitions_actions_controller.js index 00349a6..e56743b 100644 --- a/ambari-web/app/controllers/main/alerts/alert_definitions_actions_controller.js +++ b/ambari-web/app/controllers/main/alerts/alert_definitions_actions_controller.js @@ -71,16 +71,24 @@ App.MainAlertDefinitionActionsController = Em.ArrayController.extend({ }, /** - * handler when clicking on "Manage Alert Groups", a popup will show up + * Handler when clicking on "Manage Alert Groups", a popup will show up + * @method manageAlertGroups + * @return {App.ModalPopup} */ manageAlertGroups: function () { + return App.ModalPopup.show({ + header: Em.I18n.t('alerts.actions.manage_alert_groups_popup.header'), + bodyClass: App.MainAlertsManageAlertGroupView.extend({ controllerBinding: 'App.router.manageAlertGroupsController' }), + classNames: ['sixty-percent-width-modal', 'manage-configuration-group-popup'], + primary: Em.I18n.t('common.save'), + onPrimary: function () { var modifiedAlertGroups = this.get('subViewController.defsModifiedAlertGroups'); // Save modified Alert-groups @@ -136,37 +144,44 @@ App.MainAlertDefinitionActionsController = Em.ArrayController.extend({ }; runNextQuery(); }, - onSecondary: function () { - this.hide(); - }, - onClose: function () { - this.hide(); - }, + subViewController: function () { return App.router.get('manageAlertGroupsController'); }.property('App.router.manageAlertGroupsController'), + updateButtons: function () { var modified = this.get('subViewController.isDefsModified'); this.set('disablePrimary', !modified); }.observes('subViewController.isDefsModified'), - secondary: Em.I18n.t('common.cancel'), + didInsertElement: Em.K + }); }, /** - * "Manage Alert Notifications" handler + * "Manage Alert Notifications" handler + * @method manageNotifications + * @return {App.ModalPopup} */ manageNotifications: function () { + return App.ModalPopup.show({ + header: Em.I18n.t('alerts.actions.manage_alert_notifications_popup.header'), + bodyClass: App.ManageAlertNotificationsView.extend({ controllerBinding: 'App.router.manageAlertNotificationsController' }), + classNames: ['sixty-percent-width-modal', 'manage-configuration-group-popup'], + secondary: null, + primary: Em.I18n.t('common.close'), + didInsertElement: Em.K + }); } http://git-wip-us.apache.org/repos/asf/ambari/blob/7b7f0c92/ambari-web/app/controllers/main/alerts/definition_configs_controller.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/controllers/main/alerts/definition_configs_controller.js b/ambari-web/app/controllers/main/alerts/definition_configs_controller.js index 65846a1..3501078 100644 --- a/ambari-web/app/controllers/main/alerts/definition_configs_controller.js +++ b/ambari-web/app/controllers/main/alerts/definition_configs_controller.js @@ -78,6 +78,7 @@ App.MainAlertDefinitionConfigsController = Em.Controller.extend({ /** * Change options of "Component", after changing value of "Service" config + * @method onServiceSelect */ onServiceSelect: function () { var serviceProperty = this.get('configs').findProperty('label', 'Service'); @@ -89,6 +90,7 @@ App.MainAlertDefinitionConfigsController = Em.Controller.extend({ /** * Render array of configs for appropriate alert definition type + * @method renderConfigs */ renderConfigs: function () { var alertDefinition = this.get('content'); @@ -120,6 +122,7 @@ App.MainAlertDefinitionConfigsController = Em.Controller.extend({ /** * Render config properties for port-type alert definition + * @method renderPortConfigs * @returns {Array} */ renderPortConfigs: function () { @@ -161,6 +164,7 @@ App.MainAlertDefinitionConfigsController = Em.Controller.extend({ /** * Render config properties for metric-type alert definition + * @method renderMetricConfigs * @returns {Array} */ renderMetricConfigs: function () { @@ -212,6 +216,7 @@ App.MainAlertDefinitionConfigsController = Em.Controller.extend({ /** * Render config properties for web-type alert definition + * @method renderWebConfigs * @returns {Array} */ renderWebConfigs: function () { @@ -255,6 +260,7 @@ App.MainAlertDefinitionConfigsController = Em.Controller.extend({ /** * Render config properties for script-type alert definition + * @method renderScriptConfigs * @returns {Array} */ renderScriptConfigs: function () { @@ -293,6 +299,7 @@ App.MainAlertDefinitionConfigsController = Em.Controller.extend({ /** * Render config properties for aggregate-type alert definition + * @method renderAggregateConfigs * @returns {Array} */ renderAggregateConfigs: function () { @@ -310,6 +317,7 @@ App.MainAlertDefinitionConfigsController = Em.Controller.extend({ /** * Edit configs button handler + * @method editConfigs */ editConfigs: function () { this.get('configs').forEach(function (property) { @@ -321,6 +329,7 @@ App.MainAlertDefinitionConfigsController = Em.Controller.extend({ /** * Cancel edit configs button handler + * @method cancelEditConfigs */ cancelEditConfigs: function () { this.get('configs').forEach(function (property) { @@ -332,25 +341,26 @@ App.MainAlertDefinitionConfigsController = Em.Controller.extend({ /** * Save edit configs button handler + * @method saveConfigs + * @return {$.ajax} */ saveConfigs: function () { this.get('configs').setEach('isDisabled', true); this.set('canEdit', false); - var propertiesToUpdate = this.getPropertiesToUpdate(); - - App.ajax.send({ + return App.ajax.send({ name: 'alerts.update_alert_definition', sender: this, data: { id: this.get('content.id'), - data: propertiesToUpdate + data: this.getPropertiesToUpdate() } }); }, /** * Create object with new values to put it on server + * @method getPropertiesToUpdate * @returns {Object} */ getPropertiesToUpdate: function () { http://git-wip-us.apache.org/repos/asf/ambari/blob/7b7f0c92/ambari-web/app/controllers/main/alerts/definition_details_controller.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/controllers/main/alerts/definition_details_controller.js b/ambari-web/app/controllers/main/alerts/definition_details_controller.js index dda193c..6a4603c 100644 --- a/ambari-web/app/controllers/main/alerts/definition_details_controller.js +++ b/ambari-web/app/controllers/main/alerts/definition_details_controller.js @@ -47,6 +47,7 @@ App.MainAlertDefinitionDetailsController = Em.Controller.extend({ /** * Validation function to define if label field populated correctly + * @method labelValidation */ labelValidation: function () { this.set('editing.label.isError', !this.get('editing.label.value').trim()); @@ -54,6 +55,7 @@ App.MainAlertDefinitionDetailsController = Em.Controller.extend({ /** * Validation function to define if description field populated correctly + * @method descriptionValidation */ descriptionValidation: function () { this.set('editing.description.isError', !this.get('editing.description.value').trim()); @@ -71,7 +73,8 @@ App.MainAlertDefinitionDetailsController = Em.Controller.extend({ /** * Edit button handler - * @param event + * @param {object} event + * @method edit */ edit: function (event) { var element = event.context; @@ -83,7 +86,8 @@ App.MainAlertDefinitionDetailsController = Em.Controller.extend({ /** * Cancel button handler - * @param event + * @param {object} event + * @method cancelEdit */ cancelEdit: function (event) { var element = event.context; @@ -93,7 +97,7 @@ App.MainAlertDefinitionDetailsController = Em.Controller.extend({ /** * Save button handler, could save label/description/thresholds of alert definition - * @param event + * @param {object} event * @returns {$.ajax} * @method saveEdit */ @@ -118,9 +122,10 @@ App.MainAlertDefinitionDetailsController = Em.Controller.extend({ /** * "Delete" button handler - * @param event + * @param {object} event + * @method deleteAlertDefinition */ - deleteAlertDefinition : function(event) { + deleteAlertDefinition: function(event) { var alertDefinition = this.get('content'); var self = this; App.showConfirmationPopup(function() { @@ -137,10 +142,18 @@ App.MainAlertDefinitionDetailsController = Em.Controller.extend({ }); }, + /** + * Success-callback for <code>deleteAlertDefinition</code> + * @method deleteAlertDefinitionSuccess + */ deleteAlertDefinitionSuccess : function() { App.router.transitionTo('main.alerts.index'); }, + /** + * Error-callback for <code>deleteAlertDefinition</code> + * @method deleteAlertDefinitionError + */ deleteAlertDefinitionError : function(xhr, textStatus, errorThrown, opt) { console.log(textStatus); console.log(errorThrown); @@ -169,7 +182,8 @@ App.MainAlertDefinitionDetailsController = Em.Controller.extend({ /** * Router transition to host level alerts page - * @param event + * @param {object} event + * @method goToHostAlerts */ goToHostAlerts: function (event) { if (event && event.context) { http://git-wip-us.apache.org/repos/asf/ambari/blob/7b7f0c92/ambari-web/app/controllers/main/alerts/manage_alert_groups_controller.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/controllers/main/alerts/manage_alert_groups_controller.js b/ambari-web/app/controllers/main/alerts/manage_alert_groups_controller.js index 1d5bc57..04433cb 100644 --- a/ambari-web/app/controllers/main/alerts/manage_alert_groups_controller.js +++ b/ambari-web/app/controllers/main/alerts/manage_alert_groups_controller.js @@ -231,7 +231,7 @@ App.ManageAlertGroupsController = Em.Controller.extend({ }, /** - * lauch a table view of all availavle definitions to choose + * Launch a table view of all available definitions to choose */ launchDefsSelectionDialog : function(initialDefs, selectedDefs, validServices, validComponents, callback, popupDescription) { @@ -481,7 +481,7 @@ App.ManageAlertGroupsController = Em.Controller.extend({ * PUTs the new alert group information on the server. * Changes possible here are the name, definitions, notifications * - * @param {App.ConfigGroup} alertGroup + * @param {App.AlertGroup} alertGroup * @param {Function} successCallback * @param {Function} errorCallback */ http://git-wip-us.apache.org/repos/asf/ambari/blob/7b7f0c92/ambari-web/app/controllers/main/alerts/manage_alert_notifications_controller.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/controllers/main/alerts/manage_alert_notifications_controller.js b/ambari-web/app/controllers/main/alerts/manage_alert_notifications_controller.js index e30831c..160de40 100644 --- a/ambari-web/app/controllers/main/alerts/manage_alert_notifications_controller.js +++ b/ambari-web/app/controllers/main/alerts/manage_alert_notifications_controller.js @@ -19,10 +19,13 @@ var App = require('app'); App.ManageAlertNotificationsController = Em.Controller.extend({ + name: 'manageAlertNotificationsController', + isLoaded: false, /** + * List of all Alert Notifications * @type {App.AlertNotification[]} */ alertNotifications: function () { @@ -33,15 +36,21 @@ App.ManageAlertNotificationsController = Em.Controller.extend({ }.property('isLoaded'), /** + * Selected Alert Notification * @type {App.AlertNotification} */ selectedAlertNotification: null, + /** + * Load all Alert Notifications from server + * Don't do anything if controller not isLoaded + * @returns {$.ajax|null} + */ loadAlertNotifications: function () { if (this.get('isLoaded')) { - return; + return null; } - App.ajax.send({ + return App.ajax.send({ name: 'alerts.notifications', sender: this, data: {}, @@ -50,11 +59,20 @@ App.ManageAlertNotificationsController = Em.Controller.extend({ }); }, + /** + * Success-callback for load alert notifications request + * @param {object} json + * @method getAlertNotificationsSuccessCallback + */ getAlertNotificationsSuccessCallback: function (json) { App.alertNotificationMapper.map(json); this.set('isLoaded', true); }, + /** + * Error-callback for load alert notifications request + * @method getAlertNotificationsErrorCallback + */ getAlertNotificationsErrorCallback: function () { this.set('isLoaded', true); }, http://git-wip-us.apache.org/repos/asf/ambari/blob/7b7f0c92/ambari-web/app/models/alert_definition.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/models/alert_definition.js b/ambari-web/app/models/alert_definition.js index 41d5004..bf5d434 100644 --- a/ambari-web/app/models/alert_definition.js +++ b/ambari-web/app/models/alert_definition.js @@ -97,7 +97,7 @@ App.AlertDefinition = DS.Model.extend({ isCritical: function () { var summary = this.get('summary'); var state = 'CRITICAL'; - return summary[state]; + return !!summary[state]; }.property('summary'), /** @@ -107,7 +107,7 @@ App.AlertDefinition = DS.Model.extend({ isWarning: function () { var summary = this.get('summary'); var state = 'WARNING'; - return summary[state]; + return !!summary[state]; }.property('summary'), /** http://git-wip-us.apache.org/repos/asf/ambari/blob/7b7f0c92/ambari-web/app/templates/common/alerts_popup.hbs ---------------------------------------------------------------------- diff --git a/ambari-web/app/templates/common/alerts_popup.hbs b/ambari-web/app/templates/common/alerts_popup.hbs index 086e3b4..9ab715a 100644 --- a/ambari-web/app/templates/common/alerts_popup.hbs +++ b/ambari-web/app/templates/common/alerts_popup.hbs @@ -24,26 +24,30 @@ <div class="name-top">{{t alerts.fastAccess.popup.body.name}}</div> <div class="service-top">{{t common.service}}</div> <div class="last-triggered-top">{{t alerts.table.header.lastTriggered}}</div> - </div> - <div id="alert-info"> - {{#if view.isAlertEmptyList}} - <div class="alert-list-wrap">{{t alerts.fastAccess.popup.body.noalerts}}</div> - {{else}} - {{#each alertDefinition in view.contents}} - <div class="alert-list-wrap"> - <div class="alert-list-line-cursor"> - <div class="status-icon">{{{alertDefinition.status}}}</div> - <div class="name-text"><a href="#" {{action "gotoAlertDetails" alertDefinition target="view"}}>{{alertDefinition.label}}</a></div> - <div class="service-text"><a href="#" {{action "gotoService" alertDefinition.service target="view"}}>{{alertDefinition.service.displayName}}</a></div> - <div class="last-triggered-text">{{alertDefinition.lastTriggeredFormatted}}</div> + <div id="alert-info"> + {{#if view.isAlertEmptyList}} + <div class="alert-list-wrap">{{t alerts.fastAccess.popup.body.noalerts}}</div> + {{else}} + {{#each alertDefinition in view.content}} + <div class="alert-list-wrap"> + <div class="alert-list-line-cursor"> + <div class="status-icon">{{{alertDefinition.status}}}</div> + <div class="name-text"> + <a href="#" {{action "gotoAlertDetails" alertDefinition target="view"}}>{{alertDefinition.label}}</a> + </div> + <div class="service-text"> + <a href="#" {{action "gotoService" alertDefinition.service target="view"}}>{{alertDefinition.service.displayName}}</a> </div> + <div class="last-triggered-text">{{alertDefinition.lastTriggeredFormatted}}</div> </div> - {{/each}} - {{/if}} - <div class="show-more" {{action "showMore" target="view"}}><a href="#">{{t alerts.fastAccess.popup.body.showmore}}</a> - </div> + </div> + {{/each}} + {{/if}} + <div class="show-more" {{action "showMore" target="view"}}> + <a href="#">{{t alerts.fastAccess.popup.body.showmore}}</a> </div> + </div> </div> {{else}} <div class="spinner"></div> http://git-wip-us.apache.org/repos/asf/ambari/blob/7b7f0c92/ambari-web/app/templates/main/alerts/alert_definitions_actions.hbs ---------------------------------------------------------------------- diff --git a/ambari-web/app/templates/main/alerts/alert_definitions_actions.hbs b/ambari-web/app/templates/main/alerts/alert_definitions_actions.hbs index 06455fe..4187903 100644 --- a/ambari-web/app/templates/main/alerts/alert_definitions_actions.hbs +++ b/ambari-web/app/templates/main/alerts/alert_definitions_actions.hbs @@ -18,7 +18,7 @@ <div class="dropdown"> <a class="btn dropdown-toggle" data-toggle="dropdown" href="#">{{t common.actions}} <span class="caret"></span></a> - <ul class="dropdown-menu pull-right"> + <ul class="dropdown-menu"> {{#each action in controller}} <li> <a href="#" {{action actionHandler action target="controller"}}> http://git-wip-us.apache.org/repos/asf/ambari/blob/7b7f0c92/ambari-web/app/templates/main/alerts/manage_alert_groups_popup.hbs ---------------------------------------------------------------------- diff --git a/ambari-web/app/templates/main/alerts/manage_alert_groups_popup.hbs b/ambari-web/app/templates/main/alerts/manage_alert_groups_popup.hbs index 554f073..7446bd7 100644 --- a/ambari-web/app/templates/main/alerts/manage_alert_groups_popup.hbs +++ b/ambari-web/app/templates/main/alerts/manage_alert_groups_popup.hbs @@ -81,8 +81,8 @@ <div class="clearfix"></div> <div class="row-fluid"> <div class="span12 text-error" id="manage-config-group-error-div"> - {{#if view.errorMessage}} - {{errorMessage}} + {{#if controller.errorMessage}} + {{controller.errorMessage}} {{else}} {{/if}} http://git-wip-us.apache.org/repos/asf/ambari/blob/7b7f0c92/ambari-web/app/templates/main/alerts/manage_alert_notifications_popup.hbs ---------------------------------------------------------------------- diff --git a/ambari-web/app/templates/main/alerts/manage_alert_notifications_popup.hbs b/ambari-web/app/templates/main/alerts/manage_alert_notifications_popup.hbs index 201c524..1956494 100644 --- a/ambari-web/app/templates/main/alerts/manage_alert_notifications_popup.hbs +++ b/ambari-web/app/templates/main/alerts/manage_alert_notifications_popup.hbs @@ -93,8 +93,8 @@ <div class="clearfix"></div> <div class="row-fluid"> <div class="span12 text-error" id="manage-config-group-error-div"> - {{#if view.errorMessage}} - {{errorMessage}} + {{#if controller.errorMessage}} + {{controller.errorMessage}} {{else}} {{/if}} http://git-wip-us.apache.org/repos/asf/ambari/blob/7b7f0c92/ambari-web/app/views/main/alerts/manage_alert_groups_view.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/views/main/alerts/manage_alert_groups_view.js b/ambari-web/app/views/main/alerts/manage_alert_groups_view.js index a21a402..bebb615 100644 --- a/ambari-web/app/views/main/alerts/manage_alert_groups_view.js +++ b/ambari-web/app/views/main/alerts/manage_alert_groups_view.js @@ -22,27 +22,42 @@ App.MainAlertsManageAlertGroupView = Em.View.extend({ templateName: require('templates/main/alerts/manage_alert_groups_popup'), + /** + * @type {object} + */ selectedAlertGroup: null, + /** + * @type {boolean} + */ isRemoveButtonDisabled: true, + /** + * @type {boolean} + */ isRenameButtonDisabled: true, + /** + * @type {boolean} + */ isDuplicateButtonDisabled: true, + /** + * Enable/disable "Remove"/"Rename"/"Duplicate" buttons basing on <code>controller.selectedAlertGroup</code> + * @method buttonObserver + */ buttonObserver: function () { var selectedAlertGroup = this.get('controller.selectedAlertGroup'); - if(selectedAlertGroup && selectedAlertGroup.default){ - this.set('isRemoveButtonDisabled', true); - this.set('isRenameButtonDisabled', true); - this.set('isDuplicateButtonDisabled', false); - }else{ - this.set('isRemoveButtonDisabled', false); - this.set('isRenameButtonDisabled', false); - this.set('isDuplicateButtonDisabled', false); - } + var flag = selectedAlertGroup && selectedAlertGroup.default; + this.set('isRemoveButtonDisabled', flag); + this.set('isRenameButtonDisabled', flag); + this.set('isDuplicateButtonDisabled', false); }.observes('controller.selectedAlertGroup'), + /** + * Observer to prevent user select more than 1 alert group + * @method onGroupSelect + */ onGroupSelect: function () { var selectedAlertGroup = this.get('selectedAlertGroup'); // to unable user select more than one alert group at a time @@ -50,56 +65,87 @@ App.MainAlertsManageAlertGroupView = Em.View.extend({ this.set('controller.selectedAlertGroup', selectedAlertGroup[selectedAlertGroup.length - 1]); } if (selectedAlertGroup && selectedAlertGroup.length > 1) { - this.set('selectedConfigGroup', selectedAlertGroup[selectedAlertGroup.length - 1]); + this.set('selectedAlertGroup', selectedAlertGroup[selectedAlertGroup.length - 1]); } this.set('controller.selectedDefinitions', []); }.observes('selectedAlertGroup'), + /** + * Select first alert group when all groups are loaded + * @method onLoad + */ onLoad: function () { if (this.get('controller.isLoaded')) { this.set('selectedAlertGroup', this.get('controller.alertGroups')[0]); } }.observes('controller.isLoaded', 'controller.alertGroups'), + /** + * Load alert groups, definitions and notification to have all new data + * Useful if user delete some definition and immediately open "Manage Alert Groups" popup + * @method willInsertElement + */ willInsertElement: function() { this.get('controller').loadAlertGroups(); this.get('controller').loadAlertDefinitions(); this.get('controller').loadAlertNotifications(); }, + /** + * Add tooltips and try to select first alert group + * @method didInsertElement + */ didInsertElement: function () { this.onLoad(); App.tooltip($("[rel='button-info']")); App.tooltip($("[rel='button-info-dropdown']"), {placement: 'left'}); }, - addButtonTooltip: function () { - return Em.I18n.t('alerts.actions.manage_alert_groups_popup.addButton'); - }.property(), - removeButtonTooltip: function () { - return Em.I18n.t('alerts.actions.manage_alert_groups_popup.removeButton'); - }.property(), - renameButtonTooltip: function () { - return Em.I18n.t('alerts.actions.manage_alert_groups_popup.renameButton'); - }.property(), - duplicateButtonTooltip: function () { - return Em.I18n.t('alerts.actions.manage_alert_groups_popup.duplicateButton'); - }.property(), + /** + * Tooltip for "Add group"-button + * @type {string} + */ + addButtonTooltip: Em.I18n.t('alerts.actions.manage_alert_groups_popup.addButton'), + + /** + * Tooltip for "Remove group"-button + * @type {string} + */ + removeButtonTooltip: Em.I18n.t('alerts.actions.manage_alert_groups_popup.removeButton'), + + /** + * Tooltip for "Rename"-button + * @type {string} + */ + renameButtonTooltip: Em.I18n.t('alerts.actions.manage_alert_groups_popup.renameButton'), + + /** + * Tooltip for "Duplicate group"-button + * @type {string} + */ + duplicateButtonTooltip: Em.I18n.t('alerts.actions.manage_alert_groups_popup.duplicateButton'), + + /** + * Tooltip for "Add definition to group"-button + * @type {string} + */ addDefinitionTooltip: function () { if (this.get('controller.selectedAlertGroup.default')) { return Em.I18n.t('alerts.actions.manage_alert_groups_popup.addDefinitionToDefault'); - } else if (this.get('controller.selectedAlertGroup.isAddDefinitionsDisabled')) { - return Em.I18n.t('alerts.actions.manage_alert_groups_popup.addDefinitionDisabled'); - } else { - return Em.I18n.t('alerts.actions.manage_alert_groups_popup.addDefinition'); } - }.property('controller.selectedConfigGroup.isDefault', 'controller.selectedConfigGroup.isAddHostsDisabled'), - removeDefinitionTooltip: function () { - return Em.I18n.t('alerts.actions.manage_alert_groups_popup.removeDefinition'); - }.property(), - - errorMessage: function () { - return this.get('controller.errorMessage'); - }.property('controller.errorMessage') + else + if (this.get('controller.selectedAlertGroup.isAddDefinitionsDisabled')) { + return Em.I18n.t('alerts.actions.manage_alert_groups_popup.addDefinitionDisabled'); + } + else { + return Em.I18n.t('alerts.actions.manage_alert_groups_popup.addDefinition'); + } + }.property('controller.selectedAlertGroup.isDefault', 'controller.selectedAlertGroup.isAddDefinitionsDisabled'), + + /** + * Tooltip for "Remove definition from group"-button + * @type {string} + */ + removeDefinitionTooltip: Em.I18n.t('alerts.actions.manage_alert_groups_popup.removeDefinition') }); http://git-wip-us.apache.org/repos/asf/ambari/blob/7b7f0c92/ambari-web/app/views/main/alerts/manage_alert_notifications_view.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/views/main/alerts/manage_alert_notifications_view.js b/ambari-web/app/views/main/alerts/manage_alert_notifications_view.js index 4c2255d..8ed67e9 100644 --- a/ambari-web/app/views/main/alerts/manage_alert_notifications_view.js +++ b/ambari-web/app/views/main/alerts/manage_alert_notifications_view.js @@ -22,6 +22,9 @@ App.ManageAlertNotificationsView = Em.View.extend({ templateName: require('templates/main/alerts/manage_alert_notifications_popup'), + /** + * @type {App.AlertNotification} + */ selectedAlertNotification: null, selectedAlertNotificationGroups: function () { @@ -35,27 +38,37 @@ App.ManageAlertNotificationsView = Em.View.extend({ isDuplicateButtonDisabled: true, + /** + * Show EMAIL information if selected alert notification has type EMAIL + * @type {boolean} + */ showEmailDetails: function () { return this.get('controller.selectedAlertNotification.type') === 'EMAIL'; }.property('controller.selectedAlertNotification.type'), + /** + * Show SNMP information if selected alert notification has type SNMP + * @type {boolean} + */ showSNMPDetails: function () { return this.get('controller.selectedAlertNotification.type') === 'SNMP'; }.property('controller.selectedAlertNotification.type'), + /** + * Enable/disable "edit"/"remove"/"duplicate" buttons basing on <code>controller.selectedAlertNotification</code> + * @method buttonObserver + */ buttonObserver: function () { var selectedAlertNotification = this.get('controller.selectedAlertNotification'); - if (selectedAlertNotification) { - this.set('isEditButtonDisabled', false); - this.set('isRemoveButtonDisabled', false); - this.set('isDuplicateButtonDisabled', false); - } else { - this.set('isEditButtonDisabled', true); - this.set('isRemoveButtonDisabled', true); - this.set('isDuplicateButtonDisabled', true); - } + this.set('isEditButtonDisabled', !selectedAlertNotification); + this.set('isRemoveButtonDisabled', !selectedAlertNotification); + this.set('isDuplicateButtonDisabled', !selectedAlertNotification); }.observes('controller.selectedAlertNotification'), + /** + * Prevent user select more than 1 alert notification + * @method onAlertNotificationSelect + */ onAlertNotificationSelect: function () { var selectedAlertNotification = this.get('selectedAlertNotification'); var length = selectedAlertNotification.length; @@ -67,6 +80,11 @@ App.ManageAlertNotificationsView = Em.View.extend({ } }.observes('selectedAlertNotification'), + /** + * Set first alert notification as selected (if they are already loaded) + * Add some tooltips on manage buttons + * @method onLoad + */ onLoad: function () { if (this.get('controller.isLoaded')) { var notifications = this.get('controller.alertNotifications'); @@ -88,10 +106,6 @@ App.ManageAlertNotificationsView = Em.View.extend({ didInsertElement: function () { this.onLoad(); - }, - - errorMessage: function () { - return this.get('controller.errorMessage'); - }.property('controller.errorMessage') + } }); http://git-wip-us.apache.org/repos/asf/ambari/blob/7b7f0c92/ambari-web/test/controllers/main/alert_definitions_controller_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/controllers/main/alert_definitions_controller_test.js b/ambari-web/test/controllers/main/alert_definitions_controller_test.js index 03a4d80..79361c6 100644 --- a/ambari-web/test/controllers/main/alert_definitions_controller_test.js +++ b/ambari-web/test/controllers/main/alert_definitions_controller_test.js @@ -53,4 +53,36 @@ describe('App.MainAlertDefinitionsController', function() { }); + describe('#showPopup', function () { + + describe('#bodyClass', function () { + + var bodyView; + + beforeEach(function () { + controller.reopen({content: [ + App.AlertDefinition.createRecord({summary: {CRITICAL: 1}}), + App.AlertDefinition.createRecord({summary: {WARNING: 1}}), + App.AlertDefinition.createRecord({summary: {OK: 1}}), + App.AlertDefinition.createRecord({summary: {UNKNOWN: 1}}) + ]}); + bodyView = controller.showPopup().get('bodyClass').create(); + }); + + it('#content', function () { + expect(bodyView.get('content.length')).to.equal(2); + }); + + it('#isLoaded', function () { + expect(bodyView.get('isLoaded')).to.be.true; + }); + + it('#isAlertEmptyList', function () { + expect(bodyView.get('isAlertEmptyList')).to.be.false; + }); + + }); + + }); + }); http://git-wip-us.apache.org/repos/asf/ambari/blob/7b7f0c92/ambari-web/test/models/alert_definition_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/models/alert_definition_test.js b/ambari-web/test/models/alert_definition_test.js index 04a9c8e..951ac26 100644 --- a/ambari-web/test/models/alert_definition_test.js +++ b/ambari-web/test/models/alert_definition_test.js @@ -57,4 +57,55 @@ describe('App.AlertDefinition', function() { }); + describe('#isCriticalOrWarning', function () { + + Em.A([ + {summary: {CRITICAL: 1}, e: true}, + {summary: {WARNING: 1}, e: true}, + {summary: {OK: 1}, e: false}, + {summary: {UNKNOWN: 1}, e: false}, + {summary: {}, e: false} + ]).forEach(function (test, i) { + it('test ' + (i + 1), function () { + model.set('summary', test.summary); + expect(model.get('isCriticalOrWarning')).to.equal(test.e); + }); + }); + + }); + + describe('#isCritical', function () { + + Em.A([ + {summary: {CRITICAL: 1}, e: true}, + {summary: {WARNING: 1}, e: false}, + {summary: {OK: 1}, e: false}, + {summary: {UNKNOWN: 1}, e: false}, + {summary: {}, e: false} + ]).forEach(function (test, i) { + it('test ' + (i + 1), function () { + model.set('summary', test.summary); + expect(model.get('isCritical')).to.equal(test.e); + }); + }); + + }); + + describe('#isWarning', function () { + + Em.A([ + {summary: {CRITICAL: 1}, e: false}, + {summary: {WARNING: 1}, e: true}, + {summary: {OK: 1}, e: false}, + {summary: {UNKNOWN: 1}, e: false}, + {summary: {}, e: false} + ]).forEach(function (test, i) { + it('test ' + (i + 1), function () { + model.set('summary', test.summary); + expect(model.get('isWarning')).to.equal(test.e); + }); + }); + + }); + }); http://git-wip-us.apache.org/repos/asf/ambari/blob/7b7f0c92/ambari-web/test/views/main/alerts/manage_alert_groups_view_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/views/main/alerts/manage_alert_groups_view_test.js b/ambari-web/test/views/main/alerts/manage_alert_groups_view_test.js new file mode 100644 index 0000000..645856a --- /dev/null +++ b/ambari-web/test/views/main/alerts/manage_alert_groups_view_test.js @@ -0,0 +1,92 @@ +/** + * 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. + */ + +var App = require('app'); + +var view; + +describe('App.MainAlertsManageAlertGroupView', function () { + + beforeEach(function () { + + view = App.MainAlertsManageAlertGroupView.create({ + controller: Em.Object.create() + }); + + }); + + it('#buttonObserver', function () { + + Em.A([ + { + p: { + isRemoveButtonDisabled: false, + isRenameButtonDisabled: false, + isDuplicateButtonDisabled: true + }, + selectedAlertGroup: {default: true}, + m: 'selected alert group is default', + e: { + isRemoveButtonDisabled: true, + isRenameButtonDisabled: true, + isDuplicateButtonDisabled: false + } + }, + { + p: { + isRemoveButtonDisabled: true, + isRenameButtonDisabled: true, + isDuplicateButtonDisabled: true + }, + selectedAlertGroup: {default: false}, + m: 'selected alert group is not default', + e: { + isRemoveButtonDisabled: false, + isRenameButtonDisabled: false, + isDuplicateButtonDisabled: false + } + }, + { + p: { + isRemoveButtonDisabled: true, + isRenameButtonDisabled: true, + isDuplicateButtonDisabled: true + }, + selectedAlertGroup: null, + m: 'not one alert group is selected', + e: { + isRemoveButtonDisabled: false, + isRenameButtonDisabled: false, + isDuplicateButtonDisabled: false + } + } + ]).forEach(function (test) { + it(test.m, function () { + Em.keys(test.p).forEach(function (k) { + view.set(k, test.p[k]); + }); + view.set('controller.selectedAlertGroup', test.selectedAlertGroup); + Em.keys(test.e).forEach(function (k) { + expect(view.get(k)).to.equal(test.e[k]); + }); + }); + }); + + }); + +}); http://git-wip-us.apache.org/repos/asf/ambari/blob/7b7f0c92/ambari-web/test/views/main/alerts/manage_alert_notifications_view_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/views/main/alerts/manage_alert_notifications_view_test.js b/ambari-web/test/views/main/alerts/manage_alert_notifications_view_test.js new file mode 100644 index 0000000..a2822ce --- /dev/null +++ b/ambari-web/test/views/main/alerts/manage_alert_notifications_view_test.js @@ -0,0 +1,119 @@ +/** + * 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. + */ + +var App = require('app'); + +var view; + +describe('App.ManageAlertNotificationsView', function () { + + beforeEach(function () { + + view = App.ManageAlertNotificationsView.create({ + controller: Em.Object.create() + }); + + }); + + describe('#buttonObserver', function () { + + Em.A([ + { + selectedAlertNotification: {id: 1}, + m: 'some alert notification is selected', + p: { + isEditButtonDisabled: true, + isRemoveButtonDisabled: true, + isDuplicateButtonDisabled: true + }, + e: { + isEditButtonDisabled: false, + isRemoveButtonDisabled: false, + isDuplicateButtonDisabled: false + } + }, + { + selectedAlertNotification: null, + m: 'some alert notification is not selected', + p: { + isEditButtonDisabled: false, + isRemoveButtonDisabled: false, + isDuplicateButtonDisabled: false + }, + e: { + isEditButtonDisabled: true, + isRemoveButtonDisabled: true, + isDuplicateButtonDisabled: true + } + } + ]).forEach(function (test) { + it(test.m, function () { + Em.keys(test.p).forEach(function (k) { + view.set(k, test.p[k]); + }); + view.set('controller.selectedAlertNotification', test.selectedAlertNotification); + view.buttonObserver(); + Em.keys(test.e).forEach(function (k) { + expect(view.get(k)).to.equal(test.e[k]); + }); + }); + }); + + }); + + describe('#showEmailDetails', function () { + + Em.A([ + { + selectedAlertNotification: {type: 'SNMP'}, + e: false + }, + { + selectedAlertNotification: {type: 'EMAIL'}, + e: true + } + ]).forEach(function (test, i) { + it('test ' + (i + 1), function () { + view.set('controller.selectedAlertNotification', test.selectedAlertNotification); + expect(view.get('showEmailDetails')).to.equal(test.e); + }); + }); + + }); + + describe('#showSNMPDetails', function () { + + Em.A([ + { + selectedAlertNotification: {type: 'SNMP'}, + e: true + }, + { + selectedAlertNotification: {type: 'EMAIL'}, + e: false + } + ]).forEach(function (test, i) { + it('test ' + (i + 1), function () { + view.set('controller.selectedAlertNotification', test.selectedAlertNotification); + expect(view.get('showSNMPDetails')).to.equal(test.e); + }); + }); + + }); + +});