blob: 65fc90d03dd11445c1d825c1fa11d3efd2d8467f [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;
arpiagariu88086392016-06-07 15:50:10 -070067 this.site_list = this.returnData(this.sites, this.slices);
arpiagariud4f6db12016-06-06 15:25:28 -070068 })
69 .catch((e) => {
70 throw new Error(e);
71 });
arpiagariud4f6db12016-06-06 15:25:28 -070072
73
arpiagariu88086392016-06-07 15:50:10 -070074 this.returnData = (sites, slices) => {
arpiagariu88086392016-06-07 15:50:10 -070075 var i, j=0;
arpiagariud4f6db12016-06-06 15:25:28 -070076 var site_list=[];
arpiagariud4f6db12016-06-06 15:25:28 -070077
78 for(i = 0; i<sites.length; i++){
79 var instance_t = 0;
80 var instance_t_r = 0;
81 for(j=0;j<slices.length;j++){
arpiagariu88086392016-06-07 15:50:10 -070082 if (sites[i].id != null && slices[j].site !=null && sites[i].id === slices[j].site){
83 instance_t = instance_t + slices[j].instance_total;
84 instance_t_r = instance_t_r + slices[j].instance_total_ready;
85 }
arpiagariud4f6db12016-06-06 15:25:28 -070086 }
87 var data_sites = {
arpiagariu88086392016-06-07 15:50:10 -070088 'id': sites[i].id,
89 'name': sites[i].name,
90 'instance_total': instance_t,
91 'instance_total_ready': instance_t_r
arpiagariud4f6db12016-06-06 15:25:28 -070092 };
arpiagariud4f6db12016-06-06 15:25:28 -070093 site_list.push(data_sites);
94 }
arpiagariu88086392016-06-07 15:50:10 -070095 return site_list;
arpiagariud4f6db12016-06-06 15:25:28 -070096 }
97 }
98 };
99})
100.directive('siteDetail', function(){
101 return {
102 restrict: 'E',
103 scope: {},
104 bindToController: true,
105 controllerAs: 'sl',
106 templateUrl: 'templates/slicelist.html',
arpiagariu88086392016-06-07 15:50:10 -0700107 controller: function(SlicesPlus, $stateParams){
arpiagariu10bd9cb2016-06-10 13:28:34 -0700108 this.siteId = $stateParams.id;
arpiagariud4f6db12016-06-06 15:25:28 -0700109 this.tableConfig = {
110 columns: [
111 {
112 label: 'Slice List',
113 prop: 'name',
114 link: item => `/#/site/${item.site}/slice/${item.id}`
115 },
116 {
117 label: 'Allocated',
118 prop: 'instance_total'
119 },
120 {
121 label: 'Ready',
122 prop: 'instance_total_ready'
123 }
124 ]
125 };
126
127 // retrieving user list
128 SlicesPlus.query({
arpiagariu88086392016-06-07 15:50:10 -0700129 site: $stateParams.id
arpiagariud4f6db12016-06-06 15:25:28 -0700130 }).$promise
131 .then((users) => {
arpiagariu10bd9cb2016-06-10 13:28:34 -0700132 this.sliceList = users;
arpiagariud4f6db12016-06-06 15:25:28 -0700133 })
134 .catch((e) => {
135 throw new Error(e);
136 });
137 }
138 };
139})
140.directive('createSlice', function(){
141 return {
142 //sites : {},
143 restrict: 'E',
144 scope: {},
145 bindToController: true,
146 controllerAs: 'cs',
147 templateUrl: 'templates/createslice.html',
arpiagariu10bd9cb2016-06-10 13:28:34 -0700148 controller: function(Slices, SlicesPlus, Sites, Images, $stateParams, $http, $state, $q){
arpiagariud4f6db12016-06-06 15:25:28 -0700149 this.config = {
arpiagariu4a872ad2016-06-10 13:13:36 -0700150 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 -0700151 formName: 'SliceDetails',
arpiagariu4a872ad2016-06-10 13:13:36 -0700152 feedback: {
153 show: false,
154 message: 'Form submitted successfully !!!',
155 type: 'success'
156 },
arpiagariu88086392016-06-07 15:50:10 -0700157 actions: [
158 {
159 label: 'Save',
160 icon: 'ok', // refers to bootstraps glyphicon
arpiagariu4a872ad2016-06-10 13:13:36 -0700161 cb: (model, form) => { // receive the model
arpiagariu10bd9cb2016-06-10 13:28:34 -0700162 saveform(model, form).then(()=> {
163 $state.go('site', {id: this.model.site});
164 });
arpiagariud4f6db12016-06-06 15:25:28 -0700165 },
arpiagariu88086392016-06-07 15:50:10 -0700166 class: 'success'
167 }, {
168 label: 'Save and continue editing',
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);
arpiagariu88086392016-06-07 15:50:10 -0700172 },
173 class: 'primary'
174 },
175 {
176 label: 'Save and add another',
177 icon: 'ok', // refers to bootstraps glyphicon
arpiagariu10bd9cb2016-06-10 13:28:34 -0700178 cb: (model, form) => {
arpiagariuabfdab52016-06-15 10:55:41 -0700179 saveform(model,form).then(()=> {
180 $state.go('createslice',{site : this.model.site,id : ''});
181 });
arpiagariu88086392016-06-07 15:50:10 -0700182 },
183 class: 'primary'
184 }
185 ],
186 fields:
187 {
arpiagariu4a872ad2016-06-10 13:13:36 -0700188 site: {
arpiagariu88086392016-06-07 15:50:10 -0700189 label: 'Site',
190 type: 'select',
191 validators: { required: true},
192 hint: 'The Site this Slice belongs to',
arpiagariu4a872ad2016-06-10 13:13:36 -0700193 options: []
arpiagariu88086392016-06-07 15:50:10 -0700194
195 },
arpiagariu4a872ad2016-06-10 13:13:36 -0700196 name: {
arpiagariu88086392016-06-07 15:50:10 -0700197 label: 'Name',
arpiagariud4f6db12016-06-06 15:25:28 -0700198 type: 'string',
arpiagariu88086392016-06-07 15:50:10 -0700199 hint: 'The Name of the Slice',
arpiagariud4f6db12016-06-06 15:25:28 -0700200 validators: {
201 required: true
202 }
203 },
arpiagariu4a872ad2016-06-10 13:13:36 -0700204 serviceClass: {
arpiagariu88086392016-06-07 15:50:10 -0700205 label: 'ServiceClass',
206 type: 'select',
207 validators: {required: true},
208 hint: 'The Site this Slice belongs to',
209 options: [
210 {
211 id: 1,
212 label: 'Best effort'
213 }
214 ]
215 },
arpiagariud4f6db12016-06-06 15:25:28 -0700216 enabled: {
217 label: 'Enabled',
arpiagariu88086392016-06-07 15:50:10 -0700218 type: 'boolean',
219 hint: 'Status for this Slice'
arpiagariud4f6db12016-06-06 15:25:28 -0700220 },
221 description: {
222 label: 'Description',
arpiagariu88086392016-06-07 15:50:10 -0700223 type: 'string',
224 hint: 'High level description of the slice and expected activities',
arpiagariud4f6db12016-06-06 15:25:28 -0700225 validators: {
226 required: false,
227 minlength: 10
228 }
229 },
arpiagariu88086392016-06-07 15:50:10 -0700230 service: {
231 label: 'Service',
232 type: 'select',
233 validators: { required: false},
234 options: [
235 {
236 id: 0,
237 label: '--------'
238 }
239 ]
240 },
arpiagariud4f6db12016-06-06 15:25:28 -0700241 slice_url: {
242 label: 'Slice url',
arpiagariu88086392016-06-07 15:50:10 -0700243 type: 'string',
arpiagariud4f6db12016-06-06 15:25:28 -0700244 validators: {
245 required: false,
246 minlength: 10
247 }
248 },
249 max_instances: {
arpiagariu10bd9cb2016-06-10 13:28:34 -0700250 label: 'Max Instances',
251 type: 'number',
arpiagariud4f6db12016-06-06 15:25:28 -0700252 validators: {
253 required: false,
254 min: 0
255 }
256 },
arpiagariu88086392016-06-07 15:50:10 -0700257 default_isolation: {
258 label: 'Default Isolation',
259 type: 'select',
260 validators: { required: false},
261 options: [
262 {
263 id: 'vm',
264 label: 'Virtual Machine'
265 },
266 {
267 id: 'container',
268 label: 'Container'
269 },
270 {
271 id: 'container_vm',
272 label: 'Container in VM'
273 }
274 ]
arpiagariud4f6db12016-06-06 15:25:28 -0700275 },
arpiagariu88086392016-06-07 15:50:10 -0700276 default_image: {
277 label: 'Default image',
278 type: 'select',
279 validators: { required: false},
arpiagariu4a872ad2016-06-10 13:13:36 -0700280 options: []
arpiagariud4f6db12016-06-06 15:25:28 -0700281 },
arpiagariu88086392016-06-07 15:50:10 -0700282 network: {
283 label: 'Network',
284 type: 'select',
285 validators: { required: false},
286 options: [
287 {
288 id: 'default',
289 label: 'Default'
290 },
291 {
292 id: 'host',
293 label: 'Host'
294 },
295 {
296 id: 'bridged',
297 label: 'Bridged'
298 },
299 {
300 id: 'noauto',
301 label: 'No Automatic Networks'
302 }
303 ]
304 }
arpiagariud4f6db12016-06-06 15:25:28 -0700305
arpiagariu88086392016-06-07 15:50:10 -0700306 }
arpiagariud4f6db12016-06-06 15:25:28 -0700307 };
arpiagariud4f6db12016-06-06 15:25:28 -0700308 var data;
arpiagariu4a872ad2016-06-10 13:13:36 -0700309 Images.query().$promise
310 .then((users) => {
311 this.users = users;
312 data = this.users;
313 this.optionValImg = this.setData(data, {field1: 'id', field2: 'name'});
314 this.config.fields['default_image'].options = this.optionValImg;
315 })
316 .catch((e) => {
317 throw new Error(e);
318 });
319
320 // Use this method for select by seting object in fields variable of format { field1 : "val1", field2 : "val2"}
321 this.setData = (data, fields) => {
322 var i;
323 var retObj=[];
324 for(i = 0; i<data.length; i++){
325 var optVal = {id: data[i][fields.field1], label: data[i][fields.field2]};
326 retObj.push(optVal);
327
328 }
arpiagariu4a872ad2016-06-10 13:13:36 -0700329 return retObj;
330 };
331
arpiagariud4f6db12016-06-06 15:25:28 -0700332 // retrieving user list
arpiagariu4a872ad2016-06-10 13:13:36 -0700333
arpiagariu88086392016-06-07 15:50:10 -0700334 if ($stateParams.id)
335 {
arpiagariu4a872ad2016-06-10 13:13:36 -0700336 delete this.config.fields['site'];
337 this.config.exclude.push('site');
338
arpiagariu88086392016-06-07 15:50:10 -0700339 Slices.get({id: $stateParams.id}).$promise
340 .then((users) => {
341 this.users = users;
342 data = users;
arpiagariu4a872ad2016-06-10 13:13:36 -0700343
344 this.model = data;
arpiagariu88086392016-06-07 15:50:10 -0700345 })
346 .catch((e) => {
347 throw new Error(e);
348 });
349 }
350 else
351 {
arpiagariu4a872ad2016-06-10 13:13:36 -0700352
353
arpiagariu88086392016-06-07 15:50:10 -0700354 this.model = {};
arpiagariu4a872ad2016-06-10 13:13:36 -0700355 $http.get('/xoslib/tenantview/').
356 success((data) => {
357 this.userList = data;
arpiagariu4a872ad2016-06-10 13:13:36 -0700358 this.model['creator'] = this.userList.current_user_id;
359
360 });
361
362
363
364
365
366
367 Sites.query().$promise
368 .then((users) => {
369 this.users_site = users;
arpiagariu4a872ad2016-06-10 13:13:36 -0700370 this.optionVal = this.setData(this.users_site, {field1: 'id', field2: 'name'});
371 this.config.fields['site'].options = this.optionVal;
372 //= this.optionVal;
373
374 })
375 .catch((e) => {
376 throw new Error(e);
377 });
378
arpiagariu88086392016-06-07 15:50:10 -0700379 }
arpiagariu10bd9cb2016-06-10 13:28:34 -0700380
381 var saveform = (model,form) =>
382 { // receive the model
383 var deferred = $q.defer();
384 delete model.networks;
arpiagariuabfdab52016-06-15 10:55:41 -0700385 if (form.$valid )
386 {
387 if(model.id){
388 var pr = Slices.update(model).$promise;
389 }
390 else{
391 var pr = Slices.save(model).$promise;
392 }
393 pr.then((users) => {
394 this.model = users;
395 //data = users;
396 //this.model = this.users;
397 this.config.feedback.show = true;
398 deferred.resolve(this.model);
399 })
400 .catch((e) => {
401 this.config.feedback.show = true;
402 this.config.feedback.type='danger';
403 if(e.data && e.data.detail )
404 {
405 this.config.feedback.message = e.data.detail;
arpiagariu10bd9cb2016-06-10 13:28:34 -0700406 }
arpiagariuabfdab52016-06-15 10:55:41 -0700407 else {
408 this.config.feedback.message=e.statusText;
409 }
410 deferred.reject(e);
411 });
412 }
413
414 return deferred.promise;
415 }
arpiagariud4f6db12016-06-06 15:25:28 -0700416 }
417 };
arpiagariu88086392016-06-07 15:50:10 -0700418});