Skip to content

Commit

Permalink
feat(alarms): expose a link to the alarm details page (HELM-55)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesse White committed Sep 8, 2017
1 parent dc78a13 commit 8795818
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/api/OnmsServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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();
}

/**
Expand Down
12 changes: 12 additions & 0 deletions src/dao/AlarmDAO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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});
}
}
2 changes: 2 additions & 0 deletions src/model/OnmsAlarm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,6 @@ export class OnmsAlarm {
return undefined;
}

/** link to the alarm details page on the source instance */
public detailsPage: string;
}
4 changes: 4 additions & 0 deletions test/dao/AlarmDAO.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)', () => {
Expand Down Expand Up @@ -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)', () => {
Expand Down Expand Up @@ -269,4 +272,5 @@ describe('AlarmDAO with v2 API', () => {
return true;
})).resolves.toBeTruthy();
});

});

0 comments on commit 8795818

Please sign in to comment.