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
import {
11
  AsideHelpContentComponent,
12
  HelpContentComponent
13
} from "../../../shared/reusablecomponents/help-content.component";
14

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

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

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

    
29
  @ViewChild ('registerJournal')
30
  registerJournal: DatasourceCreateFormComponent;
31

    
32
  @ViewChild('interfaceFormArray')
33
  public interfaceFormArray: MyArray;
34

    
35
  group: FormGroup;
36
  interfaceFormDesc: Description = interfaceFormDesc;
37
  addDatasourceInterfaces: Type<any> = DatasourceInterfaceFormComponent;
38

    
39
  repo: Repository;
40

    
41
  /* queryParams is used to change the queryParams without refreshing the page
42
   * This was needed for Help Service [which sends back info according to the current router.url]
43
   * the param that is used is 'step' and the values are: 'basicInformation','interfaces','finish'
44
   */
45
  queryParams: Params = Object.assign({}, this.route.snapshot.queryParams);
46
  @ViewChild('topHelperContent')
47
  public topHelperContent: HelpContentComponent;
48
  @ViewChild('leftHelperContent')
49
  public leftHelperContent: AsideHelpContentComponent;
50
  @ViewChild('rightHelperContent')
51
  public rightHelperContent: AsideHelpContentComponent;
52
  @ViewChild('bottomHelperContent')
53
  public bottomHelperContent: HelpContentComponent;
54

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

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

    
65
  moveAStep(){
66
    this.errorMessage = '';
67
    if (this.showForm) {
68
      this.registerJournal.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
    this.errorMessage = '';
83
    if (this.showInterfaces) {
84
      this.setQueryParam('basicInformation');
85
      this.showForm = true;
86
      this.showInterfaces = false;
87
      this.step2 = '';
88
    } else if (this.showFinish) {
89
      this.setQueryParam('interfaces');
90
      this.showInterfaces = true;
91
      this.showFinish = false;
92
      this.step3 = '';
93
    }
94
  }
95

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

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

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

    
119
}
(8-8/10)