Skip to content

Commit

Permalink
Add importance feature
Browse files Browse the repository at this point in the history
  • Loading branch information
samr28 committed Nov 12, 2017
1 parent 6a9250b commit 211d5fb
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 5 deletions.
16 changes: 15 additions & 1 deletion scripts/agenda.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module.exports = {
update : update,
assign : assign,
unassign : unAssign,
setImportance : setImportance,
formatAgenda : formatAgenda,
getAgenda : getAgenda,
getAgendaSlack : getAgendaSlack,
Expand Down Expand Up @@ -75,14 +76,27 @@ function assign(robot, id, assignee) {
getAgenda(robot)[id].assignee = assignee;
return `Successfully assigned #${id+1} to ${assignee}`;
}

function unAssign(robot, id) {
if (getAgenda(robot)[id].assignee.length == 0) {
return `Item #${id+1} is not assigned.`;
}
getAgenda(robot)[id].assignee = '';
return `Successfully unassigned #${id+1}`;
}
function setImportance(robot, id, importance) {
let color = '';
if (importance === 'high') {
color = 'danger';
} else if (importance === 'medium') {
color = 'warning';
} else if (importance === 'low') {
color = 'good';
} else {
color = DEFAULT_ATTACHMENT_COLOR;
}
getAgenda(robot)[id-1].color = color;
return `Set item #${id} importance to ${importance}`;
}

function formatAgenda(agenda) {
if (!agenda || _.isNull(agenda)) return new Error('Empty agenda');
Expand Down
41 changes: 38 additions & 3 deletions scripts/hubot-agenda.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
// hubot add <item> - Adds <item> to the agenda
// hubot rm/rem/remove <item> - Removes <item> from the agenda
// hubot update <id> <new text> - Updates <id> with <new text>
// hubot assign <id> <assignee> - Assign an item to <assignee>
// hubot unassign <id> - Unassign an item
// hubot set importance <id> <level> - Set the importance/color of an item. <level> = 'high', 'medium', 'low', or 'default'.
// hubot li/ls/list - List the agenda
// hubot set schedule - Update the schedule
// hubot up/uptime - Get the bot's uptime
Expand Down Expand Up @@ -50,6 +53,9 @@ module.exports = function (robot) {
robot.respond(/(?:agenda )?unassign (\d+)/i, function (msg) {
unassign(robot, msg);
});
robot.respond(/(?:agenda )?set importance (\d+) (\w+)/i, function (msg) {
importance(robot, msg);
});

robot.respond(/(?:agenda )?-?v(?:ersion)?(?!.)/i, function (msg) {
utils.logMsgData(msg, `v${version}`);
Expand Down Expand Up @@ -131,9 +137,8 @@ function listAgenda(robot, msg) {
/**
* Update one of the agenda items
*
* @param {Object} robot Hubot Object
* @param {Object} robot Hubot object
* @param {Object} msg Incoming message
* @return {[type]} [description]
*/
function update(robot, msg) {
let id = msg.match[1];
Expand All @@ -150,6 +155,12 @@ function update(robot, msg) {
return msg.send(agenda.update(robot, id, value).toString());
}

/**
* Set the assignee of an item
*
* @param {Object} robot Hubot object
* @param {Object} msg Incoming message
*/
function assign(robot, msg) {
let id = msg.match[1];
let assignee = msg.match[2];
Expand All @@ -166,7 +177,12 @@ function assign(robot, msg) {
}
return msg.send(agenda.assign(robot, id, assignee).toString());
}

/**
* Resets the assignee of an item
*
* @param {Object} robot Hubot object
* @param {Object} msg Incoming message
*/
function unassign(robot, msg) {
let id = msg.match[1];
utils.logMsgData(msg, `UNASSIGN #${id}`);
Expand All @@ -179,3 +195,22 @@ function unassign(robot, msg) {
}
return msg.send(agenda.unassign(robot, id).toString());
}
/**
* Set the importance/color of an item
*
* @param {Object} robot Hubot object
* @param {Object} msg Incoming message
*/
function importance(robot, msg) {
let id = msg.match[1];
let importance = msg.match[2];
let validInput = ["high", "default", "medium", "low"];
utils.logMsgData(msg, `SET IMPORTANCE #${id} ${importance}`);
if (isNaN(id)) {
return msg.send(`I didn't understand '${id}'. Type 'agenda help' for help`);
}
if (!_.contains(validInput, importance)) {
return msg.send(`I didn't understand '${importance}'. Use 'high', 'medium', or 'low'`);
}
return msg.send(agenda.setImportance(robot, id, importance).toString());
}
8 changes: 7 additions & 1 deletion web.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ function buildHtml(cb) {
body += '<div class="container">';

for (var i = 1; i <= data.length; i++) {
body += '<div class="alert alert-' + data[i-1].color + ' alert-dismissible fade show" role="alert">';
let color;
if (data[i-1].color === 'good') {
color = 'success';
} else {
color = data[i-1].color;
}
body += '<div class="alert alert-' + color + ' alert-dismissible fade show" role="alert">';
body += i + '. ' + data[i-1].value + '<br>';
body += '<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>';
body += '</div>';
Expand Down

0 comments on commit 211d5fb

Please sign in to comment.