definition_details_view.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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. var sort = require('views/common/sort_view');
  21. App.MainAlertDefinitionDetailsView = App.TableView.extend({
  22. templateName: require('templates/main/alerts/definition_details'),
  23. /**
  24. * Determines if <code>controller.content</code> is loaded
  25. * @type {bool}
  26. */
  27. isLoaded: false,
  28. /**
  29. * @type {string}
  30. */
  31. enabledDisplay: Em.I18n.t('alerts.table.state.enabled'),
  32. /**
  33. * @type {string}
  34. */
  35. disabledDisplay: Em.I18n.t('alerts.table.state.disabled'),
  36. colPropAssoc: ['serviceName', 'hostName', 'state'],
  37. /**
  38. * return filtered number of all content number information displayed on the page footer bar
  39. * @returns {String}
  40. */
  41. filteredContentInfo: Em.computed.i18nFormat('tableView.filters.filteredAlertInstancesInfo', 'filteredCount', 'totalCount'),
  42. content: function () {
  43. return this.get('controller.alerts');
  44. }.property('controller.alerts.@each'),
  45. willInsertElement: function () {
  46. this._super();
  47. this.get('controller').clearStep();
  48. if (this.get('controller.content.isLoaded')) {
  49. this.set('isLoaded', true);
  50. this.get('controller').loadAlertInstances();
  51. } else {
  52. this.loadDefinitionDetails();
  53. }
  54. },
  55. loadDefinitionDetails: function() {
  56. var self = this,
  57. updater = App.router.get('updateController');
  58. updater.updateAlertGroups(function () {
  59. updater.updateAlertDefinitions(function () {
  60. updater.updateAlertDefinitionSummary(function () {
  61. self.set('isLoaded', true);
  62. // App.AlertDefinition doesn't represents real models
  63. // Real model (see AlertDefinition types) should be used
  64. self.set('controller.content', App.AlertDefinition.find(parseInt(self.get('controller.content.id'))));
  65. self.get('controller').loadAlertInstances();
  66. });
  67. });
  68. });
  69. },
  70. didInsertElement: function () {
  71. this.filter();
  72. this.tooltipsUpdater();
  73. },
  74. /**
  75. * Update tooltips when <code>pageContent</code> is changed
  76. * @method tooltipsUpdater
  77. */
  78. tooltipsUpdater: function () {
  79. Em.run.next(function () {
  80. App.tooltip($(".enable-disable-button"));
  81. });
  82. }.observes('controller.content.enabled'),
  83. sortView: sort.wrapperView.extend({}),
  84. /**
  85. * Sorting header for <label>alertDefinition.label</label>
  86. * @type {Em.View}
  87. */
  88. serviceSort: sort.fieldView.extend({
  89. column: 0,
  90. name: 'serviceName',
  91. displayName: Em.I18n.t('common.service')
  92. }),
  93. /**
  94. * Sorting header for <label>alertDefinition.status</label>
  95. * @type {Em.View}
  96. */
  97. hostNameSort: sort.fieldView.extend({
  98. column: 1,
  99. name: 'hostName',
  100. displayName: Em.I18n.t('common.host')
  101. }),
  102. /**
  103. * Sorting header for <label>alertDefinition.service.serviceName</label>
  104. * @type {Em.View}
  105. */
  106. stateSort: sort.fieldView.extend({
  107. column: 2,
  108. name: 'state',
  109. displayName: Em.I18n.t('common.status')
  110. }),
  111. /**
  112. * Filtering header for <label>alertInstance.hostName</label>
  113. * @type {Em.View}
  114. */
  115. hostNameFilterView: filters.createTextView({
  116. column: 1,
  117. fieldType: 'input-medium',
  118. onChangeValue: function(){
  119. this.get('parentView').updateFilter(this.get('column'), this.get('value'), 'string');
  120. }
  121. }),
  122. /**
  123. * Filtering header for <label>alertInstance.serviceName</label>
  124. * @type {Em.View}
  125. */
  126. serviceFilterView: filters.createSelectView({
  127. column: 0,
  128. fieldType: 'input-small',
  129. content: filters.getComputedServicesList(),
  130. onChangeValue: function () {
  131. this.get('parentView').updateFilter(this.get('column'), this.get('value'), 'select');
  132. }
  133. }),
  134. /**
  135. * Filtering header for <label>alertInstance.state</label>
  136. * @type {Em.View}
  137. */
  138. stateFilterView: filters.createSelectView({
  139. column: 2,
  140. fieldType: 'filter-input-width',
  141. content: [
  142. {
  143. value: '',
  144. label: Em.I18n.t('common.all')
  145. },
  146. {
  147. value: 'OK',
  148. label: 'OK'
  149. },
  150. {
  151. value: 'WARNING',
  152. label: 'WARNING'
  153. },
  154. {
  155. value: 'CRITICAL',
  156. label: 'CRITICAL'
  157. },
  158. {
  159. value: 'UNKNOWN',
  160. label: 'UNKNOWN'
  161. },
  162. {
  163. value: 'PENDING',
  164. label: 'NONE'
  165. }
  166. ],
  167. onChangeValue: function () {
  168. this.get('parentView').updateFilter(this.get('column'), this.get('value'), 'select');
  169. }
  170. }),
  171. /**
  172. * View calculates and represents count of alerts on appropriate host during last day
  173. */
  174. lastDayCount: Em.View.extend({
  175. hostName: '', // binding from template
  176. template: Ember.Handlebars.compile('<span>{{view.count}}</span>'),
  177. count: function () {
  178. var lastDayAlertsCount = this.get('parentView.controller.lastDayAlertsCount');
  179. return lastDayAlertsCount ? lastDayAlertsCount[this.get('hostName')] || 0 : Em.I18n.t('app.loadingPlaceholder');
  180. }.property('parentView.controller.lastDayAlertsCount', 'hostName')
  181. }),
  182. /**
  183. * View represents each row of instances table
  184. */
  185. instanceTableRow: Em.View.extend({
  186. tagName: 'tr',
  187. didInsertElement: function () {
  188. App.tooltip(this.$("[rel=tooltip]"));
  189. App.tooltip(this.$(".alert-text"), {
  190. placement: 'left',
  191. template: '<div class="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner alert-def-detail-tooltip"></div></div>'
  192. });
  193. },
  194. willDestroyElement: function() {
  195. this.$("[rel=tooltip]").tooltip('destroy');
  196. this.$(".alert-text").tooltip('destroy');
  197. },
  198. /**
  199. * Router transition to service page
  200. * @param event
  201. */
  202. goToService: function (event) {
  203. if (event && event.context) {
  204. App.router.transitionTo('main.services.service.summary', event.context);
  205. }
  206. },
  207. /**
  208. * Router transition to host level alerts page
  209. * @param {object} event
  210. * @method goToHostAlerts
  211. */
  212. goToHostAlerts: function (event) {
  213. if (event && event.context) {
  214. App.router.get('mainHostDetailsController').set('referer', App.router.location.lastSetURL);
  215. App.router.transitionTo('main.hosts.hostDetails.alerts', event.context);
  216. }
  217. },
  218. /**
  219. * open popup that contain full response of Alert Instance
  220. * @param {Object} event
  221. */
  222. openFullResponse: function(event) {
  223. App.showLogsPopup(Em.I18n.t('alerts.instance.fullLogPopup.header'), event.context.get('text'));
  224. }
  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. App.AlertInstanceServiceHostView = Em.View.extend({
  262. templateName: require('templates/main/alerts/instance_service_host'),
  263. /**
  264. * Define whether show link for transition to service page
  265. */
  266. serviceIsLink: function () {
  267. return App.get('services.all').contains(this.get('instance.service.serviceName'));
  268. }.property('instance.service.serviceName'),
  269. /**
  270. * Define whether show separator between service and hosts labels
  271. */
  272. showSeparator: Em.computed.and('instance.serviceDisplayName', 'instance.hostName')
  273. });