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 } from '../../domain/typeScriptClasses';
6
import { AuthenticationService } from '../../services/authentication.service';
7
import {
8
  loadingReposMessage, loadingUserRepoInfo, loadingUserRepoInfoEmpty,
9
  loadingUserRepoInfoError
10
} from '../../domain/shared-messages';
11

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

    
17
export class CompatibilityValidateTypeComponent implements OnInit {
18
  type: string = '';
19
  showDatasource: boolean;
20
  showGuidelines: boolean;
21
  showParameters: boolean;
22
  showFinish: boolean;
23
  step2: string = '';
24
  step3: string = '';
25
  step4: string = '';
26

    
27
  baseUrlList: string[] = [];
28
  errorMessage: string;
29
  loadingMessage: string;
30
  showSpinner: boolean;
31

    
32
  @ViewChild('step1ChooseBaseUrl') step1ChooseBaseUrl : CompatibilityValidateStep1Component;
33

    
34
  constructor(private route: ActivatedRoute,
35
              private authService: AuthenticationService,
36
              private repoService: RepositoryService) {}
37

    
38
  ngOnInit() {
39
    this.readType();
40
    this.getBaseUrlList();
41
  }
42

    
43
  readType() {
44
    this.type = this.route.snapshot.paramMap.get('type');
45
    console.log(this.type);
46
  }
47

    
48
  moveAStep(){
49
    if (this.showDatasource) {
50
      this.step1ChooseBaseUrl.submitForm();
51
      if (this.step1ChooseBaseUrl.chosenUrl) {
52
        this.showGuidelines = true;
53
        this.showDatasource = false;
54
        this.step2 = 'active';
55
      }
56
    } else if (this.showGuidelines) {
57
      this.showParameters = true;
58
      this.showGuidelines = false;
59
      this.step3 = 'active';
60
    } else if (this.showParameters) {
61
      this.showFinish = true;
62
      this.showParameters = false;
63
      this.step4 = 'active';
64
    }
65
  }
66

    
67
  moveBackAStep(){
68
    if (this.showGuidelines) {
69
      this.showDatasource = true;
70
      this.showGuidelines = false;
71
      this.step2 = '';
72
    } else if (this.showParameters) {
73
      this.step3 = '';
74
      this.showGuidelines = true;
75
      this.showParameters = false;
76
    } else if (this.showFinish) {
77
      this.showParameters = true;
78
      this.showFinish = false;
79
      this.step4 = '';
80
    }
81
  }
82

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

    
113
}
(6-6/13)