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', { |
arpiagariu | 0889ec0 | 2016-06-07 15:50:10 -0700 | [diff] [blame] | 16 | url: '/site/:id', |
| 17 | template: '<site-detail></site-detail>' |
arpiagariu | 827f392 | 2016-06-06 15:25:28 -0700 | [diff] [blame] | 18 | |
| 19 | }) |
| 20 | .state('createslice', { |
arpiagariu | 0889ec0 | 2016-06-07 15:50:10 -0700 | [diff] [blame] | 21 | url: '/site/:site/slice/:id?', |
| 22 | template: '<create-slice></create-slice>' |
arpiagariu | 827f392 | 2016-06-06 15:25:28 -0700 | [diff] [blame] | 23 | |
arpiagariu | 0889ec0 | 2016-06-07 15:50:10 -0700 | [diff] [blame] | 24 | }); |
arpiagariu | 827f392 | 2016-06-06 15:25:28 -0700 | [diff] [blame] | 25 | }) |
| 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', |
arpiagariu | 0889ec0 | 2016-06-07 15:50:10 -0700 | [diff] [blame] | 37 | controller: function(Sites, SlicesPlus){ |
arpiagariu | 827f392 | 2016-06-06 15:25:28 -0700 | [diff] [blame] | 38 | |
| 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 | |
arpiagariu | 827f392 | 2016-06-06 15:25:28 -0700 | [diff] [blame] | 59 | // 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); |
arpiagariu | 0889ec0 | 2016-06-07 15:50:10 -0700 | [diff] [blame] | 68 | this.site_list = this.returnData(this.sites, this.slices); |
arpiagariu | 827f392 | 2016-06-06 15:25:28 -0700 | [diff] [blame] | 69 | }) |
| 70 | .catch((e) => { |
| 71 | throw new Error(e); |
| 72 | }); |
arpiagariu | 827f392 | 2016-06-06 15:25:28 -0700 | [diff] [blame] | 73 | |
| 74 | |
arpiagariu | 0889ec0 | 2016-06-07 15:50:10 -0700 | [diff] [blame] | 75 | this.returnData = (sites, slices) => { |
arpiagariu | 827f392 | 2016-06-06 15:25:28 -0700 | [diff] [blame] | 76 | //console.log(sites,slices); |
| 77 | //console.log(sites.length) |
arpiagariu | 0889ec0 | 2016-06-07 15:50:10 -0700 | [diff] [blame] | 78 | var i, j=0; |
arpiagariu | 827f392 | 2016-06-06 15:25:28 -0700 | [diff] [blame] | 79 | var site_list=[]; |
arpiagariu | 827f392 | 2016-06-06 15:25:28 -0700 | [diff] [blame] | 80 | |
| 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++){ |
arpiagariu | 0889ec0 | 2016-06-07 15:50:10 -0700 | [diff] [blame] | 85 | 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 | } |
arpiagariu | 827f392 | 2016-06-06 15:25:28 -0700 | [diff] [blame] | 89 | } |
| 90 | var data_sites = { |
arpiagariu | 0889ec0 | 2016-06-07 15:50:10 -0700 | [diff] [blame] | 91 | 'id': sites[i].id, |
| 92 | 'name': sites[i].name, |
| 93 | 'instance_total': instance_t, |
| 94 | 'instance_total_ready': instance_t_r |
arpiagariu | 827f392 | 2016-06-06 15:25:28 -0700 | [diff] [blame] | 95 | }; |
| 96 | //console.log(sites[i].id); |
| 97 | site_list.push(data_sites); |
| 98 | } |
arpiagariu | 0889ec0 | 2016-06-07 15:50:10 -0700 | [diff] [blame] | 99 | return site_list; |
arpiagariu | 827f392 | 2016-06-06 15:25:28 -0700 | [diff] [blame] | 100 | //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', |
arpiagariu | 0889ec0 | 2016-06-07 15:50:10 -0700 | [diff] [blame] | 112 | controller: function(SlicesPlus, $stateParams){ |
arpiagariu | 827f392 | 2016-06-06 15:25:28 -0700 | [diff] [blame] | 113 | 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({ |
arpiagariu | 0889ec0 | 2016-06-07 15:50:10 -0700 | [diff] [blame] | 133 | site: $stateParams.id |
arpiagariu | 827f392 | 2016-06-06 15:25:28 -0700 | [diff] [blame] | 134 | }).$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', |
arpiagariu | 67cf397 | 2016-06-10 13:13:36 -0700 | [diff] [blame^] | 152 | controller: function(Slices, SlicesPlus, Sites, Images, $stateParams, $http, $state){ |
arpiagariu | 827f392 | 2016-06-06 15:25:28 -0700 | [diff] [blame] | 153 | //var sites; |
| 154 | //console.log(this.users.name); |
| 155 | |
| 156 | //console.log(this.config); |
| 157 | this.config = { |
arpiagariu | 67cf397 | 2016-06-10 13:13:36 -0700 | [diff] [blame^] | 158 | 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'], |
arpiagariu | 0889ec0 | 2016-06-07 15:50:10 -0700 | [diff] [blame] | 159 | formName: 'SliceDetails', |
arpiagariu | 67cf397 | 2016-06-10 13:13:36 -0700 | [diff] [blame^] | 160 | feedback: { |
| 161 | show: false, |
| 162 | message: 'Form submitted successfully !!!', |
| 163 | type: 'success' |
| 164 | }, |
arpiagariu | 0889ec0 | 2016-06-07 15:50:10 -0700 | [diff] [blame] | 165 | actions: [ |
| 166 | { |
| 167 | label: 'Save', |
| 168 | icon: 'ok', // refers to bootstraps glyphicon |
arpiagariu | 67cf397 | 2016-06-10 13:13:36 -0700 | [diff] [blame^] | 169 | 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 | } |
arpiagariu | 827f392 | 2016-06-06 15:25:28 -0700 | [diff] [blame] | 197 | }, |
arpiagariu | 0889ec0 | 2016-06-07 15:50:10 -0700 | [diff] [blame] | 198 | class: 'success' |
| 199 | }, { |
| 200 | label: 'Save and continue editing', |
| 201 | icon: 'ok', // refers to bootstraps glyphicon |
arpiagariu | 67cf397 | 2016-06-10 13:13:36 -0700 | [diff] [blame^] | 202 | 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 | } |
arpiagariu | 0889ec0 | 2016-06-07 15:50:10 -0700 | [diff] [blame] | 229 | }, |
| 230 | class: 'primary' |
| 231 | }, |
| 232 | { |
| 233 | label: 'Save and add another', |
| 234 | icon: 'ok', // refers to bootstraps glyphicon |
arpiagariu | 67cf397 | 2016-06-10 13:13:36 -0700 | [diff] [blame^] | 235 | 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 | } |
arpiagariu | 0889ec0 | 2016-06-07 15:50:10 -0700 | [diff] [blame] | 262 | }, |
| 263 | class: 'primary' |
| 264 | } |
| 265 | ], |
| 266 | fields: |
| 267 | { |
arpiagariu | 67cf397 | 2016-06-10 13:13:36 -0700 | [diff] [blame^] | 268 | site: { |
arpiagariu | 0889ec0 | 2016-06-07 15:50:10 -0700 | [diff] [blame] | 269 | label: 'Site', |
| 270 | type: 'select', |
| 271 | validators: { required: true}, |
| 272 | hint: 'The Site this Slice belongs to', |
arpiagariu | 67cf397 | 2016-06-10 13:13:36 -0700 | [diff] [blame^] | 273 | options: [] |
arpiagariu | 0889ec0 | 2016-06-07 15:50:10 -0700 | [diff] [blame] | 274 | |
| 275 | }, |
arpiagariu | 67cf397 | 2016-06-10 13:13:36 -0700 | [diff] [blame^] | 276 | name: { |
arpiagariu | 0889ec0 | 2016-06-07 15:50:10 -0700 | [diff] [blame] | 277 | label: 'Name', |
arpiagariu | 827f392 | 2016-06-06 15:25:28 -0700 | [diff] [blame] | 278 | type: 'string', |
arpiagariu | 0889ec0 | 2016-06-07 15:50:10 -0700 | [diff] [blame] | 279 | hint: 'The Name of the Slice', |
arpiagariu | 827f392 | 2016-06-06 15:25:28 -0700 | [diff] [blame] | 280 | validators: { |
| 281 | required: true |
| 282 | } |
| 283 | }, |
arpiagariu | 67cf397 | 2016-06-10 13:13:36 -0700 | [diff] [blame^] | 284 | serviceClass: { |
arpiagariu | 0889ec0 | 2016-06-07 15:50:10 -0700 | [diff] [blame] | 285 | 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 | }, |
arpiagariu | 827f392 | 2016-06-06 15:25:28 -0700 | [diff] [blame] | 296 | enabled: { |
| 297 | label: 'Enabled', |
arpiagariu | 0889ec0 | 2016-06-07 15:50:10 -0700 | [diff] [blame] | 298 | type: 'boolean', |
| 299 | hint: 'Status for this Slice' |
arpiagariu | 827f392 | 2016-06-06 15:25:28 -0700 | [diff] [blame] | 300 | }, |
| 301 | description: { |
| 302 | label: 'Description', |
arpiagariu | 0889ec0 | 2016-06-07 15:50:10 -0700 | [diff] [blame] | 303 | type: 'string', |
| 304 | hint: 'High level description of the slice and expected activities', |
arpiagariu | 827f392 | 2016-06-06 15:25:28 -0700 | [diff] [blame] | 305 | validators: { |
| 306 | required: false, |
| 307 | minlength: 10 |
| 308 | } |
| 309 | }, |
arpiagariu | 0889ec0 | 2016-06-07 15:50:10 -0700 | [diff] [blame] | 310 | service: { |
| 311 | label: 'Service', |
| 312 | type: 'select', |
| 313 | validators: { required: false}, |
| 314 | options: [ |
| 315 | { |
| 316 | id: 0, |
| 317 | label: '--------' |
| 318 | } |
| 319 | ] |
| 320 | }, |
arpiagariu | 827f392 | 2016-06-06 15:25:28 -0700 | [diff] [blame] | 321 | slice_url: { |
| 322 | label: 'Slice url', |
arpiagariu | 0889ec0 | 2016-06-07 15:50:10 -0700 | [diff] [blame] | 323 | type: 'string', |
arpiagariu | 827f392 | 2016-06-06 15:25:28 -0700 | [diff] [blame] | 324 | 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 | }, |
arpiagariu | 0889ec0 | 2016-06-07 15:50:10 -0700 | [diff] [blame] | 336 | 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 | ] |
arpiagariu | 827f392 | 2016-06-06 15:25:28 -0700 | [diff] [blame] | 354 | }, |
arpiagariu | 0889ec0 | 2016-06-07 15:50:10 -0700 | [diff] [blame] | 355 | default_image: { |
| 356 | label: 'Default image', |
| 357 | type: 'select', |
| 358 | validators: { required: false}, |
arpiagariu | 67cf397 | 2016-06-10 13:13:36 -0700 | [diff] [blame^] | 359 | options: [] |
arpiagariu | 827f392 | 2016-06-06 15:25:28 -0700 | [diff] [blame] | 360 | }, |
arpiagariu | 0889ec0 | 2016-06-07 15:50:10 -0700 | [diff] [blame] | 361 | 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 | } |
arpiagariu | 827f392 | 2016-06-06 15:25:28 -0700 | [diff] [blame] | 384 | |
arpiagariu | 0889ec0 | 2016-06-07 15:50:10 -0700 | [diff] [blame] | 385 | } |
arpiagariu | 827f392 | 2016-06-06 15:25:28 -0700 | [diff] [blame] | 386 | }; |
arpiagariu | 67cf397 | 2016-06-10 13:13:36 -0700 | [diff] [blame^] | 387 | //console.log(this.config.exclude); |
arpiagariu | 827f392 | 2016-06-06 15:25:28 -0700 | [diff] [blame] | 388 | var data; |
arpiagariu | 67cf397 | 2016-06-10 13:13:36 -0700 | [diff] [blame^] | 389 | 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 | |
arpiagariu | 827f392 | 2016-06-06 15:25:28 -0700 | [diff] [blame] | 413 | // retrieving user list |
arpiagariu | 67cf397 | 2016-06-10 13:13:36 -0700 | [diff] [blame^] | 414 | |
arpiagariu | 0889ec0 | 2016-06-07 15:50:10 -0700 | [diff] [blame] | 415 | if ($stateParams.id) |
| 416 | { |
arpiagariu | 67cf397 | 2016-06-10 13:13:36 -0700 | [diff] [blame^] | 417 | delete this.config.fields['site']; |
| 418 | this.config.exclude.push('site'); |
| 419 | |
| 420 | //console.log(this.config.exclude); |
| 421 | |
arpiagariu | 0889ec0 | 2016-06-07 15:50:10 -0700 | [diff] [blame] | 422 | Slices.get({id: $stateParams.id}).$promise |
| 423 | .then((users) => { |
| 424 | this.users = users; |
| 425 | data = users; |
arpiagariu | 67cf397 | 2016-06-10 13:13:36 -0700 | [diff] [blame^] | 426 | delete data.networks; |
| 427 | |
| 428 | this.model = data; |
arpiagariu | 0889ec0 | 2016-06-07 15:50:10 -0700 | [diff] [blame] | 429 | }) |
| 430 | .catch((e) => { |
| 431 | throw new Error(e); |
| 432 | }); |
| 433 | } |
| 434 | else |
| 435 | { |
arpiagariu | 67cf397 | 2016-06-10 13:13:36 -0700 | [diff] [blame^] | 436 | |
| 437 | |
arpiagariu | 0889ec0 | 2016-06-07 15:50:10 -0700 | [diff] [blame] | 438 | this.model = {}; |
arpiagariu | 67cf397 | 2016-06-10 13:13:36 -0700 | [diff] [blame^] | 439 | $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 | |
arpiagariu | 0889ec0 | 2016-06-07 15:50:10 -0700 | [diff] [blame] | 466 | } |
arpiagariu | 827f392 | 2016-06-06 15:25:28 -0700 | [diff] [blame] | 467 | } |
| 468 | }; |
arpiagariu | 0889ec0 | 2016-06-07 15:50:10 -0700 | [diff] [blame] | 469 | }); |