123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- /**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- var App = require('app');
- var dateUtils = require('utils/date');
- App.AlertInstance = DS.Model.extend({
- id: DS.attr('number'),
- label: DS.attr('string'),
- definitionName: DS.attr('string'),
- definitionId: DS.attr('number'),
- service: DS.belongsTo('App.Service'),
- serviceName: DS.attr('string'),
- componentName: DS.attr('string'),
- host: DS.belongsTo('App.Host'),
- scope: DS.attr('string'),
- originalTimestamp: DS.attr('number'),
- latestTimestamp: DS.attr('number'),
- maintenanceState: DS.attr('string'),
- instance: DS.attr('string'),
- state: DS.attr('string'),
- text: DS.attr('string'),
- notification: DS.hasMany('App.AlertNotification'),
- /**
- * Status icon markup
- * @type {string}
- */
- status: function () {
- var state = this.get('state');
- return '<span class="label alert-state-single-host alert-state-' + state + '">' + state + '</span>';
- }.property('state'),
- /**
- * For alerts we will have processes which are not typical
- * cluster services - like Ambari-Server. This method unifies
- * cluster services and other services into a common display-name.
- * @see App.AlertDefinition#serviceDisplayName()
- */
- serviceDisplayName : function() {
- var serviceName = this.get('service.displayName');
- if (!serviceName) {
- serviceName = this.get('serviceName');
- if (serviceName) {
- serviceName = serviceName.toCapital();
- }
- }
- return serviceName;
- }.property('serviceName', 'service.displayName'),
- /**
- * Formatted timestamp for latest instance triggering
- * @type {string}
- */
- lastCheckedFormatted: function() {
- return dateUtils.dateFormat(this.get('latestTimestamp'));
- }.property('latestTimestamp'),
- /**
- * Formatted timestamp for latest instance triggering
- * @type {string}
- */
- lastTriggeredFormatted: function() {
- return dateUtils.dateFormat(this.get('originalTimestamp'));
- }.property('originalTimestamp'),
- /**
- * Formatted timestamp with <code>$.timeago</code>
- * @type {string}
- */
- lastTriggeredAgoFormatted: function () {
- var lastTriggered = this.get('originalTimestamp');
- return lastTriggered ? $.timeago(new Date(lastTriggered)): '';
- }.property('originalTimestamp'),
- lastTriggeredVerboseDisplay : function() {
- var originalTimestamp = this.get('originalTimestamp');
- var latestTimestamp = this.get('latestTimestamp');
- return Em.I18n.t('models.alert_instance.tiggered.verbose').format(
- dateUtils.dateFormat(originalTimestamp),
- dateUtils.dateFormat(latestTimestamp));
- }.property('originalTimestamp', 'latestTimestamp'),
- /**
- * Formatted timestamp with <code>$.timeago</code>
- * @type {string}
- */
- lastTriggeredForFormatted: function () {
- var lastTriggered = this.get('originalTimestamp');
- var previousSuffixAgo = $.timeago.settings.strings.suffixAgo;
- var previousPrefixAgo = $.timeago.settings.strings.prefixAgo;
- $.timeago.settings.strings.suffixAgo = null;
- $.timeago.settings.strings.prefixAgo = 'for';
- var triggeredFor = lastTriggered ? $.timeago(new Date(lastTriggered)): '';
- $.timeago.settings.strings.suffixAgo = previousSuffixAgo;
- $.timeago.settings.strings.prefixAgo = previousPrefixAgo;
- return triggeredFor;
- }.property('originalTimestamp'),
- /**
- * List of css-classes for alert instance status
- * @type {object}
- */
- typeIcons: {
- 'DISABLED': 'icon-off'
- }
- });
- App.AlertInstance.FIXTURES = [];
|