Skip to content
line.component.ts 3.01 KiB
Newer Older
wangqinghua's avatar
wangqinghua committed
import {Component, OnInit} from '@angular/core';
import {TopologyService} from '../../topology.service';
import {LocalStorageService} from 'ngx-webstorage';
import {NzMessageService} from 'ng-zorro-antd';

declare let editor: any;
@Component({
    selector: 'smart-line',
    templateUrl: './line.component.html',
    styles: []
})
export class LineComponent implements OnInit {

    isLine = false;
    hostIds = [];

    inPageNum = 1;
    outPageNum = 1;
    inPageCount = 10;
    outPageCount = 10;

    totalNum;

    inList;
    inSelect = [];

    outList;
    outSelect = [];

    constructor(private topologySer: TopologyService, private message: NzMessageService, private localStorage: LocalStorageService,) {
    }

    //in
    incurrentPageDataChange($event: Array<{ key1: string; key2: number; key3: string; key4: string; checked: boolean }>): void {
        this.inList = $event;
    }

    inselectItem(item,e){
        if(e){
            this.inSelect = item;
        }else{
            this.inSelect = null;
        }
    }

    indeleteSelect(index){
        this.inSelect = null;
    }

    changePageIn(e){
wangqinghua's avatar
wangqinghua committed
        this.inPageNum = e;
        this.getInList();
wangqinghua's avatar
wangqinghua committed
    }

    //out

    outcurrentPageDataChange($event: Array<{ key1: string; key2: number; key3: string; key4: string; checked: boolean }>): void {
wangqinghua's avatar
wangqinghua committed
        this.outList = $event;
wangqinghua's avatar
wangqinghua committed
    }

    outselectItem(item,e){
        if(e){
            this.outSelect = item;
        }else{
            this.outSelect = null;
        }
    }

    outdeleteSelect(index){
        this.outSelect = null;
    }

    changePageOut(e){
wangqinghua's avatar
wangqinghua committed
        this.outPageNum = e;
        this.getOutList();
wangqinghua's avatar
wangqinghua committed
    }

    ngOnInit() {

    }

    showModal(hostIds) {
wangqinghua's avatar
wangqinghua committed
        this.hostIds = hostIds.split(',');
wangqinghua's avatar
wangqinghua committed
        this.isLine = true;
        this.getOutList();
        this.getInList();
    }

    getInList(){
        const data = {
wangqinghua's avatar
wangqinghua committed
            hostIds:this.hostIds,
wangqinghua's avatar
wangqinghua committed
            search:"",
            type:"in",
            pageNum:this.inPageNum,
            pageCount:this.inPageCount
        }
        this.topologySer.findFlowItemByHost(data).subscribe(
            (res)=>{
                this.totalNum = res.data.totalNum;
                this.inList = res.data.data;
            }
        )

    }

    getOutList(){
        const data = {
wangqinghua's avatar
wangqinghua committed
            hostIds:this.hostIds,
wangqinghua's avatar
wangqinghua committed
            search:"",
            type:"out",
            pageNum:this.outPageNum,
            pageCount:this.outPageCount
        }
        this.topologySer.findFlowItemByHost(data).subscribe(
            (res)=>{
                this.totalNum = res.data.totalNum;
                this.outList = res.data.data;
            }
        )

    }

    //进出口流量
    handleLineCancel() {
        this.inList = [];
        this.outList = [];
        this.isLine = false;
        localStorage.setItem("line",'false');
    }

    handleLineOk() {
        this.inList = [];
        this.outList = [];
        this.isLine = false;
        editor.utils.setLink(this.inSelect,this.outSelect);
        localStorage.setItem("line",'false');
    }

}