angular.module('camotionAdmin') .controller('SensorsController', ['$scope', 'SensorsService', 'HelperService', '$q', 'luticateAuthCache', function($scope, SensorsService, HelperService, $q, luticateAuthCache) { $scope.foreighLoaded = false; $scope.hosts = {}; $scope.sensorTypes = {}; $scope.luTable = { columns: [ { name: "Name", width: 3, getValue: function (item) { return item.Name; } }, { name: "Type", width: 3, getValue: function (item) { return $scope.sensorTypes[item.SensorTypeId].Name; } }, { name: "Description", width: 6, getValue: function (item) { return item.Description; } } ], canAdd: function() { return luticateAuthCache.hasAllEffectivePermissions([ 'CAMOTION_SENSOR_ADD', 'CAMOTION_HOST_GET' ]) }, canDel: 'CAMOTION_SENSOR_DEL', canEdit: function() { return true; }, getLoadPagePromise: function (page, perPage, query, promise) { var defer = $q.defer(); SensorsService.getAll({page: page, perPage: perPage, query: query}, promise) .then(function(sensors) { if (!$scope.foreighLoaded) { HelperService.getForeignEntities(SensorsService, promise).then(function (data) { $scope.hosts = data.hosts; $scope.sensorTypes = data.types; $scope.foreighLoaded = true; defer.resolve(sensors); }, defer.reject); } else { defer.resolve(sensors); } }, defer.reject); return defer.promise; }, getDelPromise: function (id, promise) { return SensorsService.del({sensor_id: id}, promise); }, getEditController: function () { return "SensorEdit"; } }; }]);