Project

General

Profile

1
import { Component, OnInit, Type, ViewChild } from '@angular/core';
2
import { FormBuilder, FormGroup } from '@angular/forms';
3
import { Description, interfaceFormDesc } from '../../../domain/oa-description';
4
import { DatasourceInterfaceFormComponent } from '../sources-forms/datasource-interface-form.component';
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: 'app-sr-journal',
13
  templateUrl: 'sr-journal.component.html'
14
})
15

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

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

    
25
  @ViewChild ('registerJournal')
26
  registerJournal: DatasourceCreateFormComponent;
27

    
28
  @ViewChild('interfaceFormArray')
29
  public interfaceFormArray: MyArray;
30

    
31
  group: FormGroup;
32
  interfaceFormDesc: Description = interfaceFormDesc;
33
  addDatasourceInterfaces: Type<any> = DatasourceInterfaceFormComponent;
34

    
35
  repo: Repository;
36

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

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

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

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

    
68
  moveBackAStep(){
69
    this.errorMessage = '';
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
  downloadLogo() {
93
    window.open("../../../assets/imgs/3_0ValidatedLogo.png","_blank", "enabledstatus=0,toolbar=0,menubar=0,location=0");
94
  }
95

    
96
  setQueryParam(value: string) {
97
    // set param for step
98
    this.queryParams['step'] = value;
99
    this.router.navigate([], { relativeTo: this.route, queryParams: this.queryParams });
100
  }
101

    
102
}
(8-8/10)