diff options
Diffstat (limited to 'web/static/app/app.js')
-rw-r--r-- | web/static/app/app.js | 41 |
1 files changed, 35 insertions, 6 deletions
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() { |