widget.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. displayName: DS.attr('string'),
  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. default:
  63. return Em.View;
  64. }
  65. }.property('widgetType')
  66. });
  67. App.Widget.FIXTURES = [];
  68. App.WidgetType = DS.Model.extend({
  69. name: DS.attr('string'),
  70. displayName: DS.attr('string'),
  71. description: DS.attr('string'),
  72. properties: DS.attr('array')
  73. });
  74. App.WidgetType.FIXTURES = [
  75. {
  76. id: 1,
  77. name: 'GAUGE',
  78. display_name: 'Gauge',
  79. description: Em.I18n.t('widget.type.gauge.description'),
  80. properties: [
  81. {
  82. property_name : 'warning_threshold',
  83. isRequired: true // This field is used to distinguish required properties from optional. This can be used for imposing client side validation
  84. },
  85. {
  86. property_name : 'error_threshold',
  87. isRequired: true
  88. }
  89. ]
  90. },
  91. {
  92. id: 2,
  93. name: 'NUMBER',
  94. display_name: 'Number',
  95. description: Em.I18n.t('widget.type.number.description'),
  96. properties: [
  97. {
  98. property_name : 'warning_threshold',
  99. display_name: 'warning',
  100. isRequired: false
  101. },
  102. {
  103. property_name : 'error_threshold',
  104. display_name: 'critical',
  105. isRequired: false
  106. },
  107. {
  108. property_name : 'display_unit',
  109. display_name: 'unit',
  110. isRequired: false
  111. }
  112. ]
  113. },
  114. {
  115. id: 3,
  116. name: 'GRAPH',
  117. display_name: 'Graph',
  118. description: Em.I18n.t('widget.type.graph.description'),
  119. properties: [
  120. {
  121. property_name : 'graph_type',
  122. isRequired: true
  123. },
  124. {
  125. property_name : 'time_range',
  126. isRequired: true
  127. },
  128. {
  129. property_name : 'display_unit',
  130. display_name: 'unit',
  131. isRequired: false
  132. }
  133. ]
  134. },
  135. {
  136. id: 4,
  137. name: 'TEMPLATE',
  138. display_name: 'Template',
  139. description: Em.I18n.t('widget.type.template.description'),
  140. properties: [
  141. {
  142. property_name : 'display_unit',
  143. display_name: 'unit',
  144. isRequired: false
  145. }
  146. ]
  147. }
  148. ];