blob: 9177f7f19622535fb4687e624f1995855b3e09a2 [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){
arpiagariu9ca0b8b2016-06-10 13:28:34 -0700113 this.siteId = $stateParams.id;
arpiagariu827f3922016-06-06 15:25:28 -0700114 this.tableConfig = {
115 columns: [
116 {
117 label: 'Slice List',
118 prop: 'name',
119 link: item => `/#/site/${item.site}/slice/${item.id}`
120 },
121 {
122 label: 'Allocated',
123 prop: 'instance_total'
124 },
125 {
126 label: 'Ready',
127 prop: 'instance_total_ready'
128 }
129 ]
130 };
131
132 // retrieving user list
133 SlicesPlus.query({
arpiagariu0889ec02016-06-07 15:50:10 -0700134 site: $stateParams.id
arpiagariu827f3922016-06-06 15:25:28 -0700135 }).$promise
136 .then((users) => {
arpiagariu9ca0b8b2016-06-10 13:28:34 -0700137 this.sliceList = users;
arpiagariu827f3922016-06-06 15:25:28 -0700138 })
139 .catch((e) => {
140 throw new Error(e);
141 });
142 }
143 };
144})
145.directive('createSlice', function(){
146 return {
147 //sites : {},
148 restrict: 'E',
149 scope: {},
150 bindToController: true,
151 controllerAs: 'cs',
152 templateUrl: 'templates/createslice.html',
arpiagariu67cf3972016-06-10 13:13:36 -0700153 controller: function(Slices, SlicesPlus, Sites, Images, $stateParams, $http, $state){
arpiagariu827f3922016-06-06 15:25:28 -0700154 //var sites;
155 //console.log(this.users.name);
156
157 //console.log(this.config);
158 this.config = {
arpiagariu67cf3972016-06-10 13:13:36 -0700159 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 -0700160 formName: 'SliceDetails',
arpiagariu67cf3972016-06-10 13:13:36 -0700161 feedback: {
162 show: false,
163 message: 'Form submitted successfully !!!',
164 type: 'success'
165 },
arpiagariu0889ec02016-06-07 15:50:10 -0700166 actions: [
167 {
168 label: 'Save',
169 icon: 'ok', // refers to bootstraps glyphicon
arpiagariu67cf3972016-06-10 13:13:36 -0700170 cb: (model, form) => { // receive the model
171 if (form.$valid )
172 {
173 if(model.id){
174 var pr = Slices.update(model).$promise;
175 }
176 else{
177 var pr = Slices.save(model).$promise;
178 }
179 pr.then((users) => {
180 this.users = users;
181 data = users;
182 this.model = data;
183 this.config.feedback.show = true;
184 $state.go('site',{id : this.model.site});
185 })
186 .catch((e) => {
187 this.config.feedback.show = true;
188 this.config.feedback.type='danger';
189 if(e.data)
190 {
191 console.log(e.data.detail);
192 this.config.feedback.message = e.data.detail;
193 }
194 else {
195 this.config.feedback.message=e.statusText;}
196 });
197 }
arpiagariu827f3922016-06-06 15:25:28 -0700198 },
arpiagariu0889ec02016-06-07 15:50:10 -0700199 class: 'success'
200 }, {
201 label: 'Save and continue editing',
202 icon: 'ok', // refers to bootstraps glyphicon
arpiagariu67cf3972016-06-10 13:13:36 -0700203 cb: (model, form) => { // receive the model
204 if (form.$valid )
205 {
206 if(model.id){
207 var pr = Slices.update(model).$promise;
208 }
209 else{
210 var pr = Slices.save(model).$promise;
211 }
212 pr.then((users) => {
213 this.users = users;
214 data = users;
215 this.model = data;
216 this.config.feedback.show = true;
217 })
218 .catch((e) => {
219 this.config.feedback.show = true;
220 this.config.feedback.type='danger';
221 if(e.data)
222 {
223 console.log(e.data.detail);
224 this.config.feedback.message = e.data.detail;
225 }
226 else {
227 this.config.feedback.message=e.statusText;}
228 });
229 }
arpiagariu0889ec02016-06-07 15:50:10 -0700230 },
231 class: 'primary'
232 },
233 {
234 label: 'Save and add another',
235 icon: 'ok', // refers to bootstraps glyphicon
arpiagariu67cf3972016-06-10 13:13:36 -0700236 cb: (model, form) => { // receive the model
237 if (form.$valid )
238 {
239 if(model.id){
240 var pr = Slices.update(model).$promise;
241 }
242 else{
243 var pr = Slices.save(model).$promise;
244 }
245 pr.then((users) => {
246 this.users = users;
247 data = users;
248 this.model = data;
249 this.config.feedback.show = true;
250 })
251 .catch((e) => {
252 this.config.feedback.show = true;
253 this.config.feedback.type='danger';
254 if(e.data)
255 {
256 console.log(e.data.detail);
257 this.config.feedback.message = e.data.detail;
258 }
259 else {
260 this.config.feedback.message=e.statusText;}
261 });
262 }
arpiagariu0889ec02016-06-07 15:50:10 -0700263 },
264 class: 'primary'
265 }
266 ],
267 fields:
268 {
arpiagariu67cf3972016-06-10 13:13:36 -0700269 site: {
arpiagariu0889ec02016-06-07 15:50:10 -0700270 label: 'Site',
271 type: 'select',
272 validators: { required: true},
273 hint: 'The Site this Slice belongs to',
arpiagariu67cf3972016-06-10 13:13:36 -0700274 options: []
arpiagariu0889ec02016-06-07 15:50:10 -0700275
276 },
arpiagariu67cf3972016-06-10 13:13:36 -0700277 name: {
arpiagariu0889ec02016-06-07 15:50:10 -0700278 label: 'Name',
arpiagariu827f3922016-06-06 15:25:28 -0700279 type: 'string',
arpiagariu0889ec02016-06-07 15:50:10 -0700280 hint: 'The Name of the Slice',
arpiagariu827f3922016-06-06 15:25:28 -0700281 validators: {
282 required: true
283 }
284 },
arpiagariu67cf3972016-06-10 13:13:36 -0700285 serviceClass: {
arpiagariu0889ec02016-06-07 15:50:10 -0700286 label: 'ServiceClass',
287 type: 'select',
288 validators: {required: true},
289 hint: 'The Site this Slice belongs to',
290 options: [
291 {
292 id: 1,
293 label: 'Best effort'
294 }
295 ]
296 },
arpiagariu827f3922016-06-06 15:25:28 -0700297 enabled: {
298 label: 'Enabled',
arpiagariu0889ec02016-06-07 15:50:10 -0700299 type: 'boolean',
300 hint: 'Status for this Slice'
arpiagariu827f3922016-06-06 15:25:28 -0700301 },
302 description: {
303 label: 'Description',
arpiagariu0889ec02016-06-07 15:50:10 -0700304 type: 'string',
305 hint: 'High level description of the slice and expected activities',
arpiagariu827f3922016-06-06 15:25:28 -0700306 validators: {
307 required: false,
308 minlength: 10
309 }
310 },
arpiagariu0889ec02016-06-07 15:50:10 -0700311 service: {
312 label: 'Service',
313 type: 'select',
314 validators: { required: false},
315 options: [
316 {
317 id: 0,
318 label: '--------'
319 }
320 ]
321 },
arpiagariu827f3922016-06-06 15:25:28 -0700322 slice_url: {
323 label: 'Slice url',
arpiagariu0889ec02016-06-07 15:50:10 -0700324 type: 'string',
arpiagariu827f3922016-06-06 15:25:28 -0700325 validators: {
326 required: false,
327 minlength: 10
328 }
329 },
330 max_instances: {
331 type: 'Max Instances',
332 validators: {
333 required: false,
334 min: 0
335 }
336 },
arpiagariu0889ec02016-06-07 15:50:10 -0700337 default_isolation: {
338 label: 'Default Isolation',
339 type: 'select',
340 validators: { required: false},
341 options: [
342 {
343 id: 'vm',
344 label: 'Virtual Machine'
345 },
346 {
347 id: 'container',
348 label: 'Container'
349 },
350 {
351 id: 'container_vm',
352 label: 'Container in VM'
353 }
354 ]
arpiagariu827f3922016-06-06 15:25:28 -0700355 },
arpiagariu0889ec02016-06-07 15:50:10 -0700356 default_image: {
357 label: 'Default image',
358 type: 'select',
359 validators: { required: false},
arpiagariu67cf3972016-06-10 13:13:36 -0700360 options: []
arpiagariu827f3922016-06-06 15:25:28 -0700361 },
arpiagariu0889ec02016-06-07 15:50:10 -0700362 network: {
363 label: 'Network',
364 type: 'select',
365 validators: { required: false},
366 options: [
367 {
368 id: 'default',
369 label: 'Default'
370 },
371 {
372 id: 'host',
373 label: 'Host'
374 },
375 {
376 id: 'bridged',
377 label: 'Bridged'
378 },
379 {
380 id: 'noauto',
381 label: 'No Automatic Networks'
382 }
383 ]
384 }
arpiagariu827f3922016-06-06 15:25:28 -0700385
arpiagariu0889ec02016-06-07 15:50:10 -0700386 }
arpiagariu827f3922016-06-06 15:25:28 -0700387 };
arpiagariu67cf3972016-06-10 13:13:36 -0700388 //console.log(this.config.exclude);
arpiagariu827f3922016-06-06 15:25:28 -0700389 var data;
arpiagariu67cf3972016-06-10 13:13:36 -0700390 Images.query().$promise
391 .then((users) => {
392 this.users = users;
393 data = this.users;
394 this.optionValImg = this.setData(data, {field1: 'id', field2: 'name'});
395 this.config.fields['default_image'].options = this.optionValImg;
396 })
397 .catch((e) => {
398 throw new Error(e);
399 });
400
401 // Use this method for select by seting object in fields variable of format { field1 : "val1", field2 : "val2"}
402 this.setData = (data, fields) => {
403 var i;
404 var retObj=[];
405 for(i = 0; i<data.length; i++){
406 var optVal = {id: data[i][fields.field1], label: data[i][fields.field2]};
407 retObj.push(optVal);
408
409 }
410 //console.log(retObj);
411 return retObj;
412 };
413
arpiagariu827f3922016-06-06 15:25:28 -0700414 // retrieving user list
arpiagariu67cf3972016-06-10 13:13:36 -0700415
arpiagariu0889ec02016-06-07 15:50:10 -0700416 if ($stateParams.id)
417 {
arpiagariu67cf3972016-06-10 13:13:36 -0700418 delete this.config.fields['site'];
419 this.config.exclude.push('site');
420
421 //console.log(this.config.exclude);
422
arpiagariu0889ec02016-06-07 15:50:10 -0700423 Slices.get({id: $stateParams.id}).$promise
424 .then((users) => {
425 this.users = users;
426 data = users;
arpiagariu67cf3972016-06-10 13:13:36 -0700427 delete data.networks;
428
429 this.model = data;
arpiagariu0889ec02016-06-07 15:50:10 -0700430 })
431 .catch((e) => {
432 throw new Error(e);
433 });
434 }
435 else
436 {
arpiagariu67cf3972016-06-10 13:13:36 -0700437
438
arpiagariu0889ec02016-06-07 15:50:10 -0700439 this.model = {};
arpiagariu67cf3972016-06-10 13:13:36 -0700440 $http.get('/xoslib/tenantview/').
441 success((data) => {
442 this.userList = data;
443 console.log(this.userList);
444 //this.model={}
445 this.model['creator'] = this.userList.current_user_id;
446
447 });
448
449
450
451
452
453
454 Sites.query().$promise
455 .then((users) => {
456 this.users_site = users;
457 //console.log(users);
458 this.optionVal = this.setData(this.users_site, {field1: 'id', field2: 'name'});
459 this.config.fields['site'].options = this.optionVal;
460 //= this.optionVal;
461
462 })
463 .catch((e) => {
464 throw new Error(e);
465 });
466
arpiagariu0889ec02016-06-07 15:50:10 -0700467 }
arpiagariu827f3922016-06-06 15:25:28 -0700468 }
469 };
arpiagariu0889ec02016-06-07 15:50:10 -0700470});