Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions web/htdocs/js/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@
return ok
};

exported.agentByUUID = function (agents, uuid) {
for (var i = 0; i < agents.length; i++) {
if (agents[i].uuid == uuid) {
return agents[i];
}
}
return undefined;
};

/***************************************************
pluralize(n, word [, words]) - Pluralize a number + unit.

Expand Down
4 changes: 3 additions & 1 deletion web/htdocs/js/shield.js
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,9 @@ function dispatch(page) {
});
} else if (action == 'delete') {
var agent_uuid = $(event.target).extract('agent-uuid');
modal($($.template('agents-delete', { agent: data.agents[0] }))
modal($($.template('agents-delete', {
agent: agentByUUID(data.agents, agent_uuid)
}))
.on('click', '[rel="yes"]', function (event) {
event.preventDefault();
api({
Expand Down
13 changes: 13 additions & 0 deletions web/test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,19 @@ QUnit.assert.any = function (actual, expected, message) {
});
};

QUnit.module('Agent UI Helpers');
QUnit.test('agentByUUID selects the clicked agent', function (is) {
var agents = [
{ uuid: 'first-agent', name: 'First' },
{ uuid: 'second-agent', name: 'Second' }
];

is.equal(agentByUUID(agents, 'second-agent').name, 'Second',
'the confirmation modal receives the clicked agent');
is.strictEqual(agentByUUID(agents, 'missing-agent'), undefined,
'an unknown UUID does not select another agent');
});

QUnit.module('AEGIS Data Operations');
QUnit.test('Basic Operations', function(is) {
var thing, db = $.aegis();
Expand Down