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