You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ja...@apache.org on 2015/05/20 02:25:34 UTC

ambari git commit: AMBARI-11255. Create widget: widget does not become part of the layout post creation. (jaimin)

Repository: ambari
Updated Branches:
  refs/heads/trunk be383cf3d -> 6a3c1e340


AMBARI-11255. Create widget: widget does not become part of the layout post creation. (jaimin)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/6a3c1e34
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/6a3c1e34
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/6a3c1e34

Branch: refs/heads/trunk
Commit: 6a3c1e3405fd1d030a8537d31137bd8ffba79646
Parents: be383cf
Author: Jaimin Jetly <ja...@hortonworks.com>
Authored: Tue May 19 17:25:05 2015 -0700
Committer: Jaimin Jetly <ja...@hortonworks.com>
Committed: Tue May 19 17:25:05 2015 -0700

----------------------------------------------------------------------
 .../controllers/main/service/info/summary.js    |   2 +-
 .../service/widgets/create/step3_controller.js  |   5 +-
 .../service/widgets/create/wizard_controller.js |  16 ++-
 .../app/mixins/common/widgets/widget_section.js |   6 +-
 ambari-web/app/routes/add_widget.js             | 141 -------------------
 ambari-web/app/routes/create_widget.js          | 141 +++++++++++++++++++
 ambari-web/app/routes/main.js                   |  10 +-
 .../service/widgets/create/expression_view.js   |   2 +-
 8 files changed, 168 insertions(+), 155 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/6a3c1e34/ambari-web/app/controllers/main/service/info/summary.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/service/info/summary.js b/ambari-web/app/controllers/main/service/info/summary.js
