Skip to content
monitor.component.ts 5.34 KiB
Newer Older
wangqinghua's avatar
wangqinghua committed
import { Component, OnInit } from '@angular/core';
import {TreeNodeInterface} from "../basic/basic.component";
import {
    FormBuilder,
    FormGroup,
    Validators
} from '@angular/forms';

@Component({
  selector: 'jhi-monitor',
  templateUrl: './monitor.component.html',
  styles: []
})

export class MonitorComponent implements OnInit {

    isBasicEdit = false;

    constructor(private fb: FormBuilder) { }

    data = [
        {
            key  : 1,
            key1 : '名称',
            key2 : '状态',
            key3 : '类型',
            key4 : '监控点',
            key5 : 'CPU利用率',
            children: [
                {
                    key    : 11,
                    key1 : '名称',
                    key2 : '状态',
                    key3 : '类型',
                    key4 : '监控点',
                    key5 : 'CPU利用率',
                },
                {
                    key     : 12,
                    key1 : '名称',
                    key2 : '状态',
                    key3 : '类型',
                    key4 : '监控点',
                    key5 : 'CPU利用率',
                    children: [ {
                        key    : 121,
                        key1 : '名称',
                        key2 : '状态',
                        key3 : '类型',
                        key4 : '监控点',
                        key5 : 'CPU利用率',
                    } ]
                },
                {
                    key     : 13,
                    key1 : '名称',
                    key2 : '状态',
                    key3 : '类型',
                    key4 : '监控点',
                    key5 : 'CPU利用率',
                    children: [
                        {
                            key     : 131,
                            key1 : '名称',
                            key2 : '状态',
                            key3 : '类型',
                            key4 : '监控点',
                            key5 : 'CPU利用率',
                            children: [
                                {
                                    key    : 1311,
                                    key1 : '名称',
                                    key2 : '状态',
                                    key3 : '类型',
                                    key4 : '监控点',
                                    key5 : 'CPU利用率',
                                },
                                {
                                    key    : 1312,
                                    key1 : '名称',
                                    key2 : '状态',
                                    key3 : '类型',
                                    key4 : '监控点',
                                    key5 : 'CPU利用率',
                                }
                            ]
                        }
                    ]
                }
            ]
        },
        {
            key    : 2,
            key1 : '名称',
            key2 : '状态',
            key3 : '类型',
            key4 : '监控点',
            key5 : 'CPU利用率',
        }
    ];
    expandDataCache = {};

    // collapse(array: TreeNodeInterface[], data: TreeNodeInterface, $event: boolean): void {
    //     if ($event === false) {
    //         if (data.children) {
    //             data.children.forEach(d => {
    //                 const target = array.find(a => a.key === d.key);
    //                 target.expand = false;
    //                 this.collapse(array, target, false);
    //             });
    //         } else {
    //             return;
    //         }
    //     }
    // }

    // convertTreeToList(root: object): TreeNodeInterface[] {
    //     const stack = [];
    //     const array = [];
    //     const hashMap = {};
    //     stack.push({ ...root, level: 0, expand: false });
    //
    //     while (stack.length !== 0) {
    //         const node = stack.pop();
    //         // this.visitNode(node, hashMap, array);
    //         if (node.children) {
    //             for (let i = node.children.length - 1; i >= 0; i--) {
    //                 stack.push({ ...node.children[ i ], level: node.level + 1, expand: false, parent: node });
    //             }
    //         }
    //     }
    //
    //     return array;
    // }

    // visitNode(node: TreeNodeInterface, hashMap: object, array: TreeNodeInterface[]): void {
    //     if (!hashMap[ node.key ]) {
    //         hashMap[ node.key ] = true;
    //         array.push(node);
    //     }
    // }

    validateForm: FormGroup;

    submitForm(): void {
        for (const i in this.validateForm.controls) {
            this.validateForm.controls[ i ].markAsDirty();
            this.validateForm.controls[ i ].updateValueAndValidity();
        }
    }

    ngOnInit(): void {
        // this.data.forEach(item => {
        //     this.expandDataCache[ item.key ] = this.convertTreeToList(item);
        // });
        this.validateForm = this.fb.group({
            userName: [ null, [ Validators.required ] ],
            password: [ null, [ Validators.required ] ],
            remember: [ true ]
        });
    }

    showBasicEditModal(){
        this.isBasicEdit = true;
    }

    handleOk(): void {
        this.isBasicEdit = false;
    }

    handleCancel(): void {
        this.isBasicEdit = false;
    }
}