host_alerts_view.js 7.6 KB

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