Browse Source

AMBARI-10583. Integrate widget reordering with the backend API.(xiwang)

Xi Wang 10 năm trước cách đây
mục cha
commit
2505191dda

+ 20 - 13
ambari-web/app/controllers/main/service/info/summary.js

@@ -645,25 +645,32 @@ App.MainServiceInfoSummaryController = Em.Controller.extend({
   },
 
   /**
-   * save layout
+   * save layout after re-order widgets
    * return {$.ajax}
    */
-  saveLayout: function (widgets, layout) {
+  saveReorderedLayout: function (widgets) {
+    var activeLayout = this.get('activeWidgetLayout');
     var data = {
-      "layout_name": layout.get('layoutName'),
-      "section_name": layout.get('sectionName'),
-      "scope": layout.get('scope'),
-      "widgetLayoutInfo": widgets.map(function (widget) {
-        return {
-          "widget_name": widget.get('widgetName'),
-          "id": widget.get('widgetId')
-        }
-      })
+      "WidgetLayoutInfo": {
+        "display_name": activeLayout.get("displayName"),
+        "id": activeLayout.get("id"),
+        "layout_name": activeLayout.get("layoutName"),
+        "scope": activeLayout.get("scope"),
+        "section_name": activeLayout.get("sectionName"),
+        "widgets": widgets.map(function (widget) {
+          return {
+            "id": widget.get('id')
+          }
+        })
+      }
     };
     return App.ajax.send({
-      name: 'widgets.layout.save',
+      name: 'widget.layout.edit',
       sender: this,
-      data: data
+      data: {
+        layoutId: activeLayout.get("id"),
+        data: data
+      }
     });
   },
 

+ 2 - 1
ambari-web/app/mappers/server_data_mapper.js

@@ -97,7 +97,8 @@ App.QuickDataMapper = App.ServerDataMapper.extend({
               result[i].push(this.parseIt(_data[index], config[i]));
             }
           }
-          if(_type == 'array'){
+          // As for 'widgets', just show the original order
+          if(_type == 'array' && i != 'widgets'){
             result[i] = result[i].sort();
           }
         }

+ 0 - 11
ambari-web/app/utils/ajax/ajax.js

@@ -2447,17 +2447,6 @@ var urls = {
     mock: '/data/widget_layouts/HBASE/layouts.json'
   },
 
-  'widgets.layout.save': {
-    real: '/clusters/{clusterName}/widget_layouts/{layout_name}',
-    mock: '',
-    format: function (data) {
-      return {
-        type: 'PUT',
-        data: JSON.stringify(data.data)
-      }
-    }
-  },
-
   'widget.action.delete': {
     real: '/clusters/{clusterName}/widgets/{id}',
     mock: '',

+ 1 - 3
ambari-web/app/views/main/service/info/summary.js

@@ -598,9 +598,7 @@ App.MainServiceInfoSummaryView = Em.View.extend(App.UserPref, {
           var widgets = misc.sortByOrder($("#widget_layout .widget").map(function () {
             return this.id;
           }), self.get('controller.widgets'));
-          //TODO bind to actual layout instance
-          var layout = self.get('controller.widgetLayouts').objectAt(0);
-          self.get('controller').saveLayout(widgets, layout);
+          self.get('controller').saveReorderedLayout(widgets);
         },
         activate: function (event, ui) {
           self.set('isMoving', true);