Browse Source

AMBARI-8409. Alerts UI: Alert Definition details page throws exception on page reload (onechiporenko)

Oleg Nechiporenko 10 years ago
parent
commit
15ffd2ece6

+ 10 - 0
ambari-web/app/controllers/main/alerts/definition_details_controller.js

@@ -59,6 +59,16 @@ App.MainAlertDefinitionDetailsController = Em.Controller.extend({
     this.set('editing.description.isError', !this.get('editing.description.value').trim());
   }.observes('editing.description.value'),
 
+  /**
+   * Load alert instances for current alertDefinition
+   * Start updating loaded data
+   * @method loadAlertInstances
+   */
+  loadAlertInstances: function() {
+    App.router.get('mainAlertInstancesController').loadAlertInstancesByAlertDefinition(this.get('content.id'));
+    App.router.set('mainAlertInstancesController.isUpdating', true);
+  },
+
   /**
    * Edit button handler
    * @param event

+ 1 - 0
ambari-web/app/mappers/alert_definitions_mapper.js

@@ -181,6 +181,7 @@ App.alertDefinitionsMapper = App.QuickDataMapper.create({
       if (App.router.get('mainAlertDefinitionsController')) {
         App.router.set('mainAlertDefinitionsController.mapperTimestamp', (new Date()).getTime());
       }
+      App.store.commit();
     }
   },
 

+ 6 - 5
ambari-web/app/routes/main.js

@@ -331,12 +331,13 @@ module.exports = Em.Route.extend({
     }),
 
     alertDetails: Em.Route.extend({
-      route: '/:alert_id',
-      connectOutlets: function (router, alert) {
-        router.get('mainAlertInstancesController').loadAlertInstancesByAlertDefinition(alert.get('id'));
-        router.set('mainAlertInstancesController.isUpdating', true);
-        router.get('mainController').connectOutlet('mainAlertDefinitionDetails', alert);
+
+      route: '/:alert_definition_id',
+
+      connectOutlets: function (router, alertDefinition) {
+        router.get('mainController').connectOutlet('mainAlertDefinitionDetails', alertDefinition);
       },
+
       exit: function(router) {
         router.set('mainAlertInstancesController.isUpdating', false);
       }

+ 5 - 0
ambari-web/app/templates/main/alerts/definition_details.hbs

@@ -16,6 +16,8 @@
 * limitations under the License.
 }}
 
+{{#if view.isLoaded}}
+
 <div id="alert-definition-details">
   <div class="row-fluid">
     <div class="span9">
@@ -164,3 +166,6 @@
     </div>
   </div>
 </div>
+{{else}}
+  <div class="spinner"></div>
+{{/if}}

+ 28 - 0
ambari-web/app/views/main/alerts/definition_details_view.js

@@ -22,6 +22,34 @@ App.MainAlertDefinitionDetailsView = App.TableView.extend({
 
   templateName: require('templates/main/alerts/definition_details'),
 
+  /**
+   * Determines if <code>controller.content</code> is loaded
+   * @type {bool}
+   */
+  isLoaded: false,
+
+  willInsertElement: function () {
+    var self = this,
+      updater = App.router.get('updateController');
+    if (self.get('controller.content.isLoaded')) {
+      self.set('isLoaded', true);
+      self.get('controller').loadAlertInstances();
+    }
+    else {
+      updater.updateAlertGroups(function () {
+        updater.updateAlertDefinitions(function () {
+          updater.updateAlertDefinitionSummary(function () {
+            self.set('isLoaded', true);
+            // App.AlertDefinition doesn't represents real models
+            // Real model (see AlertDefinition types) should be used
+            self.set('controller.content', App.AlertDefinition.getAllDefinitions().findProperty('id', parseInt(self.get('controller.content.id'))));
+            self.get('controller').loadAlertInstances();
+          });
+        });
+      });
+    }
+  },
+
   didInsertElement: function () {
     this.filter();
   },