diff --git a/assets/js/app/device/device.controller.js b/assets/js/app/device/device.controller.js index 8a9e36b7c7..f2f7536f32 100644 --- a/assets/js/app/device/device.controller.js +++ b/assets/js/app/device/device.controller.js @@ -25,6 +25,11 @@ vm.changeValue = changeValue; vm.updateDeviceType = updateDeviceType; vm.changeTypeDisplay = changeTypeDisplay; + vm.createDevice = createDevice; + vm.deleteDevice = deleteDevice; + vm.createDeviceType = createDeviceType; + vm.deleteDeviceType = deleteDeviceType; + vm.saving = false; vm.devices = []; vm.rooms = []; @@ -65,6 +70,21 @@ vm.rooms = data.data; }); } + + function createDevice(device){ + return deviceService.create(device) + .then(function(data){ + vm.devices.push(data.data.device); + vm.newDevice = {}; + }); + } + + function deleteDevice(index, id){ + return deviceService.deleteDevice(id) + .then(function(){ + vm.devices.splice(index, 1); + }); + } function updateDevice(device){ console.log('Updating device ' + device.name); @@ -85,6 +105,9 @@ function selectDevice(device){ vm.selectedDevice = device; + vm.newType = { + device: device.id + }; return deviceService.getDeviceTypesDevice(device.id) .then(function(data){ vm.selectedDevice.types = data.data; @@ -104,6 +127,24 @@ }); } + + function createDeviceType(deviceType){ + deviceType.sensor = deviceType.sensor || false; + return deviceService.createDeviceType(deviceType) + .then(function(data){ + vm.selectedDevice.types.push(data.data); + vm.newType = { + device: vm.selectedDevice.id + }; + }); + } + + function deleteDeviceType(index, id){ + return deviceService.deleteDeviceType(id) + .then(function(data){ + vm.selectedDevice.types.splice(index, 1); + }); + } function changeTypeDisplay(type){ if(type.display) type.display = 0; diff --git a/assets/js/app/device/device.service.js b/assets/js/app/device/device.service.js index 8fd5fe0301..e296b43736 100644 --- a/assets/js/app/device/device.service.js +++ b/assets/js/app/device/device.service.js @@ -24,7 +24,7 @@ updateDevice: updateDevice, deleteDevice: deleteDevice, getDeviceTypeByRoom: getDeviceTypeByRoom, - createType: createType, + createDeviceType: createDeviceType, getDeviceTypesDevice: getDeviceTypesDevice, getTypes: getTypes, updateDeviceType: updateDeviceType, @@ -41,16 +41,20 @@ return $http({method: 'GET', url: '/device'}); } - function create(device){ - return $http({method: 'POST', url: '/device', data: device}); + function create(device, types){ + var data = { + device: device, + types: types || [] + }; + return $http({method: 'POST', url: '/device', data: data}); } function updateDevice(device){ return $http({method: 'PATCH', url: '/device/' + device.id, data: device}); } - function deleteDevice(device){ - return $http({method: 'DELETE', url: '/device/' + device.id, data: device}); + function deleteDevice(id){ + return $http({method: 'DELETE', url: '/device/' + id}); } function getDeviceTypesDevice(id){ @@ -63,7 +67,7 @@ return $http({method: 'GET', url: '/devicetype'}); } - function createType(deviceType){ + function createDeviceType(deviceType){ return $http({method: 'POST', url: '/devicetype', data: deviceType}); } @@ -71,8 +75,8 @@ return $http({method: 'PATCH', url: '/devicetype/' + deviceType.id, data: deviceType}); } - function deleteDeviceType(deviceType){ - return $http({method: 'DELETE', url: '/devicetype/' + deviceType.id, data: deviceType}); + function deleteDeviceType(id){ + return $http({method: 'DELETE', url: '/devicetype/' + id}); } function exec(deviceType, value){ diff --git a/config/locales/en.json b/config/locales/en.json index 79f5c54860..dc62e9de50 100755 --- a/config/locales/en.json +++ b/config/locales/en.json @@ -61,6 +61,11 @@ "devices-control": "Control my devices", "device-name": "Name", "device-action": "Action", + "device-create-name": "Name", + "device-create-identifier": "Identifier", + "device-create-protocol": "Protocol", + "device-create-service": "Service", + "device-create-button": "Create", "notification-update-available-title": "Update available !", "notification-update-available-text": "New version of Gladys :", "installation-step": "Step", diff --git a/config/locales/fr.json b/config/locales/fr.json index a1f258200e..084286e1a2 100755 --- a/config/locales/fr.json +++ b/config/locales/fr.json @@ -226,6 +226,11 @@ "devices-types-display": "Afficher", "devices-types-display-no": "Non", "devices-types-display-yes": "Oui", + "device-create-name": "Nom", + "device-create-identifier": "Identifier", + "device-create-protocol": "Protocol", + "device-create-service": "Service", + "device-create-button": "Créer", "notification-update-available-title": "Mise à jour disponible !", "notification-update-available-text": "Nouvelle version de Gladys :", "installation-step": "Etape", diff --git a/views/device/index.ejs b/views/device/index.ejs index 8cc19ca148..3842c6b86f 100644 --- a/views/device/index.ejs +++ b/views/device/index.ejs @@ -107,16 +107,19 @@