Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export class Example {
constructor(description, apiFilter) {
this.apiFilter = apiFilter;
this.description = description;
}
}
// Some examples to use
export const Examples = [
new Example("Show all alarms", new API.Filter()),
new Example("Show all alarms for location 'Default'",
new API.Filter().withAndRestriction(new API.Restriction("node.location.locationName", API.Comparators.EQ, 'Default'))),
new Example("Show all alarms with a severity between 'Warning' and 'Major'",
new API.Filter()
.withAndRestriction(new API.Restriction("alarm.severity", API.Comparators.GE, Model.Severities.WARNING.label))
.withAndRestriction(new API.Restriction("alarm.severity", API.Comparators.LE, Model.Severities.MAJOR.label))),
new Example("Show all alarms for nodes in category 'Servers'",
new API.Filter().withAndRestriction(new API.Restriction("category.name", API.Comparators.EQ, 'Severs'))),
new Example("Show all unacknowledged alarms",
new API.Filter().withAndRestriction(new API.Restriction("alarmAckTime", API.Comparators.EQ, 'null'))),
new Example("Show all acknowledged alarms",
new API.Filter().withAndRestriction(new API.Restriction("alarmAckTime", API.Comparators.NE, 'null'))),
];
export class Example {
constructor(description, apiFilter) {
this.apiFilter = apiFilter;
this.description = description;
}
}
// Some examples to use
export const Examples = [
new Example("Show all alarms", new API.Filter()),
new Example("Show all alarms for location 'Default'",
new API.Filter().withAndRestriction(new API.Restriction("node.location.locationName", API.Comparators.EQ, 'Default'))),
new Example("Show all alarms with a severity between 'Warning' and 'Major'",
new API.Filter()
.withAndRestriction(new API.Restriction("alarm.severity", API.Comparators.GE, Model.Severities.WARNING.label))
.withAndRestriction(new API.Restriction("alarm.severity", API.Comparators.LE, Model.Severities.MAJOR.label))),
new Example("Show all alarms for nodes in category 'Servers'",
new API.Filter().withAndRestriction(new API.Restriction("category.name", API.Comparators.EQ, 'Severs'))),
new Example("Show all unacknowledged alarms",
new API.Filter().withAndRestriction(new API.Restriction("alarmAckTime", API.Comparators.EQ, 'null'))),
new Example("Show all acknowledged alarms",
new API.Filter().withAndRestriction(new API.Restriction("alarmAckTime", API.Comparators.NE, 'null'))),
];
.then(property => {
if (!property) {
return this.q.when([]);
}
// Special handling for properties
switch(property.id) {
// Severity is handled separately as otherwise the severity ordinal vs the severity label would be
// used, but that may not be ideal for the user
case 'severity':
return this.q.when(_.map(Model.Severities, severity => {
return {
id: severity.id,
label: severity.label
}
}));
}
return property.findValues({limit: 1000}).then(values => {
return values.filter(value => value !== null).map(value => {
return {id: value, label: value, text: value ? String(value) : value, value: value}
});
});
});
}
it('should interpolate a variable that refers to an object', () => {
const ca = new CustomAction('foo', 'http://bar/$severity');
const alarm = new Model.OnmsAlarm();
alarm.severity = Model.Severities.NORMAL;
expect(ca.interpolate(alarm)).to.equal('http://bar/NORMAL');
});
it('should validate a variable with a number index', () => {
severityForLabel(label) {
const sev = Model.Severities[label];
if (sev) {
return sev.id;
} else {
console.warn('Unable to determine severity for "' + label + '".');
return -1;
}
}
it('should validate a variable that refers to an object', () => {
const ca = new CustomAction('foo', 'http://bar/$severity');
const alarm = new Model.OnmsAlarm();
alarm.severity = Model.Severities.NORMAL;
expect(ca.validate(alarm)).to.be.true;
});
it('should interpolate a variable that refers to an object', () => {
let escalatableRows = _.filter(this.rows, row => {
let severity = row.alarm.severity;
return severity.index >= Model.Severities.CLEARED.index && severity.index < Model.Severities.CRITICAL.index;
});
this.addOptionToContextMenu('General', 'Escalate', escalatableRows,
return v => {
if (v === null || v === void 0) {
return '-';
}
if (column.style.displayAs === 'label') {
return Model.Severities[v].toDisplayString();
} else if (column.style.displayAs === 'labelCaps') {
return v;
} else {
var icon = TableRenderer.getIconForSeverity(v.toLowerCase());
return `<i title="${v}" class="icon severity-icon fa ${icon}"></i>`;
}
};
}