alert_definitions_view.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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. var filters = require('views/common/filter_view'),
  20. sort = require('views/common/sort_view'),
  21. date = require('utils/date');
  22. App.MainAlertDefinitionsView = App.TableView.extend({
  23. templateName: require('templates/main/alerts'),
  24. content: function() {
  25. return this.get('controller.content');
  26. }.property('controller.content.@each'),
  27. /**
  28. * @type {number}
  29. */
  30. totalCount: function () {
  31. return this.get('content.length');
  32. }.property('content.length'),
  33. colPropAssoc: ['', 'label', 'summary', 'service.serviceName', 'lastTriggered', 'groups'],
  34. sortView: sort.wrapperView,
  35. /**
  36. * Sorting header for <label>alertDefinition.label</label>
  37. * @type {Em.View}
  38. */
  39. nameSort: sort.fieldView.extend({
  40. column: 1,
  41. name: 'label',
  42. displayName: Em.I18n.t('common.name')
  43. }),
  44. /**
  45. * Sorting header for <label>alertDefinition.status</label>
  46. * @type {Em.View}
  47. */
  48. statusSort: sort.fieldView.extend({
  49. column: 2,
  50. name: 'summary',
  51. displayName: Em.I18n.t('common.status'),
  52. type: 'alert_status'
  53. }),
  54. /**
  55. * Sorting header for <label>alertDefinition.service.serviceName</label>
  56. * @type {Em.View}
  57. */
  58. serviceSort: sort.fieldView.extend({
  59. column: 3,
  60. name: 'service.serviceName',
  61. displayName: Em.I18n.t('common.service'),
  62. type: 'string'
  63. }),
  64. /**
  65. * Sorting header for <label>alertDefinition.lastTriggeredSort</label>
  66. * @type {Em.View}
  67. */
  68. lastTriggeredSort: sort.fieldView.extend({
  69. column: 4,
  70. name: 'lastTriggered',
  71. displayName: Em.I18n.t('alerts.table.header.lastTriggered'),
  72. type: 'number'
  73. }),
  74. /**
  75. * Filtering header for <label>alertDefinition.label</label>
  76. * @type {Em.View}
  77. */
  78. nameFilterView: filters.createTextView({
  79. column: 1,
  80. fieldType: 'filter-input-width',
  81. onChangeValue: function(){
  82. this.get('parentView').updateFilter(this.get('column'), this.get('value'), 'string');
  83. }
  84. }),
  85. /**
  86. * Filtering header for <label>alertDefinition.status</label>
  87. * @type {Em.View}
  88. */
  89. stateFilterView: filters.createSelectView({
  90. column: 2,
  91. fieldType: 'filter-input-width',
  92. content: [
  93. {
  94. value: '',
  95. label: Em.I18n.t('common.all')
  96. },
  97. {
  98. value: 'OK',
  99. label: 'OK'
  100. },
  101. {
  102. value: 'WARNING',
  103. label: 'WARNING'
  104. },
  105. {
  106. value: 'CRITICAL',
  107. label: 'CRITICAL'
  108. },
  109. {
  110. value: 'UNKNOWN',
  111. label: 'UNKNOWN'
  112. },
  113. {
  114. value: 'PENDING',
  115. label: 'PENDING'
  116. }
  117. ],
  118. onChangeValue: function () {
  119. this.get('parentView').updateFilter(this.get('column'), this.get('value'), 'alert_status');
  120. }
  121. }),
  122. /**
  123. * Filtering header for <label>alertDefinition.service.serviceName</label>
  124. * @type {Em.View}
  125. */
  126. serviceFilterView: filters.createSelectView({
  127. column: 3,
  128. fieldType: 'filter-input-width',
  129. content: function () {
  130. return [
  131. {
  132. value: '',
  133. label: Em.I18n.t('common.all')
  134. }
  135. ].concat(App.Service.find().map(function (service) {
  136. return {
  137. value: service.get('serviceName'),
  138. label: service.get('displayName')
  139. }
  140. }));
  141. }.property('App.router.clusterController.isLoaded'),
  142. onChangeValue: function () {
  143. this.get('parentView').updateFilter(this.get('column'), this.get('value'), 'select');
  144. }
  145. }),
  146. /**
  147. * Filtering header for <label>alertDefinition.lastTriggered</label>
  148. * @type {Em.View}
  149. */
  150. triggeredFilterView: filters.createSelectView({
  151. column: 4,
  152. appliedEmptyValue: ["", ""],
  153. fieldType: 'filter-input-width,modified-filter',
  154. content: [
  155. {
  156. value: 'Any',
  157. label: Em.I18n.t('any')
  158. },
  159. {
  160. value: 'Past 1 hour',
  161. label: 'Past 1 hour'
  162. },
  163. {
  164. value: 'Past 1 Day',
  165. label: 'Past 1 Day'
  166. },
  167. {
  168. value: 'Past 2 Days',
  169. label: 'Past 2 Days'
  170. },
  171. {
  172. value: 'Past 7 Days',
  173. label: 'Past 7 Days'
  174. },
  175. {
  176. value: 'Past 14 Days',
  177. label: 'Past 14 Days'
  178. },
  179. {
  180. value: 'Past 30 Days',
  181. label: 'Past 30 Days'
  182. }
  183. ],
  184. emptyValue: 'Any',
  185. onChangeValue: function () {
  186. this.get('parentView').updateFilter(this.get('column'), this.get('value'), 'date');
  187. }
  188. }),
  189. alertGroupFilterView: filters.createSelectView({
  190. column: 5,
  191. fieldType: 'filter-input-width',
  192. content: [],
  193. didInsertElement: function() {
  194. this._super();
  195. this.updateContent();
  196. },
  197. /**
  198. * Update list of <code>App.AlertGroup</code> used in the filter
  199. * @method updateContent
  200. */
  201. updateContent: function() {
  202. this.set('content', [
  203. {
  204. value: '',
  205. label: Em.I18n.t('common.all') + ' (' + this.get('parentView.controller.content.length') + ')'
  206. }
  207. ].concat(App.AlertGroup.find().map(function (group) {
  208. return {
  209. value: group.get('id'),
  210. label: group.get('displayNameDefinitions')
  211. };
  212. })));
  213. }.observes('App.router.clusterController.isLoaded', 'controller.mapperTimestamp'),
  214. onChangeValue: function () {
  215. this.get('parentView').updateFilter(this.get('column'), this.get('value'), 'alert_group');
  216. }
  217. }),
  218. /**
  219. * Filtered number of all content number information displayed on the page footer bar
  220. * @returns {String}
  221. */
  222. filteredContentInfo: function () {
  223. return this.t('alerts.filters.filteredAlertsInfo').format(this.get('filteredCount'), this.get('totalCount'));
  224. }.property('filteredCount', 'totalCount'),
  225. /**
  226. * Determines how display "back"-link - as link or text
  227. * @type {string}
  228. */
  229. paginationLeftClass: function () {
  230. if (this.get("startIndex") > 1) {
  231. return "paginate_previous";
  232. }
  233. return "paginate_disabled_previous";
  234. }.property("startIndex", 'filteredCount'),
  235. /**
  236. * Determines how display "next"-link - as link or text
  237. * @type {string}
  238. */
  239. paginationRightClass: function () {
  240. if ((this.get("endIndex")) < this.get("filteredCount")) {
  241. return "paginate_next";
  242. }
  243. return "paginate_disabled_next";
  244. }.property("endIndex", 'filteredCount'),
  245. /**
  246. * Show previous-page if user not in the first page
  247. * @method previousPage
  248. */
  249. previousPage: function () {
  250. if (this.get('paginationLeftClass') === 'paginate_previous') {
  251. this._super();
  252. }
  253. },
  254. /**
  255. * Show next-page if user not in the last page
  256. * @method nextPage
  257. */
  258. nextPage: function () {
  259. if (this.get('paginationRightClass') === 'paginate_next') {
  260. this._super();
  261. }
  262. }
  263. });