Matteo Scandolo | d2044a4 | 2017-08-07 16:08:28 -0700 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2017-present Open Networking Foundation |
| 4 | |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | |
Arpit Agarwal | 711b1ec | 2016-06-27 13:28:54 -0700 | [diff] [blame] | 19 | 'use strict';
|
| 20 |
|
| 21 | angular.module('xos.tenant', [
|
| 22 | 'ngResource',
|
| 23 | 'ngCookies',
|
| 24 | 'ui.router',
|
| 25 | 'xos.helpers'
|
| 26 | ])
|
| 27 | .config(($stateProvider) => {
|
| 28 | $stateProvider
|
| 29 | .state('site-list', {
|
| 30 | url: '/',
|
| 31 | template: '<site-list></site-list>'
|
| 32 | })
|
| 33 | .state('site', {
|
| 34 | url: '/site/:id',
|
| 35 | template: '<site-detail></site-detail>'
|
| 36 |
|
| 37 | })
|
| 38 | .state('createslice', {
|
| 39 | url: '/site/:site/slice/:id?',
|
| 40 | template: '<create-slice></create-slice>'
|
| 41 |
|
| 42 | });
|
| 43 | })
|
| 44 | .config(function($httpProvider){
|
| 45 | $httpProvider.interceptors.push('NoHyperlinks');
|
| 46 | })
|
| 47 | .directive('siteList', function(){
|
| 48 | return {
|
| 49 | //sites : {},
|
| 50 | restrict: 'E',
|
| 51 | scope: {},
|
| 52 | bindToController: true,
|
| 53 | controllerAs: 'vm',
|
| 54 | templateUrl: 'templates/users-list.tpl.html',
|
| 55 | controller: function(Sites, SlicesPlus){
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 | this.tableConfig = {
|
| 60 | columns: [
|
| 61 | {
|
| 62 | label: 'Site',
|
| 63 | prop: 'name',
|
| 64 | link: item => `#/site/${item.id}`
|
| 65 | },
|
| 66 | {
|
| 67 | label: 'Allocated',
|
| 68 | prop: 'instance_total'
|
| 69 | },
|
| 70 | {
|
| 71 | label: 'Ready',
|
| 72 | prop: 'instance_total_ready'
|
| 73 | }
|
| 74 | ]
|
| 75 | };
|
| 76 |
|
| 77 | // retrieving user list
|
| 78 | Sites.query().$promise
|
| 79 | .then((users) => {
|
| 80 | this.sites = users;
|
| 81 | return SlicesPlus.query().$promise
|
| 82 | })
|
| 83 | .then((users) => {
|
| 84 | this.slices = users;
|
| 85 | this.site_list = this.returnData(this.sites, this.slices);
|
| 86 | })
|
| 87 | .catch((e) => {
|
| 88 | throw new Error(e);
|
| 89 | });
|
| 90 |
|
| 91 |
|
| 92 | this.returnData = (sites, slices) => {
|
| 93 | var i, j=0;
|
| 94 | var site_list=[];
|
| 95 |
|
| 96 | for(i = 0; i<sites.length; i++){
|
| 97 | var instance_t = 0;
|
| 98 | var instance_t_r = 0;
|
| 99 | for(j=0;j<slices.length;j++){
|
| 100 | if (sites[i].id != null && slices[j].site !=null && sites[i].id === slices[j].site){
|
| 101 | instance_t = instance_t + slices[j].instance_total;
|
| 102 | instance_t_r = instance_t_r + slices[j].instance_total_ready;
|
| 103 | }
|
| 104 | }
|
| 105 | var data_sites = {
|
| 106 | 'id': sites[i].id,
|
| 107 | 'name': sites[i].name,
|
| 108 | 'instance_total': instance_t,
|
| 109 | 'instance_total_ready': instance_t_r
|
| 110 | };
|
| 111 | site_list.push(data_sites);
|
| 112 | }
|
| 113 | return site_list;
|
| 114 | }
|
| 115 | }
|
| 116 | };
|
| 117 | });
|