arpiagariu | 827f392 | 2016-06-06 15:25:28 -0700 | [diff] [blame] | 1 | 'use strict'; |
| 2 | |
| 3 | angular.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', { |
| 16 | url:'/site/:id', |
| 17 | template:'<site-detail></site-detail>' |
| 18 | |
| 19 | }) |
| 20 | .state('createslice', { |
| 21 | url:'/site/:site/slice/', |
| 22 | template:'<create-slice></create-slice>' |
| 23 | |
| 24 | }) |
| 25 | .state('editslice', { |
| 26 | url:'/site/:site/slice/:id?', |
| 27 | template:'<edit-slice></edit-slice>' |
| 28 | |
| 29 | });; |
| 30 | |
| 31 | }) |
| 32 | .config(function($httpProvider){ |
| 33 | $httpProvider.interceptors.push('NoHyperlinks'); |
| 34 | }) |
| 35 | .directive('usersList', function(){ |
| 36 | return { |
| 37 | //sites : {}, |
| 38 | restrict: 'E', |
| 39 | scope: {}, |
| 40 | bindToController: true, |
| 41 | controllerAs: 'vm', |
| 42 | templateUrl: 'templates/users-list.tpl.html', |
| 43 | controller: function(Sites,SlicesPlus){ |
| 44 | |
| 45 | |
| 46 | |
| 47 | this.tableConfig = { |
| 48 | columns: [ |
| 49 | { |
| 50 | label: 'Site1', |
| 51 | prop: 'name', |
| 52 | link: item => `/#/site/${item.id}` |
| 53 | }, |
| 54 | { |
| 55 | label: 'Allocated', |
| 56 | prop: 'instance_total' |
| 57 | }, |
| 58 | { |
| 59 | label: 'Ready', |
| 60 | prop: 'instance_total_ready' |
| 61 | } |
| 62 | ] |
| 63 | }; |
| 64 | |
| 65 | var sites; |
| 66 | // retrieving user list |
| 67 | Sites.query().$promise |
| 68 | .then((users) => { |
| 69 | this.sites = users; |
| 70 | return SlicesPlus.query().$promise |
| 71 | }) |
| 72 | .then((users) => { |
| 73 | this.slices = users; |
| 74 | //console.log(this.sites,this.slices); |
| 75 | this.site_list = this.returnData(this.sites,this.slices); |
| 76 | }) |
| 77 | .catch((e) => { |
| 78 | throw new Error(e); |
| 79 | }); |
| 80 | //console.log(sites); |
| 81 | |
| 82 | |
| 83 | this.returnData = (sites,slices) => { |
| 84 | //console.log(sites,slices); |
| 85 | //console.log(sites.length) |
| 86 | var i,j=0; |
| 87 | var site_list=[]; |
| 88 | var slice_list = []; |
| 89 | |
| 90 | for(i = 0; i<sites.length; i++){ |
| 91 | var instance_t = 0; |
| 92 | var instance_t_r = 0; |
| 93 | for(j=0;j<slices.length;j++){ |
| 94 | if (sites[i].id != null && slices[j].site !=null && sites[i].id == slices[j].site){ |
| 95 | console.log(sites[i].id,slices[j].id); |
| 96 | instance_t = instance_t + slices[j].instance_total; |
| 97 | instance_t_r = instance_t_r + slices[j].instance_total_ready; |
| 98 | } |
| 99 | } |
| 100 | var data_sites = { |
| 101 | 'id': sites[i].id, |
| 102 | 'name': sites[i].name, |
| 103 | 'instance_total' :instance_t, |
| 104 | 'instance_total_ready' : instance_t_r |
| 105 | }; |
| 106 | //console.log(sites[i].id); |
| 107 | site_list.push(data_sites); |
| 108 | } |
| 109 | return site_list |
| 110 | //this.site_list = site_list; |
| 111 | } |
| 112 | } |
| 113 | }; |
| 114 | }) |
| 115 | .directive('siteDetail', function(){ |
| 116 | return { |
| 117 | restrict: 'E', |
| 118 | scope: {}, |
| 119 | bindToController: true, |
| 120 | controllerAs: 'sl', |
| 121 | templateUrl: 'templates/slicelist.html', |
| 122 | controller: function(SlicesPlus,$stateParams){ |
| 123 | console.log($stateParams); |
| 124 | this.siteId = $stateParams.id; |
| 125 | this.tableConfig = { |
| 126 | columns: [ |
| 127 | { |
| 128 | label: 'Slice List', |
| 129 | prop: 'name', |
| 130 | link: item => `/#/site/${item.site}/slice/${item.id}` |
| 131 | }, |
| 132 | { |
| 133 | label: 'Allocated', |
| 134 | prop: 'instance_total' |
| 135 | }, |
| 136 | { |
| 137 | label: 'Ready', |
| 138 | prop: 'instance_total_ready' |
| 139 | } |
| 140 | ] |
| 141 | }; |
| 142 | |
| 143 | // retrieving user list |
| 144 | SlicesPlus.query({ |
| 145 | site:$stateParams.id |
| 146 | }).$promise |
| 147 | .then((users) => { |
| 148 | this.users = users; |
| 149 | }) |
| 150 | .catch((e) => { |
| 151 | throw new Error(e); |
| 152 | }); |
| 153 | } |
| 154 | }; |
| 155 | }) |
| 156 | .directive('createSlice', function(){ |
| 157 | return { |
| 158 | //sites : {}, |
| 159 | restrict: 'E', |
| 160 | scope: {}, |
| 161 | bindToController: true, |
| 162 | controllerAs: 'cs', |
| 163 | templateUrl: 'templates/createslice.html', |
| 164 | controller: function(Slices,SlicesPlus,$stateParams){ |
| 165 | //var sites; |
| 166 | //console.log(this.users.name); |
| 167 | |
| 168 | //console.log(this.config); |
| 169 | this.config = { |
| 170 | exclude: ['password', 'last_login'], |
| 171 | formName: 'SliceDetails', |
| 172 | actions: [ |
| 173 | { |
| 174 | label: 'Save', |
| 175 | icon: 'ok', // refers to bootstraps glyphicon |
| 176 | cb: (user) => { // receive the model |
| 177 | console.log(user); |
| 178 | }, |
| 179 | class: 'success' |
| 180 | },{ |
| 181 | label: 'Save and continue editing', |
| 182 | icon: 'ok', // refers to bootstraps glyphicon |
| 183 | cb: (user) => { // receive the model |
| 184 | console.log(user); |
| 185 | }, |
| 186 | class: 'primary' |
| 187 | },{ |
| 188 | label: 'Save and add another', |
| 189 | icon: 'ok', // refers to bootstraps glyphicon |
| 190 | cb: (user) => { // receive the model |
| 191 | console.log(user); |
| 192 | }, |
| 193 | class: 'primary' |
| 194 | } |
| 195 | ], |
| 196 | fields: |
| 197 | { |
| 198 | site_select : { |
| 199 | label:'Site', |
| 200 | type:'select', |
| 201 | validators:{ required: true,}, |
| 202 | hint : 'The Site this Slice belongs to', |
| 203 | options:[ |
| 204 | { |
| 205 | id:0, |
| 206 | label:"---Site---" |
| 207 | }, |
| 208 | { |
| 209 | id:1, |
| 210 | label:"---Site1---" |
| 211 | }], |
| 212 | |
| 213 | }, |
| 214 | first_name: { |
| 215 | label:'Name', |
| 216 | type: 'string', |
| 217 | hint: 'The Name of the Slice', |
| 218 | validators: { |
| 219 | required: true |
| 220 | } |
| 221 | }, |
| 222 | service_class : { |
| 223 | label:'ServiceClass', |
| 224 | type:'select', |
| 225 | validators:{ required: true,}, |
| 226 | hint : 'The Site this Slice belongs to', |
| 227 | options:[ |
| 228 | { |
| 229 | id:0, |
| 230 | label:"Best effort" |
| 231 | }, |
| 232 | ], |
| 233 | }, |
| 234 | enabled: { |
| 235 | label: 'Enabled', |
| 236 | type : 'boolean', |
| 237 | hint:'Status for this Slice' |
| 238 | }, |
| 239 | description: { |
| 240 | label: 'Description', |
| 241 | type : 'string', |
| 242 | hint:'High level description of the slice and expected activities', |
| 243 | validators: { |
| 244 | required: false, |
| 245 | minlength: 10 |
| 246 | } |
| 247 | }, |
| 248 | service : { |
| 249 | label:'Service', |
| 250 | type:'select', |
| 251 | validators:{ required: false,}, |
| 252 | options:[ |
| 253 | { |
| 254 | id:0, |
| 255 | label:"--------" |
| 256 | }, |
| 257 | ], |
| 258 | }, |
| 259 | slice_url: { |
| 260 | label: 'Slice url', |
| 261 | type : 'string', |
| 262 | validators: { |
| 263 | required: false, |
| 264 | minlength: 10 |
| 265 | } |
| 266 | }, |
| 267 | max_instances: { |
| 268 | type: 'Max Instances', |
| 269 | validators: { |
| 270 | required: false, |
| 271 | min: 0 |
| 272 | } |
| 273 | }, |
| 274 | default_isolation : { |
| 275 | label:'Default Isolation', |
| 276 | type:'select', |
| 277 | validators:{ required: false,}, |
| 278 | options:[ |
| 279 | { |
| 280 | id:0, |
| 281 | label:"Virtual Machine" |
| 282 | },{ |
| 283 | id:1, |
| 284 | label:"Container" |
| 285 | },{ |
| 286 | id:2, |
| 287 | label:"Container in VM" |
| 288 | }, |
| 289 | ], |
| 290 | }, |
| 291 | default_image : { |
| 292 | label:'Default image', |
| 293 | type:'select', |
| 294 | validators:{ required: false,}, |
| 295 | options:[ |
| 296 | { |
| 297 | id:0, |
| 298 | label:"trusty-server-multi-nic" |
| 299 | }, |
| 300 | ], |
| 301 | }, |
| 302 | network : { |
| 303 | label:'Network', |
| 304 | type:'select', |
| 305 | validators:{ required: false,}, |
| 306 | options:[ |
| 307 | { |
| 308 | id:0, |
| 309 | label:"Default" |
| 310 | }, |
| 311 | { |
| 312 | id:1, |
| 313 | label:"Host" |
| 314 | }, |
| 315 | { |
| 316 | id:2, |
| 317 | label:"Bridged" |
| 318 | }, |
| 319 | { |
| 320 | id:3, |
| 321 | label:"No Automatic Networks" |
| 322 | }, |
| 323 | ], |
| 324 | }, |
| 325 | |
| 326 | } |
| 327 | }; |
| 328 | |
| 329 | var data; |
| 330 | // retrieving user list |
| 331 | |
| 332 | |
| 333 | //Slices.get({id :$stateParams.id}).$promise |
| 334 | //.then((users) => { |
| 335 | // this.users = users; |
| 336 | // //console.log(users.name); |
| 337 | // data = users; |
| 338 | //}) |
| 339 | //.catch((e) => { |
| 340 | // throw new Error(e); |
| 341 | //}); |
| 342 | |
| 343 | //console.log(this.users); |
| 344 | //console.log(this.config.fields.site_select.options); |
| 345 | this.model = { |
| 346 | }; |
| 347 | } |
| 348 | }; |
| 349 | }) |
| 350 | .directive('editSlice', function(){ |
| 351 | return { |
| 352 | //sites : {}, |
| 353 | restrict: 'E', |
| 354 | scope: {}, |
| 355 | bindToController: true, |
| 356 | controllerAs: 'cs', |
| 357 | templateUrl: 'templates/createslice.html', |
| 358 | controller: function(Slices,SlicesPlus,$stateParams){ |
| 359 | //var sites; |
| 360 | //console.log(this.users.name); |
| 361 | |
| 362 | //console.log(this.config); |
| 363 | this.config = { |
| 364 | exclude: ['password', 'last_login'], |
| 365 | formName: 'SliceDetails', |
| 366 | actions: [ |
| 367 | { |
| 368 | label: 'Save', |
| 369 | icon: 'ok', // refers to bootstraps glyphicon |
| 370 | cb: (user) => { // receive the model |
| 371 | console.log(user); |
| 372 | }, |
| 373 | class: 'success' |
| 374 | },{ |
| 375 | label: 'Save and continue editing', |
| 376 | icon: 'ok', // refers to bootstraps glyphicon |
| 377 | cb: (user) => { // receive the model |
| 378 | console.log(user); |
| 379 | }, |
| 380 | class: 'primary' |
| 381 | },{ |
| 382 | label: 'Save and add another', |
| 383 | icon: 'ok', // refers to bootstraps glyphicon |
| 384 | cb: (user) => { // receive the model |
| 385 | console.log(user); |
| 386 | }, |
| 387 | class: 'primary' |
| 388 | } |
| 389 | ], |
| 390 | fields: |
| 391 | { |
| 392 | site_select : { |
| 393 | label:'Site', |
| 394 | type:'select', |
| 395 | validators:{ required: true,}, |
| 396 | hint : 'The Site this Slice belongs to', |
| 397 | options:[ |
| 398 | { |
| 399 | id:0, |
| 400 | label:"---Site---" |
| 401 | }, |
| 402 | { |
| 403 | id:1, |
| 404 | label:"---Site1---" |
| 405 | }], |
| 406 | |
| 407 | }, |
| 408 | first_name: { |
| 409 | label:'Name', |
| 410 | type: 'string', |
| 411 | hint: 'The Name of the Slice', |
| 412 | validators: { |
| 413 | required: true |
| 414 | } |
| 415 | }, |
| 416 | service_class : { |
| 417 | label:'ServiceClass', |
| 418 | type:'select', |
| 419 | validators:{ required: true,}, |
| 420 | hint : 'The Site this Slice belongs to', |
| 421 | options:[ |
| 422 | { |
| 423 | id:0, |
| 424 | label:"Best effort" |
| 425 | }, |
| 426 | ], |
| 427 | }, |
| 428 | enabled: { |
| 429 | label: 'Enabled', |
| 430 | type : 'boolean', |
| 431 | hint:'Status for this Slice' |
| 432 | }, |
| 433 | description: { |
| 434 | label: 'Description', |
| 435 | type : 'string', |
| 436 | hint:'High level description of the slice and expected activities', |
| 437 | validators: { |
| 438 | required: false, |
| 439 | minlength: 10 |
| 440 | } |
| 441 | }, |
| 442 | service : { |
| 443 | label:'Service', |
| 444 | type:'select', |
| 445 | validators:{ required: false,}, |
| 446 | options:[ |
| 447 | { |
| 448 | id:0, |
| 449 | label:"--------" |
| 450 | }, |
| 451 | ], |
| 452 | }, |
| 453 | slice_url: { |
| 454 | label: 'Slice url', |
| 455 | type : 'string', |
| 456 | validators: { |
| 457 | required: false, |
| 458 | minlength: 10 |
| 459 | } |
| 460 | }, |
| 461 | max_instances: { |
| 462 | type: 'Max Instances', |
| 463 | validators: { |
| 464 | required: false, |
| 465 | min: 0 |
| 466 | } |
| 467 | }, |
| 468 | default_isolation : { |
| 469 | label:'Default Isolation', |
| 470 | type:'select', |
| 471 | validators:{ required: false,}, |
| 472 | options:[ |
| 473 | { |
| 474 | id:0, |
| 475 | label:"Virtual Machine" |
| 476 | },{ |
| 477 | id:1, |
| 478 | label:"Container" |
| 479 | },{ |
| 480 | id:2, |
| 481 | label:"Container in VM" |
| 482 | }, |
| 483 | ], |
| 484 | }, |
| 485 | default_image : { |
| 486 | label:'Default image', |
| 487 | type:'select', |
| 488 | validators:{ required: false,}, |
| 489 | options:[ |
| 490 | { |
| 491 | id:0, |
| 492 | label:"trusty-server-multi-nic" |
| 493 | }, |
| 494 | ], |
| 495 | }, |
| 496 | network : { |
| 497 | label:'Network', |
| 498 | type:'select', |
| 499 | validators:{ required: false,}, |
| 500 | options:[ |
| 501 | { |
| 502 | id:0, |
| 503 | label:"Default" |
| 504 | }, |
| 505 | { |
| 506 | id:1, |
| 507 | label:"Host" |
| 508 | }, |
| 509 | { |
| 510 | id:2, |
| 511 | label:"Bridged" |
| 512 | }, |
| 513 | { |
| 514 | id:3, |
| 515 | label:"No Automatic Networks" |
| 516 | }, |
| 517 | ], |
| 518 | }, |
| 519 | |
| 520 | } |
| 521 | }; |
| 522 | |
| 523 | var data; |
| 524 | // retrieving user list |
| 525 | |
| 526 | |
| 527 | Slices.get({id :$stateParams.id}).$promise |
| 528 | .then((users) => { |
| 529 | this.users = users; |
| 530 | //console.log(users.name); |
| 531 | data = users; |
| 532 | }) |
| 533 | .catch((e) => { |
| 534 | throw new Error(e); |
| 535 | }); |
| 536 | |
| 537 | //console.log(this.users); |
| 538 | //console.log(this.config.fields.site_select.options); |
| 539 | this.model = { |
| 540 | first_name : "Teo" |
| 541 | }; |
| 542 | } |
| 543 | }; |
| 544 | }); |
| 545 | |
| 546 | |
| 547 | |