Project

General

Profile

« Previous | Next » 

Revision 50536

temporary commit for Panagiotis

View differences:

datasource-interface-form.component.ts
3 3
import { Validators } from '@angular/forms';
4 4
import {
5 5
  formErrorRequiredFields, formSuccessAddedInterface,
6
  invalidCustomBaseUrl
6
  invalidCustomBaseUrl, loadingValSetsError, noServiceMessage
7 7
} from '../../../domain/shared-messages';
8 8
import { ValidatorService } from '../../../services/validator.service';
9
import { ActivatedRoute } from '@angular/router';
10
import { RepositoryService } from '../../../services/repository.service';
9 11

  
10 12
@Component ({
11 13
  selector: 'datasource-interface-form',
......
16 18

  
17 19
  successMessage: string;
18 20
  errorMessage: string;
21

  
22
  mode: string;
23

  
24
  identifiedBaseUrl: boolean;
25
  valSets: string[] = [];
19 26
  existingValSet: boolean;
20 27

  
28
  compClasses: Map<string,string> = new Map<string,string>();
29
  classCodes: string[] = [];
30

  
21 31
  readonly groupDefinition = {
22 32
    baseUrl: ['', Validators.required],
23 33
    selectValidationSet: [''],
......
25 35
    compatibilityLevel: ['', Validators.required],
26 36
  };
27 37

  
28
  constructor(injector: Injector, private valService: ValidatorService){
38
  constructor(injector: Injector,
39
              private valService: ValidatorService,
40
              private repoService: RepositoryService,
41
              private route: ActivatedRoute){
29 42
    super(injector);
30 43
  }
31 44

  
32
  ngOnInit(){
45
  ngOnInit() {
33 46

  
34
    super.ngOnInit();
35
    console.log(this.group,this.parentGroup);
47
    setTimeout(() => {
48
      super.ngOnInit();
49
      this.getMode();
36 50

  
37
    if (this.data && this.data.length) {
38
/*
39
      this.group.patchValue({
40
        baseUrl : this.data[0].baseUrl,
41
        selectValidationSet : this.data[0].accessSet,
42
        compatibilityLevel : this.data[0].desiredCompatibilityLevel
43
      });
44
*/
45
      this.patchData.next({
46
        baseUrl : this.data[0].baseUrl,
47
        selectValidationSet : this.data[0].accessSet,
48
        compatibilityLevel : this.data[0].desiredCompatibilityLevel
49
      });
50
      this.data.splice(0,1);
51
    }
51
      console.log(this.group, this.parentGroup);
52
      if (this.data && this.data.length) {
53
/*          this.group.patchValue({
54
            baseUrl : this.data[0].baseUrl,
55
            selectValidationSet : this.data[0].accessSet,
56
            compatibilityLevel : this.data[0].desiredCompatibilityLevel
57
          });*/
58
        this.patchData.next({
59
          baseUrl: this.data[0].baseUrl,
60
/*          selectValidationSet: this.data[0].accessSet,  [ IS THIS THE CORRECT FIELD ?????]*/
61
          compatibilityLevel: this.data[0].desiredCompatibilityLevel
62
        });
63
        this.identifyBaseUrl(this.data[0].baseUrl);
64
        this.getCompatibilityClasses();
65
        this.data.splice(0, 1);
66
      }
52 67

  
53
    this.existingValSet = true;
54
    this.getMyControl('customValidationSet').disable();
55
  }
68
      this.existingValSet = true;
69
      this.getMyControl('customValidationSet').disable();
70
    }, 1500);
71
}
56 72

  
57

  
58 73
  chooseValSet(existingValSet: boolean) {
59 74
     if(existingValSet) {
60 75
       this.existingValSet = true;
......
68 83
  }
69 84

  
70 85
  saveInterface() {
71
    if(this.group.valid) {
72
      let response: boolean;
73
      this.valService.identifyRepository(this.group.get('baseUrl').value).subscribe(
74
        res => response = res,
75
        error => console.log(error)
76
      );
77
      if ( response ) {
86
    if (this.group.valid) {
87
      if (this.identifiedBaseUrl) {
78 88
        this.successMessage = formSuccessAddedInterface;
79 89
        this.errorMessage = '';
80 90
      } else {
81
        this.errorMessage = invalidCustomBaseUrl;
82
        this.successMessage = '';
91
        let response: boolean;
92
        response = this.identifyBaseUrl(this.group.get('baseUrl').value);
93
        if (response) {
94
          this.successMessage = formSuccessAddedInterface;
95
          this.errorMessage = '';
96
        } else {
97
          this.errorMessage = invalidCustomBaseUrl;
98
          this.successMessage = '';
99
        }
83 100
      }
84 101
    } else {
85 102
      this.errorMessage = formErrorRequiredFields;
......
87 104
    }
88 105
  }
89 106

  
107
  identifyBaseUrl(url: string) {
108
    let response: boolean;
109
    this.valService.identifyRepository(url).subscribe(
110
      res => {
111
        response = res;
112
        if (response) {
113
          this.getValidationSets(url);
114
          this.identifiedBaseUrl = true;
115
        }
116
      },
117
      error => {
118
        console.log(error);
119
        response = false;
120
      }
121
    );
122
    return response;
123
  }
124

  
125
  getValidationSets(url: string) {
126
    if (url) {
127
      this.valService.getSetsOfRepository(url)
128
        .subscribe(
129
          sets => this.valSets = sets,
130
          error => {
131
            this.errorMessage = loadingValSetsError
132
          }
133
        );
134
    }
135
  }
136

  
137
  getCompatibilityClasses() {
138
    this.repoService.getCompatibilityClasses(this.mode).subscribe(
139
      classes => {
140
        this.compClasses = classes;
141
        for (let key in this.compClasses){
142
          this.classCodes.push(key);
143
        }
144
      },
145
      error => {
146
        this.errorMessage = noServiceMessage;
147
        console.log(error);
148
      }
149
    );
150
  }
151

  
152
  getMode() {
153
    if (this.route.snapshot.paramMap.get('id')) {
154
      this.mode = this.route.snapshot.paramMap.get('id').split("_")[0];
155
    } else {
156
      this.mode = this.route.snapshot.url[0].path;
157
    }
158
  }
159

  
90 160
}

Also available in: Unified diff