Fix test identities
[groupbasedpolicy.git] / groupbasedpolicy-ui / module / src / main / resources / gbp / epg / epg-list.service.js
1 define([], function() {
2     'use strict';
3
4     angular.module('app.gbp').service('EpgListService', EpgListService);
5
6     EpgListService.$inject = ['Restangular', 'EpgService'];
7
8     function EpgListService(Restangular, EpgService) {
9         /* methods */
10         this.createList = createList;
11
12         function EpgList() {
13             /* properties */
14             this.data = [];
15             /* methods */
16             this.setData = setData;
17             this.get = get;
18
19             /* Implementation */
20             /**
21              * fills EpgList object with data
22              * @param data
23              */
24             function setData(data) {
25                 var self = this;
26                 data.forEach(function(dataElement) {
27                     self.data.push(EpgService.createObject(dataElement));
28                 });
29             }
30
31             function get(dataStore, idTenant) {
32                 /* jshint validthis:true */
33                 var self = this;
34
35                 var restObj = Restangular.one('restconf').one(dataStore).one('policy:tenants').one('tenant')
36                     .one(idTenant).one('policy');
37
38                 return restObj.get().then(function(data) {
39                     if (data.policy['endpoint-group']) {
40                         self.setData(data.policy['endpoint-group']);
41                     }
42                 });
43             }
44         }
45
46         function createList() {
47             var obj = new EpgList();
48
49             return obj;
50         }
51     }
52
53     return EpgListService;
54 });