Permalink
Browse files

feat(alarms): expose a link to the alarm details page (HELM-55)

  • Loading branch information...
j-white committed Sep 8, 2017
1 parent dc78a13 commit 8795818d639dd83f4e2e2de5d800c0c4220be395
Showing with 25 additions and 2 deletions.
  1. +7 −2 src/api/OnmsServer.ts
  2. +12 −0 src/dao/AlarmDAO.ts
  3. +2 −0 src/model/OnmsAlarm.ts
  4. +4 −0 test/dao/AlarmDAO.spec.ts
View
@@ -60,9 +60,10 @@ export class OnmsServer {
/**
* Given a relative URL fragment, construct a URL for that fragment on the server.
* @param forFragment - The URL fragment to append to the server URL.
* @parm withQuery - Query parameters to be appended to the URL.
* @returns A complete URL.
*/
public resolveURL(forFragment?: string) {
public resolveURL(forFragment?: string, withQuery?: any) {
if (!this.url) {
return undefined;
}
@@ -72,7 +73,11 @@ export class OnmsServer {
if (forFragment.indexOf('/') === 0 || forFragment.indexOf('http') === 0) {
return forFragment;
}
return URI(this.url).segment(forFragment).toString();
let uri = URI(this.url).segment(forFragment);
if (withQuery !== undefined) {
uri = uri.addQuery(withQuery);
}
return uri.toString();
}
/**
View
@@ -388,6 +388,8 @@ export class AlarmDAO extends AbstractDAO<number, OnmsAlarm> {
alarm.sticky = this.toMemo(data.stickyMemo);
alarm.journal = this.toMemo(data.reductionKeyMemo);
alarm.detailsPage = this.getDetailsPage(alarm);
return alarm;
}
@@ -507,4 +509,14 @@ export class AlarmDAO extends AbstractDAO<number, OnmsAlarm> {
return this.httpDelete(this.pathToAlarmsEndpoint() + '/' + alarmId + '/' + type);
}
/**
* Retrieves the URL to the details page for the given alarm.
*
* @param {number|OnmsAlarm} alarm - The [[OnmsAlarm]] or alarm ID.
* @returns {URL} URL on the associated OpenNMS server for the alarm details page.
*/
private getDetailsPage(alarm: number|OnmsAlarm): string {
const alarmId = (typeof(alarm) === 'number' ? alarm : alarm.id);
return this.http.server.resolveURL(`alarm/detail.htm`, {id: alarmId});
}
}
View
@@ -96,4 +96,6 @@ export class OnmsAlarm {
return undefined;
}
/** link to the alarm details page on the source instance */
public detailsPage: string;
}
@@ -46,6 +46,8 @@ describe('AlarmDAO with v1 API', () => {
it('AlarmDAO.get(404725)', () => {
return dao.get(404725).then((alarm) => {
expect(alarm.id).toEqual(404725);
// Spot check some of the known properties
expect(alarm.detailsPage).toEqual('http://demo.opennms.org/opennms/alarm/detail.htm?id=404725');
});
});
it('AlarmDAO.find(id=404725)', () => {
@@ -166,6 +168,7 @@ describe('AlarmDAO with v2 API', () => {
expect(alarm.location).toEqual('Default');
expect(alarm.lastEvent.label).toEqual('OpenNMS-defined node event: nodeDown');
expect(alarm.lastEvent.location).toEqual('Default');
expect(alarm.detailsPage).toEqual('http://demo.opennms.org/opennms/alarm/detail.htm?id=6806');
});
});
it('AlarmDAO.find(id=6806)', () => {
@@ -269,4 +272,5 @@ describe('AlarmDAO with v2 API', () => {
return true;
})).resolves.toBeTruthy();
});
});

0 comments on commit 8795818

Please sign in to comment.