blob: a08764ee83c63fafc81f5eb0020ce41ee141e8b5 [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',
arpiagariu67cf3972016-06-10 13:13:36 -0700152 controller: function(Slices, SlicesPlus, Sites, Images, $stateParams, $http, $state){
arpiagariu827f3922016-06-06 15:25:28 -0700153 //var sites;
154 //console.log(this.users.name);
155
156 //console.log(this.config);
157 this.config = {
arpiagariu67cf3972016-06-10 13:13:36 -0700158 exclude: ['site', 'password', 'last_login', 'mount_data_sets', 'default_flavor', 'creator', 'exposed_ports', 'networks', 'omf_friendly', 'omf_friendly', 'no_sync', 'no_policy', 'lazy_blocked', 'write_protect', 'deleted', 'backend_status', 'backend_register', 'policed', 'enacted', 'updated', 'created', 'validators', 'humanReadableName'],
arpiagariu0889ec02016-06-07 15:50:10 -0700159 formName: 'SliceDetails',
arpiagariu67cf3972016-06-10 13:13:36 -0700160 feedback: {
161 show: false,
162 message: 'Form submitted successfully !!!',
163 type: 'success'
164 },
arpiagariu0889ec02016-06-07 15:50:10 -0700165 actions: [
166 {
167 label: 'Save',
168 icon: 'ok', // refers to bootstraps glyphicon
arpiagariu67cf3972016-06-10 13:13:36 -0700169 cb: (model, form) => { // receive the model
170 if (form.$valid )
171 {
172 if(model.id){
173 var pr = Slices.update(model).$promise;
174 }
175 else{
176 var pr = Slices.save(model).$promise;
177 }
178 pr.then((users) => {
179 this.users = users;
180 data = users;
181 this.model = data;
182 this.config.feedback.show = true;
183 $state.go('site',{id : this.model.site});
184 })
185 .catch((e) => {
186 this.config.feedback.show = true;
187 this.config.feedback.type='danger';
188 if(e.data)
189 {
190 console.log(e.data.detail);
191 this.config.feedback.message = e.data.detail;
192 }
193 else {
194 this.config.feedback.message=e.statusText;}
195 });
196 }
arpiagariu827f3922016-06-06 15:25:28 -0700197 },
arpiagariu0889ec02016-06-07 15:50:10 -0700198 class: 'success'
199 }, {
200 label: 'Save and continue editing',
201 icon: 'ok', // refers to bootstraps glyphicon
arpiagariu67cf3972016-06-10 13:13:36 -0700202 cb: (model, form) => { // receive the model
203 if (form.$valid )
204 {
205 if(model.id){
206 var pr = Slices.update(model).$promise;
207 }
208 else{
209 var pr = Slices.save(model).$promise;
210 }
211 pr.then((users) => {
212 this.users = users;
213 data = users;
214 this.model = data;
215 this.config.feedback.show = true;
216 })
217 .catch((e) => {
218 this.config.feedback.show = true;
219 this.config.feedback.type='danger';
220 if(e.data)
221 {
222 console.log(e.data.detail);
223 this.config.feedback.message = e.data.detail;
224 }
225 else {
226 this.config.feedback.message=e.statusText;}
227 });
228 }
arpiagariu0889ec02016-06-07 15:50:10 -0700229 },
230 class: 'primary'
231 },
232 {
233 label: 'Save and add another',
234 icon: 'ok', // refers to bootstraps glyphicon
arpiagariu67cf3972016-06-10 13:13:36 -0700235 cb: (model, form) => { // receive the model
236 if (form.$valid )
237 {
238 if(model.id){
239 var pr = Slices.update(model).$promise;
240 }
241 else{
242 var pr = Slices.save(model).$promise;
243 }
244 pr.then((users) => {
245 this.users = users;
246 data = users;
247 this.model = data;
248 this.config.feedback.show = true;
249 })
250 .catch((e) => {
251 this.config.feedback.show = true;
252 this.config.feedback.type='danger';
253 if(e.data)
254 {
255 console.log(e.data.detail);
256 this.config.feedback.message = e.data.detail;
257 }
258 else {
259 this.config.feedback.message=e.statusText;}
260 });
261 }
arpiagariu0889ec02016-06-07 15:50:10 -0700262 },
263 class: 'primary'
264 }
265 ],
266 fields:
267 {
arpiagariu67cf3972016-06-10 13:13:36 -0700268 site: {
arpiagariu0889ec02016-06-07 15:50:10 -0700269 label: 'Site',
270 type: 'select',
271 validators: { required: true},
272 hint: 'The Site this Slice belongs to',
arpiagariu67cf3972016-06-10 13:13:36 -0700273 options: []
arpiagariu0889ec02016-06-07 15:50:10 -0700274
275 },
arpiagariu67cf3972016-06-10 13:13:36 -0700276 name: {
arpiagariu0889ec02016-06-07 15:50:10 -0700277 label: 'Name',
arpiagariu827f3922016-06-06 15:25:28 -0700278 type: 'string',
arpiagariu0889ec02016-06-07 15:50:10 -0700279 hint: 'The Name of the Slice',
arpiagariu827f3922016-06-06 15:25:28 -0700280 validators: {
281 required: true
282 }
283 },
arpiagariu67cf3972016-06-10 13:13:36 -0700284 serviceClass: {
arpiagariu0889ec02016-06-07 15:50:10 -0700285 label: 'ServiceClass',
286 type: 'select',
287 validators: {required: true},
288 hint: 'The Site this Slice belongs to',
289 options: [
290 {
291 id: 1,
292 label: 'Best effort'
293 }
294 ]
295 },
arpiagariu827f3922016-06-06 15:25:28 -0700296 enabled: {
297 label: 'Enabled',
arpiagariu0889ec02016-06-07 15:50:10 -0700298 type: 'boolean',
299 hint: 'Status for this Slice'
arpiagariu827f3922016-06-06 15:25:28 -0700300 },
301 description: {
302 label: 'Description',
arpiagariu0889ec02016-06-07 15:50:10 -0700303 type: 'string',
304 hint: 'High level description of the slice and expected activities',
arpiagariu827f3922016-06-06 15:25:28 -0700305 validators: {
306 required: false,
307 minlength: 10
308 }
309 },
arpiagariu0889ec02016-06-07 15:50:10 -0700310 service: {
311 label: 'Service',
312 type: 'select',
313 validators: { required: false},
314 options: [
315 {
316 id: 0,
317 label: '--------'
318 }
319 ]
320 },
arpiagariu827f3922016-06-06 15:25:28 -0700321 slice_url: {
322 label: 'Slice url',
arpiagariu0889ec02016-06-07 15:50:10 -0700323 type: 'string',
arpiagariu827f3922016-06-06 15:25:28 -0700324 validators: {
325 required: false,
326 minlength: 10
327 }
328 },
329 max_instances: {
330 type: 'Max Instances',
331 validators: {
332 required: false,
333 min: 0
334 }
335 },
arpiagariu0889ec02016-06-07 15:50:10 -0700336 default_isolation: {
337 label: 'Default Isolation',
338 type: 'select',
339 validators: { required: false},
340 options: [
341 {
342 id: 'vm',
343 label: 'Virtual Machine'
344 },
345 {
346 id: 'container',
347 label: 'Container'
348 },
349 {
350 id: 'container_vm',
351 label: 'Container in VM'
352 }
353 ]
arpiagariu827f3922016-06-06 15:25:28 -0700354 },
arpiagariu0889ec02016-06-07 15:50:10 -0700355 default_image: {
356 label: 'Default image',
357 type: 'select',
358 validators: { required: false},
arpiagariu67cf3972016-06-10 13:13:36 -0700359 options: []
arpiagariu827f3922016-06-06 15:25:28 -0700360 },
arpiagariu0889ec02016-06-07 15:50:10 -0700361 network: {
362 label: 'Network',
363 type: 'select',
364 validators: { required: false},
365 options: [
366 {
367 id: 'default',
368 label: 'Default'
369 },
370 {
371 id: 'host',
372 label: 'Host'
373 },
374 {
375 id: 'bridged',
376 label: 'Bridged'
377 },
378 {
379 id: 'noauto',
380 label: 'No Automatic Networks'
381 }
382 ]
383 }
arpiagariu827f3922016-06-06 15:25:28 -0700384
arpiagariu0889ec02016-06-07 15:50:10 -0700385 }
arpiagariu827f3922016-06-06 15:25:28 -0700386 };
arpiagariu67cf3972016-06-10 13:13:36 -0700387 //console.log(this.config.exclude);
arpiagariu827f3922016-06-06 15:25:28 -0700388 var data;
arpiagariu67cf3972016-06-10 13:13:36 -0700389 Images.query().$promise
390 .then((users) => {
391 this.users = users;
392 data = this.users;
393 this.optionValImg = this.setData(data, {field1: 'id', field2: 'name'});
394 this.config.fields['default_image'].options = this.optionValImg;
395 })
396 .catch((e) => {
397 throw new Error(e);
398 });
399
400 // Use this method for select by seting object in fields variable of format { field1 : "val1", field2 : "val2"}
401 this.setData = (data, fields) => {
402 var i;
403 var retObj=[];
404 for(i = 0; i<data.length; i++){
405 var optVal = {id: data[i][fields.field1], label: data[i][fields.field2]};
406 retObj.push(optVal);
407
408 }
409 //console.log(retObj);
410 return retObj;
411 };
412
arpiagariu827f3922016-06-06 15:25:28 -0700413 // retrieving user list
arpiagariu67cf3972016-06-10 13:13:36 -0700414
arpiagariu0889ec02016-06-07 15:50:10 -0700415 if ($stateParams.id)
416 {
arpiagariu67cf3972016-06-10 13:13:36 -0700417 delete this.config.fields['site'];
418 this.config.exclude.push('site');
419
420 //console.log(this.config.exclude);
421
arpiagariu0889ec02016-06-07 15:50:10 -0700422 Slices.get({id: $stateParams.id}).$promise
423 .then((users) => {
424 this.users = users;
425 data = users;
arpiagariu67cf3972016-06-10 13:13:36 -0700426 delete data.networks;
427
428 this.model = data;
arpiagariu0889ec02016-06-07 15:50:10 -0700429 })
430 .catch((e) => {
431 throw new Error(e);
432 });
433 }
434 else
435 {
arpiagariu67cf3972016-06-10 13:13:36 -0700436
437
arpiagariu0889ec02016-06-07 15:50:10 -0700438 this.model = {};
arpiagariu67cf3972016-06-10 13:13:36 -0700439 $http.get('/xoslib/tenantview/').
440 success((data) => {
441 this.userList = data;
442 console.log(this.userList);
443 //this.model={}
444 this.model['creator'] = this.userList.current_user_id;
445
446 });
447
448
449
450
451
452
453 Sites.query().$promise
454 .then((users) => {
455 this.users_site = users;
456 //console.log(users);
457 this.optionVal = this.setData(this.users_site, {field1: 'id', field2: 'name'});
458 this.config.fields['site'].options = this.optionVal;
459 //= this.optionVal;
460
461 })
462 .catch((e) => {
463 throw new Error(e);
464 });
465
arpiagariu0889ec02016-06-07 15:50:10 -0700466 }
arpiagariu827f3922016-06-06 15:25:28 -0700467 }
468 };
arpiagariu0889ec02016-06-07 15:50:10 -0700469});