Project

General

Profile

1
import { Component, OnInit, Type, ViewChild } from '@angular/core';
2
import { RegisterDatasourceShareableComponent } from './register-datasource-shareable.component';
3
import { DatasourceInfoFormComponent } from '../sources-forms/datasource-info-form.component';
4
import { Repository, RepositoryInterface } from '../../../domain/typeScriptClasses';
5
import { DatasourceInterfaceFormComponent } from '../sources-forms/datasource-interface-form.component';
6
import { Description, interfaceFormDesc } from '../../../domain/oa-description';
7
import { FormBuilder, FormGroup } from '@angular/forms';
8
import { RepositoryService } from '../../../services/repository.service';
9

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

    
15

    
16
export class SrDataComponent implements OnInit {
17
  showRepositories: boolean;
18
  showForm: boolean;
19
  showInterfaces: boolean;
20
  showFinish: boolean;
21
  step2: string = '';
22
  step3: string = '';
23
  step4: string = '';
24

    
25
  datasourceId: string;
26
  repo: Repository;
27

    
28
  @ViewChild('datasourcesByCountry')
29
  public datasourcesByCountry: RegisterDatasourceShareableComponent;
30

    
31
  @ViewChild('updateDatasource')
32
  public updateDatasource: DatasourceInfoFormComponent;
33

    
34
  group: FormGroup;
35
  interfaceFormDesc: Description = interfaceFormDesc;
36
  updateDatasourceInterfaces: Type<any> = DatasourceInterfaceFormComponent;
37
  repoInterfaces: RepositoryInterface[] = [];
38

    
39
  constructor(
40
    private fb: FormBuilder,
41
    private repoService: RepositoryService) {}
42

    
43
  ngOnInit() {
44
    this.showRepositories=true;
45
  }
46

    
47
  moveAStep(){
48
    if(this.showRepositories) {
49
      if (this.datasourcesByCountry.goToNextStep()) {
50
        this.showRepositories = false;
51
        this.showForm = true;
52
        this.step2 = 'active';
53
        console.log(`got datasource with id ${this.datasourceId}`);
54
      }
55
    } else if(this.showForm) {
56
      if (this.updateDatasource.updateRepo()){
57
        this.showForm = false;
58
        this.showInterfaces = true;
59
        this.step3 = 'active';
60
        this.group = this.fb.group({});
61
        this.getRepoInterfaces();
62
      }
63
    } else if(this.showInterfaces) {
64
        this.showInterfaces = false;
65
        this.showFinish = true;
66
        this.step4 = 'active';
67
    }
68
  }
69

    
70
  moveBackAStep(){
71
    if(this.showForm) {
72
      this.showRepositories = true;
73
      this.showForm = false;
74
      this.step2 = '';
75
    } else if(this.showInterfaces) {
76
      this.showForm = true;
77
      this.showInterfaces = false;
78
      this.step3 = '';
79
    } else if(this.showFinish) {
80
      this.showInterfaces = true;
81
      this.showFinish = false;
82
      this.step4 = '';
83
    }
84
  }
85

    
86

    
87
  getRepoId(emitedId: string) {
88
    this.datasourceId = emitedId;
89
  }
90

    
91
  getCurrentRepo(repo: Repository) {
92
    this.repo = repo;
93
  }
94

    
95
  getRepoInterfaces() {
96
    this.repoService.getRepositoryInterface(this.datasourceId).subscribe(
97
      interfaces => { this.repoInterfaces = interfaces; console.log(this.repoInterfaces.length)},
98
      error => console.log(error)
99
    );
100
  }
101

    
102
}
(6-6/10)