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
      if(this.step1ChooseBaseUrl.goToNext()) {
51
        this.showGuidelines = true;
52
        this.showDatasource = false;
53
        this.step2 = 'active';
54
      }
55
    } else if (this.showGuidelines) {
56
      this.showParameters = true;
57
      this.showGuidelines = false;
58
      this.step3 = 'active';
59
    } else if (this.showParameters) {
60
      this.showFinish = true;
61
      this.showParameters = false;
62
      this.step4 = 'active';
63
    }
64
  }
65

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

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

    
112
}
(6-6/13)