Project

General

Profile

1
import { Component, OnInit, Type, ViewChild } from '@angular/core';
2
import { FormBuilder, FormGroup } from '@angular/forms';
3
import { DatasourceInterfaceFormComponent } from './sources-forms/datasource-interface-form.component';
4
import { Repository, RepositoryInterface } from '../../domain/typeScriptClasses';
5
import { RepositoryService } from '../../services/repository.service';
6
import { ActivatedRoute } from '@angular/router';
7
import {
8
  Description,
9
  interfaceFormDesc,
10
} from '../../domain/oa-description';
11
import { formInfoLoading, loadingRepoError } from '../../domain/shared-messages';
12
import { DatasourceUpdateFormComponent } from './sources-forms/datasource-update-form.component';
13
import {ConfirmationDialogComponent} from "../../shared/reusablecomponents/confirmation-dialog.component";
14

    
15

    
16

    
17
@Component ({
18
  selector: 'sources-update-repo',
19
  templateUrl: 'sources-update-repo.component.html'
20
})
21

    
22
export class SourcesUpdateRepoComponent implements OnInit {
23
  loadingMessage: string;
24
  errorMessage: string;
25

    
26
  repoId: string;
27
  logoURL: string;
28
  repo: Repository;
29
  repoInterfaces: RepositoryInterface[] = [];
30

    
31
  @ViewChild('datasourceUpdateForm') datasourceUpdateForm: DatasourceUpdateFormComponent;
32

    
33
  group: FormGroup;
34
  interfaceFormDesc: Description = interfaceFormDesc;
35
  updateDatasourceInterfaces: Type<any> = DatasourceInterfaceFormComponent;
36

    
37
  isModalShown: boolean;
38
  @ViewChild('updateLogoUrlModal')
39
  public updateLogoUrlModal: ConfirmationDialogComponent;
40

    
41
  constructor (
42
    private fb: FormBuilder,
43
    private repoService: RepositoryService,
44
    private route: ActivatedRoute )
45
  {}
46

    
47

    
48
  ngOnInit() {
49
    this.readRepoId();
50
  }
51

    
52
  readRepoId() {
53
    this.repoId = this.route.snapshot.paramMap.get('id');
54
    console.log(`repoId is ${this.repoId}`);
55
    this.getRepo();
56
    this.getRepoInterfaces();
57
  }
58

    
59
  getRepo() {
60
    if (this.repoId) {
61
      this.loadingMessage = formInfoLoading;
62
      this.repoService.getRepositoryById(this.repoId).subscribe(
63
        repo => {
64
          this.repo = repo;
65
        },
66
        error => {
67
          console.log(error);
68
          this.loadingMessage = '';
69
          this.errorMessage = loadingRepoError;
70
        },
71
        () => {
72
          this.loadingMessage = '';
73
          this.logoURL = this.repo.logoUrl;
74
        }
75
      );
76
    }
77
  }
78

    
79
  getRepoInterfaces() {
80
    this.group = this.fb.group({});
81
    this.repoService.getRepositoryInterface(this.repoId).subscribe(
82
      interfaces => {
83
        this.repoInterfaces = interfaces.sort( function(a,b) {
84
          if(a.id<b.id){
85
            return -1;
86
          } else if(a.id>b.id){
87
            return 1;
88
          } else {
89
            return 0;
90
          }
91
        });
92
        console.log(`the number of interfaces for ${this.repoId} is ${this.repoInterfaces.length}`);
93
      },
94
      error => {
95
        console.log(error);
96
        this.loadingMessage = '';
97
        this.errorMessage = loadingRepoError;
98
      }, () => this.loadingMessage = ''
99
    );
100
  }
101

    
102
  updateLogoUrl(logoUrl: string){
103
    this.updateLogoUrlModal.ids = [logoUrl];
104
    this.updateLogoUrlModal.showModal();
105
  }
106

    
107
  updatedLogoUrl(event: any) {
108
    this.repo.logoUrl = this.logoURL;
109
    this.datasourceUpdateForm.updateGroup.get('logoUrl').setValue(this.logoURL);
110
    this.datasourceUpdateForm.updateRepo();
111

    
112
  }
113

    
114
  getNewLogoUrl( event: any ) {
115
    this.logoURL = event.target.value;
116

    
117
  }
118

    
119
}
(4-4/10)