Tenant, EPG, Contract initial commit 24/38424/2
authorDaniel Malachovsky <dmalacho@cisco.com>
Thu, 5 May 2016 13:32:32 +0000 (15:32 +0200)
committerDaniel Malachovsky <dmalacho@cisco.com>
Tue, 10 May 2016 07:47:13 +0000 (07:47 +0000)
- added Tenant files with examples how to use
- added empty EPG and Contract files

Change-Id: I4ea6a09e14cea801d2cbf67b137dc57ac166f2d9
Signed-off-by: Daniel Malachovsky <dmalacho@cisco.com>
15 files changed:
groupbasedpolicy-ui/bundle/src/main/resources/OSGI-INF/blueprint/blueprint.xml
groupbasedpolicy-ui/module/src/main/resources/gbp/common/gbp.controller.js [new file with mode: 0644]
groupbasedpolicy-ui/module/src/main/resources/gbp/common/gbp.module.js [new file with mode: 0644]
groupbasedpolicy-ui/module/src/main/resources/gbp/common/gbp.service.js [new file with mode: 0644]
groupbasedpolicy-ui/module/src/main/resources/gbp/contract/contract.controller.js [new file with mode: 0644]
groupbasedpolicy-ui/module/src/main/resources/gbp/contract/contract.tpl.html [new file with mode: 0644]
groupbasedpolicy-ui/module/src/main/resources/gbp/epg/epg.controller.js [new file with mode: 0644]
groupbasedpolicy-ui/module/src/main/resources/gbp/epg/epg.tpl.html [new file with mode: 0644]
groupbasedpolicy-ui/module/src/main/resources/gbp/gbp.controller.js [deleted file]
groupbasedpolicy-ui/module/src/main/resources/gbp/gbp.module.js [deleted file]
groupbasedpolicy-ui/module/src/main/resources/gbp/main.js
groupbasedpolicy-ui/module/src/main/resources/gbp/tenant/tenant-list.service.js [new file with mode: 0644]
groupbasedpolicy-ui/module/src/main/resources/gbp/tenant/tenant.controller.js [new file with mode: 0644]
groupbasedpolicy-ui/module/src/main/resources/gbp/tenant/tenant.service.js [new file with mode: 0644]
groupbasedpolicy-ui/module/src/main/resources/gbp/tenant/tenant.tpl.html [new file with mode: 0644]

index 7031224b86c62fd01aca1262ce7b162ec4092a6c..d72587c44bf09dbc8c10724502c5f63cf97c733e 100644 (file)
@@ -7,7 +7,7 @@
         <property name="moduleName" value="gbp"/>
         <property name="url" value="/src/app/gbp"/>
         <property name="directory" value="/gbp"/>
-        <property name="requireJs" value="app/gbp/gbp.module"/>
+        <property name="requireJs" value="app/gbp/main"/>
         <property name="angularJs" value="app.gbp"/>
                <property name="cssDependencies">
             <list></list>
