diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2015-11-01 00:38:12 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2015-11-01 00:38:12 +0100 |
commit | 2173df227821aefe1cf9aee5d8165fa0a24961e9 (patch) | |
tree | 9948292d30bb3950c497a98bfb9fc7e873a80c2b | |
parent | 13ebc9d3f82f686ca2bc8388095feeb9067e2e40 (diff) | |
download | diller-server-2173df227821aefe1cf9aee5d8165fa0a24961e9.tar.gz diller-server-2173df227821aefe1cf9aee5d8165fa0a24961e9.tar.bz2 diller-server-2173df227821aefe1cf9aee5d8165fa0a24961e9.tar.xz diller-server-2173df227821aefe1cf9aee5d8165fa0a24961e9.zip |
web:
o Removing dupliated name and description fields from device.
-rw-r--r-- | src/web/DillerWeb.js | 26 | ||||
-rw-r--r-- | web/static/app/templates/device-edit-attribute.modal.html | 2 | ||||
-rw-r--r-- | web/static/app/templates/device.html | 25 |
3 files changed, 23 insertions, 30 deletions
diff --git a/src/web/DillerWeb.js b/src/web/DillerWeb.js index bcb15d4..3f1d107 100644 --- a/src/web/DillerWeb.js +++ b/src/web/DillerWeb.js @@ -20,8 +20,11 @@ function DillerWeb(tx, config) { function genericErrorHandler(res) { return function (data) { + if (typeof data === 'string') { + data = {message: data} + } log.warn('fail', data); - return res.status(500).json({message: 'fail', data: data}) + return res.status(500).json(data); } } @@ -58,25 +61,24 @@ function DillerWeb(tx, config) { var body = req.body; + var p; if (!body.attribute) { res.status(400).json({message: 'Required keys: "attribute" and "value".'}); } else if (body.attribute == 'name' || body.attribute == 'description') { var attributes = {}; attributes[body.attribute] = body.value; - return diller.updateDeviceAttributes(deviceId, attributes) - .then(function () { - return pg.batch([ - dao.deviceById(deviceId), - dao.devicePropertiesByDeviceId(deviceId)] - ); - }) - .then(function (data) { - res.json(deviceResponse(data)); - }, genericErrorHandler(res)); + p = diller.updateDeviceAttributes(deviceId, attributes); } else { - res.status(400).json({message: 'Unsupported attribute: ' + body.attribute}); + p = Promise.reject('Unsupported attribute: ' + body.attribute); } + + return p.then(function () { + return pg.batch([ + dao.deviceById(deviceId), + dao.devicePropertiesByDeviceId(deviceId)] + ); + }); }).then(function (data) { var device = data[0]; device.properties = data[1]; diff --git a/web/static/app/templates/device-edit-attribute.modal.html b/web/static/app/templates/device-edit-attribute.modal.html index 10314e5..2e57f2d 100644 --- a/web/static/app/templates/device-edit-attribute.modal.html +++ b/web/static/app/templates/device-edit-attribute.modal.html @@ -7,7 +7,7 @@ </div> <div class="modal-body"> <fieldset class="form-group"> - <label for="attribute" style="text-transform: capitalize">{{ctrl.label}}</label> + <label for="attribute" class="text-capitalize">{{ctrl.label}}</label> <input type="text" class="form-control" id="attribute" autofocus ng-model="ctrl.value"/> </fieldset> diff --git a/web/static/app/templates/device.html b/web/static/app/templates/device.html index fbda67f..e3c988d 100644 --- a/web/static/app/templates/device.html +++ b/web/static/app/templates/device.html @@ -2,9 +2,17 @@ <h1> {{(ctrl.device.name || ctrl.device.key)}} + + <a ng-click="ctrl.editDeviceAttribute('name')" class="pull-right" style="font-size: 1rem;"> + <i class="fa fa-edit"/> + </a> </h1> <p ng-if="ctrl.device.description"> + <a ng-click="ctrl.editDeviceAttribute('description')" class="pull-right"> + <i class="fa fa-edit"/> + </a> + {{ctrl.device.description}} </p> @@ -69,23 +77,6 @@ {{ctrl.device.created_timestamp | date}} </dd> - - <dt class="col-sm-3">Name</dt> - <dd class="col-sm-9"> - {{ctrl.device.name}} - <a ng-click="ctrl.editDeviceAttribute('name')" class="pull-right"> - <i class="fa fa-edit"/> - </a> - </dd> - - <dt class="col-sm-3">Description</dt> - <dd class="col-sm-9"> - {{ctrl.device.description}} - - <a ng-click="ctrl.editDeviceAttribute('description')" class="pull-right"> - <i class="fa fa-edit"/> - </a> - </dd> </dl> <h3>Properties</h3> |