index c56a922..69e6328 100644
--- a/ambari-web/app/controllers/main/service/info/summary.js
+++ b/ambari-web/app/controllers/main/service/info/summary.js
@@ -586,7 +586,7 @@ App.MainServiceInfoSummaryController = Em.Controller.extend(App.WidgetSectionMix
    * create widget
    */
   createWidget: function () {
-    App.router.send('addServiceWidget', Em.Object.create({
+    App.router.send('createServiceWidget', Em.Object.create({
       layout: this.get('activeWidgetLayout'),
       serviceName: this.get('content.serviceName')
     }));

http://git-wip-us.apache.org/repos/asf/ambari/blob/6a3c1e34/ambari-web/app/controllers/main/service/widgets/create/step3_controller.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/service/widgets/create/step3_controller.js b/ambari-web/app/controllers/main/service/widgets/create/step3_controller.js
index 24b32f8..00b12f4 100644
--- a/ambari-web/app/controllers/main/service/widgets/create/step3_controller.js
+++ b/ambari-web/app/controllers/main/service/widgets/create/step3_controller.js
@@ -122,7 +122,10 @@ App.WidgetWizardStep3Controller = Em.Controller.extend({
         description: this.get('widgetDescription') || "",
         scope: this.get('widgetScope').toUpperCase(),
         author: this.get('widgetAuthor'),
-        metrics: this.get('widgetMetrics'),
+        metrics: this.get('widgetMetrics').map(function (metric) {
+          delete metric.data;
+          return metric;
+        }),
         values: this.get('widgetValues').map(function (value) {
           delete value.computedValue;
           return value;

http://git-wip-us.apache.org/repos/asf/ambari/blob/6a3c1e34/ambari-web/app/controllers/main/service/widgets/create/wizard_controller.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/service/widgets/create/wizard_controller.js b/ambari-web/app/controllers/main/service/widgets/create/wizard_controller.js
index 4c1dd06..0fec8eb 100644
--- a/ambari-web/app/controllers/main/service/widgets/create/wizard_controller.js
+++ b/ambari-web/app/controllers/main/service/widgets/create/wizard_controller.js
@@ -37,10 +37,10 @@ App.WidgetWizardController = App.WizardController.extend({
     widgetType: "",
 
     /**
-     * @type {number}
+     * @type {Object}
      * @default null
      */
-    layoutId: null,
+    layout: null,
 
     /**
      * Example:
@@ -102,6 +102,7 @@ App.WidgetWizardController = App.WizardController.extend({
         callback: function () {
           this.load('widgetService');
           this.load('widgetType');
+          this.load('layout', true);
         }
       }
     ],
@@ -344,12 +345,17 @@ App.WidgetWizardController = App.WizardController.extend({
    * @param data
    */
   postWidgetDefinitionSuccessCallback: function (data) {
-    if (Em.isNone(this.get('content.layoutId'))) return;
-    var widgets = App.WidgetLayout.find(this.get('content.layoutId')).get('widgets').toArray();
+    if (Em.isNone(this.get('content.layout'))) return;
+    var widgets = this.get('content.layout.widgets').map(function(item){
+      return Em.Object.create({id: item});
+    });
     widgets.pushObject(Em.Object.create({
       id: data.resources[0].WidgetInfo.id
     }));
-    App.router.get('mainServiceInfoSummaryController').saveWidgetLayout(widgets);
+    var mainServiceInfoSummaryController = App.router.get('mainServiceInfoSummaryController');
+    mainServiceInfoSummaryController.saveWidgetLayout(widgets, Em.Object.create(this.get('content.layout'))).done(function() {
+      mainServiceInfoSummaryController.updateActiveLayout();
+    });
   },
 
   /**

http://git-wip-us.apache.org/repos/asf/ambari/blob/6a3c1e34/ambari-web/app/mixins/common/widgets/widget_section.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/mixins/common/widgets/widget_section.js b/ambari-web/app/mixins/common/widgets/widget_section.js
index 20863c3..2a22854 100644
--- a/ambari-web/app/mixins/common/widgets/widget_section.js
+++ b/ambari-web/app/mixins/common/widgets/widget_section.js
@@ -232,10 +232,12 @@ App.WidgetSectionMixin = Ember.Mixin.create({
 
   /**
    * save layout after re-order widgets
+   * @param {Array} widgets
+   * @param {Object} widgetLayout:  Optional. by default active widget layout is honored.
    * return {$.ajax}
    */
-  saveWidgetLayout: function (widgets) {
-    var activeLayout = this.get('activeWidgetLayout');
+  saveWidgetLayout: function (widgets, widgetLayout) {
+    var activeLayout = widgetLayout || this.get('activeWidgetLayout');
     var data = {
       "WidgetLayoutInfo": {
         "display_name": activeLayout.get("displayName"),

http://git-wip-us.apache.org/repos/asf/ambari/blob/6a3c1e34/ambari-web/app/routes/add_widget.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/routes/add_widget.js b/ambari-web/app/routes/add_widget.js
deleted file mode 100644
index 2631b16..0000000
--- a/ambari-web/app/routes/add_widget.js
+++ /dev/null
@@ -1,141 +0,0 @@
-/**
- * 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');
-
-module.exports = App.WizardRoute.extend({
-  route: '/widget/add',
-  enter: function (router, context) {
-    router.get('mainController').dataLoading().done(function () {
-      var widgetWizardController = router.get('widgetWizardController');
-      App.router.get('updateController').set('isWorking', false);
-      var popup = App.ModalPopup.show({
-        classNames: ['full-width-modal'],
-        header: Em.I18n.t('widget.create.wizard.header'),
-        bodyClass: App.WidgetWizardView.extend({
-          controller: widgetWizardController
-        }),
-        primary: Em.I18n.t('form.cancel'),
-        showFooter: false,
-        secondary: null,
-
-        onClose: function () {
-          widgetWizardController.cancel();
-        },
-
-        didInsertElement: function () {
-          this.fitHeight();
-        }
-
-      });
-      widgetWizardController.set('popup', popup);
-      var currentClusterStatus = App.clusterStatus.get('value');
-      if (currentClusterStatus) {
-        if (App.get('testMode')) {
-          widgetWizardController.setCurrentStep(App.db.data.WidgetWizard.currentStep);
-        } else {
-          var currStep = App.get('router.widgetWizardController.currentStep');
-          widgetWizardController.setCurrentStep(currStep);
-        }
-      }
-      Em.run.next(function () {
-        router.transitionTo('step' + widgetWizardController.get('currentStep'));
-      });
-    });
-  },
-
-  step1: Em.Route.extend({
-    route: '/step1',
-
-    connectOutlets: function (router) {
-      var controller = router.get('widgetWizardController');
-      controller.dataLoading().done(function () {
-        router.get('widgetWizardController').setCurrentStep('1');
-        controller.loadAllPriorSteps();
-        controller.connectOutlet('widgetWizardStep1', controller.get('content'));
-      });
-    },
-
-    unroutePath: function () {
-      return false;
-    },
-
-    next: function (router) {
-      var widgetWizardController = router.get('widgetWizardController');
-      var widgetStep1controller = router.get('widgetWizardStep1Controller');
-      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');
-    }
-  }),
-
-  step2: Em.Route.extend({
-    route: '/step2',
-
-    connectOutlets: function (router) {
-      var controller = router.get('widgetWizardController');
-      controller.dataLoading().done(function () {
-        router.get('widgetWizardController').setCurrentStep('2');
-        controller.loadAllPriorSteps();
-        controller.connectOutlet('widgetWizardStep2', controller.get('content'));
-      });
-    },
-    unroutePath: function () {
-      return false;
-    },
-    back: Em.Router.transitionTo('step1'),
-
-    next: function (router) {
-      var widgetWizardController = router.get('widgetWizardController');
-      var widgetStep2controller = router.get('widgetWizardStep2Controller');
-      widgetWizardController.save('widgetProperties', widgetStep2controller.get('widgetProperties'));
-      widgetWizardController.save('widgetMetrics', widgetStep2controller.get('widgetMetrics'));
-      widgetWizardController.save('widgetValues', widgetStep2controller.get('widgetValues'));
-      widgetWizardController.save('templateValue', widgetStep2controller.get('templateValue'));
-      widgetWizardController.save('widgetName', "");
-      widgetWizardController.save('widgetDescription', "");
-      widgetWizardController.save('widgetScope', null);
-      router.transitionTo('step3');
-    }
-  }),
-
-  step3: Em.Route.extend({
-    route: '/step3',
-
-    connectOutlets: function (router) {
-      var controller = router.get('widgetWizardController');
-      controller.dataLoading().done(function () {
-        router.get('widgetWizardController').setCurrentStep('3');
-        controller.loadAllPriorSteps();
-        controller.connectOutlet('widgetWizardStep3', controller.get('content'));
-      });
-    },
-    unroutePath: function () {
-      return false;
-    },
-    back: Em.Router.transitionTo('step2'),
-    complete: function (router, context) {
-      router.get('widgetWizardController').postWidgetDefinition(context);
-    }
-  })
-});

http://git-wip-us.apache.org/repos/asf/ambari/blob/6a3c1e34/ambari-web/app/routes/create_widget.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/routes/create_widget.js b/ambari-web/app/routes/create_widget.js
new file mode 100644
index 0000000..1557227
--- /dev/null
+++ b/ambari-web/app/routes/create_widget.js
@@ -0,0 +1,141 @@
+/**
+ * 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');
+
+module.exports = App.WizardRoute.extend({
+  route: '/widget/create',
+  enter: function (router, context) {
+    router.get('mainController').dataLoading().done(function () {
+      var widgetWizardController = router.get('widgetWizardController');
+      App.router.get('updateController').set('isWorking', false);
+      var popup = App.ModalPopup.show({
+        classNames: ['full-width-modal'],
+        header: Em.I18n.t('widget.create.wizard.header'),
+        bodyClass: App.WidgetWizardView.extend({
+          controller: widgetWizardController
+        }),
+        primary: Em.I18n.t('form.cancel'),
+        showFooter: false,
+        secondary: null,
+
+        onClose: function () {
+          widgetWizardController.cancel();
+        },
+
+        didInsertElement: function () {
+          this.fitHeight();
+        }
+
+      });
+      widgetWizardController.set('popup', popup);
+      var currentClusterStatus = App.clusterStatus.get('value');
+      if (currentClusterStatus) {
+        if (App.get('testMode')) {
+          widgetWizardController.setCurrentStep(App.db.data.WidgetWizard.currentStep);
+        } else {
+          var currStep = App.get('router.widgetWizardController.currentStep');
+          widgetWizardController.setCurrentStep(currStep);
+        }
+      }
+      Em.run.next(function () {
+        router.transitionTo('step' + widgetWizardController.get('currentStep'));
+      });
+    });
+  },
+
+  step1: Em.Route.extend({
+    route: '/step1',
+
+    connectOutlets: function (router) {
+      var controller = router.get('widgetWizardController');
+      controller.dataLoading().done(function () {
+        router.get('widgetWizardController').setCurrentStep('1');
+        controller.loadAllPriorSteps();
+        controller.connectOutlet('widgetWizardStep1', controller.get('content'));
+      });
+    },
+
+    unroutePath: function () {
+      return false;
+    },
+
+    next: function (router) {
+      var widgetWizardController = router.get('widgetWizardController');
+      var widgetStep1controller = router.get('widgetWizardStep1Controller');
+      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');
+    }
+  }),
+
+  step2: Em.Route.extend({
+    route: '/step2',
+
+    connectOutlets: function (router) {
+      var controller = router.get('widgetWizardController');
+      controller.dataLoading().done(function () {
+        router.get('widgetWizardController').setCurrentStep('2');
+        controller.loadAllPriorSteps();
+        controller.connectOutlet('widgetWizardStep2', controller.get('content'));
+      });
+    },
+    unroutePath: function () {
+      return false;
+    },
+    back: Em.Router.transitionTo('step1'),
+
+    next: function (router) {
+      var widgetWizardController = router.get('widgetWizardController');
+      var widgetStep2controller = router.get('widgetWizardStep2Controller');
+      widgetWizardController.save('widgetProperties', widgetStep2controller.get('widgetProperties'));
+      widgetWizardController.save('widgetMetrics', widgetStep2controller.get('widgetMetrics'));
+      widgetWizardController.save('widgetValues', widgetStep2controller.get('widgetValues'));
+      widgetWizardController.save('templateValue', widgetStep2controller.get('templateValue'));
+      widgetWizardController.save('widgetName', "");
+      widgetWizardController.save('widgetDescription', "");
+      widgetWizardController.save('widgetScope', null);
+      router.transitionTo('step3');
+    }
+  }),
+
+  step3: Em.Route.extend({
+    route: '/step3',
+
+    connectOutlets: function (router) {
+      var controller = router.get('widgetWizardController');
+      controller.dataLoading().done(function () {
+        router.get('widgetWizardController').setCurrentStep('3');
+        controller.loadAllPriorSteps();
+        controller.connectOutlet('widgetWizardStep3', controller.get('content'));
+      });
+    },
+    unroutePath: function () {
+      return false;
+    },
+    back: Em.Router.transitionTo('step2'),
+    complete: function (router, context) {
+      router.get('widgetWizardController').postWidgetDefinition(context);
+    }
+  })
+});

http://git-wip-us.apache.org/repos/asf/ambari/blob/6a3c1e34/ambari-web/app/routes/main.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/routes/main.js b/ambari-web/app/routes/main.js
index 45a9102..5875c77 100644
--- a/ambari-web/app/routes/main.js
+++ b/ambari-web/app/routes/main.js
@@ -563,16 +563,18 @@ module.exports = Em.Route.extend(App.RouterRedirections, {
 
   }),
 
-  addServiceWidget: function (router, context) {
+  createServiceWidget: function (router, context) {
     if (context) {
       var widgetController = router.get('widgetWizardController');
       widgetController.save('widgetService', context.get('serviceName'));
-      widgetController.save('layoutId', context.get('layout.id'));
+      var layout = JSON.parse(JSON.stringify(context.get('layout')));
+      layout.widgets = context.get('layout.widgets').mapProperty('id');
+      widgetController.save('layout', layout);
     }
-    router.transitionTo('addWidget');
+    router.transitionTo('createWidget');
   },
 
-  addWidget: require('routes/add_widget'),
+  createWidget: require('routes/create_widget'),
 
   editServiceWidget: function (router, context) {
     if (context) {

http://git-wip-us.apache.org/repos/asf/ambari/blob/6a3c1e34/ambari-web/app/views/main/service/widgets/create/expression_view.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/main/service/widgets/create/expression_view.js b/ambari-web/app/views/main/service/widgets/create/expression_view.js
index a232d89..25c39b3 100644
--- a/ambari-web/app/views/main/service/widgets/create/expression_view.js
+++ b/ambari-web/app/views/main/service/widgets/create/expression_view.js
@@ -271,7 +271,7 @@ App.AddMetricExpressionView = Em.View.extend({
       var data = this.get('parentView').get('expression.data'),
         id = (data.length > 0) ? Math.max.apply(this.get('parentView'), data.mapProperty('id')) + 1 : 1;
       result.set('id', id);
-      if (event.context.get('showAggregateSelect') && aggregateFunction !== 'avg') {
+      if (event.context.get('showAggregateSelect')) {
         result.set('metricPath', result.get('metricPath') + '._' + aggregateFunction);
         result.set('name', result.get('name') + '._' + aggregateFunction);
       }