Преглед изворни кода

AMBARI-10938. Incorrect behavior for clone and edit widget wizard. (jaimin)

Jaimin Jetly пре 10 година
родитељ
комит
bd44220a56

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

@@ -95,7 +95,7 @@ App.WidgetWizardStep3Controller = Em.Controller.extend({
     this.set('widgetProperties', this.get('content.widgetProperties'));
     this.set('widgetValues', this.get('content.widgetValues'));
     this.set('widgetMetrics', this.get('content.widgetMetrics'));
-    this.set('widgetAuthor', App.router.get('loginName'));
+    this.set('widgetAuthor', this.get('content.widgetAuthor'));
     this.set('widgetName', this.get('content.widgetName'));
     this.set('widgetDescription', this.get('content.widgetDescription'));
     this.set('isSharedChecked', this.get('content.widgetScope') == 'CLUSTER');
@@ -120,6 +120,7 @@ App.WidgetWizardStep3Controller = Em.Controller.extend({
         widget_type: this.get('content.widgetType'),
         description: this.get('widgetDescription') || "",
         scope: this.get('widgetScope').toUpperCase(),
+        author: this.get('widgetAuthor'),
         "metrics": this.get('widgetMetrics').map(function (metric) {
           return {
             "name": metric.name,

+ 3 - 0
ambari-web/app/controllers/main/service/widgets/create/wizard_controller.js

@@ -92,6 +92,9 @@ App.WidgetWizardController = App.WizardController.extend({
     templateValue: null,
     widgetName: null,
     widgetDescription: null,
+    widgetAuthor: function () {
+      return App.router.get('loginName');
+    }.property('App.router.loginName'),
     widgetScope: null
   }),
 

+ 3 - 0
ambari-web/app/controllers/main/service/widgets/edit_controller.js

@@ -81,6 +81,7 @@ App.WidgetEditController = App.WidgetWizardController.extend({
     widgetName: null,
     widgetDescription: null,
     widgetScope: null,
+    widgetAuthor: null,
     widgetId: null
   }),
 
@@ -111,6 +112,7 @@ App.WidgetEditController = App.WidgetWizardController.extend({
         callback: function () {
           this.load('widgetName');
           this.load('widgetDescription');
+          this.load('widgetAuthor');
         }
       }
     ]
@@ -199,6 +201,7 @@ App.WidgetEditController = App.WidgetWizardController.extend({
     this.save('widgetValues', []);
     this.save('widgetName', '');
     this.save('widgetDescription', '');
+    this.save('widgetAuthor', '');
     this.save('widgetScope', '');
     this.save('allMetrics', []);
     this.save('expressions', []);

+ 4 - 12
ambari-web/app/mixins/common/widgets/widget_mixin.js

@@ -494,26 +494,18 @@ App.WidgetMixin = Ember.Mixin.create({
     var data = this.collectWidgetData();
     if (isClone) {
       data.WidgetInfo.widget_name += this.get('CLONE_SUFFIX');
-      //TODO remove setting diplay_name once API supports it
+      //TODO remove setting display_name once API supports it
       data.WidgetInfo.display_name = data.WidgetInfo.widget_name;
+      data.WidgetInfo.scope = 'USER';
     }
-    if (isEditClonedWidget) {
-      return App.ajax.send({
-        name: 'widgets.wizard.add',
-        sender: this,
-        data: {
-          data: data
-        },
-        success: 'editNewClonedWidget'
-      });
-    }
+    var successCallback =  isEditClonedWidget ? 'editNewClonedWidget' :  'postWidgetDefinitionSuccessCallback';
     return App.ajax.send({
       name: 'widgets.wizard.add',
       sender: this,
       data: {
         data: data
       },
-      success: 'postWidgetDefinitionSuccessCallback'
+      success: successCallback
     });
   },
 

+ 1 - 1
ambari-web/app/models/widget_property.js

@@ -214,10 +214,10 @@ App.WidgetPropertyTypes = [
      * @returns {boolean}
      */
     validate: function (value) {
+      value = Number(('' + value).trim());
       if (!value) {
         return true;
       }
-      value = ('' + value).trim();
       return validator.isValidFloat(value) && value > this.get('MIN_VALUE') && value <= this.get('MAX_VALUE');
     },
 

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

@@ -585,6 +585,7 @@ module.exports = Em.Route.extend(App.RouterRedirections, {
       widgetController.save('widgetName', context.get('widgetName'));
       widgetController.save('widgetDescription', context.get('description'));
       widgetController.save('widgetScope', context.get('scope'));
+      widgetController.save('widgetAuthor', context.get('author'));
       widgetController.save('widgetId', context.get('id'));
       widgetController.save('allMetrics', []);
       router.get('widgetWizardStep2Controller').convertData(context, widgetController);

+ 1 - 1
ambari-web/app/utils/ajax/ajax.js

@@ -2411,7 +2411,7 @@ var urls = {
   },
 
   'widgets.all.mine.get': {
-    real: '/clusters/{clusterName}/widgets?WidgetInfo/author={loginName}&fields=*',
+    real: '/clusters/{clusterName}/widgets?WidgetInfo/scope=USER&WidgetInfo/author={loginName}&fields=*',
     mock: '/data/widget_layouts/all_mine_widgets.json'
   },