diff --git a/db/schema.v0.sql b/db/schema.v0.sql index e1b8541..61ac7c6 100644 --- a/db/schema.v0.sql +++ b/db/schema.v0.sql @@ -290,12 +290,13 @@ CREATE TABLE IF NOT EXISTS `roster_user` ( CREATE TABLE IF NOT EXISTS `contact_mode` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL, + `label` varchar(255) NOT NULL, PRIMARY KEY (`id`) ); -- ----------------------------------------------------- -- Initialize contact modes -- ----------------------------------------------------- -INSERT INTO `contact_mode` (`name`) +INSERT INTO `contact_mode` (`name`, `label`) VALUES ('email'), ('sms'), ('call'), ('slack'); -- ----------------------------------------------------- diff --git a/src/oncall/api/v0/modes.py b/src/oncall/api/v0/modes.py index d4b880d..2fff82d 100644 --- a/src/oncall/api/v0/modes.py +++ b/src/oncall/api/v0/modes.py @@ -7,9 +7,9 @@ def on_get(req, resp): Get all contact modes """ connection = db.connect() - cursor = connection.cursor() - cursor.execute('SELECT `name` FROM `contact_mode`') - data = [row[0] for row in cursor] + cursor = connection.cursor(db.DictCursor) + cursor.execute('SELECT `name`, `label` FROM `contact_mode`') + data = cursor.fetchall() cursor.close() connection.close() resp.body = json_dumps(data) diff --git a/src/oncall/ui/static/js/oncall.js b/src/oncall/ui/static/js/oncall.js index a99f105..d8d7732 100644 --- a/src/oncall/ui/static/js/oncall.js +++ b/src/oncall/ui/static/js/oncall.js @@ -2009,6 +2009,7 @@ var oncall = { }, init: function(){ Handlebars.registerPartial('settings-subheader', this.data.settingsSubheaderTemplate); + oncall.getModes(); this.getData(); }, events: function(){ @@ -2023,6 +2024,22 @@ var oncall = { } }, renderPage: function(data){ + $.when( + oncall.data.modesPromise + ).done(function() { + let contactModes = []; + + for(let key in data.contacts) + { + let currentMode = oncall.data.modes.find(x => x.name === key); + contactModes.push({ + key: currentMode.label, + value: data.contacts[key] + }); + } + data.contactmodes = contactModes; + data.telmodes = ["Phone", "SMS Number"]; + }); var template = Handlebars.compile(this.data.pageSource), self = this; oncall.data.timezonesPromise.done(function() { diff --git a/src/oncall/ui/templates/index.html b/src/oncall/ui/templates/index.html index eafee41..2ca8424 100644 --- a/src/oncall/ui/templates/index.html +++ b/src/oncall/ui/templates/index.html @@ -1159,46 +1159,27 @@ + {{#each contactmodes}}