rebuild GUI structure(only changed modules' name)
[vnfsdk/refrepo.git] / extsys / src / main / webapp / extsys / vim / js / vimChartController.js
1 /*
2  * Copyright 2016-2017 ZTE Corporation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 var vm = avalon
17     .define({
18         $id: "vimChartController",
19         $vimChartUrl: '../../api/vim/v1/{vim_id}/resource',
20         $tenantChartUrl: '../../api/vim/v1/{vim_id}/resource/{tenant_name}',
21         $tenantListUrl: '../../api/vim/v1/{vim_id}/tenants',
22         $tenantRoleUrl: '../../api/vim/v1/{vim_id}/roles',
23         vimInfo: {
24             name: name,
25             id: id,
26             tenant: tenant,
27             isAdmin: true
28         },
29         tenantSelectList: {
30             condName: $.i18n.prop("com_zte_ums_eco_roc_vim_type"),
31             component_type: 'select',
32             selectItems: []
33         },
34         initChart: function () {
35
36             //has admin role
37             var tenantRoleUrl = vm.$tenantRoleUrl.replace("{vim_id}", vm.vimInfo.id);
38             $.ajax({
39                 "type": 'get',
40                 "url": tenantRoleUrl,
41                 "dataType": "json",
42                 success: function (resp) {
43                     vm.vimInfo.isAdmin = (resp == null) ? false : resp.isAdminRole;
44
45                 },
46                 error: function (XMLHttpRequest, textStatus, errorThrown) {
47                     vimChart.growl("get [tenant Role] is error :" + textStatus + ":" + errorThrown, "danger");
48                 },
49                 complete: function () {
50                     if (vm.vimInfo.isAdmin == true) {
51
52                         //get all resource 
53                         vm.vimChartLoad();
54
55                         //get tenant list
56                         vm.vimListLoad();
57                     }
58
59                 }
60             });
61             //get resource of tenant 
62             vm.tenantChartLoad();
63         },
64         gotoVimPage: function () {
65             window.parent.ZteFrameWork.goToURLByIDAndNewAction('eco_roc_vimmgr');
66         },
67         vimListLoad: function () {
68             var tenantListUrl = vm.$tenantListUrl.replace("{vim_id}", vm.vimInfo.id);
69             $.ajax({
70                 "type": 'get',
71                 "url": tenantListUrl,
72                 "dataType": "json",
73                 success: function (resp) {
74                     vm.tenantSelectList.selectItems = (resp == null) ? [] : resp;
75                 },
76                 error: function (XMLHttpRequest, textStatus, errorThrown) {
77                     vimChart.growl("get [tenant List] is error :" + textStatus + ":" + errorThrown, "danger");
78                 }
79             });
80         },
81         vimChartLoad: function () {
82             var viminitData = {
83                 "resource": {
84                     "cpu": 0,
85                     "memoryMb": 503,
86                     "diskGb": 9.8
87                 },
88                 "usage": {
89                     "cpu": 0,
90                     "memoryMb": 0,
91                     "diskGb": 0
92                 }
93             }
94
95             vimChart.vimPieChartInit();
96
97             var vimChartUrl = vm.$vimChartUrl.replace("{vim_id}", vm.vimInfo.id);
98
99
100             $.ajax({
101                 "type": 'get',
102                 "url": vimChartUrl,
103                 "dataType": "json",
104                 success: function (resp) {
105                     var vimData = (resp == null) ? viminitData : resp;
106                     vimChart.vimPieChart(vimData);
107                 },
108                 error: function (XMLHttpRequest, textStatus, errorThrown) {
109                     vimChart.growl("get [virtual machine manager resource using status] is error :" + textStatus + ":" + errorThrown, "danger");
110                 }
111             });
112
113         },
114         tenantChartLoad: function () {
115             var tenantChartUrl = vm.$tenantChartUrl.replace("{vim_id}", vm.vimInfo.id).replace("{tenant_name}", vm.vimInfo.tenant);
116
117             var tenantinitData = {
118                 "tenant_name": "",
119                 "errormsg": "",
120                 "quota": {
121                     "cpu": 0,
122                     "memoryMb": 0,
123                     "instances": 0,
124                     "floatingIps": 0,
125                     "securityGroups": 0,
126                     "volumeStorage": 0,
127                     "volumes": 0
128                 },
129                 "usage": {
130                     "cpu": 0,
131                     "memoryMb": 0,
132                     "instances": 0,
133                     "floatingIps": 0,
134                     "securityGroups": 0,
135                     "volumeStorage": 0,
136                     "volumes": 0
137                 }
138             };
139             vimChart.tenantPieChartInit();
140             $.ajax({
141                 "type": 'get',
142                 "url": tenantChartUrl,
143                 "dataType": "json",
144                 success: function (resp) {
145                     var tenantData = (resp == null) ? tenantinitData : resp;
146                     if (tenantData.errormsg != null) {
147                         vimChart.growl(tenantData.errormsg, "danger");
148                     }
149                     vimChart.tenantPieChart(tenantData);
150                 },
151                 error: function (XMLHttpRequest, textStatus, errorThrown) {
152                     vimChart.growl("get [tenant quota using status] occur error :" + textStatus + ":" + errorThrown, "danger");
153                 }
154             });
155
156         }
157
158     });
159 avalon.scan();
160 vm.initChart();