alert_definitions_controller.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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.MainAlertDefinitionsController = Em.ArrayController.extend({
  20. name: 'mainAlertDefinitionsController',
  21. /**
  22. * Timestamp when <code>App.alertDefinitionsMapper</code> run last time
  23. * Current <code>content</code> is updated on when it changed
  24. * @type {number|null}
  25. */
  26. mapperTimestamp: null,
  27. /**
  28. * List of all <code>App.AlertDefinition</code>
  29. * Consists of:
  30. * <ul>
  31. * <li>App.PortAlertDefinition</li>
  32. * <li>App.MetricsAlertDefinition</li>
  33. * <li>App.WebAlertDefinition</li>
  34. * <li>App.AggregateAlertDefinition</li>
  35. * <li>App.ScriptAlertDefinition</li>
  36. * </ul>
  37. * @type {App.AlertDefinition[]}
  38. */
  39. content: function() {
  40. return App.AlertDefinition.getAllDefinitions();
  41. }.property('mapperTimestamp'),
  42. /**
  43. * Enable/disable alertDefinition confirmation popup
  44. * @param {object} event
  45. * @method toggleState
  46. */
  47. toggleState: function(event) {
  48. var alertDefinition = event.context;
  49. var self = this;
  50. var bodyMessage = Em.Object.create({
  51. confirmMsg: alertDefinition.get('enabled') ? Em.I18n.t('alerts.table.state.enabled.confirm.msg') : Em.I18n.t('alerts.table.state.disabled.confirm.msg'),
  52. confirmButton: alertDefinition.get('enabled') ? Em.I18n.t('alerts.table.state.enabled.confirm.btn') : Em.I18n.t('alerts.table.state.disabled.confirm.btn')
  53. });
  54. return App.showConfirmationFeedBackPopup(function (query) {
  55. self.toggleDefinitionState (alertDefinition);
  56. }, bodyMessage);
  57. },
  58. /**
  59. * Enable/disable alertDefinition
  60. * @param {object} alertDefinition
  61. * @returns {$.ajax}
  62. * @method toggleDefinitionState
  63. */
  64. toggleDefinitionState: function(alertDefinition) {
  65. return App.ajax.send({
  66. name: 'alerts.update_alert_definition',
  67. sender: this,
  68. data: {
  69. id: alertDefinition.get('id'),
  70. data: {
  71. "AlertDefinition/enabled": !alertDefinition.get('enabled')
  72. }
  73. }
  74. });
  75. },
  76. /**
  77. * alerts number to show up on top-nav bar: number of critical/warning alerts
  78. */
  79. allAlertsCount: function () {
  80. return this.get('content').filterProperty('isCriticalOrWarning').get('length');
  81. }.property('content.@each.isCriticalOrWarning'),
  82. /**
  83. * calcuale critical/warning count for each service, to show up the label on services menu
  84. */
  85. getCriticalAlertsCountForService: function(service) {
  86. var alertsForService = this.get('content').filterProperty('service', service);
  87. return alertsForService.filterProperty('isCriticalOrWarning').get('length');
  88. },
  89. /**
  90. * Onclick handler for alerts number located right to bg ops number
  91. */
  92. showPopup: function(){
  93. var self = this;
  94. return App.ModalPopup.show({
  95. header: Em.I18n.t('alerts.fastAccess.popup.header').format(self.get('allAlertsCount')),
  96. classNames: ['sixty-percent-width-modal', 'alerts-popup'],
  97. secondary: null,
  98. isHideBodyScroll: true,
  99. closeModelPopup: function () {
  100. this.hide();
  101. },
  102. onPrimary: function () {
  103. this.closeModelPopup();
  104. },
  105. onClose: function () {
  106. this.closeModelPopup();
  107. },
  108. bodyClass: App.TableView.extend({
  109. templateName: require('templates/common/alerts_popup'),
  110. controller: self,
  111. contents: function () {
  112. // show crit/warn alerts only.
  113. return this.get('controller.content').filterProperty('isCriticalOrWarning');
  114. }.property('controller.content.@each.isCriticalOrWarning'),
  115. isLoaded: function () {
  116. return this.get('controller.content.length');
  117. }.property('controller.content.length'),
  118. isAlertEmptyList: function () {
  119. return !this.get('contents.length');
  120. }.property('contents.length'),
  121. gotoAlertDetails: function (event) {
  122. this.get('parentView').closeModelPopup();
  123. App.router.transitionTo('main.alerts.alertDetails', event.context);
  124. },
  125. gotoService: function (event) {
  126. this.get('parentView').closeModelPopup();
  127. App.router.transitionTo('main.services.service', event.context);
  128. },
  129. showMore: function () {
  130. this.get('parentView').closeModelPopup();
  131. App.router.transitionTo('main.alerts.index');
  132. },
  133. totalCount: function () {
  134. return this.get('contents.length');
  135. }.property('contents.length')
  136. })
  137. })
  138. }
  139. });