浏览代码

AMBARI-6463. Installer wizard not showing service configs for selected services on renavigation. (jaimin)

Jaimin Jetly 10 年之前
父节点
当前提交
cb2bb4dbcf

+ 3 - 1
ambari-web/app/app.js

@@ -28,7 +28,9 @@ module.exports = Em.Application.create({
     revision: 4,
     adapter: DS.FixtureAdapter.create({
       simulateRemoteResponse: false
-    })
+    }),
+    typeMaps: {},
+    recordCache: []
   }),
   isAdmin: false,
   /**

+ 1 - 11
ambari-web/app/controllers/wizard.js

@@ -516,21 +516,11 @@ App.WizardController = Em.Controller.extend(App.LocalStorage, {
 
   loadedServiceComponents: null,
 
-  /**
-   * Clean store from already loaded data.
-   **/
-  clearStackModels: function () {
-    if (App.StackService.find().get('content').length) {
-      App.StackServiceComponent.find().set('content', []);
-      App.StackService.find().set('content', []);
-    }
-  },
   /**
    * Generate serviceComponents as pr the stack definition  and save it to localdata
    * called form stepController step4WizardController
    */
   loadServiceComponents: function () {
-    this.clearStackModels();
     return App.ajax.send({
       name: 'wizard.service_components',
       sender: this,
@@ -575,7 +565,7 @@ App.WizardController = Em.Controller.extend(App.LocalStorage, {
       }, this);
     }
 
-    App.stackServiceMapper.map(jsonData);
+    App.stackServiceMapper.mapStackServices(jsonData);
   },
 
   loadServiceComponentsErrorCallback: function (request, ajaxOptions, error) {

+ 22 - 2
ambari-web/app/mappers/stack_service_mapper.js

@@ -55,6 +55,13 @@ App.stackServiceMapper = App.QuickDataMapper.create({
     }
   },
 
+  mapStackServices: function(json) {
+    this.clearStackModels();
+    App.resetDsStoreTypeMap(App.StackServiceComponent);
+    App.resetDsStoreTypeMap(App.StackService);
+    this.map(json);
+  },
+
   map: function (json) {
     var model = this.get('model');
     var result = [];
@@ -75,12 +82,25 @@ App.stackServiceMapper = App.QuickDataMapper.create({
         result.push(this.parseIt(stackService, this.get('config')));
       }
     }, this);
-    if (!$.mocho)
-      App.store.commit();
     App.store.loadMany(this.get('component_model'), stackServiceComponents);
     App.store.loadMany(model, result);
   },
 
+  /**
+   * Clean store from already loaded data.
+   **/
+  clearStackModels: function () {
+    var models = [App.StackServiceComponent, App.StackService];
+    models.forEach(function (model) {
+      var records = App.get('store').findAll(model).filterProperty('id');
+      records.forEach(function (rec) {
+        Ember.run(this, function () {
+          rec.deleteRecord();
+        });
+      }, this);
+    }, this);
+  },
+
   rearrangeServicesForDisplayOrder: function (array, displayOrderArray) {
     return array.sort(function (a, b) {
       var aValue = displayOrderArray.indexOf(a.StackServices.service_name) != -1 ? displayOrderArray.indexOf(a.StackServices.service_name) : array.length;

+ 26 - 0
ambari-web/app/utils/helper.js

@@ -740,3 +740,29 @@ DS.attr.transforms.array = {
     return deserialized;
   }
 };
+
+/**
+ *  Utility method to delete all existing records of a DS.Model type from the model's associated map and
+ *  store's persistence layer (recordCache)
+ * @param type DS.Model Class
+ */
+App.resetDsStoreTypeMap = function(type) {
+  var allRecords = App.get('store.recordCache');  //This fetches all records in the ember-data persistence layer
+  var typeMaps = App.get('store.typeMaps');
+  var guidForType = Em.guidFor(type);
+  var typeMap = typeMaps[guidForType];
+  if (typeMap) {
+    var idToClientIdMap = typeMap.idToCid;
+    for (var id in idToClientIdMap) {
+      if (idToClientIdMap.hasOwnProperty(id) && idToClientIdMap[id]) {
+        delete allRecords[idToClientIdMap[id]];  // deletes the cached copy of the record from the store
+      }
+    }
+    typeMaps[guidForType] = {
+      idToCid: {},
+      clientIds: [],
+      cidToHash: {},
+      recordArrays: []
+    };
+  }
+};