Browse Source

cameras get/add/edit/del

develop
Robin Thoni 9 years ago
parent
commit
14bb0241f2

+ 6
- 0
admin/app.js View File

33
             controller:'HostsController'
33
             controller:'HostsController'
34
         });
34
         });
35
 
35
 
36
+        $stateProvider.state('cameras',{
37
+            url:'/cameras',
38
+            templateUrl:'views/cameras.html',
39
+            controller:'CamerasController'
40
+        });
41
+
36
         $urlRouterProvider.otherwise('/');
42
         $urlRouterProvider.otherwise('/');
37
 
43
 
38
         $httpProvider.interceptors.push(['luticateAuthCache', '$injector', '$q',
44
         $httpProvider.interceptors.push(['luticateAuthCache', '$injector', '$q',

+ 76
- 0
admin/controllers/cameras.controller.js View File

1
+angular.module('camotionAdmin')
2
+    .controller('CamerasController', ['$scope', 'CamerasService', 'HelperService', '$q', 'luticateAuthCache',
3
+        function($scope, CamerasService, HelperService, $q, luticateAuthCache) {
4
+
5
+            $scope.foreighLoaded = false;
6
+            $scope.hosts = {};
7
+            $scope.entityTypes = {};
8
+
9
+            $scope.luTable = {
10
+                columns: [
11
+                    {
12
+                        name: "Name",
13
+                        width: 3,
14
+                        getValue: function (item) {
15
+                            return item.Name;
16
+                        }
17
+                    },
18
+                    {
19
+                        name: "Type",
20
+                        width: 3,
21
+                        getValue: function (item) {
22
+                            return $scope.entityTypes[item.EntityTypeId].Name;
23
+                        }
24
+                    }, {
25
+                        name: "Description",
26
+                        width: 6,
27
+                        getValue: function (item) {
28
+                            return item.Description;
29
+                        }
30
+                    }
31
+                ],
32
+
33
+                canAdd: function()
34
+                {
35
+                    return luticateAuthCache.hasAllEffectivePermissions([
36
+                        'CAMOTION_CAMERA_ADD',
37
+                        'CAMOTION_HOST_GET'
38
+                    ])
39
+                },
40
+
41
+                canDel: 'CAMOTION_CAMERA_DEL',
42
+
43
+                canEdit: function()
44
+                {
45
+                    return true;
46
+                },
47
+
48
+                getLoadPagePromise: function (page, perPage, query, promise) {
49
+                    var defer = $q.defer();
50
+                    CamerasService.getAll({page: page, perPage: perPage, query: query}, promise)
51
+                        .then(function(cameras)
52
+                        {
53
+                            if (!$scope.foreighLoaded) {
54
+                                HelperService.getForeignEntities(promise).then(function (data) {
55
+                                    $scope.hosts = data.hosts;
56
+                                    $scope.entityTypes = data.entityTypes;
57
+                                    $scope.foreighLoaded = true;
58
+                                    defer.resolve(cameras);
59
+                                }, defer.reject);
60
+                            }
61
+                            else {
62
+                                defer.resolve(cameras);
63
+                            }
64
+                        }, defer.reject);
65
+                    return defer.promise;
66
+                },
67
+
68
+                getDelPromise: function (id, promise) {
69
+                    return CamerasService.del({camera_id: id}, promise);
70
+                },
71
+
72
+                getEditController: function () {
73
+                    return "CameraEdit";
74
+                }
75
+            };
76
+    }]);

+ 70
- 0
admin/controllers/modals/cameraedit.controller.js View File

1
+/**
2
+ * Created by robin on 11/4/15.
3
+ */
4
+
5
+angular.module('camotionAdmin')
6
+    .controller('CameraEditController', ['$scope', 'CamerasService', 'data', 'dialogs', '$q', 'luticateAuthCache', 'HelperService',
7
+        function($scope, CamerasService, data, dialogs, $q, luticateAuthCache, HelperService) {
8
+            if (data != null) {
9
+                $scope.camera = data;
10
+                $scope.camera.camera_id = $scope.camera.Id;
11
+                $scope.permission = "CAMOTION_CAMERA_EDIT";
12
+            }
13
+            else {
14
+                $scope.camera = {
15
+                    Name: "",
16
+                    Description: "",
17
+                    Token: "",
18
+                    HostId: null,
19
+                    EntityTypeId: null
20
+                };
21
+                $scope.permission = "CAMOTION_CAMERA_ADD";
22
+            }
23
+
24
+            $scope.hosts = {};
25
+            $scope.entityTypes = {};
26
+            var promiseLoadForeign = {
27
+                id: "promiseLoadForeign",
28
+                groups: ["modal"]
29
+            };
30
+
31
+            HelperService.getForeignEntities(promiseLoadForeign).then(function(data)
32
+            {
33
+                $scope.hosts = data.hosts;
34
+                $scope.entityTypes = data.entityTypes;
35
+                if ($scope.camera.Id == null) {
36
+                    var keys = Object.keys($scope.hosts);
37
+                    if (keys.length != 0) {
38
+                        $scope.camera.HostId = $scope.hosts[keys[0]].Id;
39
+                    }keys = Object.keys($scope.entityTypes);
40
+                    if (keys.length != 0) {
41
+                        $scope.camera.EntityTypeId = $scope.entityTypes[keys[0]].Id;
42
+                    }
43
+                }
44
+            });
45
+
46
+            $scope.submitForm = function()
47
+            {
48
+                if (luticateAuthCache.hasEffectivePermission($scope.permission)) {
49
+                    if ($scope.camera.Id != null) {
50
+                        var promiseEditCamera = {
51
+                            id: "promiseEditCamera",
52
+                            loaderGroups: ["modal"]
53
+                        };
54
+                        return CamerasService.edit($scope.camera, promiseEditCamera);
55
+                    }
56
+                    else {
57
+                        var promiseAddCamera = {
58
+                            id: "promiseAddCamera",
59
+                            loaderGroups: ["modal"]
60
+                        };
61
+                        return CamerasService.add($scope.camera, promiseAddCamera);
62
+                    }
63
+                }
64
+                else {
65
+                    var defer = $q.defer();
66
+                    defer.resolve();
67
+                    return defer.promise;
68
+                }
69
+            };
70
+        }]);

+ 4
- 0
admin/index.html View File

37
     <script src="controllers/home.controller.js"></script>
37
     <script src="controllers/home.controller.js"></script>
38
     <script src="controllers/navbar.controller.js"></script>
38
     <script src="controllers/navbar.controller.js"></script>
39
     <script src="controllers/hosts.controller.js"></script>
39
     <script src="controllers/hosts.controller.js"></script>
40
+    <script src="controllers/cameras.controller.js"></script>
40
 
41
 
41
     <!-- Modal Controller -->
42
     <!-- Modal Controller -->
42
     <script src="controllers/modals/hostedit.controller.js"></script>
43
     <script src="controllers/modals/hostedit.controller.js"></script>
44
+    <script src="controllers/modals/cameraedit.controller.js"></script>
43
 
45
 
44
     <!-- SDK -->
46
     <!-- SDK -->
47
+    <script src="../sdk/helper.js"></script>
45
     <script src="../sdk/hosts.js"></script>
48
     <script src="../sdk/hosts.js"></script>
49
+    <script src="../sdk/cameras.js"></script>
46
 
50
 
47
     <!-- Directives -->
51
     <!-- Directives -->
48
 
52
 

+ 4
- 0
admin/views/cameras.html View File

1
+<!-- Page Content -->
2
+<div class="container">
3
+    <lu-edit-table options="luTable" class="row col-sm-8 col-sm-offset-2"></lu-edit-table>
4
+</div>

+ 38
- 0
admin/views/modals/cameraedit.html View File

1
+<dialog-ok-cancel title="{{ camera.Id == null ? 'Add' : 'Edit'}} camera {{ host.Name }}">
2
+    <div class="form-group">
3
+        <label for="name" class="col-sm-2 control-label">Name</label>
4
+        <div class="col-sm-9">
5
+            <input id="name" class="form-control" ng-model="camera.Name" required lu-enable-permission="{{ permission }}"/>
6
+        </div>
7
+    </div>
8
+    <div class="form-group">
9
+        <label for="url" class="col-sm-2 control-label">Description</label>
10
+        <div class="col-sm-9">
11
+            <input id="url" class="form-control" ng-model="camera.Description" lu-enable-permission="{{ permission }}"/>
12
+        </div>
13
+    </div>
14
+    <div class="form-group">
15
+        <label for="dropdownHost" class="col-sm-2 control-label">Host</label>
16
+        <div class="btn-group">
17
+                <button class="btn btn-default dropdown-toggle" type="button" id="dropdownHost" data-toggle="dropdown">
18
+                    {{ hosts[camera.HostId].Name }}
19
+                    <span class="caret"></span>
20
+                </button>
21
+                <ul class="dropdown-menu">
22
+                    <li ng-repeat="host in hosts"><a ng-click="camera.HostId = host.Id" href="">{{ host.Name }}</a></li>
23
+                </ul>
24
+            </div>
25
+    </div>
26
+    <div class="form-group">
27
+        <label for="dropdownType" class="col-sm-2 control-label">Type</label>
28
+        <div class="btn-group">
29
+            <button class="btn btn-default dropdown-toggle" type="button" id="dropdownType" data-toggle="dropdown">
30
+                {{ entityTypes[camera.EntityTypeId].Name }}
31
+                <span class="caret"></span>
32
+            </button>
33
+            <ul class="dropdown-menu">
34
+                <li ng-repeat="type in entityTypes"><a ng-click="camera.EntityTypeId = type.Id" href="">{{ type.Name }}</a></li>
35
+            </ul>
36
+        </div>
37
+    </div>
38
+</dialog-ok-cancel>

+ 1
- 0
admin/views/navbar.html View File

17
             <ul class="nav navbar-nav navbar-left">
17
             <ul class="nav navbar-nav navbar-left">
18
                 <li><a href="/luticate" ng-show="canSeeLuticate()">Luticate</a></li>
18
                 <li><a href="/luticate" ng-show="canSeeLuticate()">Luticate</a></li>
19
                 <li><a ui-sref="hosts" lu-show-permission="CAMOTION_HOST_GET">Hosts</a></li>
19
                 <li><a ui-sref="hosts" lu-show-permission="CAMOTION_HOST_GET">Hosts</a></li>
20
+                <li><a ui-sref="cameras" lu-show-permission="CAMOTION_CAMERA_GET">Cameras</a></li>
20
             </ul>
21
             </ul>
21
             <ul class="nav navbar-nav navbar-right">
22
             <ul class="nav navbar-nav navbar-right">
22
                 <ul class="nav navbar-nav navbar-right">
23
                 <ul class="nav navbar-nav navbar-right">

+ 44
- 0
sdk/cameras.js View File

1
+/**
2
+ * Created by robin on 11/21/15.
3
+ */
4
+(function () {
5
+    'use strict';
6
+
7
+    angular.module('camotionAdmin')
8
+        .factory('CamerasService', ['luticateRequest', function (luticateRequest) {
9
+
10
+            var CamerasService = {};
11
+
12
+            CamerasService.add = function(data, promise)
13
+            {
14
+                return luticateRequest.post("/api/cameras/add", {camera: JSON.stringify(data)}, null, promise);
15
+            };
16
+
17
+            CamerasService.getAll = function(data, promise)
18
+            {
19
+                return luticateRequest.get("/api/cameras", data, promise);
20
+            };
21
+
22
+            CamerasService.getAllTypes = function(promise)
23
+            {
24
+                return luticateRequest.get("/api/cameras/types", null, promise);
25
+            };
26
+
27
+            CamerasService.get = function(data, promise)
28
+            {
29
+                return luticateRequest.get("/api/cameras/" + data.camera_id , null, promise);
30
+            };
31
+
32
+            CamerasService.edit = function(data, promise)
33
+            {
34
+                return luticateRequest.post("/api/cameras/" + data.camera_id + "/edit", {camera: JSON.stringify(data)}, null, promise);
35
+            };
36
+
37
+            CamerasService.del = function(data, promise)
38
+            {
39
+                return luticateRequest.post("/api/cameras/" + data.camera_id + "/del", null, null, promise);
40
+            };
41
+
42
+            return CamerasService;
43
+        }]);
44
+})();

+ 39
- 0
sdk/helper.js View File

1
+/**
2
+ * Created by robin on 11/21/15.
3
+ */
4
+
5
+(function () {
6
+    'use strict';
7
+
8
+    angular.module('camotionAdmin')
9
+        .factory('HelperService', ['HostsService', 'CamerasService', '$q', function (HostsService, CamerasService, $q) {
10
+
11
+            var HelperService = {};
12
+
13
+            HelperService.getForeignEntities = function (promise) {
14
+                var defer = $q.defer();
15
+                HostsService.getAll({}, promise).then(function (hosts) {
16
+                    var hostsArray = {};
17
+                    for (var i = 0; i < hosts.Data.length; ++i) {
18
+                        var host = hosts.Data[i];
19
+                        hostsArray[host.Id] = host;
20
+                    }
21
+                    CamerasService.getAllTypes(promise).then(function(types)
22
+                    {
23
+                        var typesArray = {};
24
+                        for (var i = 0; i < types.Data.length; ++i) {
25
+                            var type = types.Data[i];
26
+                            typesArray[type.Id] = type;
27
+                        }
28
+                        defer.resolve({
29
+                            hosts: hostsArray,
30
+                            entityTypes: typesArray
31
+                        });
32
+                    }, defer.reject);
33
+                }, defer.reject);
34
+                return defer.promise;
35
+            };
36
+
37
+            return HelperService;
38
+        }]);
39
+})();

Loading…
Cancel
Save