widget_mapper.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. App.widgetMapper = App.QuickDataMapper.create({
  19. model: App.Widget,
  20. config: {
  21. id: 'id',
  22. layout_id: 'layout_id',
  23. widget_name: 'widget_name',
  24. default_order: 'default_order',
  25. widget_type: 'widget_type',
  26. service_name: 'service_name',
  27. section_name: 'section_name',
  28. time_created: 'time_created',
  29. author: 'author',
  30. properties: 'properties',
  31. metrics: 'metrics',
  32. values: 'values',
  33. description: 'description',
  34. scope: 'scope'
  35. },
  36. map: function (json) {
  37. if (!this.get('model')) return;
  38. if (json.widgets) {
  39. var result = [];
  40. json.widgets.forEach(function (item, index) {
  41. item.WidgetInfo.section_name = json.section_name;
  42. item.WidgetInfo.layout_id = json.id;
  43. item.WidgetInfo.metrics = JSON.parse(item.WidgetInfo.metrics);
  44. item.WidgetInfo.properties = JSON.parse(item.WidgetInfo.properties);
  45. item.WidgetInfo.values = JSON.parse(item.WidgetInfo.values);
  46. item.WidgetInfo.default_order = (index + 1);
  47. result.push(this.parseIt(item.WidgetInfo, this.config));
  48. }, this);
  49. App.store.commit();
  50. App.store.loadMany(this.get('model'), result);
  51. }
  52. }
  53. });