Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 1 | import {Component, OnInit, ViewChild} from '@angular/core'; |
| 2 | import {DrawingBoardTreeComponent} from "./drawing-board-tree/drawing-board-tree.component"; |
| 3 | import {AvailableModelsTreeComponent} from "./available-models-tree/available-models-tree.component"; |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 4 | import {ITreeNode} from "angular-tree-component/dist/defs/api"; |
| 5 | import {TreeComponent} from 'angular-tree-component'; |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 6 | import {ActivatedRoute} from "@angular/router"; |
| 7 | import * as _ from 'lodash'; |
| 8 | import {DrawingBoardModes} from "./drawing-board.modes"; |
| 9 | import {NgRedux} from "@angular-redux/store"; |
| 10 | import {AppState} from "../../shared/store/reducers"; |
| 11 | import {updateDrawingBoardStatus} from "../../shared/storeUtil/utils/global/global.actions"; |
| 12 | import {FeatureFlagsService, Features} from "../../shared/services/featureFlag/feature-flags.service"; |
| 13 | import {ComponentInfoService} from "./component-info/component-info.service"; |
| 14 | import {ComponentInfoModel, ComponentInfoType} from "./component-info/component-info-model"; |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 15 | |
| 16 | @Component({ |
| 17 | selector: 'service-planning', |
| 18 | templateUrl: './service-planning.component.html', |
| 19 | styleUrls: ['./service-planning.component.scss'] |
| 20 | }) |
| 21 | |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 22 | export class ServicePlanningComponent implements OnInit { |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 23 | |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 24 | constructor(private route: ActivatedRoute, |
| 25 | private store: NgRedux<AppState>) { |
| 26 | } |
| 27 | |
| 28 | pageMode: DrawingBoardModes = DrawingBoardModes.CREATE; |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 29 | @ViewChild(DrawingBoardTreeComponent) drawingModelTree; |
| 30 | @ViewChild(AvailableModelsTreeComponent) availableModelTree; |
| 31 | |
| 32 | isShowTree(): boolean { |
| 33 | return true; |
| 34 | } |
| 35 | |
| 36 | public highlightNodeBySelectingInstance(modelId: number): void { |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 37 | // modelId might be undefined, e.g., if selected instance has no source in model |
| 38 | let matchInstance = modelId ? this.availableModelTree.tree.treeModel.getNodeBy((node: ITreeNode) => (node.data.modelUniqueId) === modelId) : undefined; |
| 39 | if (matchInstance) { |
| 40 | matchInstance.setActiveAndVisible().expand(); |
| 41 | } else { |
| 42 | this.clearSelectionInTree(this.availableModelTree.tree); |
| 43 | } |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 44 | } |
| 45 | |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 46 | public highlightInstancesBySelectingNode(uniqueId: string): void { |
| 47 | if (this.isShowTree()) { |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 48 | let _this = this; |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 49 | let matchInstances = _this.searchTree(uniqueId); |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 50 | if (!matchInstances.length) |
| 51 | _this.clearSelectionInTree(_this.drawingModelTree.tree); |
| 52 | matchInstances.forEach(function (instance, index) { |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 53 | let multi: boolean = !!index; |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 54 | _this.drawingModelTree.tree.treeModel.getNodeById(instance.id) |
| 55 | .setActiveAndVisible(multi).expand(); |
| 56 | }); |
| 57 | |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | clearSelectionInTree(tree: TreeComponent): void { |
| 62 | let activateNode = tree.treeModel.getActiveNode(); |
| 63 | activateNode ? activateNode.toggleActivated().blur() : null; |
| 64 | } |
| 65 | |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 66 | searchTree(uniqueId: string) { |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 67 | let _this = this; |
| 68 | let results = []; |
| 69 | let nodes = _this.drawingModelTree.nodes; |
| 70 | nodes.forEach(function (node) { |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 71 | _this.searchTreeNode(node, uniqueId, results); |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 72 | }); |
| 73 | return results; |
| 74 | } |
| 75 | |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 76 | searchTreeNode(node, uniqueId: string, results): void { |
| 77 | if ((node.modelUniqueId) === uniqueId) { |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 78 | results.push(node); |
| 79 | } |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 80 | |
| 81 | if (node.children != null) { |
| 82 | for (let i = 0; i < node.children.length; i++) { |
| 83 | this.searchTreeNode(node.children[i], uniqueId, results); |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 84 | } |
| 85 | } |
| 86 | } |
| 87 | |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 88 | ngOnInit(): void { |
| 89 | this.pageMode = (!_.isNil(this.route.routeConfig.path) && this.route.routeConfig.path !== "") ? this.route.routeConfig.path as DrawingBoardModes : DrawingBoardModes.CREATE; |
| 90 | this.store.dispatch(updateDrawingBoardStatus(this.pageMode)); |
| 91 | } |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 92 | |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 93 | isShowComponentInfo():boolean { |
| 94 | return FeatureFlagsService.getFlagState(Features.FLAG_1906_COMPONENT_INFO, this.store) |
| 95 | } |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 96 | |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 97 | clickOutside(): void{ |
| 98 | this.clearSelectionInTree(this.drawingModelTree.tree); |
| 99 | this.clearSelectionInTree(this.availableModelTree.tree); |
| 100 | ComponentInfoService.triggerComponentInfoChange.next(new ComponentInfoModel(ComponentInfoType.SERVICE, [], [])) |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 101 | } |
| 102 | } |
| 103 | |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 104 | export class ServicePlanningEmptyComponent extends ServicePlanningComponent { |
| 105 | isShowTree(): boolean { |
| 106 | return false; |
| 107 | } |
| 108 | } |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 109 | |