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/app.js | 41 +++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) (limited to 'web/static/app/app.js') 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() { -- cgit v1.2.3