summaryrefslogtreecommitdiffstats
path: root/vid-webpack-master/src/app/drawingBoard/service-planning/service-planning.component.ts
blob: 59988f7c32e59a01d226d28079d3bb5dbeb3f8b3 (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
import {Component, OnInit, ViewChild} from '@angular/core';
import {DrawingBoardTreeComponent} from "./drawing-board-tree/drawing-board-tree.component";
import {AvailableModelsTreeComponent} from "./available-models-tree/available-models-tree.component";
import {ITreeNode} from "angular-tree-component/dist/defs/api";
import {TreeComponent} from 'angular-tree-component';
import {ActivatedRoute} from "@angular/router";
import * as _ from 'lodash';
import {DrawingBoardModes} from "./drawing-board.modes";
import {NgRedux} from "@angular-redux/store";
import {AppState} from "../../shared/store/reducers";
import {updateDrawingBoardStatus} from "../../shared/storeUtil/utils/global/global.actions";
import {FeatureFlagsService, Features} from "../../shared/services/featureFlag/feature-flags.service";
import {ComponentInfoService} from "./component-info/component-info.service";
import {ComponentInfoModel, ComponentInfoType} from "./component-info/component-info-model";

@Component({
  selector: 'service-planning',
  templateUrl: './service-planning.component.html',
  styleUrls: ['./service-planning.component.scss']
})

export class ServicePlanningComponent implements OnInit {

  constructor(private route: ActivatedRoute,
              private  store: NgRedux<AppState>) {
  }

  pageMode: DrawingBoardModes = DrawingBoardModes.CREATE;
  @ViewChild(DrawingBoardTreeComponent, {static: false}) drawingModelTree;
  @ViewChild(AvailableModelsTreeComponent, {static: false}) availableModelTree;

  isShowTree(): boolean {
    return true;
  }

  public highlightNodeBySelectingInstance(modelId: number): void {
    // modelId might be undefined, e.g., if selected instance has no source in model
    let matchInstance = modelId ? this.availableModelTree.tree.treeModel.getNodeBy((node: ITreeNode) => (node.data.modelUniqueId) === modelId) : undefined;
    if (matchInstance) {
      matchInstance.setActiveAndVisible().expand();
    } else {
      this.clearSelectionInTree(this.availableModelTree.tree);
    }
  }

  public highlightInstancesBySelectingNode(uniqueId: string): void {
    if (this.isShowTree()) {
      let _this = this;
      let matchInstances = _this.searchTree(uniqueId);
      if (!matchInstances.length)
        _this.clearSelectionInTree(_this.drawingModelTree.tree);
      matchInstances.forEach(function (instance, index) {
        let multi: boolean = !!index;
        _this.drawingModelTree.tree.treeModel.getNodeById(instance.id)
          .setActiveAndVisible(multi).expand();
      });

    }
  }

  clearSelectionInTree(tree: TreeComponent): void {
    let activateNode = tree.treeModel.getActiveNode();
    activateNode ? activateNode.toggleActivated().blur() : null;
  }

  searchTree(uniqueId: string) {
    let _this = this;
    let results = [];
    let nodes = _this.drawingModelTree.nodes;
    nodes.forEach(function (node) {
      _this.searchTreeNode(node, uniqueId, results);
    });
    return results;
  }

  searchTreeNode(node, uniqueId: string, results): void {
    if ((node.modelUniqueId) === uniqueId) {
      results.push(node);
    }

    if (node.children != null) {
      for (let i = 0; i < node.children.length; i++) {
        this.searchTreeNode(node.children[i], uniqueId, results);
      }
    }
  }

  ngOnInit(): void {
    this.pageMode = (!_.isNil(this.route.routeConfig.path) && this.route.routeConfig.path !== "") ? this.route.routeConfig.path as DrawingBoardModes : DrawingBoardModes.CREATE;
    this.store.dispatch(updateDrawingBoardStatus(this.pageMode));
  }

  isShowComponentInfo():boolean {
    return FeatureFlagsService.getFlagState(Features.FLAG_1906_COMPONENT_INFO, this.store)
  }

  clickOutside(): void{
    this.clearSelectionInTree(this.drawingModelTree.tree);
    this.clearSelectionInTree(this.availableModelTree.tree);
    ComponentInfoService.triggerComponentInfoChange.next(new ComponentInfoModel(ComponentInfoType.SERVICE, [], []))
  }
}

export class ServicePlanningEmptyComponent extends ServicePlanningComponent {
  isShowTree(): boolean {
    return false;
  }
}