import {Component, OnInit} from '@angular/core';
import {Router} from '@angular/router';
import {Http} from '@angular/http';
import {LayoutService} from '../layout.service';
import {LocalStorageService, SessionStorageService} from 'ngx-webstorage';
import {CommonService} from '../../shared/common/common.service';

@Component({
    selector: 'jhi-sidebar',
    templateUrl: './sidebar.component.html',
    styles: [
            ` span i {
            margin-right: 10px;
        } `
    ]
})
export class SidebarComponent implements OnInit {
    token: boolean;

    menuList = [{
        "id": "61fbf8d185184cd0ad3afb071c350f35",
        "parentId": "b9a99765784c44378141c789fd8e8c80",
        "name": "综合监控",
        "code": "monitor",
        "url": "",
        "imageUrl": "zhjk",
        "showOrder": 2,
        "checked":false,
    }, {
        "id": "gc44aacf0db14ac28f0189b6d68d8097",
        "parentId": "b9a99765784c44378141c789fd8e8c80",
        "name": "告警管理",
        "code": "warning",
        "url": null,
        "imageUrl": "gjgl",
        "showOrder": 3,
        "checked":false,
    }, {
        "id": "ed8ad2d8aca64d1ea896fb659b64b258",
        "parentId": "b9a99765784c44378141c789fd8e8c80",
        "name": "网络拓扑",
        "code": "networkTopology",
        "url": null,
        "imageUrl": "wltp",
        "showOrder": 4,
        "checked":false,
    }, {
        "id": "844f455d4e11448cad99f40a913980f9",
        "parentId": "b9a99765784c44378141c789fd8e8c80",
        "name": "统计分析",
        "code": "analysis",
        "url": null,
        "imageUrl": "tjfx",
        "showOrder": 5,
        "checked":false,
    }, {
        "id": "0b117c84245a4e2ea8a47696cf2a84c3",
        "parentId": "b9a99765784c44378141c789fd8e8c80",
        "name": "运维工作",
        "code": "work",
        "url": null,
        "imageUrl": "ywgz",
        "showOrder": 7,
        "checked":false,
    }, {
        "id": "0050d077f2ef4f3ab7289bf7d0f215ed",
        "parentId": "b9a99765784c44378141c789fd8e8c80",
        "name": "系统管理",
        "code": "systemManage",
        "url": "",
        "imageUrl": "xtgl",
        "showOrder": 9,
        "checked":false,
    }, {
        "id": "74f82e90eb954cfbb3899cb3a1309d9f",
        "parentId": "61fbf8d185184cd0ad3afb071c350f35",
        "name": "基础资源监控",
        "code": "basicMonitor",
        "url": "basic",
        "imageUrl": null,
        "showOrder": 20,
        "checked":false,
    }, {
        "id": "4344ebab149f432785d68ba44808cef4",
        "parentId": "61fbf8d185184cd0ad3afb071c350f35",
        "name": "网站监测",
        "code": "networkCheck",
        "url": "networkCheck",
        "imageUrl": null,
        "showOrder": 23,
        "checked":false,
    }, {
        "id": "8046ff846b084444a17ace798d5edd54",
        "parentId": "gc44aacf0db14ac28f0189b6d68d8097",
        "name": "当前告警",
        "code": "currentWarning",
        "url": "nowAlarm",
        "imageUrl": null,
        "showOrder": 30,
        "checked":false,
    }, {
        "id": "fea1222fe75e4c47b2376712c1f85c92",
        "parentId": "gc44aacf0db14ac28f0189b6d68d8097",
        "name": "告警记录",
        "code": "warningReport",
        "url": "alarmList",
        "imageUrl": null,
        "showOrder": 31,
        "checked":false,
    }, {
        "id": "f610f1243374404ca61d60c58d3c1acc",
        "parentId": "gc44aacf0db14ac28f0189b6d68d8097",
        "name": "告警推送日志",
        "code": "warningLog",
        "url": "alarmLog",
        "imageUrl": null,
        "showOrder": 32,
        "checked":false,
    }, {
        "id": "079f2fd721a7413dba4b884db7f548d1",
        "parentId": "gc44aacf0db14ac28f0189b6d68d8097",
        "name": "告警推送设置",
        "code": "warningSet",
        "url": "alarmSet",
        "imageUrl": null,
        "showOrder": 33,
        "checked":false,
    }, {
        "id": "945de8965e2547db8d1622d990abf8bf",
        "parentId": "gc44aacf0db14ac28f0189b6d68d8097",
        "name": "发送推送设置",
        "code": "sendSet",
        "url": "sendSet",
        "imageUrl": null,
        "showOrder": 34,
        "checked":false,
    }, {
        "id": "35cfe93b5abd40b0a628d9efe458acc6",
        "parentId": "ed8ad2d8aca64d1ea896fb659b64b258",
        "name": "网络拓扑图",
        "code": "neTopology",
        "url": "neTopology",
        "imageUrl": null,
        "showOrder": 40,
        "checked":false,
    }, {
        "id": "4927d17f0fef48469212e6095663750b",
        "parentId": "ed8ad2d8aca64d1ea896fb659b64b258",
        "name": "拓扑图标管理",
        "code": "topoImg",
        "url": "topoImg",
        "imageUrl": null,
        "showOrder": 41,
        "checked":false,
    }, {
        "id": "6cf6928899c0482496d6a6d96b9a1f8c",
        "parentId": "ed8ad2d8aca64d1ea896fb659b64b258",
        "name": "流量趋势",
        "code": "flowTrend",
        "url": "flowTrend",
        "imageUrl": null,
        "showOrder": 42,
        "checked":false,
    }, {
        "id": "6b4e1efa60a5411ba9f0721521aeeef0",
        "parentId": "844f455d4e11448cad99f40a913980f9",
        "name": "资源告警统计",
        "code": "resourceAlarm",
        "url": "resourceAlarm",
        "imageUrl": null,
        "showOrder": 50,
        "checked":false,
    }, {
        "id": "68aac639bec6467d8fd4a52d9184504f",
        "parentId": "844f455d4e11448cad99f40a913980f9",
        "name": "资源可用性统计",
        "code": "resourceUsabil",
        "url": "resourceUsabil",
        "imageUrl": null,
        "showOrder": 51,
        "checked":false,
    }, {
        "id": "2c529665252341bebd289c2758b66ad2",
        "parentId": "844f455d4e11448cad99f40a913980f9",
        "name": "运维工作统计",
        "code": "operationWork",
        "url": "operationWork",
        "imageUrl": null,
        "showOrder": 53,
        "checked":false,
    },  {
        "id": "f94960af576c4bd99cbbbb4a9020f5f1",
        "parentId": "0b117c84245a4e2ea8a47696cf2a84c3",
        "name": "事件处置",
        "code": "workHandle",
        "url": "workHandle",
        "imageUrl": null,
        "showOrder": 70,
        "checked":false,
    }, {
        "id": "d7209f1d3a8b4f02ae8fc3f8b30b8aa1",
        "parentId": "0b117c84245a4e2ea8a47696cf2a84c3",
        "name": "巡检计划",
        "code": "inspectPlan",
        "url": "inspectPlan",
        "imageUrl": null,
        "showOrder": 71,
        "checked":false,
    }, {
        "id": "3e864a2900574eb289816e74f576a439",
        "parentId": "0b117c84245a4e2ea8a47696cf2a84c3",
        "name": "资产备件",
        "code": "assetPart",
        "url": "assetPart",
        "imageUrl": null,
        "showOrder": 74,
        "checked":false,
    }, {
            "id": "3e864a2900574eb279816e74f576a439",
            "parentId": "0b117c84245a4e2ea8a47696cf2a84c3",
            "name": "参数配置",
            "code": "params",
            "url": "params",
            "imageUrl": null,
            "showOrder": 75,
            "checked":false,
        },{
        "id": "1d17dc2e439f4fd9a3037a619c3eb275",
        "parentId": "0050d077f2ef4f3ab7289bf7d0f215ed",
        "name": "组织用户",
        "code": "organizationUser",
        "url": "group",
        "imageUrl": null,
        "showOrder": 90,
        "checked":false,
    }, {
        "id": "3ca073e2c3a24a0fadef89e204ff0dfc",
        "parentId": "0050d077f2ef4f3ab7289bf7d0f215ed",
        "name": "角色与权限",
        "code": "role",
        "url": "power",
        "imageUrl": null,
        "showOrder": 91,
        "checked":false,
    }, {
        "id": "3dba52e512034b3188f6fc0dc77d88dc",
        "parentId": "0050d077f2ef4f3ab7289bf7d0f215ed",
        "name": "系统审计",
        "code": "systemCount",
        "url": "audit",
        "imageUrl": null,
        "showOrder": 92,
        "checked":false,
    }, {
        "id": "5cf71cff20eb46909c966a11329c35ec",
        "parentId": "0050d077f2ef4f3ab7289bf7d0f215ed",
        "name": "审核管理",
        "code": "approveManage",
        "url": "examine",
        "imageUrl": null,
        "showOrder": 93,
        "checked":false,
    }];

    constructor(public router: Router, private http: Http,
                public layoutSer: LayoutService,
                public commonSer: CommonService,
                private $localStorage: LocalStorageService,
                private $sessionStorage: SessionStorageService) {
    }

    ngOnInit() {
        // this.getMenu();
        this.menuList = this.commonSer.listToTree('id', 'parentId', this.menuList);
    }

    getMenu() {
        this.layoutSer.getMenu().subscribe(
            (res) => {
                if (res.errCode == 10000) {
                    this.menuList = this.commonSer.listToTree('id', 'parentId', res.data);
                }
            }
        );
    }

    //简单使用

    openHandler(value: string): void {
        for (let key in this.menuList) {
            if (key !== value) {
                this.menuList[key].checked = false;
            }
        }
    }

    goTo(route) {
        this.router.navigate([route]);
    }

    goToRoute(node){
        console.log(node);
        this.$localStorage.store("moduleId",node.id);
        this.router.navigate(["app/main/"+ node.url]);
    }
}
