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 | 0889ec0 | 2016-06-07 15:50:10 -0700 | [diff] [blame^] | 152 | controller: function(Slices, SlicesPlus, $stateParams){ |
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 | 0889ec0 | 2016-06-07 15:50:10 -0700 | [diff] [blame^] | 158 | exclude: ['password', 'last_login'], |
| 159 | formName: 'SliceDetails', |
| 160 | actions: [ |
| 161 | { |
| 162 | label: 'Save', |
| 163 | icon: 'ok', // refers to bootstraps glyphicon |
| 164 | cb: (user) => { // receive the model |
| 165 | console.log(user); |
arpiagariu | 827f392 | 2016-06-06 15:25:28 -0700 | [diff] [blame] | 166 | }, |
arpiagariu | 0889ec0 | 2016-06-07 15:50:10 -0700 | [diff] [blame^] | 167 | class: 'success' |
| 168 | }, { |
| 169 | label: 'Save and continue editing', |
| 170 | icon: 'ok', // refers to bootstraps glyphicon |
| 171 | cb: (user) => { // receive the model |
| 172 | console.log(user); |
| 173 | }, |
| 174 | class: 'primary' |
| 175 | }, |
| 176 | { |
| 177 | label: 'Save and add another', |
| 178 | icon: 'ok', // refers to bootstraps glyphicon |
| 179 | cb: (user) => { // receive the model |
| 180 | console.log(user); |
| 181 | }, |
| 182 | class: 'primary' |
| 183 | } |
| 184 | ], |
| 185 | fields: |
| 186 | { |
| 187 | site_select: { |
| 188 | label: 'Site', |
| 189 | type: 'select', |
| 190 | validators: { required: true}, |
| 191 | hint: 'The Site this Slice belongs to', |
| 192 | options: [ |
| 193 | { |
| 194 | id: 0, |
| 195 | label: '---Site---' |
| 196 | }, |
| 197 | { |
| 198 | id: 1, |
| 199 | label: '---Site1---' |
| 200 | }] |
| 201 | |
| 202 | }, |
arpiagariu | 827f392 | 2016-06-06 15:25:28 -0700 | [diff] [blame] | 203 | first_name: { |
arpiagariu | 0889ec0 | 2016-06-07 15:50:10 -0700 | [diff] [blame^] | 204 | label: 'Name', |
arpiagariu | 827f392 | 2016-06-06 15:25:28 -0700 | [diff] [blame] | 205 | type: 'string', |
arpiagariu | 0889ec0 | 2016-06-07 15:50:10 -0700 | [diff] [blame^] | 206 | hint: 'The Name of the Slice', |
arpiagariu | 827f392 | 2016-06-06 15:25:28 -0700 | [diff] [blame] | 207 | validators: { |
| 208 | required: true |
| 209 | } |
| 210 | }, |
arpiagariu | 0889ec0 | 2016-06-07 15:50:10 -0700 | [diff] [blame^] | 211 | service_class: { |
| 212 | label: 'ServiceClass', |
| 213 | type: 'select', |
| 214 | validators: {required: true}, |
| 215 | hint: 'The Site this Slice belongs to', |
| 216 | options: [ |
| 217 | { |
| 218 | id: 1, |
| 219 | label: 'Best effort' |
| 220 | } |
| 221 | ] |
| 222 | }, |
arpiagariu | 827f392 | 2016-06-06 15:25:28 -0700 | [diff] [blame] | 223 | enabled: { |
| 224 | label: 'Enabled', |
arpiagariu | 0889ec0 | 2016-06-07 15:50:10 -0700 | [diff] [blame^] | 225 | type: 'boolean', |
| 226 | hint: 'Status for this Slice' |
arpiagariu | 827f392 | 2016-06-06 15:25:28 -0700 | [diff] [blame] | 227 | }, |
| 228 | description: { |
| 229 | label: 'Description', |
arpiagariu | 0889ec0 | 2016-06-07 15:50:10 -0700 | [diff] [blame^] | 230 | type: 'string', |
| 231 | hint: 'High level description of the slice and expected activities', |
arpiagariu | 827f392 | 2016-06-06 15:25:28 -0700 | [diff] [blame] | 232 | validators: { |
| 233 | required: false, |
| 234 | minlength: 10 |
| 235 | } |
| 236 | }, |
arpiagariu | 0889ec0 | 2016-06-07 15:50:10 -0700 | [diff] [blame^] | 237 | service: { |
| 238 | label: 'Service', |
| 239 | type: 'select', |
| 240 | validators: { required: false}, |
| 241 | options: [ |
| 242 | { |
| 243 | id: 0, |
| 244 | label: '--------' |
| 245 | } |
| 246 | ] |
| 247 | }, |
arpiagariu | 827f392 | 2016-06-06 15:25:28 -0700 | [diff] [blame] | 248 | slice_url: { |
| 249 | label: 'Slice url', |
arpiagariu | 0889ec0 | 2016-06-07 15:50:10 -0700 | [diff] [blame^] | 250 | type: 'string', |
arpiagariu | 827f392 | 2016-06-06 15:25:28 -0700 | [diff] [blame] | 251 | validators: { |
| 252 | required: false, |
| 253 | minlength: 10 |
| 254 | } |
| 255 | }, |
| 256 | max_instances: { |
| 257 | type: 'Max Instances', |
| 258 | validators: { |
| 259 | required: false, |
| 260 | min: 0 |
| 261 | } |
| 262 | }, |
arpiagariu | 0889ec0 | 2016-06-07 15:50:10 -0700 | [diff] [blame^] | 263 | default_isolation: { |
| 264 | label: 'Default Isolation', |
| 265 | type: 'select', |
| 266 | validators: { required: false}, |
| 267 | options: [ |
| 268 | { |
| 269 | id: 'vm', |
| 270 | label: 'Virtual Machine' |
| 271 | }, |
| 272 | { |
| 273 | id: 'container', |
| 274 | label: 'Container' |
| 275 | }, |
| 276 | { |
| 277 | id: 'container_vm', |
| 278 | label: 'Container in VM' |
| 279 | } |
| 280 | ] |
arpiagariu | 827f392 | 2016-06-06 15:25:28 -0700 | [diff] [blame] | 281 | }, |
arpiagariu | 0889ec0 | 2016-06-07 15:50:10 -0700 | [diff] [blame^] | 282 | default_image: { |
| 283 | label: 'Default image', |
| 284 | type: 'select', |
| 285 | validators: { required: false}, |
| 286 | options: [ |
| 287 | { |
| 288 | id: 0, |
| 289 | label: 'trusty-server-multi-nic' |
| 290 | } |
| 291 | ] |
arpiagariu | 827f392 | 2016-06-06 15:25:28 -0700 | [diff] [blame] | 292 | }, |
arpiagariu | 0889ec0 | 2016-06-07 15:50:10 -0700 | [diff] [blame^] | 293 | network: { |
| 294 | label: 'Network', |
| 295 | type: 'select', |
| 296 | validators: { required: false}, |
| 297 | options: [ |
| 298 | { |
| 299 | id: 'default', |
| 300 | label: 'Default' |
| 301 | }, |
| 302 | { |
| 303 | id: 'host', |
| 304 | label: 'Host' |
| 305 | }, |
| 306 | { |
| 307 | id: 'bridged', |
| 308 | label: 'Bridged' |
| 309 | }, |
| 310 | { |
| 311 | id: 'noauto', |
| 312 | label: 'No Automatic Networks' |
| 313 | } |
| 314 | ] |
| 315 | } |
arpiagariu | 827f392 | 2016-06-06 15:25:28 -0700 | [diff] [blame] | 316 | |
arpiagariu | 0889ec0 | 2016-06-07 15:50:10 -0700 | [diff] [blame^] | 317 | } |
arpiagariu | 827f392 | 2016-06-06 15:25:28 -0700 | [diff] [blame] | 318 | }; |
arpiagariu | 827f392 | 2016-06-06 15:25:28 -0700 | [diff] [blame] | 319 | |
| 320 | var data; |
| 321 | // retrieving user list |
arpiagariu | 0889ec0 | 2016-06-07 15:50:10 -0700 | [diff] [blame^] | 322 | if ($stateParams.id) |
| 323 | { |
| 324 | Slices.get({id: $stateParams.id}).$promise |
| 325 | .then((users) => { |
| 326 | this.users = users; |
| 327 | data = users; |
arpiagariu | 2744cfb | 2016-06-06 17:02:29 -0700 | [diff] [blame] | 328 | this.model = { |
arpiagariu | 0889ec0 | 2016-06-07 15:50:10 -0700 | [diff] [blame^] | 329 | first_name: data.name, |
| 330 | service_class: data.serviceClass, |
| 331 | enabled: data.enabled, |
| 332 | description: data.description, |
| 333 | service: data.service, |
| 334 | slice_url: data.slice_url, |
| 335 | max_instances: data.max_instances, |
| 336 | default_isolation: data.default_isolation, |
| 337 | default_image: data.default_image, |
| 338 | network: data.network |
| 339 | }; |
| 340 | }) |
| 341 | .catch((e) => { |
| 342 | throw new Error(e); |
| 343 | }); |
| 344 | } |
| 345 | else |
| 346 | { |
| 347 | this.model = {}; |
| 348 | } |
arpiagariu | 827f392 | 2016-06-06 15:25:28 -0700 | [diff] [blame] | 349 | } |
| 350 | }; |
arpiagariu | 0889ec0 | 2016-06-07 15:50:10 -0700 | [diff] [blame^] | 351 | }); |