Skip to content

Commit

Permalink
triggers panel: fix undefined username in acknowledges #393
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderzobnin committed Mar 23, 2018
1 parent 4c3c799 commit 0c8308a
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 21 deletions.
20 changes: 20 additions & 0 deletions dist/panel-triggers/specs/panel_ctrl.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,26 @@ describe('TriggerPanelCtrl', () => {
});
});
});

describe('When formatting acknowledges', () => {
beforeEach(() => {
ctx.panelCtrl = createPanelCtrl();
});

it('should build proper user name', () => {
const ack = {
alias: 'alias', name: 'name', surname: 'surname'
};

const formatted = ctx.panelCtrl.formatAcknowledge(ack);
expect(formatted.user).toBe('alias (name surname)');
});

it('should return empty name if it is not defined', () => {
const formatted = ctx.panelCtrl.formatAcknowledge({});
expect(formatted.user).toBe('');
});
});
});

const defaultTrigger = {
Expand Down
27 changes: 17 additions & 10 deletions dist/panel-triggers/triggers_panel_ctrl.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/panel-triggers/triggers_panel_ctrl.js.map

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions src/panel-triggers/specs/panel_ctrl.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,26 @@ describe('TriggerPanelCtrl', () => {
});
});
});

describe('When formatting acknowledges', () => {
beforeEach(() => {
ctx.panelCtrl = createPanelCtrl();
});

it('should build proper user name', () => {
const ack = {
alias: 'alias', name: 'name', surname: 'surname'
};

const formatted = ctx.panelCtrl.formatAcknowledge(ack);
expect(formatted.user).toBe('alias (name surname)');
});

it('should return empty name if it is not defined', () => {
const formatted = ctx.panelCtrl.formatAcknowledge({});
expect(formatted.user).toBe('');
});
});
});

const defaultTrigger = {
Expand Down
26 changes: 16 additions & 10 deletions src/panel-triggers/triggers_panel_ctrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,16 +243,7 @@ export class TriggerPanelCtrl extends PanelCtrl {
});

if (event) {
trigger.acknowledges = _.map(event.acknowledges, ack => {
let timestamp = moment.unix(ack.clock);
if (this.panel.customLastChangeFormat) {
ack.time = timestamp.format(this.panel.lastChangeFormat);
} else {
ack.time = timestamp.format(this.defaultTimeFormat);
}
ack.user = ack.alias + ' (' + ack.name + ' ' + ack.surname + ')';
return ack;
});
trigger.acknowledges = _.map(event.acknowledges, this.formatAcknowledge.bind(this));
}

if (!trigger.lastEvent.eventid) {
Expand All @@ -264,6 +255,21 @@ export class TriggerPanelCtrl extends PanelCtrl {
});
}

formatAcknowledge(ack) {
let timestamp = moment.unix(ack.clock);
if (this.panel.customLastChangeFormat) {
ack.time = timestamp.format(this.panel.lastChangeFormat);
} else {
ack.time = timestamp.format(this.defaultTimeFormat);
}
ack.user = ack.alias || '';
if (ack.name || ack.surname) {
const fullName = `${ack.name || ''} ${ack.surname || ''}`;
ack.user += ` (${fullName})`;
}
return ack;
}

filterTriggersPre(triggerList, ds) {
// Filter triggers by description
let triggerFilter = this.panel.targets[ds].trigger.filter;
Expand Down

0 comments on commit 0c8308a

Please sign in to comment.