Project

General

Profile

« Previous | Next » 

Revision 51015

almost finished everything!

View differences:

datasource-interface-form.component.ts
2 2
import { MyGroup } from '../../../shared/reusablecomponents/forms/my-group.interface';
3 3
import { FormBuilder, Validators } from '@angular/forms';
4 4
import {
5
  formErrorRequiredFields, formErrorWasntSaved, formSubmitting, formSuccessAddedInterface, formSuccessUpdatedInterface,
5
  formErrorRequiredFields, formErrorWasntSaved, formInfoLoading, formSubmitting, formSuccessAddedInterface,
6
  formSuccessUpdatedInterface,
6 7
  invalidCustomBaseUrl, noServiceMessage
7 8
} from '../../../domain/shared-messages';
8 9
import { ValidatorService } from '../../../services/validator.service';
9 10
import { ActivatedRoute } from '@angular/router';
10 11
import { RepositoryService } from '../../../services/repository.service';
11 12
import { InterfaceInformation, Repository, RepositoryInterface } from '../../../domain/typeScriptClasses';
13
import {
14
  baseUrlDesc, compatibilityLevelDesc, customValSetDesc, Description,
15
  existingValSetDesc
16
} from '../../../domain/oa-description';
12 17

  
13 18
@Component ({
14 19
  selector: 'datasource-interface-form',
......
22 27
  errorMessage: string;
23 28

  
24 29
  currentRepository: Repository;
30
  isNew: boolean;
25 31

  
26 32
  identifiedBaseUrl: boolean;
27 33
  existingValSet: boolean;
......
38 44
    customValidationSet: [''],
39 45
    compatibilityLevel: ['', Validators.required]
40 46
  };
47
  baseUrlDesc: Description = baseUrlDesc;
48
  existingValSetDesc: Description = existingValSetDesc;
49
  customValSetDesc: Description = customValSetDesc;
50
  compatibilityLevelDesc: Description = compatibilityLevelDesc;
41 51

  
42 52
  constructor(injector: Injector,
43 53
              private valService: ValidatorService,
......
46 56
  }
47 57

  
48 58
  ngOnInit() {
49
      this.currentRepository = <Repository>this.otherData;
50
      this.getCompatibilityClasses();
51
      console.log(`other data is: ${JSON.stringify(this.otherData)}`);
52
      if (this.data && this.data.length) {
53
        this.currentInterface = this.data[0];
54
        this.patchData.next({
55
            baseUrl: this.data[0].baseUrl,
56
            selectValidationSet: '',
57
            customValidationSet: '',
59
    this.currentRepository = <Repository>this.otherData;
60
    this.getCompatibilityClasses();
61
    console.log(`other data is: ${JSON.stringify(this.otherData)}`);
62
    if (this.data && this.data.length) {
63
      this.currentInterface = this.data[0];
64
      this.patchData.next({
65
          baseUrl: this.data[0].baseUrl,
66
          selectValidationSet: '',
67
          customValidationSet: '',
58 68
          compatibilityLevel:this.data[0].desiredCompatibilityLevel
59
          }
60
        );
61
        this.getInterfaceInfo(this.data[0].baseUrl);
62
        this.data.splice(0,1);
63
      }
64
      super.ngOnInit();
65
      console.log(this.group, this.parentGroup);
66
      this.existingValSet = true;
67
      this.getMyControl('customValidationSet').disable();
69
      });
70
      this.getMyControl('baseUrl').disable();
71
      this.getInterfaceInfo(this.data[0].baseUrl);
72
      this.data.splice(0,1);
73
    }
74
    super.ngOnInit();
75
    console.log(this.group, this.parentGroup);
76
    this.existingValSet = true;
77
    this.getMyControl('customValidationSet').disable();
68 78
  }
69 79

  
70 80
  chooseValSet(existingValSet: boolean) {
......
82 92
  saveInterface() {
83 93
    this.errorMessage = '';
84 94
    this.successMessage = '';
85
    if (this.group.valid) {
95
    if (this.group.valid && ( this.getMyControl('selectValidationSet').value || this.getMyControl('customValidationSet').value ) ) {
86 96
      if (this.identifiedBaseUrl) {
87 97
        let baseUrl = this.getMyControl('baseUrl').value;
88 98
        let valset: string = '';
......
108 118
  }
109 119

  
110 120
  getInterfaceInfo(baseUrl: string) {
121
    this.successMessage = '';
122
    this.errorMessage = '';
123
    this.loadingMessage = formInfoLoading;
111 124
    if(baseUrl) {
112 125
      this.valService.getInterfaceInformation(baseUrl).subscribe(
113 126
        info => {
114 127
          this.interfaceInfo = info;
115 128
          if (this.interfaceInfo.identified) {
116 129
            this.identifiedBaseUrl = true;
117
            this.errorMessage = '';
118 130
          } else {
119 131
            this.errorMessage = invalidCustomBaseUrl;
120 132
          }
......
125 137
        },
126 138
        error => {
127 139
          console.log(error);
140
          this.loadingMessage = '';
128 141
          this.identifiedBaseUrl = false;
129 142
          this.errorMessage = noServiceMessage;
130
        }
143
        },
144
        () => this.loadingMessage = ''
131 145
      );
132 146
    }
133 147
  }
......
158 172
    this.repoService.updateInterface(this.currentInterface).subscribe(
159 173
      response => {
160 174
        console.log(`updateRepository responded ${response}`);
161
        this.loadingMessage = '';
162 175
        if (response == '200') {
163 176
          this.successMessage = formSuccessUpdatedInterface;
164 177
        } else {
......
169 182
        console.log(error);
170 183
        this.loadingMessage = '';
171 184
        this.errorMessage = formErrorWasntSaved;
172
      }
185
      },
186
      () => this.loadingMessage = ''
173 187
    );
174 188
  }
175 189

  
......
196 210
        this.loadingMessage = '';
197 211
        if (this.currentInterface.id) {
198 212
          this.successMessage = formSuccessAddedInterface;
213
          this.isNew = true
199 214
        } else {
200 215
          this.errorMessage = formErrorWasntSaved;
201 216
        }
......
204 219
  }
205 220

  
206 221
  ngOnDestroy() {
207
    if (this.currentInterface && this.toBeDeleted) {
222
    if (this.currentInterface && this.currentInterface.id && this.toBeDeleted) {
208 223
/*      this.repoService.deleteInterface(this.currentInterface.id).subscribe(
209 224
        response => console.log(`deleteInterface responded: ${response}`),
210 225
        error => console.log(error)
......
215 230
    }
216 231
  }
217 232

  
233
  remove
218 234

  
219 235
}

Also available in: Unified diff