diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2015-10-31 12:04:28 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2015-10-31 12:04:28 +0100 |
commit | 02d6e77bd180cbbf6f7f6e1a69c670e922d8204d (patch) | |
tree | c55847b71e589f79ce6537f2b61f3691fe8bf220 /web/static | |
parent | dd72e7992f126c4a42a0791228400738072f297d (diff) | |
download | diller-server-02d6e77bd180cbbf6f7f6e1a69c670e922d8204d.tar.gz diller-server-02d6e77bd180cbbf6f7f6e1a69c670e922d8204d.tar.bz2 diller-server-02d6e77bd180cbbf6f7f6e1a69c670e922d8204d.tar.xz diller-server-02d6e77bd180cbbf6f7f6e1a69c670e922d8204d.zip |
web:
o Starting on edit button for device name.
Diffstat (limited to 'web/static')
-rw-r--r-- | web/static/app/DillerRpc.js | 13 | ||||
-rw-r--r-- | web/static/app/app.js | 29 | ||||
-rw-r--r-- | web/static/app/templates/device-edit-attribute.modal.html | 13 | ||||
-rw-r--r-- | web/static/app/templates/device.html | 8 |
4 files changed, 60 insertions, 3 deletions
diff --git a/web/static/app/DillerRpc.js b/web/static/app/DillerRpc.js index de90aee..b1939f4 100644 --- a/web/static/app/DillerRpc.js +++ b/web/static/app/DillerRpc.js @@ -16,6 +16,15 @@ function DillerRpc($http, DillerConfig) { return $http(req); } + function patchDevice(deviceId, payload) { + var req = {}; + req.method = 'patch'; + req.url = baseUrl + '/api/device/:deviceId'; + req.url = req.url.replace(/:deviceId/, deviceId); + req.data = payload; + return $http(req); + } + function getValues(propertyId) { var req = {}; req.method = 'get'; @@ -27,6 +36,7 @@ function DillerRpc($http, DillerConfig) { return { getDevices: getDevices, getDevice: getDevice, + patchDevice: patchDevice, getValues: getValues }; } @@ -38,6 +48,9 @@ DillerRpcResolve.getDevices = function(DillerRpc) { DillerRpcResolve.getDevice = function(DillerRpc, $route) { return DillerRpc.getDevice($route.current.params.deviceId); }; +DillerRpcResolve.patchDevice = function(DillerRpc, $route) { + return DillerRpc.patchDevice($route.current.params.deviceId, $route.current.params.payload); +}; DillerRpcResolve.getValues = function(DillerRpc, $route) { return DillerRpc.getValues($route.current.params.propertyId); }; diff --git a/web/static/app/app.js b/web/static/app/app.js index 6fa1f71..134afc8 100644 --- a/web/static/app/app.js +++ b/web/static/app/app.js @@ -5,10 +5,35 @@ ctrl.devices = devices.data.devices; } - function DeviceController(device) { + function DeviceController($uibModal, device, DillerRpc) { var ctrl = this; ctrl.device = device.data.device; + + ctrl.editDeviceAttribute = function (attributeName) { + var outer = ctrl; + $uibModal.open({ + controller: function ($uibModalInstance) { + var ctrl = this; + + ctrl.attributeName = attributeName; + ctrl.value = outer.device[attributeName]; + + ctrl.value = 'yoyo'; + + ctrl.update = function () { + + DillerRpc.patchDevice(outer.device.id, {attribute: attributeName, value: ctrl.value}) + .then(function (res) { + $uibModalInstance.close({}); + }); + }; + }, + controllerAs: 'ctrl', + bindToController: true, + templateUrl: 'app/templates/device-edit-attribute.modal.html' + }); + } } function PropertyController($timeout, $route, DillerRpc, device, values) { @@ -110,7 +135,7 @@ } angular - .module('Diller', ['ngRoute']) + .module('Diller', ['ngRoute', 'ui.bootstrap']) .config(config) .filter('timestamp', TimestampFilter) .directive('dlTimestamp', DlTimestampDirective) diff --git a/web/static/app/templates/device-edit-attribute.modal.html b/web/static/app/templates/device-edit-attribute.modal.html new file mode 100644 index 0000000..e471e5f --- /dev/null +++ b/web/static/app/templates/device-edit-attribute.modal.html @@ -0,0 +1,13 @@ +<div class="modal-header"> + <button type="button" class="close" ng-click="$dismiss()"> + <span>×</span> + </button> + <h4 class="modal-title">Edit device {{attributeName}}</h4> +</div> +<div class="modal-body"> + <p>One fine body…</p> +</div> +<div class="modal-footer"> + <button type="button" class="btn btn-secondary" ng-click="$dismiss()">Cancel</button> + <button type="button" class="btn btn-primary" ng-click="ctrl.update()">Update</button> +</div> diff --git a/web/static/app/templates/device.html b/web/static/app/templates/device.html index b8936f3..d126f1d 100644 --- a/web/static/app/templates/device.html +++ b/web/static/app/templates/device.html @@ -59,7 +59,13 @@ <dd class="col-sm-9">{{ctrl.device.created_timestamp | date}}</dd> <dt class="col-sm-3">Name</dt> - <dd class="col-sm-9"> {{ctrl.device.name}}</dd> + <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}}</dd> |