diff --git a/groupbasedpolicy-ui/module/src/main/resources/gbp/common/gbp.controller.js b/groupbasedpolicy-ui/module/src/main/resources/gbp/common/gbp.controller.js
new file mode 100644 (file)
index 0000000..ede0eff
--- /dev/null
@@ -0,0 +1,11 @@
+define(['app/gbp/common/gbp.service'], function () {
+    'use strict';
+
+    angular.module('app.gbp').controller('RootGbpCtrl', RootGbpCtrl);
+
+    RootGbpCtrl.$inject = ['$scope', 'RootGbpService'];
+
+    function RootGbpCtrl($scope, RootGbpService) {
+
+    }
+});
diff --git a/groupbasedpolicy-ui/module/src/main/resources/gbp/common/gbp.module.js b/groupbasedpolicy-ui/module/src/main/resources/gbp/common/gbp.module.js
new file mode 100644 (file)
index 0000000..37eaf5d
--- /dev/null
@@ -0,0 +1,101 @@
+define([
+    'app/routingConfig',
+    'Restangular',
+    'angular-translate-loader-partial'], function () {
+
+    var gbp = angular.module('app.gbp',
+        [
+            'app.core', 'ui.router.state', 'restangular',
+        ]);
+
+    gbp.register = gbp; // for adding services, controllers, directives etc. to angular module before bootstrap
+
+    gbp.config(function ($stateProvider, $compileProvider, $controllerProvider, $provide, NavHelperProvider,
+                         $translateProvider, $translatePartialLoaderProvider) {
+        gbp.register = {
+            controller: $controllerProvider.register,
+            directive: $compileProvider.directive,
+            factory: $provide.factory,
+            service: $provide.service,
+        };
+
+        /*$translatePartialLoaderProvider.addPart('app/gbp/assets/data/locale');*/
+
+        NavHelperProvider.addControllerUrl('app/gbp/contract/contract.controller');
+        NavHelperProvider.addControllerUrl('app/gbp/epg/epg.controller');
+        NavHelperProvider.addControllerUrl('app/gbp/common/gbp.controller');
+        NavHelperProvider.addControllerUrl('app/gbp/tenant/tenant.controller');
+
+        NavHelperProvider.addToMenu('gbp', {
+            'link': '#/gbp/index',
+            'active': 'main.gbp',
+            'title': 'GBP',
+            'icon': 'icon-level-down',
+            'page': {
+                'title': 'GBP',
+                'description': 'GBP ui',
+            },
+        });
+
+        var access = routingConfig.accessLevels;
+
+        $stateProvider.state('main.gbp', {
+            url: 'gbp',
+            abstract: true,
+            // access: access.public,
+            views: {
+                'content': {
+                    templateUrl: 'src/app/gbp/common/views/root.tpl.html',
+
+                },
+            },
+        });
+
+        $stateProvider.state('main.gbp.index', {
+            url: '/index',
+            access: access.admin,
+            views: {
+                '': {
+                    controller: 'RootGbpCtrl',
+                    templateUrl: 'src/app/gbp/common/views/index.tpl.html',
+                },
+            },
+        });
+
+        $stateProvider.state('main.gbp.tenant', {
+            url: '/tenant',
+            access: access.admin,
+            views: {
+                '': {
+                    controller: 'TenantController',
+                    templateUrl: 'src/app/gbp/tenant/tenant.tpl.html',
+                },
+            },
+        });
+
+        $stateProvider.state('main.gbp.epg', {
+            url: '/epg',
+            access: access.admin,
+            views: {
+                '': {
+                    controller: 'EpgController',
+                    templateUrl: 'src/app/gbp/epg/epg.tpl.html',
+                },
+            },
+        });
+
+        $stateProvider.state('main.gbp.contract', {
+            url: '/contract',
+            access: access.admin,
+            views: {
+                '': {
+                    controller: 'ContractController',
+                    templateUrl: 'src/app/gbp/contract/contract.tpl.html',
+                },
+            },
+        });
+
+    });
+
+    return gbp;
+});
diff --git a/groupbasedpolicy-ui/module/src/main/resources/gbp/common/gbp.service.js b/groupbasedpolicy-ui/module/src/main/resources/gbp/common/gbp.service.js
new file mode 100644 (file)
index 0000000..00e5768
--- /dev/null
@@ -0,0 +1,11 @@
+define([], function () {
+    'use strict';
+
+    angular.module('app.gbp').service('RootGbpService', RootGbpService);
+
+    RootGbpService.$inject = [];
+
+    function RootGbpService() {
+
+    }
+});
diff --git a/groupbasedpolicy-ui/module/src/main/resources/gbp/contract/contract.controller.js b/groupbasedpolicy-ui/module/src/main/resources/gbp/contract/contract.controller.js
new file mode 100644 (file)
index 0000000..5d3fa1d
--- /dev/null
@@ -0,0 +1,13 @@
+define([
+
+], function () {
+    'use strict';
+
+    angular.module('app.gbp').controller('ContractController', ContractController);
+
+    ContractController.$inject = ['$scope'];
+
+    function ContractController($scope) {
+
+    }
+});
diff --git a/groupbasedpolicy-ui/module/src/main/resources/gbp/contract/contract.tpl.html b/groupbasedpolicy-ui/module/src/main/resources/gbp/contract/contract.tpl.html
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/groupbasedpolicy-ui/module/src/main/resources/gbp/epg/epg.controller.js b/groupbasedpolicy-ui/module/src/main/resources/gbp/epg/epg.controller.js
new file mode 100644 (file)
index 0000000..44d6e3e
--- /dev/null
@@ -0,0 +1,13 @@
+define([
+
+], function () {
+    'use strict';
+
+    angular.module('app.gbp').controller('EpgController', EpgController);
+
+    EpgController.$inject = ['$scope'];
+
+    function EpgController($scope) {
+
+    }
+});
diff --git a/groupbasedpolicy-ui/module/src/main/resources/gbp/epg/epg.tpl.html b/groupbasedpolicy-ui/module/src/main/resources/gbp/epg/epg.tpl.html
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/groupbasedpolicy-ui/module/src/main/resources/gbp/gbp.controller.js b/groupbasedpolicy-ui/module/src/main/resources/gbp/gbp.controller.js
deleted file mode 100644 (file)
index c659623..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-define(['app/gbp/gbp.module'], function (gbp) {
-
-  gbp.register.controller('rootGbpCtrl', ['$rootScope', '$scope',
-    function ($rootScope, $scope) {
-
-  }]);
-});
diff --git a/groupbasedpolicy-ui/module/src/main/resources/gbp/gbp.module.js b/groupbasedpolicy-ui/module/src/main/resources/gbp/gbp.module.js
deleted file mode 100644 (file)
index afb5b37..0000000
+++ /dev/null
@@ -1,78 +0,0 @@
-define([
-    'app/routingConfig',
-    'Restangular',
-    'angular-translate-loader-partial'], function () {
-
-    var gbp = angular.module('app.gbp',
-        [
-            'app.core', 'ui.router.state', 'restangular'
-        ]);
-
-    gbp.register = gbp; // for adding services, controllers, directives etc. to angular module before bootstrap
-
-    gbp.config(function ($stateProvider,$compileProvider,$controllerProvider, $provide, NavHelperProvider,
-                         $translateProvider, $translatePartialLoaderProvider) {
-        gbp.register = {
-            controller: $controllerProvider.register,
-            directive: $compileProvider.directive,
-            factory: $provide.factory,
-            service: $provide.service
-        };
-
-        //$translatePartialLoaderProvider.addPart('app/gbp/assets/data/locale');
-
-        NavHelperProvider.addControllerUrl('app/gbp/gbp.controller');
-
-        NavHelperProvider.addToMenu('gbp', {
-            "link": "#/gbp/index",
-            "active": "main.gbp",
-            "title": "GBP",
-            "icon": "icon-level-down",
-            "page": {
-                "title": "GBP",
-                "description": "GBP ui"
-            }
-        });
-
-        var access = routingConfig.accessLevels;
-
-        $stateProvider.state('main.gbp', {
-            url: 'gbp',
-            abstract: true,
-            // access: access.public,
-            views: {
-                'content': {
-                    templateUrl: 'src/app/gbp/common/views/root.tpl.html',
-
-                }
-            }
-        });
-
-        $stateProvider.state('main.gbp.index', {
-            url: '/index',
-            access: access.admin,
-            views: {
-                '': {
-                    controller: 'rootGbpCtrl',
-                    templateUrl: 'src/app/gbp/common/views/index.tpl.html'
-                }
-            }
-        });
-
-        // TODO: serve it
-        /*$stateProvider.state('main.gbp.tenant', {
-            url: '/tenant',
-            access: access.admin,
-            views: {
-                'gbp': {
-                    controller: 'gbpTenantController',
-                    controllerAs: 'tenantCtrl',
-                    templateUrl: 'src/app/gbp/views/tenant.tpl.html'
-                }
-            }
-        });*/
-
-    });
-
-    return gbp;
-});
index 3e1ce0db9c6df29320bb020b5f529450e289f8d2..2dac6b0cff0b58ab90765b1bb3d8ded038d24797 100644 (file)
@@ -1,12 +1,6 @@
 require.config({
-  paths : {
-
-  },
-
-  shim : {
-
-  },
-
+    paths: {},
+    shim: {},
 });
 
