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