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

    
11
@Component ({
12
  selector: 'sr-aggregator',
13
  templateUrl: 'sr-aggregator.component.html'
14
})
15

    
16
export class SrAggregatorComponent implements OnInit {
17
  errorMessage: string;
18

    
19
  showForm: boolean;
20
  showInterfaces: boolean;
21
  showFinish: boolean;
22
  step2: string = '';
23
  step3: string = '';
24

    
25
  repo: Repository;
26

    
27

    
28
  /* queryParams is used to change the queryParams without refreshing the page
29
   * This was needed for Help Service [which sends back info according to the current router.url]
30
   * the param that is used is 'step' and the values are: 'basicInformation','interfaces','finish'
31
   */
32
  queryParams: Params = Object.assign({}, this.route.snapshot.queryParams);
33

    
34
  @ViewChild ('registerAggregator')
35
  registerAggregator: DatasourceCreateFormComponent;
36

    
37
  @ViewChild('interfaceFormArray')
38
  public interfaceFormArray: MyArray;
39

    
40
  group: FormGroup;
41
  interfaceFormDesc: Description = interfaceFormDesc;
42
  addDatasourceInterfaces: Type<any> = DatasourceInterfaceFormComponent;
43

    
44
  constructor(
45
    private fb: FormBuilder,
46
    private route: ActivatedRoute,
47
    private router: Router) {}
48

    
49
  ngOnInit() {
50
    this.setQueryParam('basicInformation');
51
    this.showForm = true;
52
  }
53

    
54
  moveAStep(){
55
    if (this.showForm) {
56
      this.registerAggregator.registerDatasource();
57
    } else if (this.showInterfaces) {
58
      if (this.interfaceFormArray.checkIfOneElementExists()) {
59
        this.setQueryParam('finish');
60
        this.showInterfaces = false;
61
        this.showFinish = true;
62
        this.step3 = 'active';
63
      } else {
64
        this.errorMessage = noInterfacesSaved;
65
      }
66
    }
67
  }
68

    
69
  moveBackAStep(){
70
    if (this.showInterfaces) {
71
      this.setQueryParam('basicInformation');
72
      this.showForm = true;
73
      this.showInterfaces = false;
74
      this.step2 = '';
75
    } else if (this.showFinish) {
76
      this.setQueryParam('interfaces');
77
      this.showInterfaces = true;
78
      this.showFinish = false;
79
      this.step3 = '';
80
    }
81
  }
82

    
83
  getCurrentRepo(repo: Repository) {
84
    this.repo = repo;
85
    this.setQueryParam('interfaces');
86
    this.showForm = false;
87
    this.showInterfaces = true;
88
    this.step2 = 'active';
89
    this.group = this.fb.group({});
90
  }
91

    
92
  updateInterfaceCount(addedInterface: boolean) {
93

    
94
  }
95

    
96
  downloadLogo() {
97
    window.open("../../../assets/imgs/3_0ValidatedLogo.png","_blank", "enabledstatus=0,toolbar=0,menubar=0,location=0");
98
  }
99

    
100
  setQueryParam(value: string) {
101
    // set param for step
102
    this.queryParams['step'] = value;
103
    this.router.navigate([], { relativeTo: this.route, queryParams: this.queryParams });
104
  }
105

    
106
}
(4-4/10)