-define(['app/gbp/gbp.module']);
+define(['app/gbp/common/gbp.module']);
diff --git a/groupbasedpolicy-ui/module/src/main/resources/gbp/tenant/tenant-list.service.js b/groupbasedpolicy-ui/module/src/main/resources/gbp/tenant/tenant-list.service.js
new file mode 100644 (file)
index 0000000..3a8ef8f
--- /dev/null
@@ -0,0 +1,53 @@
+define([], function () {
+    'use strict';
+
+    angular.module('app.gbp').service('TenantListService', TenantListService);
+
+    TenantListService.$inject = ['Restangular', 'TenantService'];
+
+    function TenantListService(Restangular, TenantService) {
+        /* methods */
+        this.createList = createList;
+
+        function TenantList() {
+            /* properties */
+            this.data = [];
+            /* methods */
+            this.setData = setData;
+            this.get = get;
+
+            /* Implementation */
+            /**
+             * fills TenantList object with data
+             * @param data
+             */
+            function setData(data) {
+                var self = this;
+                data.forEach(function (dataElement) {
+                    self.data.push(TenantService.createObject(dataElement));
+                });
+            }
+
+            function get(dataStore) {
+                /* jshint validthis:true */
+                var self = this;
+
+                var restObj = Restangular.one('restconf').one(dataStore).one('policy:tenants');
+
+                return restObj.get().then(function(data) {
+                    if (data.tenants.tenant) {
+                        self.setData(data.tenants.tenant);
+                    }
+                });
+            }
+        }
+
+        function createList() {
+            var obj = new TenantList();
+
+            return obj;
+        }
+    }
+
+    return TenantListService;
+});
diff --git a/groupbasedpolicy-ui/module/src/main/resources/gbp/tenant/tenant.controller.js b/groupbasedpolicy-ui/module/src/main/resources/gbp/tenant/tenant.controller.js
new file mode 100644 (file)
index 0000000..63ae553
--- /dev/null
@@ -0,0 +1,21 @@
+define([
+    'app/gbp/tenant/tenant.service',
+    'app/gbp/tenant/tenant-list.service',
+], function () {
+    'use strict';
+
+    angular.module('app.gbp').controller('TenantController', TenantController);
+
+    TenantController.$inject = ['$scope', 'TenantService', 'TenantListService'];
+
+    function TenantController($scope, TenantService, TenantListService) {
+        $scope.tenant = TenantService.createObject();
+        $scope.tenant.get('newTenant');
+        console.log('Tenant', $scope.tenant);
+
+        $scope.tenants = TenantListService.createList();
+        $scope.tenants.get('config');
+
+        console.log('Tenants', $scope.tenants);
+    }
+});
diff --git a/groupbasedpolicy-ui/module/src/main/resources/gbp/tenant/tenant.service.js b/groupbasedpolicy-ui/module/src/main/resources/gbp/tenant/tenant.service.js
new file mode 100644 (file)
index 0000000..7ec1ea8
--- /dev/null
@@ -0,0 +1,73 @@
+define([], function () {
+    'use strict';
+
+    angular.module('app.gbp').service('TenantService', TenantService);
+
+    TenantService.$inject = ['Restangular'];
+
+    function TenantService(Restangular) {
+        /* methods */
+        this.createObject = createObject;
+
+
+        /**
+         * Tenant constructor
+         * @constructor
+         */
+        function Tenant() {
+            /* properties */
+            this.data = {};
+            /* methods */
+            this.setData = setData;
+            this.get = get;
+
+            /* Implementation */
+            /**
+             * fills Tenant object with data
+             * @param data
+             */
+            function setData(data) {
+                this.data.id = data.id;
+                this.data.name = data.name;
+                this.data.description = data.description;
+
+                // TODO: use objects
+                this.data['forwarding-context'] = data['forwarding-context'];
+                this.data.policy = data.policy;
+            }
+
+            /**
+             * gets one Tenant object from Restconf
+             * @param id
+             * @returns {*}
+             */
+            function get(id) {
+                var self = this;
+
+                var restObj = Restangular.one('restconf').one('config').one('policy:tenants').one('tenant')
+                    .one(this.data.id || id);
+
+                return restObj.get().then(function (data) {
+                    self.setData(data.tenant[0]);
+                });
+            }
+        }
+
+        /**
+         * creates Tenant object and fills it with data if available
+         * @param data
+         * @returns {Tenant}
+         */
+        function createObject(data) {
+            var obj = new Tenant();
+
+            if (data) {
+                obj.setData(data);
+            }
+
+            return obj;
+        }
+    }
+
+    return TenantService;
+});
diff --git a/groupbasedpolicy-ui/module/src/main/resources/gbp/tenant/tenant.tpl.html b/groupbasedpolicy-ui/module/src/main/resources/gbp/tenant/tenant.tpl.html
new file mode 100644 (file)
index 0000000..7bc3436
--- /dev/null
@@ -0,0 +1,8 @@
+Tenant<br/>
+id: {{tenant.data.id}}<br/>
+name: {{tenant.data.name}}<br/>
+description: {{tenant.data.description}}<br/>
+
+<section ng-repeat="tenantElement in tenants.data">
+    {{tenantElement.data.id}}, {{tenantElement.data.name}}, {{tenantElement.data.description}}<br/>
+</section>