widget.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. var App = require('app');
  19. App.Widget = DS.Model.extend({
  20. widgetName: DS.attr('string'),
  21. /**
  22. * types:
  23. * - GAUGE (shown as a percentage dial)
  24. * - HEATMAP
  25. * - GRAPH (Line graph and stack graph)
  26. * - NUMBER (e.g., “1 ms” for RPC latency)
  27. * - LINKS
  28. * - TEMPLATE
  29. */
  30. widgetType: DS.attr('string'),
  31. layout: DS.belongsTo('App.WidgetLayout'),
  32. description: DS.attr('string'),
  33. serviceName: DS.attr('string'),
  34. timeCreated: DS.attr('number'),
  35. sectionName: DS.attr('string'),
  36. author: DS.attr('string'),
  37. scope: DS.attr('string'),
  38. properties: DS.attr('object'),
  39. expression: DS.attr('array'),
  40. metrics: DS.attr('array'),
  41. values: DS.attr('array'),
  42. isVisible: DS.attr('boolean', {defaultValue: true}),
  43. /**
  44. * @type {number}
  45. * @default 0
  46. */
  47. defaultOrder: 0, // This field is not derived from API but needs to be filled in the mapper on the client side
  48. /**
  49. * @type Em.View
  50. * @class
  51. */
  52. viewClass: function () {
  53. switch (this.get('widgetType')) {
  54. case 'GRAPH':
  55. return App.GraphWidgetView;
  56. case 'TEMPLATE':
  57. return App.TemplateWidgetView;
  58. case 'NUMBER':
  59. return App.NumberWidgetView;
  60. case 'GAUGE':
  61. return App.GaugeWidgetView;
  62. case 'HEATMAP':
  63. return App.HeatmapWidgetView;
  64. default:
  65. return Em.View;
  66. }
  67. }.property('widgetType')
  68. });
  69. App.Widget.FIXTURES = [];
  70. App.WidgetType = DS.Model.extend({
  71. name: DS.attr('string'),
  72. displayName: DS.attr('string'),
  73. iconPath: DS.attr('string'),
  74. description: DS.attr('string'),
  75. properties: DS.attr('array')
  76. });
  77. App.WidgetType.FIXTURES = [
  78. {
  79. id: 'GAUGE',
  80. name: 'GAUGE',
  81. icon_path: '/img/widget-gauge.png',
  82. display_name: 'Gauge',
  83. description: Em.I18n.t('widget.type.gauge.description'),
  84. properties: [
  85. {
  86. name : 'threshold',
  87. isRequired: false,
  88. smallValue: '0.7',
  89. bigValue: '0.9'
  90. }
  91. ]
  92. },
  93. {
  94. id: 'NUMBER',
  95. name: 'NUMBER',
  96. icon_path: '/img/widget-number.png',
  97. display_name: 'Number',
  98. description: Em.I18n.t('widget.type.number.description'),
  99. properties: [
  100. {
  101. name : 'threshold',
  102. isRequired: false,
  103. smallValue: '10',
  104. bigValue: '20',
  105. MAX_VALUE: Infinity
  106. },
  107. {
  108. name : 'display_unit',
  109. isRequired: false,
  110. value: '',
  111. placeholder: 'Optional: MB, ms, etc.'
  112. }
  113. ]
  114. },
  115. {
  116. id: 'GRAPH',
  117. name: 'GRAPH',
  118. display_name: 'Graph',
  119. icon_path: '/img/widget-graph.png',
  120. description: Em.I18n.t('widget.type.graph.description'),
  121. properties: [
  122. {
  123. name : 'graph_type',
  124. isRequired: true,
  125. value: 'LINE'
  126. },
  127. {
  128. name : 'display_unit',
  129. isRequired: false,
  130. value: '',
  131. placeholder: 'Optional: MB, ms, etc.'
  132. }
  133. ]
  134. },
  135. {
  136. id: 'TEMPLATE',
  137. name: 'TEMPLATE',
  138. icon_path: '/img/widget-template.png',
  139. display_name: 'Template',
  140. description: Em.I18n.t('widget.type.template.description'),
  141. properties: []
  142. }
  143. ];