Project

General

Profile

1
import { Component, OnInit, ViewChild } from '@angular/core';
2
import { ActivatedRoute } from '@angular/router';
3
import { CompatibilityValidateStep1Component } from './compatibility-validate-forms/compatibility-validate-step1.component';
4
import { RepositoryService } from '../../services/repository.service';
5
import { Repository, RuleSet } from '../../domain/typeScriptClasses';
6
import { AuthenticationService } from '../../services/authentication.service';
7
import {
8
  loadingReposMessage, loadingRuleSets, loadingRuleSetsError, loadingUserRepoInfo, loadingUserRepoInfoEmpty,
9
  loadingUserRepoInfoError, noRuleSets
10
} from '../../domain/shared-messages';
11
import { ValidatorService } from '../../services/validator.service';
12
import { CompatibilityValidateStep2Component } from './compatibility-validate-forms/compatibility-validate-step2.component';
13

    
14
@Component ({
15
  selector: 'compatibility-validate-literature',
16
  templateUrl: 'compatibility-validate-type.component.html'
17
})
18

    
19
export class CompatibilityValidateTypeComponent implements OnInit {
20
  type: string = '';
21

    
22
  showDatasource: boolean;
23
  showGuidelines: boolean;
24
  showParameters: boolean;
25
  showFinish: boolean;
26

    
27
  step2: string = '';
28
  step3: string = '';
29
  step4: string = '';
30

    
31
  baseUrlList: string[] = [];
32
  ruleSets: RuleSet[] = [];
33

    
34
  errorMessage: string;
35
  loadingMessage: string;
36
  showSpinner: boolean;
37

    
38
  @ViewChild('step1ChooseBaseUrl') step1ChooseBaseUrl : CompatibilityValidateStep1Component;
39
  @ViewChild('step2ChooseGuidelines') step2ChooseGuidelines : CompatibilityValidateStep2Component;
40

    
41
  constructor(private route: ActivatedRoute,
42
              private authService: AuthenticationService,
43
              private repoService: RepositoryService,
44
              private valService: ValidatorService) {}
45

    
46
  ngOnInit() {
47
    this.readType();
48
    this.getBaseUrlList();
49
  }
50

    
51
  readType() {
52
    this.type = this.route.snapshot.paramMap.get('type');
53
    console.log(this.type);
54
  }
55

    
56
  moveAStep(){
57
    if (this.showDatasource) {
58
      if (this.step1ChooseBaseUrl.submitForm()) {
59
        this.getRuleSetsForType();
60
      }
61
    } else if (this.showGuidelines) {
62
      this.showParameters = true;
63
      this.showGuidelines = false;
64
      this.step3 = 'active';
65
    } else if (this.showParameters) {
66
      this.showFinish = true;
67
      this.showParameters = false;
68
      this.step4 = 'active';
69
    }
70
  }
71

    
72
  moveBackAStep () {
73
    if (this.showGuidelines) {
74
      this.showDatasource = true;
75
      this.showGuidelines = false;
76
      this.step2 = '';
77
    } else if (this.showParameters) {
78
      this.step3 = '';
79
      this.showGuidelines = true;
80
      this.showParameters = false;
81
    } else if (this.showFinish) {
82
      this.showParameters = true;
83
      this.showFinish = false;
84
      this.step4 = '';
85
    }
86
  }
87

    
88
  /* retrieves the baseUrl list for the registered repositories of the user */
89
  getBaseUrlList(): void {
90
    this.showSpinner = true;
91
    this.loadingMessage = loadingUserRepoInfo;
92
//    this.repoService.getUrlsOfUserRepos(this.authService.getUserEmail()) RESTORE AFTER FINISH!!
93
    this.repoService.getUrlsOfUserRepos('ant.lebesis@gmail.com')
94
      .subscribe(
95
        repos => this.baseUrlList = repos.sort( function(a , b){
96
          if(a < b ){
97
            return -1;
98
          } else if(a > b ){
99
            return 1;
100
          } else {
101
            return 0;
102
          }
103
        }),
104
        error => {
105
          console.log(error);
106
          this.showSpinner = false;
107
          this.loadingMessage = '';
108
          this.errorMessage = loadingUserRepoInfoError;
109
        },
110
        () => {
111
          this.showSpinner = false;
112
          this.loadingMessage = '';
113
          this.showDatasource = true;
114
        }
115
      );
116
  }
117

    
118
  getRuleSetsForType() {
119
    this.showSpinner = true;
120
    this.loadingMessage = loadingRuleSets;
121
    this.valService.getRuleSets(this.type)
122
      .subscribe(
123
        rules => this.ruleSets = rules,
124
        error => {
125
          this.showSpinner = false;
126
          this.loadingMessage = '';
127
          this.errorMessage = loadingRuleSetsError;
128
        },
129
        () => {
130
          this.showSpinner = false;
131
          this.loadingMessage = '';
132
          this.showDatasource = false;
133
          this.step2 = 'active';
134
          if (this.ruleSets.length) {
135
            this.showGuidelines = true;
136
          } else {
137
            this.errorMessage = noRuleSets;
138
          }
139
        }
140
      );
141
  }
142
}
(6-6/13)