rebuild GUI structure(only changed modules' name)
[vnfsdk/refrepo.git] / resmgr / src / main / webapp / resmgr-nfv / js / vim.js
1 /* Copyright 2016-2017, Huawei Technologies Co., Ltd.
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *    http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 function loadVimData() {
16     var requestUrl = app_url+"/v1/resmanage/vim/vimInfo";
17     $.ajax({
18         type: "GET",
19         url: requestUrl,
20         contentType: "application/json",
21         success: function (jsonobj) {
22             printCharts(jsonobj.data[0].used.cpu,
23                 jsonobj.data[0].total.cpu, jsonobj.data[0].used.memory, jsonobj.data[0].total.memory, jsonobj.data[0].used.disk, jsonobj.data[0].total.disk);
24
25         },
26         error: function (xhr, ajaxOptions, thrownError) {
27             bootbox.alert("Error on getting data (here display the test data) : " + xhr.responseText);
28             printCharts(11, 12, 21, 22, 31, 32);
29         }
30     });
31 }
32 function printCharts(v11, v12, v21, v22, v31, v32) {
33     var cpuChart = new Chart($("#cpuChart"), {
34         type: 'doughnut',
35         data: {
36             labels: ["used", "available"],
37             datasets: [{
38                 data: [v11, v12],
39                 backgroundColor: ["#FFCE56", "#36A2EB"],
40                 hoverBackgroundColor: ["#FFCE56", "#36A2EB"]
41             }]
42         },
43         options: {
44             animation: {
45                 animateScale: true,
46                 animateRotate: true
47
48             }
49         }
50     });
51     var memoryChart = new Chart($("#memoryChart"), {
52         type: 'doughnut',
53         data: {
54             labels: ["used", "available"],
55             datasets: [{
56                 data: [v21, v22],
57                 backgroundColor: ["#FF6384", "#36A2EB"],
58                 hoverBackgroundColor: ["#FF6384", "#36A2EB"]
59             }]
60         },
61         options: {
62
63             animation: {
64                 animateScale: true,
65                 animateRotate: true
66
67             }
68         }
69     });
70     var diskChart = new Chart($("#diskChart"), {
71         type: 'doughnut',
72         data: {
73             labels: ["used", "available"],
74             datasets: [{
75                 data: [v31, v32],
76                 backgroundColor: ["#FF6384", "green"],
77                 hoverBackgroundColor: ["#FF6384", "green"]
78             }]
79         },
80         options: {
81             animation: {
82                 animateScale: true,
83                 animateRotate: true
84
85             }
86         }
87     });
88 }
89
90 $(function () {
91     loadVimData();
92
93 })