Arpit Agarwal | 711b1ec | 2016-06-27 13:28:54 -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('site-list', {
|
| 12 | url: '/',
|
| 13 | template: '<site-list></site-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/:id?',
|
| 22 | template: '<create-slice></create-slice>'
|
| 23 |
|
| 24 | });
|
| 25 | })
|
| 26 | .config(function($httpProvider){
|
| 27 | $httpProvider.interceptors.push('NoHyperlinks');
|
| 28 | })
|
| 29 | .directive('siteList', function(){
|
| 30 | return {
|
| 31 | //sites : {},
|
| 32 | restrict: 'E',
|
| 33 | scope: {},
|
| 34 | bindToController: true,
|
| 35 | controllerAs: 'vm',
|
| 36 | templateUrl: 'templates/users-list.tpl.html',
|
| 37 | controller: function(Sites, SlicesPlus){
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 | this.tableConfig = {
|
| 42 | columns: [
|
| 43 | {
|
| 44 | label: 'Site',
|
| 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 |
|
| 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 | this.site_list = this.returnData(this.sites, this.slices);
|
| 68 | })
|
| 69 | .catch((e) => {
|
| 70 | throw new Error(e);
|
| 71 | });
|
| 72 |
|
| 73 |
|
| 74 | this.returnData = (sites, slices) => {
|
| 75 | var i, j=0;
|
| 76 | var site_list=[];
|
| 77 |
|
| 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++){
|
| 82 | 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 | }
|
| 86 | }
|
| 87 | var data_sites = {
|
| 88 | 'id': sites[i].id,
|
| 89 | 'name': sites[i].name,
|
| 90 | 'instance_total': instance_t,
|
| 91 | 'instance_total_ready': instance_t_r
|
| 92 | };
|
| 93 | site_list.push(data_sites);
|
| 94 | }
|
| 95 | return site_list;
|
| 96 | }
|
| 97 | }
|
| 98 | };
|
| 99 | });
|