alert_group.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. /**
  20. * Represents an alert-group on the cluster.
  21. * A alert group is a collection of alert definitions
  22. *
  23. * Alert group hierarchy is at 2 levels. For
  24. * each service there is a 'Default' alert group
  25. * containing all definitions , this group is read-only
  26. *
  27. * User can create new alert group containing alert definitions from
  28. * any service.
  29. */
  30. App.AlertGroup = DS.Model.extend({
  31. id: null,
  32. name: null,
  33. description: null,
  34. default: null,
  35. definitions: [],
  36. targets: [],
  37. displayName: function () {
  38. var name = this.get('name');
  39. if (name && name.length > App.config.CONFIG_GROUP_NAME_MAX_LENGTH) {
  40. var middle = Math.floor(App.config.CONFIG_GROUP_NAME_MAX_LENGTH / 2);
  41. name = name.substring(0, middle) + "..." + name.substring(name.length-middle);
  42. }
  43. return this.get('default') ? (name + ' Default') : name;
  44. }.property('name', 'default'),
  45. displayNameDefinitions: function () {
  46. return this.get('displayName') + ' (' + this.get('definitions.length') + ')';
  47. }.property('displayName', 'definitions.length')
  48. });
  49. App.AlertGroup.FIXTURES = [];
  50. App.AlertGroupComplex = Ember.Object.extend({
  51. id: null,
  52. name: null,
  53. description: null,
  54. default: null,
  55. definitions: [],
  56. targets: [],
  57. /**
  58. * all alert definitions that belong to all services
  59. */
  60. alertDefinitionsBinding: 'App.router.manageAlertGroupsController.alertDefinitions',
  61. displayName: function () {
  62. var name = this.get('name');
  63. if (name && name.length > App.config.CONFIG_GROUP_NAME_MAX_LENGTH) {
  64. var middle = Math.floor(App.config.CONFIG_GROUP_NAME_MAX_LENGTH / 2);
  65. name = name.substring(0, middle) + "..." + name.substring(name.length-middle);
  66. }
  67. return this.get('default') ? (name + ' Default') : name;
  68. }.property('name', 'default'),
  69. displayNameDefinitions: function () {
  70. return this.get('displayName') + ' (' + this.get('definitions.length') + ')';
  71. }.property('displayName', 'definitions.length'),
  72. /**
  73. * Provides alert definitions which are available for inclusion in
  74. * non-default alert groups.
  75. */
  76. availableDefinitions: function () {
  77. if (this.get('default')) return [];
  78. var usedDefinitionsMap = {};
  79. var availableDefinitions = [];
  80. var sharedDefinitions = this.get('alertDefinitions');
  81. this.get('definitions').forEach(function (def) {
  82. usedDefinitionsMap[def.name] = true;
  83. });
  84. sharedDefinitions.forEach(function (shared_def) {
  85. if (!usedDefinitionsMap[shared_def.get('name')]) {
  86. availableDefinitions.pushObject(shared_def);
  87. }
  88. });
  89. return availableDefinitions;
  90. }.property('alertDefinitions', 'definitions.@each', 'definitions.length'),
  91. isAddDefinitionsDisabled: function () {
  92. return (this.get('default') || this.get('availableDefinitions.length') === 0);
  93. }.property('availableDefinitions.length')
  94. });