blob: 20cf2f06f42d4fc8e6315141909e47c3a857e2e3 [file] [log] [blame]
arpiagariu827f3922016-06-06 15:25:28 -07001'use strict';
2
3angular.module('xos.tenant', [
4 'ngResource',
5 'ngCookies',
6 'ui.router',
7 'xos.helpers'
8])
9.config(($stateProvider) => {
10 $stateProvider
11 .state('user-list', {
12 url: '/',
13 template: '<users-list></users-list>'
14 })
15 .state('site', {
arpiagariu0889ec02016-06-07 15:50:10 -070016 url: '/site/:id',
17 template: '<site-detail></site-detail>'
arpiagariu827f3922016-06-06 15:25:28 -070018
19 })
20 .state('createslice', {
arpiagariu0889ec02016-06-07 15:50:10 -070021 url: '/site/:site/slice/:id?',
22 template: '<create-slice></create-slice>'
arpiagariu827f3922016-06-06 15:25:28 -070023
arpiagariu0889ec02016-06-07 15:50:10 -070024 });
arpiagariu827f3922016-06-06 15:25:28 -070025})
26.config(function($httpProvider){
27 $httpProvider.interceptors.push('NoHyperlinks');
28})
29.directive('usersList', function(){
30 return {
31 //sites : {},
32 restrict: 'E',
33 scope: {},
34 bindToController: true,
35 controllerAs: 'vm',
36 templateUrl: 'templates/users-list.tpl.html',
arpiagariu0889ec02016-06-07 15:50:10 -070037 controller: function(Sites, SlicesPlus){
arpiagariu827f3922016-06-06 15:25:28 -070038
39
40
41 this.tableConfig = {
42 columns: [
43 {
44 label: 'Site1',
45 prop: 'name',
46 link: item => `/#/site/${item.id}`
47 },
48 {
49 label: 'Allocated',
50 prop: 'instance_total'
51 },
52 {
53 label: 'Ready',
54 prop: 'instance_total_ready'
55 }
56 ]
57 };
58
arpiagariu827f3922016-06-06 15:25:28 -070059 // retrieving user list
60 Sites.query().$promise
61 .then((users) => {
62 this.sites = users;
63 return SlicesPlus.query().$promise
64 })
65 .then((users) => {
66 this.slices = users;
67 //console.log(this.sites,this.slices);
arpiagariu0889ec02016-06-07 15:50:10 -070068 this.site_list = this.returnData(this.sites, this.slices);
arpiagariu827f3922016-06-06 15:25:28 -070069 })
70 .catch((e) => {
71 throw new Error(e);
72 });
arpiagariu827f3922016-06-06 15:25:28 -070073
74
arpiagariu0889ec02016-06-07 15:50:10 -070075 this.returnData = (sites, slices) => {
arpiagariu827f3922016-06-06 15:25:28 -070076 //console.log(sites,slices);
77 //console.log(sites.length)
arpiagariu0889ec02016-06-07 15:50:10 -070078 var i, j=0;
arpiagariu827f3922016-06-06 15:25:28 -070079 var site_list=[];
arpiagariu827f3922016-06-06 15:25:28 -070080
81 for(i = 0; i<sites.length; i++){
82 var instance_t = 0;
83 var instance_t_r = 0;
84 for(j=0;j<slices.length;j++){
arpiagariu0889ec02016-06-07 15:50:10 -070085 if (sites[i].id != null && slices[j].site !=null && sites[i].id === slices[j].site){
86 instance_t = instance_t + slices[j].instance_total;
87 instance_t_r = instance_t_r + slices[j].instance_total_ready;
88 }
arpiagariu827f3922016-06-06 15:25:28 -070089 }
90 var data_sites = {
arpiagariu0889ec02016-06-07 15:50:10 -070091 'id': sites[i].id,
92 'name': sites[i].name,
93 'instance_total': instance_t,
94 'instance_total_ready': instance_t_r
arpiagariu827f3922016-06-06 15:25:28 -070095 };
96 //console.log(sites[i].id);
97 site_list.push(data_sites);
98 }
arpiagariu0889ec02016-06-07 15:50:10 -070099 return site_list;
arpiagariu827f3922016-06-06 15:25:28 -0700100 //this.site_list = site_list;
101 }
102 }
103 };
104})
105.directive('siteDetail', function(){
106 return {
107 restrict: 'E',
108 scope: {},
109 bindToController: true,
110 controllerAs: 'sl',
111 templateUrl: 'templates/slicelist.html',
arpiagariu0889ec02016-06-07 15:50:10 -0700112 controller: function(SlicesPlus, $stateParams){
arpiagariu827f3922016-06-06 15:25:28 -0700113 this.tableConfig = {
114 columns: [
115 {
116 label: 'Slice List',
117 prop: 'name',
118 link: item => `/#/site/${item.site}/slice/${item.id}`
119 },
120 {
121 label: 'Allocated',
122 prop: 'instance_total'
123 },
124 {
125 label: 'Ready',
126 prop: 'instance_total_ready'
127 }
128 ]
129 };
130
131 // retrieving user list
132 SlicesPlus.query({
arpiagariu0889ec02016-06-07 15:50:10 -0700133 site: $stateParams.id
arpiagariu827f3922016-06-06 15:25:28 -0700134 }).$promise
135 .then((users) => {
136 this.users = users;
137 })
138 .catch((e) => {
139 throw new Error(e);
140 });
141 }
142 };
143})
144.directive('createSlice', function(){
145 return {
146 //sites : {},
147 restrict: 'E',
148 scope: {},
149 bindToController: true,
150 controllerAs: 'cs',
151 templateUrl: 'templates/createslice.html',
arpiagariu0889ec02016-06-07 15:50:10 -0700152 controller: function(Slices, SlicesPlus, $stateParams){
arpiagariu827f3922016-06-06 15:25:28 -0700153 //var sites;
154 //console.log(this.users.name);
155
156 //console.log(this.config);
157 this.config = {
arpiagariu0889ec02016-06-07 15:50:10 -0700158 exclude: ['password', 'last_login'],
159 formName: 'SliceDetails',
160 actions: [
161 {
162 label: 'Save',
163 icon: 'ok', // refers to bootstraps glyphicon
164 cb: (user) => { // receive the model
165 console.log(user);
arpiagariu827f3922016-06-06 15:25:28 -0700166 },
arpiagariu0889ec02016-06-07 15:50:10 -0700167 class: 'success'
168 }, {
169 label: 'Save and continue editing',
170 icon: 'ok', // refers to bootstraps glyphicon
171 cb: (user) => { // receive the model
172 console.log(user);
173 },
174 class: 'primary'
175 },
176 {
177 label: 'Save and add another',
178 icon: 'ok', // refers to bootstraps glyphicon
179 cb: (user) => { // receive the model
180 console.log(user);
181 },
182 class: 'primary'
183 }
184 ],
185 fields:
186 {
187 site_select: {
188 label: 'Site',
189 type: 'select',
190 validators: { required: true},
191 hint: 'The Site this Slice belongs to',
192 options: [
193 {
194 id: 0,
195 label: '---Site---'
196 },
197 {
198 id: 1,
199 label: '---Site1---'
200 }]
201
202 },
arpiagariu827f3922016-06-06 15:25:28 -0700203 first_name: {
arpiagariu0889ec02016-06-07 15:50:10 -0700204 label: 'Name',
arpiagariu827f3922016-06-06 15:25:28 -0700205 type: 'string',
arpiagariu0889ec02016-06-07 15:50:10 -0700206 hint: 'The Name of the Slice',
arpiagariu827f3922016-06-06 15:25:28 -0700207 validators: {
208 required: true
209 }
210 },
arpiagariu0889ec02016-06-07 15:50:10 -0700211 service_class: {
212 label: 'ServiceClass',
213 type: 'select',
214 validators: {required: true},
215 hint: 'The Site this Slice belongs to',
216 options: [
217 {
218 id: 1,
219 label: 'Best effort'
220 }
221 ]
222 },
arpiagariu827f3922016-06-06 15:25:28 -0700223 enabled: {
224 label: 'Enabled',
arpiagariu0889ec02016-06-07 15:50:10 -0700225 type: 'boolean',
226 hint: 'Status for this Slice'
arpiagariu827f3922016-06-06 15:25:28 -0700227 },
228 description: {
229 label: 'Description',
arpiagariu0889ec02016-06-07 15:50:10 -0700230 type: 'string',
231 hint: 'High level description of the slice and expected activities',
arpiagariu827f3922016-06-06 15:25:28 -0700232 validators: {
233 required: false,
234 minlength: 10
235 }
236 },
arpiagariu0889ec02016-06-07 15:50:10 -0700237 service: {
238 label: 'Service',
239 type: 'select',
240 validators: { required: false},
241 options: [
242 {
243 id: 0,
244 label: '--------'
245 }
246 ]
247 },
arpiagariu827f3922016-06-06 15:25:28 -0700248 slice_url: {
249 label: 'Slice url',
arpiagariu0889ec02016-06-07 15:50:10 -0700250 type: 'string',
arpiagariu827f3922016-06-06 15:25:28 -0700251 validators: {
252 required: false,
253 minlength: 10
254 }
255 },
256 max_instances: {
257 type: 'Max Instances',
258 validators: {
259 required: false,
260 min: 0
261 }
262 },
arpiagariu0889ec02016-06-07 15:50:10 -0700263 default_isolation: {
264 label: 'Default Isolation',
265 type: 'select',
266 validators: { required: false},
267 options: [
268 {
269 id: 'vm',
270 label: 'Virtual Machine'
271 },
272 {
273 id: 'container',
274 label: 'Container'
275 },
276 {
277 id: 'container_vm',
278 label: 'Container in VM'
279 }
280 ]
arpiagariu827f3922016-06-06 15:25:28 -0700281 },
arpiagariu0889ec02016-06-07 15:50:10 -0700282 default_image: {
283 label: 'Default image',
284 type: 'select',
285 validators: { required: false},
286 options: [
287 {
288 id: 0,
289 label: 'trusty-server-multi-nic'
290 }
291 ]
arpiagariu827f3922016-06-06 15:25:28 -0700292 },
arpiagariu0889ec02016-06-07 15:50:10 -0700293 network: {
294 label: 'Network',
295 type: 'select',
296 validators: { required: false},
297 options: [
298 {
299 id: 'default',
300 label: 'Default'
301 },
302 {
303 id: 'host',
304 label: 'Host'
305 },
306 {
307 id: 'bridged',
308 label: 'Bridged'
309 },
310 {
311 id: 'noauto',
312 label: 'No Automatic Networks'
313 }
314 ]
315 }
arpiagariu827f3922016-06-06 15:25:28 -0700316
arpiagariu0889ec02016-06-07 15:50:10 -0700317 }
arpiagariu827f3922016-06-06 15:25:28 -0700318 };
arpiagariu827f3922016-06-06 15:25:28 -0700319
320 var data;
321 // retrieving user list
arpiagariu0889ec02016-06-07 15:50:10 -0700322 if ($stateParams.id)
323 {
324 Slices.get({id: $stateParams.id}).$promise
325 .then((users) => {
326 this.users = users;
327 data = users;
arpiagariu2744cfb2016-06-06 17:02:29 -0700328 this.model = {
arpiagariu0889ec02016-06-07 15:50:10 -0700329 first_name: data.name,
330 service_class: data.serviceClass,
331 enabled: data.enabled,
332 description: data.description,
333 service: data.service,
334 slice_url: data.slice_url,
335 max_instances: data.max_instances,
336 default_isolation: data.default_isolation,
337 default_image: data.default_image,
338 network: data.network
339 };
340 })
341 .catch((e) => {
342 throw new Error(e);
343 });
344 }
345 else
346 {
347 this.model = {};
348 }
arpiagariu827f3922016-06-06 15:25:28 -0700349 }
350 };
arpiagariu0889ec02016-06-07 15:50:10 -0700351});