Browse Source

AMBARI-10516 Create widget wizard: Restore data for preview widget. (atkach)

Andrii Tkach 10 years ago
parent
commit
cf5703a7cd

+ 142 - 20
ambari-web/app/controllers/main/service/widgets/create/step2_controller.js

@@ -21,11 +21,7 @@ var App = require('app');
 App.WidgetWizardStep2Controller = Em.Controller.extend({
   name: "widgetWizardStep2Controller",
 
-  /**
-   * views of properties
-   * @type {Array}
-   */
-  widgetPropertiesViews: [],
+  EXPRESSION_PREFIX: 'Expression',
 
   /**
    * actual values of properties in API format
@@ -43,6 +39,29 @@ App.WidgetWizardStep2Controller = Em.Controller.extend({
    */
   widgetMetrics: [],
 
+  /**
+   * @type {Array}
+   */
+  expressions: [],
+
+  /**
+   * used only for GRAPH widget
+   * @type {Array}
+   */
+  dataSets: [],
+
+  /**
+   * content of template of Template widget
+   * @type {string}
+   */
+  templateValue: '',
+
+  /**
+   * views of properties
+   * @type {Array}
+   */
+  widgetPropertiesViews: [],
+
   propertiesMap: {
     "warning_threshold": {
       name: 'threshold',
@@ -81,21 +100,124 @@ App.WidgetWizardStep2Controller = Em.Controller.extend({
     }, this);
   }.property('content.allMetrics'),
 
+  /**
+   * @type {boolean}
+   */
+  isSubmitDisabled: function() {
+    if (this.get('widgetPropertiesViews').someProperty('isValid', false)) {
+      return true;
+    }
+    switch (this.get('content.widgetType')) {
+      case "NUMBER":
+      case "GAUGE":
+        return this.get('expressions')[0] &&
+          (this.get('expressions')[0].get('editMode') ||
+          this.get('expressions')[0].get('data.length') === 0);
+      case "GRAPH":
+        return this.get('dataSets.length') > 0 &&
+          (this.get('dataSets').someProperty('expression.editMode') ||
+          this.get('dataSets').someProperty('expression.data.length', 0));
+      case "TEMPLATE":
+        return !this.get('templateValue') ||
+          this.get('expressions.length') > 0 &&
+          (this.get('expressions').someProperty('editMode') ||
+          this.get('expressions').someProperty('data.length', 0));
+    }
+    return false;
+  }.property('widgetPropertiesViews.@each.isValid',
+    'expressions.@each.editMode',
+    'dataSets.@each.expression'),
+
+  /**
+   * Add data set
+   * @param {object|null} event
+   * @param {boolean} isDefault
+   */
+  addDataSet: function(event, isDefault) {
+    var id = (isDefault) ? 1 :(Math.max.apply(this, this.get('dataSets').mapProperty('id')) + 1);
+
+    this.get('dataSets').pushObject(Em.Object.create({
+      id: id,
+      label: '',
+      isRemovable: !isDefault,
+      expression: {
+        data: [],
+        editMode: false
+      }
+    }));
+  },
+
+  /**
+   * Remove data set
+   * @param {object} event
+   */
+  removeDataSet: function(event) {
+    this.get('dataSets').removeObject(event.context);
+  },
+
+  /**
+   * Add expression
+   * @param {object|null} event
+   * @param {boolean} isDefault
+   */
+  addExpression: function(event, isDefault) {
+    var id = (isDefault) ? 1 :(Math.max.apply(this, this.get('expressions').mapProperty('id')) + 1);
+
+    this.get('expressions').pushObject(Em.Object.create({
+      id: id,
+      isRemovable: !isDefault,
+      data: [],
+      alias: '{{' + this.get('EXPRESSION_PREFIX') + id + '}}',
+      editMode: false
+    }));
+  },
+
+  /**
+   * Remove expression
+   * @param {object} event
+   */
+  removeExpression: function(event) {
+    this.get('expressions').removeObject(event.context);
+  },
+
+  /**
+   * initialize data
+   * widget should have at least one expression or dataSet
+   */
+  initWidgetData: function() {
+    this.set('widgetProperties', this.get('content.widgetProperties'));
+    this.set('widgetValues', this.get('content.widgetValues'));
+    this.set('widgetMetrics', this.get('content.widgetMetrics'));
+    this.set('expressions', this.get('content.expressions').map(function (item) {
+      return Em.Object.create(item);
+    }, this));
+    this.set('dataSets', this.get('content.dataSets').map(function (item) {
+      return Em.Object.create(item);
+    }, this));
+    this.set('templateValue', this.get('content.templateValue'));
+    if (this.get('expressions.length') === 0) {
+      this.addExpression(null, true);
+    }
+    if (this.get('dataSets.length') === 0) {
+      this.addDataSet(null, true);
+    }
+  },
+
   /**
    * update preview widget with latest expression data
    * @param {Em.View} view
    */
-  updateExpressions: function (view) {
+  updateExpressions: function () {
     var widgetType = this.get('content.widgetType');
     var expressionData = {
       values: [],
       metrics: []
     };
-    if (view.get('expressions').length > 0 && view.get('dataSets').length > 0) {
+    if (this.get('expressions').length > 0 && this.get('dataSets').length > 0) {
       switch (widgetType) {
         case 'GAUGE':
         case 'NUMBER':
-          expressionData = this.parseExpression(view.get('expressions')[0]);
+          expressionData = this.parseExpression(this.get('expressions')[0]);
           expressionData.values = [
             {
               value: expressionData.value
@@ -103,16 +225,16 @@ App.WidgetWizardStep2Controller = Em.Controller.extend({
           ];
           break;
         case 'TEMPLATE':
-          expressionData = this.parseTemplateExpression(view);
+          expressionData = this.parseTemplateExpression(this);
           break;
         case 'GRAPH':
-          expressionData = this.parseGraphDataset(view);
+          expressionData = this.parseGraphDataset(this);
           break;
       }
     }
     this.set('widgetValues', expressionData.values);
     this.set('widgetMetrics', expressionData.metrics);
-  },
+  }.observes('templateValue', 'dataSets.@each.label'),
 
   /**
    * parse Graph data set
@@ -247,8 +369,8 @@ App.WidgetWizardStep2Controller = Em.Controller.extend({
   renderGaugeProperties: function () {
     return [
       App.WidgetProperties.Thresholds.PercentageThreshold.create({
-        smallValue: '0.7',
-        bigValue: '0.9',
+        smallValue: this.get('widgetProperties.warning_threshold') || '0.7',
+        bigValue: this.get('widgetProperties.error_threshold') || '0.9',
         isRequired: true
       })
     ];
@@ -262,12 +384,12 @@ App.WidgetWizardStep2Controller = Em.Controller.extend({
   renderNumberProperties: function () {
     return [
       App.WidgetProperties.Threshold.create({
-        smallValue: '10',
-        bigValue: '20',
+        smallValue: this.get('widgetProperties.warning_threshold') || '10',
+        bigValue: this.get('widgetProperties.error_threshold') || '20',
         isRequired: false
       }),
       App.WidgetProperties.Unit.create({
-        value: 'MB',
+        value: this.get('widgetProperties.display_unit') || 'MB',
         isRequired: false
       })
     ];
@@ -281,7 +403,7 @@ App.WidgetWizardStep2Controller = Em.Controller.extend({
   renderTemplateProperties: function (widgetProperties) {
     return [
       App.WidgetProperties.Unit.create({
-        value: 'MB',
+        value: this.get('widgetProperties.display_unit') || 'MB',
         isRequired: false
       })
     ];
@@ -295,15 +417,15 @@ App.WidgetWizardStep2Controller = Em.Controller.extend({
   renderGraphProperties: function (widgetProperties) {
     return [
       App.WidgetProperties.GraphType.create({
-        value: 'LINE',
+        value: this.get('widgetProperties.graph_type') || 'LINE',
         isRequired: true
       }),
       App.WidgetProperties.TimeRange.create({
-        value: 'Last 1 hour',
+        value: this.get('widgetProperties.time_range') || 'Last 1 hour',
         isRequired: true
       }),
       App.WidgetProperties.Unit.create({
-        value: 'MB',
+        value: this.get('widgetProperties.display_unit') || 'MB',
         isRequired: false
       })
     ];

+ 2 - 0
ambari-web/app/controllers/main/service/widgets/create/step3_controller.js

@@ -81,6 +81,8 @@ App.WidgetWizardStep3Controller = Em.Controller.extend({
     this.set('widgetValues', this.get('content.widgetValues'));
     this.set('widgetMetrics', this.get('content.widgetMetrics'));
     this.set('widgetAuthor', App.router.get('loginName'));
+    this.set('widgetName', '');
+    this.set('widgetDescription', '');
   },
 
   //TODO: Following computed propert needs to be implemented. Next button should be enabled when there is no validation error and all required fields are filled

+ 59 - 96
ambari-web/app/controllers/main/service/widgets/create/wizard_controller.js

@@ -81,11 +81,45 @@ App.WidgetWizardController = App.WizardController.extend({
      * }]
      */
     widgetValues: [],
+    expressions: [],
+    dataSets: [],
+    templateValue: null,
     widgetName: null,
     widgetDescription: null,
     widgetScope: null
   }),
 
+  loadMap: {
+    '1': [
+      {
+        type: 'sync',
+        callback: function () {
+          this.load('widgetService');
+          this.load('widgetType');
+        }
+      }
+    ],
+    '2': [
+      {
+        type: 'sync',
+        callback: function () {
+          this.load('widgetProperties', true);
+          this.load('widgetValues', true);
+          this.load('widgetMetrics', true);
+          this.load('expressions', true);
+          this.load('dataSets', true);
+          this.load('templateValue', true);
+        }
+      },
+      {
+        type: 'async',
+        callback: function () {
+          return this.loadAllMetrics();
+        }
+      }
+    ]
+  },
+
   /**
    * set current step
    * @param {string} currentStep
@@ -97,12 +131,7 @@ App.WidgetWizardController = App.WizardController.extend({
     if (App.get('testMode') || skipStateSave) {
       return;
     }
-    App.clusterStatus.setClusterStatus({
-      clusterName: this.get('content.cluster.name'),
-      clusterState: 'WIDGET_DEPLOY',
-      wizardControllerName: 'widgetWizardController',
-      localdb: App.db.data
-    });
+    this.saveClusterStatus('WIDGET_DEPLOY');
   },
 
   setStepsEnable: function () {
@@ -119,32 +148,32 @@ App.WidgetWizardController = App.WizardController.extend({
 
   /**
    * save status of the cluster.
-   * @param clusterStatus object with status,requestId fields.
+   * @param {object} clusterStatus
    */
   saveClusterStatus: function (clusterStatus) {
-    var oldStatus = this.toObject(this.get('content.cluster'));
-    clusterStatus = jQuery.extend(oldStatus, clusterStatus);
-    if (clusterStatus.requestId) {
-      clusterStatus.requestId.forEach(function (requestId) {
-        if (clusterStatus.oldRequestsId.indexOf(requestId) === -1) {
-          clusterStatus.oldRequestsId.push(requestId)
-        }
-      }, this);
-    }
-    this.set('content.cluster', clusterStatus);
-    this.save('cluster');
-  },
-
-  loadWidgetService: function () {
-    this.set('content.widgetService', this.getDBProperty('widgetService'));
-  },
-
-  loadWidgetType: function () {
-    this.set('content.widgetType', this.getDBProperty('widgetType'));
+    App.clusterStatus.setClusterStatus({
+      clusterState: clusterStatus,
+      wizardControllerName: 'widgetWizardController',
+      localdb: App.db.data
+    });
   },
 
-  loadWidgetProperties: function () {
-    this.set('content.widgetProperties', this.getDBProperty('widgetProperties'));
+  /**
+   * save wizard properties to controller and localStorage
+   * @param {string} name
+   * @param value
+   */
+  save: function (name, value) {
+    this.set('content.' + name, value);
+    if (Array.isArray(value)) {
+      value = value.map(function (item) {
+        return this.toObject(item);
+      }, this);
+    } else if (typeof value === 'object') {
+      value = this.toObject(value);
+    }
+    this.setDBProperty(name, value);
+    console.log(this.get('name') + ": saved " + name, value);
   },
 
   /**
@@ -217,73 +246,7 @@ App.WidgetWizardController = App.WizardController.extend({
         }
       }
     }
-    this.saveAllMetrics(result);
-  },
-
-  loadWidgetValues: function () {
-    this.set('content.widgetValues', this.getDBProperty('widgetValues'));
-  },
-
-  loadWidgetMetrics: function () {
-    this.set('content.widgetMetrics', this.getDBProperty('widgetMetrics'));
-  },
-
-  saveWidgetService: function (widgetService) {
-    this.setDBProperty('widgetService', widgetService);
-    this.set('content.widgetService', widgetService);
-  },
-
-  saveWidgetType: function (widgetType) {
-    this.setDBProperty('widgetType', widgetType);
-    this.set('content.widgetType', widgetType);
-  },
-
-  saveWidgetProperties: function (widgetProperties) {
-    this.setDBProperty('widgetProperties', widgetProperties);
-    this.set('content.widgetProperties', widgetProperties);
-  },
-
-  saveAllMetrics: function (allMetrics) {
-    this.setDBProperty('allMetrics', allMetrics);
-    this.set('content.allMetrics', allMetrics);
-  },
-
-  saveWidgetMetrics: function (widgetMetrics) {
-    this.setDBProperty('widgetMetrics', widgetMetrics);
-    this.set('content.widgetMetrics', widgetMetrics);
-  },
-
-  saveWidgetValues: function (widgetValues) {
-    this.setDBProperty('widgetValues', widgetValues);
-    this.set('content.widgetValues', widgetValues);
-  },
-
-  loadMap: {
-    '1': [
-      {
-        type: 'sync',
-        callback: function () {
-          this.loadWidgetService();
-          this.loadWidgetType();
-        }
-      }
-    ],
-    '2': [
-      {
-        type: 'sync',
-        callback: function () {
-          this.loadWidgetProperties();
-          this.loadWidgetValues();
-          this.loadWidgetMetrics();
-        }
-      },
-      {
-        type: 'async',
-        callback: function () {
-          return this.loadAllMetrics();
-        }
-      }
-    ]
+    this.save('allMetrics', result);
   },
 
   /**
@@ -307,7 +270,7 @@ App.WidgetWizardController = App.WizardController.extend({
    */
   finish: function () {
     this.setCurrentStep('1', false, true);
-    this.saveWidgetType('');
+    this.save('widgetType', '');
     this.resetDbNamespace();
     App.get('router.updateController').updateAll();
   }

+ 11 - 5
ambari-web/app/routes/add_widget.js

@@ -97,11 +97,14 @@ module.exports = App.WizardRoute.extend({
     next: function (router) {
       var widgetWizardController = router.get('widgetWizardController');
       var widgetStep1controller = router.get('widgetWizardStep1Controller');
-      widgetWizardController.saveWidgetType(widgetStep1controller.get('widgetType'));
-      widgetWizardController.setDBProperty('widgetProperties', []);
+      widgetWizardController.save('widgetType', widgetStep1controller.get('widgetType'));
+      widgetWizardController.setDBProperty('widgetProperties', {});
       widgetWizardController.setDBProperty('widgetMetrics', []);
       widgetWizardController.setDBProperty('allMetrics', []);
       widgetWizardController.setDBProperty('widgetValues', []);
+      widgetWizardController.setDBProperty('expressions', []);
+      widgetWizardController.setDBProperty('dataSets', []);
+      widgetWizardController.setDBProperty('templateValue', '');
       router.transitionTo('step2');
     }
   }),
@@ -125,9 +128,12 @@ module.exports = App.WizardRoute.extend({
     next: function (router) {
       var widgetWizardController = router.get('widgetWizardController');
       var widgetStep2controller = router.get('widgetWizardStep2Controller');
-      widgetWizardController.saveWidgetProperties(widgetStep2controller.get('widgetProperties'));
-      widgetWizardController.saveWidgetMetrics(widgetStep2controller.get('widgetMetrics'));
-      widgetWizardController.saveWidgetValues(widgetStep2controller.get('widgetValues'));
+      widgetWizardController.save('widgetProperties', widgetStep2controller.get('widgetProperties'));
+      widgetWizardController.save('widgetMetrics', widgetStep2controller.get('widgetMetrics'));
+      widgetWizardController.save('widgetValues', widgetStep2controller.get('widgetValues'));
+      widgetWizardController.save('expressions', widgetStep2controller.get('expressions'));
+      widgetWizardController.save('dataSets', widgetStep2controller.get('dataSets'));
+      widgetWizardController.save('templateValue', widgetStep2controller.get('templateValue'));
       widgetWizardController.setDBProperty('widgetName', null);
       widgetWizardController.setDBProperty('widgetDescription', null);
       widgetWizardController.setDBProperty('widgetScope', null);

+ 1 - 1
ambari-web/app/routes/main.js

@@ -564,7 +564,7 @@ module.exports = Em.Route.extend(App.RouterRedirections, {
   addServiceWidget: function (router, context) {
     if (context) {
       var widgetController = router.get('widgetWizardController');
-      widgetController.saveWidgetService(context.get('serviceName'));
+      widgetController.save('widgetService', context.get('serviceName'));
     }
     router.transitionTo('addWidget');
   },

+ 1 - 1
ambari-web/app/templates/main/service/widgets/create/expression.hbs

@@ -45,7 +45,7 @@
 {{else}}
   <a {{action startEdit target="view"}} class="edit-link"><i class="icon-edit"></i></a>
   {{#if view.expression.isRemovable}}
-    <a {{action removeExpression view.expression target="view.parentView"}} class="remove-link"><i class="icon-trash"></i></a>
+    <a {{action removeExpression view.expression target="controller"}} class="remove-link"><i class="icon-trash"></i></a>
   {{/if}}
   {{#if view.expression.data.length}}
     <div class="metric-field">

+ 2 - 2
ambari-web/app/templates/main/service/widgets/create/step2.hbs

@@ -32,7 +32,7 @@
 
   <div>
     <form class="form-horizontal">
-      {{#each property in controller.widgetPropertiesViews}}
+      {{#each property in widgetPropertiesViews}}
         <div {{bindAttr class=":control-group property.name property.isValid::error"}}>
           <label class="control-label">{{property.label}}
             {{#if property.isRequired }}
@@ -50,6 +50,6 @@
 
   <div class="btn-area">
     <button id="add-widget-step2-back" class="btn" {{action back}}>&larr; {{t common.back}}</button>
-    <button id="add-widget-step2-next" class="btn btn-success pull-right" {{bindAttr disabled="view.isSubmitDisabled"}} {{action "next" target="controller"}}>{{t common.next}} &rarr;</button>
+    <button id="add-widget-step2-next" class="btn btn-success pull-right" {{bindAttr disabled="isSubmitDisabled"}} {{action "next" target="controller"}}>{{t common.next}} &rarr;</button>
   </div>
 </div>

+ 3 - 3
ambari-web/app/templates/main/service/widgets/create/step2_graph.hbs

@@ -24,7 +24,7 @@
   </div>
 </div>
 
-{{#each dataSet in view.dataSets}}
+{{#each dataSet in dataSets}}
   <fieldset>
     <legend>{{t common.dataSet}}&nbsp;{{dataSet.id}}</legend>
     <h5>
@@ -33,13 +33,13 @@
     <h5>{{t common.expression}}:</h5>
     {{view App.WidgetWizardExpressionView expressionBinding="dataSet.expression"}}
     {{#if dataSet.isRemovable}}
-      <a {{action removeDataSet dataSet target="view"}} class="remove-link"><i class="icon-trash"></i></a>
+      <a {{action removeDataSet dataSet target="controller"}} class="remove-link"><i class="icon-trash"></i></a>
     {{/if}}
   </fieldset>
 {{/each}}
 
 <div class="align-right">
-  <a href="#" {{action addDataSet target="view"}}>
+  <a href="#" {{action addDataSet target="controller"}}>
     <i class="icon-plus"></i>
     {{t widget.create.wizard.step2.addDataset}}
   </a>

+ 1 - 1
ambari-web/app/templates/main/service/widgets/create/step2_number.hbs

@@ -24,6 +24,6 @@
   </div>
 </div>
 
-{{#each expression in view.expressions}}
+{{#each expression in expressions}}
   {{view App.WidgetWizardExpressionView expressionBinding="expression"}}
 {{/each}}

+ 4 - 4
ambari-web/app/templates/main/service/widgets/create/step2_template.hbs

@@ -23,7 +23,7 @@
 </div>
 
 <div class="template">
-  {{view Ember.TextArea valueBinding="view.templateValue"}}
+  {{view Ember.TextArea valueBinding="templateValue"}}
 </div>
 
 <div class="alert alert-info">
@@ -33,13 +33,13 @@
   </div>
 </div>
 
-{{#each expression in view.expressions}}
-  <h5>{{view.EXPRESSION_PREFIX}}{{expression.id}}</h5>
+{{#each expression in expressions}}
+  <h5>{{EXPRESSION_PREFIX}}{{expression.id}}</h5>
   {{view App.WidgetWizardExpressionView expressionBinding="expression"}}
 {{/each}}
 
 <div class="align-right">
-  <a href="#" {{action addExpression target="view"}}>
+  <a href="#" {{action addExpression target="controller"}}>
     <i class="icon-plus"></i>
     {{t widget.create.wizard.step2.addExpression}}
   </a>

+ 3 - 1
ambari-web/app/views/main/service/widgets/create/expression_view.js

@@ -148,7 +148,7 @@ App.WidgetWizardExpressionView = Em.View.extend({
     }
 
     this.set('isInvalid', isInvalid);
-    if (!isInvalid) this.get('parentView').updatePreview();
+    if (!isInvalid) this.get('controller').updateExpressions();
   }.observes('expression.data.length'),
 
   /**
@@ -202,6 +202,8 @@ App.WidgetWizardExpressionView = Em.View.extend({
          */
         selectedComponent: null,
 
+        showMore: Em.K,
+
         selectComponents: function (event) {
           var component = this.get('componentMap').findProperty('serviceName', event.context.get('serviceName'))
             .get('components').findProperty('id', event.context.get('id'));

+ 2 - 108
ambari-web/app/views/main/service/widgets/create/step2_view.js

@@ -20,14 +20,6 @@ App.WidgetWizardStep2View = Em.View.extend({
 
   templateName: require('templates/main/service/widgets/create/step2'),
 
-  EXPRESSION_PREFIX: 'Expression',
-
-  /**
-   * content of template of Template widget
-   * @type {string}
-   */
-  templateValue: '',
-
   /**
    * calculate template by widget type
    */
@@ -49,109 +41,11 @@ App.WidgetWizardStep2View = Em.View.extend({
     }
   }.property('controller.content.widgetType'),
 
-  /**
-   * @type {Array}
-   */
-  expressions: [],
-
-  /**
-   * used only for GRAPH widget
-   * @type {Array}
-   */
-  dataSets: [],
-
-  /**
-   * @type {boolean}
-   */
-  isSubmitDisabled: function() {
-    if (this.get('controller.widgetPropertiesViews').someProperty('isValid', false)) {
-      return true;
-    }
-    switch (this.get('controller.content.widgetType')) {
-      case "NUMBER":
-      case "GAUGE":
-        return this.get('expressions')[0] &&
-          (this.get('expressions')[0].get('editMode') ||
-          this.get('expressions')[0].get('data.length') === 0);
-      case "GRAPH":
-        return this.get('dataSets.length') > 0 &&
-          (this.get('dataSets').someProperty('expression.editMode') ||
-          this.get('dataSets').someProperty('expression.data.length', 0));
-      case "TEMPLATE":
-        return !this.get('templateValue') ||
-          this.get('expressions.length') > 0 &&
-          (this.get('expressions').someProperty('editMode') ||
-          this.get('expressions').someProperty('data.length', 0));
-    }
-    return false;
-  }.property('controller.widgetProperties.@each.isValid',
-             'expressions.@each.editMode',
-             'dataSets.@each.expression'),
-
-  /**
-   * Add data set
-   * @param {object|null} event
-   * @param {boolean} isDefault
-   */
-  addDataSet: function(event, isDefault) {
-    var id = (isDefault) ? 1 :(Math.max.apply(this, this.get('dataSets').mapProperty('id')) + 1);
-
-    this.get('dataSets').pushObject(Em.Object.create({
-      id: id,
-      label: '',
-      isRemovable: !isDefault,
-      expression: Em.Object.create({
-        data: [],
-        editMode: false
-      })
-    }));
-  },
-
-  /**
-   * Remove data set
-   * @param {object} event
-   */
-  removeDataSet: function(event) {
-    this.get('dataSets').removeObject(event.context);
-  },
-
-  /**
-   * Add expression
-   * @param {object|null} event
-   * @param {boolean} isDefault
-   */
-  addExpression: function(event, isDefault) {
-    var id = (isDefault) ? 1 :(Math.max.apply(this, this.get('expressions').mapProperty('id')) + 1);
-
-    this.get('expressions').pushObject(Em.Object.create({
-      id: id,
-      isRemovable: !isDefault,
-      data: [],
-      alias: '{{' + this.get('EXPRESSION_PREFIX') + id + '}}',
-      editMode: false
-    }));
-  },
-
-  /**
-   * Remove expression
-   * @param {object} event
-   */
-  removeExpression: function(event) {
-    this.get('expressions').removeObject(event.context);
-  },
-
-  updatePreview: function() {
-    this.get('controller').updateExpressions(this);
-  }.observes('templateValue', 'dataSets.@each.label'),
-
   didInsertElement: function () {
     var controller = this.get('controller');
+    controller.initWidgetData();
     controller.renderProperties();
-    this.get('expressions').clear();
-    this.get('dataSets').clear();
-    this.addExpression(null, true);
-    this.addDataSet(null, true);
-    controller.updateExpressions(this);
+    controller.updateExpressions();
   }
 });
 

+ 2 - 2
ambari-web/test/views/main/service/widgets/create/expression_view_test.js

@@ -24,8 +24,8 @@ describe('App.WidgetWizardExpressionView', function () {
     expression: {
       data: []
     },
-    parentView: Em.Object.create({
-      updatePreview: Em.K
+    controller: Em.Object.create({
+      updateExpressions: Em.K
     })
   });