alert_definitions_controller.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 customDatePopup = require('/views/common/custom_date_popup');
  20. App.MainAlertDefinitionsController = Em.ArrayController.extend({
  21. name: 'mainAlertDefinitionsController',
  22. /**
  23. * Timestamp when <code>App.alertDefinitionsMapper</code> run last time
  24. * Current <code>content</code> is updated on when it changed
  25. * @type {number|null}
  26. */
  27. mapperTimestamp: null,
  28. /**
  29. * List of all <code>App.AlertDefinition</code>
  30. * Consists of:
  31. * <ul>
  32. * <li>App.PortAlertDefinition</li>
  33. * <li>App.MetricsAlertDefinition</li>
  34. * <li>App.WebAlertDefinition</li>
  35. * <li>App.AggregateAlertDefinition</li>
  36. * <li>App.ScriptAlertDefinition</li>
  37. * </ul>
  38. * @type {App.AlertDefinition[]}
  39. */
  40. content: function() {
  41. return Array.prototype.concat.call(Array.prototype, App.PortAlertDefinition.find().toArray(),
  42. App.MetricsAlertDefinition.find().toArray(),
  43. App.WebAlertDefinition.find().toArray(),
  44. App.AggregateAlertDefinition.find().toArray(),
  45. App.ScriptAlertDefinition.find().toArray());
  46. }.property('mapperTimestamp'),
  47. /**
  48. * Object for lastTriggered-filter
  49. * @type {Em.Object}
  50. */
  51. modifiedFilter: Em.Object.create({
  52. optionValue: 'Any',
  53. filterModified: function () {
  54. var time = "";
  55. var curTime = new Date().getTime();
  56. switch (this.get('optionValue')) {
  57. case 'Past 1 hour':
  58. time = curTime - 3600000;
  59. break;
  60. case 'Past 1 Day':
  61. time = curTime - 86400000;
  62. break;
  63. case 'Past 2 Days':
  64. time = curTime - 172800000;
  65. break;
  66. case 'Past 7 Days':
  67. time = curTime - 604800000;
  68. break;
  69. case 'Past 14 Days':
  70. time = curTime - 1209600000;
  71. break;
  72. case 'Past 30 Days':
  73. time = curTime - 2592000000;
  74. break;
  75. case 'Custom':
  76. case 'Custom2':
  77. customDatePopup.showCustomDatePopup(this, this.get('actualValues'));
  78. break;
  79. case 'Any':
  80. time = "";
  81. break;
  82. }
  83. if (this.get('modified') !== "Custom") {
  84. this.set("actualValues.startTime", time);
  85. this.set("actualValues.endTime", '');
  86. }
  87. }.observes('optionValue'),
  88. cancel: function () {
  89. this.set('optionValue', 'Any');
  90. },
  91. actualValues: Em.Object.create({
  92. startTime: "",
  93. endTime: ""
  94. })
  95. }),
  96. toggleState: Em.K
  97. });