widget.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. serviceName: DS.attr('string'),
  33. componentName: DS.attr('string'),
  34. timeCreated: DS.attr('number'),
  35. sectionName: DS.attr('string'),
  36. author: DS.attr('string'),
  37. properties: DS.attr('object'),
  38. expression: DS.attr('array'),
  39. metrics: DS.attr('array'),
  40. values: DS.attr('array'),
  41. isVisible: DS.attr('boolean'),
  42. /**
  43. * @type {number}
  44. * @default 0
  45. */
  46. defaultOrder: 0, // This field is not derived from API but needs to be filled in the mapper on the client side
  47. /**
  48. * @type Em.View
  49. * @class
  50. */
  51. viewClass: function () {
  52. switch (this.get('widgetType')) {
  53. case 'GRAPH':
  54. return App.GraphWidgetView;
  55. case 'NUMBER':
  56. return App.TemplateWidgetView;
  57. case 'GAUGE':
  58. return App.GaugeWidgetView;
  59. default:
  60. return Em.View;
  61. }
  62. }.property('widgetType')
  63. });
  64. App.WidgetType = DS.Model.extend({
  65. name: DS.attr('string'),
  66. displayName: DS.attr('string'),
  67. description: DS.attr('string'),
  68. properties: DS.attr('array')
  69. });
  70. App.Widget.FIXTURES = [];
  71. App.WidgetType.FIXTURES = [
  72. {
  73. id: 1,
  74. name: 'GAUGE',
  75. display_name: 'Gauge',
  76. description: Em.I18n.t('widget.type.gauge.description'),
  77. properties: [
  78. {
  79. property_name : 'warning_threshold',
  80. isRequired: true // This field is used to distinguish required properties from optional. This can be used for imposing client side validation
  81. },
  82. {
  83. property_name : 'error_threshold',
  84. isRequired: true
  85. }
  86. ]
  87. },
  88. {
  89. id: 2,
  90. name: 'NUMBER',
  91. display_name: 'Number',
  92. description: Em.I18n.t('widget.type.number.description'),
  93. properties: [
  94. {
  95. property_name : 'warning_threshold',
  96. display_name: 'warning',
  97. isRequired: false
  98. },
  99. {
  100. property_name : 'error_threshold',
  101. display_name: 'critical',
  102. isRequired: false
  103. },
  104. {
  105. property_name : 'display_unit',
  106. display_name: 'unit',
  107. isRequired: false
  108. }
  109. ]
  110. },
  111. {
  112. id: 3,
  113. name: 'GRAPH',
  114. display_name: 'Graph',
  115. description: Em.I18n.t('widget.type.graph.description'),
  116. properties: [
  117. {
  118. property_name : 'graph_type',
  119. isRequired: true
  120. },
  121. {
  122. property_name : 'time_range',
  123. isRequired: true
  124. }
  125. ]
  126. },
  127. {
  128. id: 4,
  129. name: 'TEMPLATE',
  130. display_name: 'Template',
  131. description: Em.I18n.t('widget.type.template.description'),
  132. properties: [
  133. ]
  134. }
  135. ];