Browse Source

AMBARI-3576 Common "get" and "set" methods. (atkach)

atkach 11 years ago
parent
commit
6001f062c8
2 changed files with 32 additions and 0 deletions
  1. 20 0
      ambari-web/app/controllers/wizard.js
  2. 12 0
      ambari-web/app/utils/db.js

+ 20 - 0
ambari-web/app/controllers/wizard.js

@@ -38,6 +38,26 @@ App.WizardController = Em.Controller.extend({
     }
   },
 
+  dbNamespace: function(){
+    return this.get('name').capitalize().replace('Controller', "");
+  }.property('name'),
+  /**
+   * get property from local storage
+   * @param key
+   * @return {*}
+   */
+  getDBProperty: function(key){
+    return App.db.get(this.get('dbNamespace'), key);
+  },
+  /**
+   * set property to local storage
+   * @param key
+   * @param value
+   */
+  setDBProperty: function(key, value){
+    App.db.set(this.get('dbNamespace'), key, value);
+  },
+
   setStepsEnable: function () {
     for (var i = 1; i <= this.totalSteps; i++) {
       var step = this.get('isStepDisabled').findProperty('step', i);

+ 12 - 0
ambari-web/app/utils/db.js

@@ -88,6 +88,18 @@ if (localStorage.getObject('ambari') == null) {
   App.db.cleanUp();
 }
 
+App.db.get = function (namespace, key) {
+  console.log('TRACE: Entering db:get' + key);
+  App.db.data = localStorage.getObject('ambari');
+  return App.db.data[namespace][key];
+};
+
+App.db.set = function (namespace, key, value) {
+  console.log('TRACE: Entering db:set' + key + ';value: ' + value);
+  App.db.data = localStorage.getObject('ambari');
+  App.db.data[namespace][key] = value;
+  localStorage.setObject('ambari', App.db.data);
+};
 /*
  * setter methods
  */