alert_instance.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 dateUtils = require('utils/date');
  20. App.AlertInstance = DS.Model.extend({
  21. id: DS.attr('number'),
  22. label: DS.attr('string'),
  23. definitionName: DS.attr('string'),
  24. definitionId: DS.attr('number'),
  25. service: DS.belongsTo('App.Service'),
  26. componentName: DS.attr('string'),
  27. host: DS.belongsTo('App.Host'),
  28. scope: DS.attr('string'),
  29. originalTimestamp: DS.attr('number'),
  30. latestTimestamp: DS.attr('number'),
  31. maintenanceState: DS.attr('string'),
  32. instance: DS.attr('string'),
  33. state: DS.attr('string'),
  34. text: DS.attr('string'),
  35. notification: DS.hasMany('App.AlertNotification'),
  36. /**
  37. * Status icon markup
  38. * @type {string}
  39. */
  40. status: function () {
  41. var state = this.get('state');
  42. return '<span class="label alert-state-single-host alert-state-' + state + '">' + state + '</span>';
  43. }.property('state'),
  44. /**
  45. * Formatted timestamp for latest instance triggering
  46. * @type {string}
  47. */
  48. lastTriggeredFormatted: function() {
  49. return dateUtils.dateFormat(this.get('originalTimestamp'));
  50. }.property('originalTimestamp'),
  51. /**
  52. * Formatted timestamp with <code>$.timeago</code>
  53. * @type {string}
  54. */
  55. lastTriggeredAgoFormatted: function () {
  56. var lastTriggered = this.get('originalTimestamp');
  57. return lastTriggered ? $.timeago(new Date(lastTriggered)): '';
  58. }.property('originalTimestamp'),
  59. /**
  60. * List of css-classes for alert instance status
  61. * @type {object}
  62. */
  63. typeIcons: {
  64. 'DISABLED': 'icon-off'
  65. }
  66. });
  67. App.AlertInstance.FIXTURES = [];