Project

General

Profile

1
import { Component, OnInit, Type, ViewChild } from '@angular/core';
2
import { DatasourceInterfaceFormComponent } from '../sources-forms/datasource-interface-form.component';
3
import { Description, interfaceFormDesc } from '../../../domain/oa-description';
4
import { FormBuilder, FormGroup } from '@angular/forms';
5
import { Repository } from '../../../domain/typeScriptClasses';
6
import { DatasourceCreateFormComponent } from '../sources-forms/datasource-create-form.component';
7
import {ActivatedRoute, Params, Router} from "@angular/router";
8
import {MyArray} from "../../../shared/reusablecomponents/forms/my-array.interface";
9
import {noInterfacesSaved} from "../../../domain/shared-messages";
10
import {
11
  AsideHelpContentComponent,
12
  HelpContentComponent
13
} from "../../../shared/reusablecomponents/help-content.component";
14

    
15
@Component ({
16
  selector: 'sr-aggregator',
17
  templateUrl: 'sr-aggregator.component.html'
18
})
19

    
20
export class SrAggregatorComponent implements OnInit {
21
  errorMessage: string;
22

    
23
  showForm: boolean;
24
  showInterfaces: boolean;
25
  showFinish: boolean;
26
  step2: string = '';
27
  step3: string = '';
28

    
29
  repo: Repository;
30

    
31

    
32
  /* queryParams is used to change the queryParams without refreshing the page
33
   * This was needed for Help Service [which sends back info according to the current router.url]
34
   * the param that is used is 'step' and the values are: 'basicInformation','interfaces','finish'
35
   */
36
  queryParams: Params = Object.assign({}, this.route.snapshot.queryParams);
37
  @ViewChild('topHelperContent')
38
  public topHelperContent: HelpContentComponent;
39
  @ViewChild('leftHelperContent')
40
  public leftHelperContent: AsideHelpContentComponent;
41
  @ViewChild('rightHelperContent')
42
  public rightHelperContent: AsideHelpContentComponent;
43
  @ViewChild('bottomHelperContent')
44
  public bottomHelperContent: HelpContentComponent;
45

    
46
  @ViewChild ('registerAggregator')
47
  registerAggregator: DatasourceCreateFormComponent;
48

    
49
  @ViewChild('interfaceFormArray')
50
  public interfaceFormArray: MyArray;
51

    
52
  group: FormGroup;
53
  interfaceFormDesc: Description = interfaceFormDesc;
54
  addDatasourceInterfaces: Type<any> = DatasourceInterfaceFormComponent;
55

    
56
  constructor(
57
    private fb: FormBuilder,
58
    private route: ActivatedRoute,
59
    private router: Router) {}
60

    
61
  ngOnInit() {
62
    this.setQueryParam('basicInformation');
63
    this.showForm = true;
64
  }
65

    
66
  moveAStep(){
67
    if (this.showForm) {
68
      this.registerAggregator.registerDatasource();
69
    } else if (this.showInterfaces) {
70
      if (this.interfaceFormArray.checkIfOneElementExists()) {
71
        this.setQueryParam('finish');
72
        this.showInterfaces = false;
73
        this.showFinish = true;
74
        this.step3 = 'active';
75
      } else {
76
        this.errorMessage = noInterfacesSaved;
77
      }
78
    }
79
  }
80

    
81
  moveBackAStep(){
82
    if (this.showInterfaces) {
83
      this.setQueryParam('basicInformation');
84
      this.showForm = true;
85
      this.showInterfaces = false;
86
      this.step2 = '';
87
    } else if (this.showFinish) {
88
      this.setQueryParam('interfaces');
89
      this.showInterfaces = true;
90
      this.showFinish = false;
91
      this.step3 = '';
92
    }
93
  }
94

    
95
  getCurrentRepo(repo: Repository) {
96
    this.repo = repo;
97
    this.setQueryParam('interfaces');
98
    this.showForm = false;
99
    this.showInterfaces = true;
100
    this.step2 = 'active';
101
    this.group = this.fb.group({});
102
  }
103

    
104
  updateInterfaceCount(addedInterface: boolean) {
105

    
106
  }
107

    
108
  downloadLogo() {
109
    window.open("../../../assets/imgs/3_0ValidatedLogo.png","_blank", "enabledstatus=0,toolbar=0,menubar=0,location=0");
110
  }
111

    
112
  setQueryParam(value: string) {
113
    // set param for step
114
    this.queryParams['step'] = value;
115
    this.router.navigate([], { relativeTo: this.route, queryParams: this.queryParams });
116
    this.rightHelperContent.ngOnInit();
117
    this.topHelperContent.ngOnInit();
118
    this.leftHelperContent.ngOnInit();
119
    this.bottomHelperContent.ngOnInit();
120
  }
121

    
122
}
(4-4/10)