From f7ff8a837bed336a14aa0442ed8286f3ef78f577 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sun, 1 Nov 2015 01:06:40 +0100 Subject: core: o Adding updates of device property's name and description. web: o Ading editing of property name and description. --- web/static/app/DillerRpc.js | 15 +++++++- web/static/app/app.js | 41 ++++++++++++++++++---- .../app/templates/device-edit-attribute.modal.html | 32 ----------------- web/static/app/templates/device.html | 13 ++++--- web/static/app/templates/edit-attribute.modal.html | 32 +++++++++++++++++ web/static/app/templates/front-page.html | 10 +++--- web/static/app/templates/property.html | 38 +++++++++++++------- 7 files changed, 121 insertions(+), 60 deletions(-) delete mode 100644 web/static/app/templates/device-edit-attribute.modal.html create mode 100644 web/static/app/templates/edit-attribute.modal.html (limited to 'web') diff --git a/web/static/app/DillerRpc.js b/web/static/app/DillerRpc.js index b1939f4..f865dc5 100644 --- a/web/static/app/DillerRpc.js +++ b/web/static/app/DillerRpc.js @@ -33,11 +33,21 @@ function DillerRpc($http, DillerConfig) { return $http(req); } + function patchProperty(propertyId, payload) { + var req = {}; + req.method = 'patch'; + req.url = baseUrl + '/api/property/:propertyId/values'; + req.url = req.url.replace(/:propertyId/, propertyId); + req.data = payload; + return $http(req); + } + return { getDevices: getDevices, getDevice: getDevice, patchDevice: patchDevice, - getValues: getValues + getValues: getValues, + patchProperty: patchProperty }; } @@ -54,3 +64,6 @@ DillerRpcResolve.patchDevice = function(DillerRpc, $route) { DillerRpcResolve.getValues = function(DillerRpc, $route) { return DillerRpc.getValues($route.current.params.propertyId); }; +DillerRpcResolve.patchProperty = function(DillerRpc, $route) { + return DillerRpc.patchProperty($route.current.params.propertyId, $route.current.params.payload); +}; diff --git a/web/static/app/app.js b/web/static/app/app.js index fa4c4cc..22c7f83 100644 --- a/web/static/app/app.js +++ b/web/static/app/app.js @@ -10,7 +10,7 @@ ctrl.device = device.data.device; - ctrl.propertyChunks = _.chunk(ctrl.device.properties, 3); + ctrl.propertyChunks = _(ctrl.device.properties).sortByAll(['name', 'key']).chunk(3).value(); ctrl.editDeviceAttribute = function (attributeName) { var outer = ctrl; @@ -18,7 +18,7 @@ controller: function ($uibModalInstance) { var ctrl = this; - ctrl.attributeName = attributeName; + ctrl.title = 'Edit device ' + attributeName; ctrl.label = attributeName.substr(0, 1).toUpperCase() + attributeName.substr(1); ctrl.value = outer.device[attributeName]; @@ -34,16 +34,19 @@ }, controllerAs: 'ctrl', bindToController: true, - templateUrl: 'app/templates/device-edit-attribute.modal.html' + templateUrl: 'app/templates/edit-attribute.modal.html' }); } } - function PropertyController($timeout, $route, DillerRpc, device, values) { + function PropertyController($timeout, $route, $uibModal, DillerRpc, device, values) { var ctrl = this; - ctrl.device = device.data.device; - ctrl.property = _.find(ctrl.device.properties, {id: $route.current.params.propertyId}); + function updateData(device) { + ctrl.device = device.data.device; + ctrl.property = _.find(ctrl.device.properties, {id: $route.current.params.propertyId}); + } + updateData(device); ctrl.values = values.data.values; var refreshPromise; @@ -59,6 +62,32 @@ $timeout.cancel(refreshPromise); }) }; + + ctrl.editPropertyAttribute = function (attributeName) { + var outer = ctrl; + $uibModal.open({ + controller: function ($uibModalInstance) { + var ctrl = this; + + ctrl.title = 'Edit property ' + attributeName; + ctrl.label = attributeName.substr(0, 1).toUpperCase() + attributeName.substr(1); + ctrl.value = outer.property[attributeName]; + + ctrl.update = function () { + DillerRpc.patchProperty(outer.property.id, {attribute: attributeName, value: ctrl.value}) + .then(function (res) { + updateData(res); + $uibModalInstance.close({}); + }, function (res) { + ctrl.error = res.data.message; + }); + }; + }, + controllerAs: 'ctrl', + bindToController: true, + templateUrl: 'app/templates/edit-attribute.modal.html' + }); + } } function TimestampFilter() { diff --git a/web/static/app/templates/device-edit-attribute.modal.html b/web/static/app/templates/device-edit-attribute.modal.html deleted file mode 100644 index 2e57f2d..0000000 --- a/web/static/app/templates/device-edit-attribute.modal.html +++ /dev/null @@ -1,32 +0,0 @@ -
- - - -
diff --git a/web/static/app/templates/device.html b/web/static/app/templates/device.html index e3c988d..09452a8 100644 --- a/web/static/app/templates/device.html +++ b/web/static/app/templates/device.html @@ -8,12 +8,15 @@ -

+

- {{ctrl.device.description}} + + + Edit description +