Project

General

Profile

« Previous | Next » 

Revision 50346

continued sources-register

View differences:

sources-update-repo.component.ts
1 1
import { Component, OnInit, Type } from '@angular/core';
2
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
3
import { UpdateDatasourceInterfaceFormComponent } from './update-datasource-interface-form.component';
4
import { Country, Repository, RepositoryInterface } from '../../domain/typeScriptClasses';
2
import { FormBuilder, FormGroup } from '@angular/forms';
3
import { DatasourceInterfaceFormComponent } from './sources-forms/datasource-interface-form.component';
4
import { RepositoryInterface } from '../../domain/typeScriptClasses';
5 5
import { RepositoryService } from '../../services/repository.service';
6 6
import { ActivatedRoute } from '@angular/router';
7 7
import {
8 8
  Description,
9 9
  interfaceFormDesc,
10
  softwarePlatformDesc,
11
  platformNameDesc,
12
  officialNameDesc,
13
  repoDescriptionDesc,
14
  countryDesc,
15
  longtitudeDesc,
16
  latitudeDesc,
17
  websiteUrlDesc,
18
  institutionNameDesc,
19
  englishNameDesc,
20
  logoUrlDesc,
21
  timezoneDesc,
22
  datasourceTypeDesc,
23
  adminEmailDesc
24 10
} from '../../domain/oa-description';
25
import { formErrorRequiredFields, formSuccessUpdatedRepo } from '../../domain/shared-messages';
26 11

  
27 12

  
28 13

  
......
34 19
export class SourcesUpdateRepoComponent implements OnInit {
35 20

  
36 21
  repoId = '';
37
  selectedRepo: Repository;
38
  countries: Country[];
39 22
  repoInterfaces: RepositoryInterface[] = [];
40 23

  
41
  errorMessage: string;
42
  successMessage: string;
43

  
44 24
  group: FormGroup;
45 25
  interfaceFormDesc: Description = interfaceFormDesc;
46
  updateDatasourceInterfaces : Type<any> = UpdateDatasourceInterfaceFormComponent;
26
  updateDatasourceInterfaces : Type<any> = DatasourceInterfaceFormComponent;
47 27

  
48
  interfaceDummyList = [
49
    {
50
      baseUrl: 'WWW.FDGLKSDJFGLKDJSF.GR',
51
      selectValidationSet: 'blabla',
52
      compatibilityLevel: 'moreblabla'
53
    },
54
    {
55
      baseUrl: 'WWW.FDGLKSDJFGLKDJSfdgdfgF.GR',
56
      selectValidationSet: 'blabla2',
57
      compatibilityLevel: 'blabla1'
58
    }
59
  ];
60

  
61
  updateGroup: FormGroup;
62
  readonly updateGroupDefinition = {
63
    softwarePlatform : '',
64
    platformName : '',
65
    officialName : '',
66
    repoDescription : '',
67
    country : '',
68
    longtitude : '',
69
    latitude : '',
70
    websiteUrl : '',
71
    institutionName : '',
72
    englishName: ['', Validators.required],
73
    logoUrl: '',
74
    timezone: ['', Validators.required],
75
    datasourceType: ['', Validators.required],
76
    adminEmail: ['', Validators.required]
77
  };
78

  
79
  softwarePlatformDesc : Description = softwarePlatformDesc;
80
  platformNameDesc : Description = platformNameDesc;
81
  officialNameDesc : Description = officialNameDesc;
82
  repoDescriptionDesc : Description = repoDescriptionDesc;
83
  countryDesc : Description = countryDesc;
84
  longtitudeDesc : Description = longtitudeDesc;
85
  latitudeDesc : Description = latitudeDesc;
86
  websiteUrlDesc : Description = websiteUrlDesc;
87
  institutionNameDesc : Description = institutionNameDesc;
88
  englishNameDesc : Description = englishNameDesc;
89
  logoUrlDesc : Description = logoUrlDesc;
90
  timezoneDesc : Description = timezoneDesc;
91
  datasourceTypeDesc : Description = datasourceTypeDesc;
92
  adminEmailDesc : Description = adminEmailDesc;
93

  
94

  
95 28
  constructor (
96 29
    private fb: FormBuilder,
97 30
    private repoService: RepositoryService,
......
101 34

  
102 35
  ngOnInit() {
103 36
    this.readRepoId();
104
    this.loadUpdateTab();
105 37
    this.loadInterfacesTab();
106 38

  
107 39
  }
......
110 42
    this.repoId = this.route.snapshot.paramMap.get('id');
111 43
  }
112 44

  
113
  getRepo() {
114
    this.repoService.getRepositoryById(this.repoId).subscribe(
115
      repo => {
116
        this.selectedRepo = repo;
117
        if(this.selectedRepo) {
118
          this.updateGroup.setValue({
119
            softwarePlatform: '', //this.selectedRepo.WHICH FIELD ??
120
            platformName: this.selectedRepo.typology,
121
            officialName: this.selectedRepo.officialName,
122
            repoDescription: this.selectedRepo.description,
123
            country: this.selectedRepo.countryCode,
124
            longtitude: this.selectedRepo.longitude,
125
            latitude: this.selectedRepo.latitude,
126
            websiteUrl: this.selectedRepo.websiteUrl,
127
            institutionName: this.selectedRepo.organization,
128
            englishName: this.selectedRepo.englishName,
129
            logoUrl: this.selectedRepo.logoUrl,
130
            timezone: this.selectedRepo.timezone,
131
            datasourceType: this.selectedRepo.datasourceType,
132
            adminEmail: this.selectedRepo.contactEmail
133
          });
134
        }
135
        this.updateGroup.get('softwarePlatform').disable();
136
        this.updateGroup.get('platformName').disable();
137
        this.updateGroup.get('officialName').disable();
138
        this.updateGroup.get('repoDescription').disable();
139
        this.updateGroup.get('country').disable();
140
        this.updateGroup.get('longtitude').disable();
141
        this.updateGroup.get('latitude').disable();
142
        this.updateGroup.get('websiteUrl').disable();
143
        this.updateGroup.get('institutionName').disable();
144
      },
145
      error =>console.log(error)
146
    )
147
  }
148 45

  
149 46
  getRepoInterfaces() {
150 47
    this.repoService.getRepositoryInterface(this.repoId).subscribe(
......
153 50
    );
154 51
  }
155 52

  
156
  getCountries() {
157
    this.repoService.getCountries()
158
      .subscribe(
159
        countries => this.countries = countries.sort( function(a,b){
160
          if(a.name<b.name){
161
            return -1;
162
          } else if(a.name>b.name){
163
            return 1;
164
          } else {
165
            return 0;
166
          }
167
        } ),
168
        error => console.log(error)
169
      );
170
  }
171

  
172
  loadUpdateTab() {
173
    this.updateGroup = this.fb.group(this.updateGroupDefinition);
174
    this.getCountries();
175
    this.getRepo();
176
    //set initial values
177
  }
178

  
179 53
  loadInterfacesTab() {
180 54
    this.getRepoInterfaces();
181 55
    this.group = this.fb.group({});
......
193 67
*/
194 68
  }
195 69

  
196
  updateRepo(){
197
    if(this.updateGroup.valid){
198
      this.successMessage = formSuccessUpdatedRepo;
199
      this.errorMessage = '';
200
    } else {
201
      this.errorMessage = formErrorRequiredFields;
202
      this.successMessage = '';
203
    }
204
  }
205 70

  
206 71
}

Also available in: Unified diff