blob: e5f702e600697d1731091bc8a30d431aa2e6a15f [file] [log] [blame]
arpiagariud4f6db12016-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', {
arpiagariu88086392016-06-07 15:50:10 -070016 url: '/site/:id',
17 template: '<site-detail></site-detail>'
arpiagariud4f6db12016-06-06 15:25:28 -070018
19 })
20 .state('createslice', {
arpiagariu88086392016-06-07 15:50:10 -070021 url: '/site/:site/slice/:id?',
22 template: '<create-slice></create-slice>'
arpiagariud4f6db12016-06-06 15:25:28 -070023
arpiagariu88086392016-06-07 15:50:10 -070024 });
arpiagariud4f6db12016-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',
arpiagariu88086392016-06-07 15:50:10 -070037 controller: function(Sites, SlicesPlus){
arpiagariud4f6db12016-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
arpiagariud4f6db12016-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);
arpiagariu88086392016-06-07 15:50:10 -070068 this.site_list = this.returnData(this.sites, this.slices);
arpiagariud4f6db12016-06-06 15:25:28 -070069 })
70 .catch((e) => {
71 throw new Error(e);
72 });
arpiagariud4f6db12016-06-06 15:25:28 -070073
74
arpiagariu88086392016-06-07 15:50:10 -070075 this.returnData = (sites, slices) => {
arpiagariud4f6db12016-06-06 15:25:28 -070076 //console.log(sites,slices);
77 //console.log(sites.length)
arpiagariu88086392016-06-07 15:50:10 -070078 var i, j=0;
arpiagariud4f6db12016-06-06 15:25:28 -070079 var site_list=[];
arpiagariud4f6db12016-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++){
arpiagariu88086392016-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 }
arpiagariud4f6db12016-06-06 15:25:28 -070089 }
90 var data_sites = {
arpiagariu88086392016-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
arpiagariud4f6db12016-06-06 15:25:28 -070095 };
96 //console.log(sites[i].id);
97 site_list.push(data_sites);
98 }
arpiagariu88086392016-06-07 15:50:10 -070099 return site_list;
arpiagariud4f6db12016-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',
arpiagariu88086392016-06-07 15:50:10 -0700112 controller: function(SlicesPlus, $stateParams){
arpiagariu10bd9cb2016-06-10 13:28:34 -0700113 this.siteId = $stateParams.id;
arpiagariud4f6db12016-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({
arpiagariu88086392016-06-07 15:50:10 -0700134 site: $stateParams.id
arpiagariud4f6db12016-06-06 15:25:28 -0700135 }).$promise
136 .then((users) => {
arpiagariu10bd9cb2016-06-10 13:28:34 -0700137 this.sliceList = users;
arpiagariud4f6db12016-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',
arpiagariu10bd9cb2016-06-10 13:28:34 -0700153 controller: function(Slices, SlicesPlus, Sites, Images, $stateParams, $http, $state, $q){
arpiagariud4f6db12016-06-06 15:25:28 -0700154 //var sites;
155 //console.log(this.users.name);
156
157 //console.log(this.config);
158 this.config = {
arpiagariu4a872ad2016-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'],
arpiagariu88086392016-06-07 15:50:10 -0700160 formName: 'SliceDetails',
arpiagariu4a872ad2016-06-10 13:13:36 -0700161 feedback: {
162 show: false,
163 message: 'Form submitted successfully !!!',
164 type: 'success'
165 },
arpiagariu88086392016-06-07 15:50:10 -0700166 actions: [
167 {
168 label: 'Save',
169 icon: 'ok', // refers to bootstraps glyphicon
arpiagariu4a872ad2016-06-10 13:13:36 -0700170 cb: (model, form) => { // receive the model
arpiagariu10bd9cb2016-06-10 13:28:34 -0700171 saveform(model, form).then(()=> {
172 $state.go('site', {id: this.model.site});
173 });
arpiagariud4f6db12016-06-06 15:25:28 -0700174 },
arpiagariu88086392016-06-07 15:50:10 -0700175 class: 'success'
176 }, {
177 label: 'Save and continue editing',
178 icon: 'ok', // refers to bootstraps glyphicon
arpiagariu4a872ad2016-06-10 13:13:36 -0700179 cb: (model, form) => { // receive the model
arpiagariu10bd9cb2016-06-10 13:28:34 -0700180 saveform(model,form);
arpiagariu88086392016-06-07 15:50:10 -0700181 },
182 class: 'primary'
183 },
184 {
185 label: 'Save and add another',
186 icon: 'ok', // refers to bootstraps glyphicon
arpiagariu10bd9cb2016-06-10 13:28:34 -0700187 cb: (model, form) => {
188 saveform(model,form).then(()=> {
189 $state.go('createslice',{site : this.model.site,id : ''});
190 });
arpiagariu88086392016-06-07 15:50:10 -0700191 },
192 class: 'primary'
193 }
194 ],
195 fields:
196 {
arpiagariu4a872ad2016-06-10 13:13:36 -0700197 site: {
arpiagariu88086392016-06-07 15:50:10 -0700198 label: 'Site',
199 type: 'select',
200 validators: { required: true},
201 hint: 'The Site this Slice belongs to',
arpiagariu4a872ad2016-06-10 13:13:36 -0700202 options: []
arpiagariu88086392016-06-07 15:50:10 -0700203
204 },
arpiagariu4a872ad2016-06-10 13:13:36 -0700205 name: {
arpiagariu88086392016-06-07 15:50:10 -0700206 label: 'Name',
arpiagariud4f6db12016-06-06 15:25:28 -0700207 type: 'string',
arpiagariu88086392016-06-07 15:50:10 -0700208 hint: 'The Name of the Slice',
arpiagariud4f6db12016-06-06 15:25:28 -0700209 validators: {
210 required: true
211 }
212 },
arpiagariu4a872ad2016-06-10 13:13:36 -0700213 serviceClass: {
arpiagariu88086392016-06-07 15:50:10 -0700214 label: 'ServiceClass',
215 type: 'select',
216 validators: {required: true},
217 hint: 'The Site this Slice belongs to',
218 options: [
219 {
220 id: 1,
221 label: 'Best effort'
222 }
223 ]
224 },
arpiagariud4f6db12016-06-06 15:25:28 -0700225 enabled: {
226 label: 'Enabled',
arpiagariu88086392016-06-07 15:50:10 -0700227 type: 'boolean',
228 hint: 'Status for this Slice'
arpiagariud4f6db12016-06-06 15:25:28 -0700229 },
230 description: {
231 label: 'Description',
arpiagariu88086392016-06-07 15:50:10 -0700232 type: 'string',
233 hint: 'High level description of the slice and expected activities',
arpiagariud4f6db12016-06-06 15:25:28 -0700234 validators: {
235 required: false,
236 minlength: 10
237 }
238 },
arpiagariu88086392016-06-07 15:50:10 -0700239 service: {
240 label: 'Service',
241 type: 'select',
242 validators: { required: false},
243 options: [
244 {
245 id: 0,
246 label: '--------'
247 }
248 ]
249 },
arpiagariud4f6db12016-06-06 15:25:28 -0700250 slice_url: {
251 label: 'Slice url',
arpiagariu88086392016-06-07 15:50:10 -0700252 type: 'string',
arpiagariud4f6db12016-06-06 15:25:28 -0700253 validators: {
254 required: false,
255 minlength: 10
256 }
257 },
258 max_instances: {
arpiagariu10bd9cb2016-06-10 13:28:34 -0700259 label: 'Max Instances',
260 type: 'number',
arpiagariud4f6db12016-06-06 15:25:28 -0700261 validators: {
262 required: false,
263 min: 0
264 }
265 },
arpiagariu88086392016-06-07 15:50:10 -0700266 default_isolation: {
267 label: 'Default Isolation',
268 type: 'select',
269 validators: { required: false},
270 options: [
271 {
272 id: 'vm',
273 label: 'Virtual Machine'
274 },
275 {
276 id: 'container',
277 label: 'Container'
278 },
279 {
280 id: 'container_vm',
281 label: 'Container in VM'
282 }
283 ]
arpiagariud4f6db12016-06-06 15:25:28 -0700284 },
arpiagariu88086392016-06-07 15:50:10 -0700285 default_image: {
286 label: 'Default image',
287 type: 'select',
288 validators: { required: false},
arpiagariu4a872ad2016-06-10 13:13:36 -0700289 options: []
arpiagariud4f6db12016-06-06 15:25:28 -0700290 },
arpiagariu88086392016-06-07 15:50:10 -0700291 network: {
292 label: 'Network',
293 type: 'select',
294 validators: { required: false},
295 options: [
296 {
297 id: 'default',
298 label: 'Default'
299 },
300 {
301 id: 'host',
302 label: 'Host'
303 },
304 {
305 id: 'bridged',
306 label: 'Bridged'
307 },
308 {
309 id: 'noauto',
310 label: 'No Automatic Networks'
311 }
312 ]
313 }
arpiagariud4f6db12016-06-06 15:25:28 -0700314
arpiagariu88086392016-06-07 15:50:10 -0700315 }
arpiagariud4f6db12016-06-06 15:25:28 -0700316 };
arpiagariu4a872ad2016-06-10 13:13:36 -0700317 //console.log(this.config.exclude);
arpiagariud4f6db12016-06-06 15:25:28 -0700318 var data;
arpiagariu4a872ad2016-06-10 13:13:36 -0700319 Images.query().$promise
320 .then((users) => {
321 this.users = users;
322 data = this.users;
323 this.optionValImg = this.setData(data, {field1: 'id', field2: 'name'});
324 this.config.fields['default_image'].options = this.optionValImg;
325 })
326 .catch((e) => {
327 throw new Error(e);
328 });
329
330 // Use this method for select by seting object in fields variable of format { field1 : "val1", field2 : "val2"}
331 this.setData = (data, fields) => {
332 var i;
333 var retObj=[];
334 for(i = 0; i<data.length; i++){
335 var optVal = {id: data[i][fields.field1], label: data[i][fields.field2]};
336 retObj.push(optVal);
337
338 }
339 //console.log(retObj);
340 return retObj;
341 };
342
arpiagariud4f6db12016-06-06 15:25:28 -0700343 // retrieving user list
arpiagariu4a872ad2016-06-10 13:13:36 -0700344
arpiagariu88086392016-06-07 15:50:10 -0700345 if ($stateParams.id)
346 {
arpiagariu4a872ad2016-06-10 13:13:36 -0700347 delete this.config.fields['site'];
348 this.config.exclude.push('site');
349
350 //console.log(this.config.exclude);
351
arpiagariu88086392016-06-07 15:50:10 -0700352 Slices.get({id: $stateParams.id}).$promise
353 .then((users) => {
354 this.users = users;
355 data = users;
arpiagariu4a872ad2016-06-10 13:13:36 -0700356
357 this.model = data;
arpiagariu88086392016-06-07 15:50:10 -0700358 })
359 .catch((e) => {
360 throw new Error(e);
361 });
362 }
363 else
364 {
arpiagariu4a872ad2016-06-10 13:13:36 -0700365
366
arpiagariu88086392016-06-07 15:50:10 -0700367 this.model = {};
arpiagariu4a872ad2016-06-10 13:13:36 -0700368 $http.get('/xoslib/tenantview/').
369 success((data) => {
370 this.userList = data;
371 console.log(this.userList);
372 //this.model={}
373 this.model['creator'] = this.userList.current_user_id;
374
375 });
376
377
378
379
380
381
382 Sites.query().$promise
383 .then((users) => {
384 this.users_site = users;
385 //console.log(users);
386 this.optionVal = this.setData(this.users_site, {field1: 'id', field2: 'name'});
387 this.config.fields['site'].options = this.optionVal;
388 //= this.optionVal;
389
390 })
391 .catch((e) => {
392 throw new Error(e);
393 });
394
arpiagariu88086392016-06-07 15:50:10 -0700395 }
arpiagariu10bd9cb2016-06-10 13:28:34 -0700396
397 var saveform = (model,form) =>
398 { // receive the model
399 var deferred = $q.defer();
400 delete model.networks;
401 if (form.$valid )
402 {
403 if(model.id){
404 var pr = Slices.update(model).$promise;
405 }
406 else{
407 var pr = Slices.save(model).$promise;
408 }
409 pr.then((users) => {
410 this.model = users;
411 //data = users;
412 //this.model = this.users;
413 this.config.feedback.show = true;
414 deferred.resolve(this.model);
415 })
416 .catch((e) => {
417 this.config.feedback.show = true;
418 this.config.feedback.type='danger';
419 if(e.data && e.data.detail )
420 {
421 this.config.feedback.message = e.data.detail;
422 }
423 else {
424 this.config.feedback.message=e.statusText;
425 }
426 deferred.reject(e);
427 });
428 }
429
430 return deferred.promise;
431 }
arpiagariud4f6db12016-06-06 15:25:28 -0700432 }
433 };
arpiagariu88086392016-06-07 15:50:10 -0700434});