aboutsummaryrefslogtreecommitdiffstats
path: root/usecaseui-monitor/src/main/webapp/app/uui/fusion/scripts/controller/topology-diagram.js
blob: d9d5078a919ba4a3bf9a0a5819357dd1c5ca10aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
 Copyright (C) 2017 CMCC, Inc. and others. All rights reserved.

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 */
app.controller('topologyCtrl', ['$scope', '$http', '$location', 'drawTree', '$timeout', function ($scope, $http, $location, drawTree, $timeout) {

    // 获取拓补图盒子
    var myChart = echarts.init(document.getElementById("tree-container"));
    // 请求数据,渲染选项标签
    $http({
        method: 'GET',
        url: global_url + '/topology/services'
    }).then(function successCallback(response) {
        $scope.serviceType = response.data;
        $scope.selectedName = response.data[0];
    }, function errorCallback(error) {

    }).then(function () {
        // 默认渲染第一条拓补图
        $http({
            method: 'GET',
            url: global_url + '/topology/' + $scope.selectedName.ServiceName,
        }).then(function successCallback(response) {
            drawTree.treeChart(false, response.data, myChart);

        }, function errorCallback(error) {

        })
    });

    // 点击切换拓补图
    $scope.selectedNameChanged = function (selectedName) {
        $http({
            method: 'GET',
            url: global_url + '/topology/' + selectedName.ServiceName,
        }).then(function successCallback(response) {
            drawTree.treeChart(true, response.data, myChart);
        }, function errorCallback(error) {

        })
    };

}]).factory('drawTree', function () {
    function treeChart(isChange, data, myChart) {

        if (isChange) {
            myChart.clear(); //如果切换就清空下
        }
        data.symbol = "image://./app/uui/fusion/images/E2E.png";
        for (k in data.children) {
            data.children[k].symbol = "image://./app/uui/fusion/images/NS.png";
            if (data.children[k].children) {
                for (i in data.children[k].children) {
                    if (data.children[k].children[i].isAlarm) {
                        data.children[k].children[i].symbol = "image://./app/uui/fusion/images/vnf-alarm.png";
                    } else {
                        data.children[k].children[i].symbol = "image://./app/uui/fusion/images/vnf-1.png";
                    }
                }
            }
        }

        var option = {
            tooltip: {
                trigger: 'item',
                triggerOn: 'mousemove'
            },
            series: [{
                type: 'tree',
                top: '20%',
                left: '7%',
                bottom: '20%',
                right: '10%',
                symbolSize: 50,
                orient: 'vertical',
                label: {
                    normal: {
                        position: 'bottom',
                        fontSize: 16,
                        color: '#000'
                    }
                },
                leaves: {
                    label: {
                        normal: {
                            position: 'right',
                            verticalAlign: 'middle',
                            align: 'left'
                        }
                    }
                },
                lineStyle: {
                    width: 3,
                    curveness: 0,
                },
                data: [data],
                expandAndCollapse: true
            }]
        }
        myChart.setOption(option, true);
    }
    return {
        treeChart: treeChart
    }
})