Catalog alignment
[sdc.git] / catalog-ui / src / app / ng2 / pages / composition / graph / connection-wizard / from-node-step / from-node-step.component.ts
1 import { Component, forwardRef, Inject, OnInit } from '@angular/core';
2 import { Match } from 'app/models';
3 import { Capability } from 'app/models/capability';
4 import { Requirement } from 'app/models/requirement';
5 import { IStepComponent } from 'app/models/wizard-step';
6 import { Dictionary } from 'lodash';
7 import { ConnectionWizardService } from '../connection-wizard.service';
8
9 @Component({
10     selector: 'from-node-step',
11     templateUrl: './from-node-step.component.html'
12 })
13
14 export class FromNodeStepComponent implements IStepComponent, OnInit{
15
16     optionalRequirementsMap: Dictionary<Requirement[]>;
17     optionalCapabilitiesMap: Dictionary<Capability[]>;
18
19     constructor(@Inject(forwardRef(() => ConnectionWizardService)) public connectWizardService: ConnectionWizardService) {}
20
21     ngOnInit() {
22         this.optionalRequirementsMap = this.connectWizardService.getOptionalRequirementsByInstanceUniqueId(true);
23         this.optionalCapabilitiesMap = this.connectWizardService.getOptionalCapabilitiesByInstanceUniqueId(false);
24     }
25
26     preventNext = (): boolean => {
27         return !this.connectWizardService.selectedMatch || (!this.connectWizardService.selectedMatch.capability && !this.connectWizardService.selectedMatch.requirement);
28     }
29
30     preventBack = (): boolean => {
31         return true;
32     }
33
34     private updateSelectedReqOrCap = (selected: Requirement|Capability): void => {
35         if (!selected) {
36             this.connectWizardService.selectedMatch = null;
37         } else if (selected instanceof Requirement) {
38             this.connectWizardService.selectedMatch = new Match(<Requirement>selected, null, true, this.connectWizardService.connectRelationModel.fromNode.componentInstance.uniqueId, null);
39         } else {
40             this.connectWizardService.selectedMatch = new Match(null, <Capability>selected , false, null, this.connectWizardService.connectRelationModel.fromNode.componentInstance.uniqueId);
41         }
42     }
43
44 }