Project

General

Profile

1
import { Component, OnInit, ViewChild } from '@angular/core';
2
import { ActivatedRoute, Router } from '@angular/router';
3
import { JobResultEntry, StoredJob } from '../../domain/typeScriptClasses';
4
import { MonitorService } from '../../services/monitor.service';
5
import { loadingJobSummary, loadingJobSummaryError, noContentRulesResults,
6
         noUsageRulesResults } from '../../domain/shared-messages';
7
import { ConfirmationDialogComponent } from '../../shared/reusablecomponents/confirmation-dialog.component';
8
import { AuthenticationService } from '../../services/authentication.service';
9

    
10
@Component({
11
  selector: 'app-compatibility-validation-results',
12
  templateUrl: 'compatibility-validation-results.component.html'
13
})
14

    
15
export class CompatibilityValidationResultsComponent implements OnInit {
16
  errorMessage: string;
17
  loadingMessage: string;
18
  noRulesTested: string;
19
  noContent: string;
20
  noUsage: string;
21

    
22
  jobSummary: StoredJob;
23
  contentResults: JobResultEntry[] = [];
24
  usageResults: JobResultEntry[] = [];
25
  currentErrors: string[] = [];
26

    
27
  modalTitle: string;
28
  isModalShown: boolean;
29

    
30
  @ViewChild('checkErrors')
31
  public checkErrors: ConfirmationDialogComponent;
32

    
33
  constructor (private route: ActivatedRoute,
34
               private router: Router,
35
               private monitorService: MonitorService,
36
               private authService: AuthenticationService) {}
37

    
38
  ngOnInit () {
39
    if (this.authService.getIsUserLoggedIn()) {
40
        this.getJobInfo();
41
    } else {
42
      const id = this.route.snapshot.paramMap.get('id');
43
      this.authService.redirectUrl = '/compatibility/browseHistory/' + id;
44
      this.authService.loginWithState();
45
    }
46
  }
47

    
48
  getJobInfo() {
49
    const id = this.route.snapshot.paramMap.get('id');
50
    this.loadingMessage = loadingJobSummary;
51
    this.monitorService.getJobSummary(id, 'all').subscribe(
52
      job => {
53
        this.jobSummary = job;
54
        if (this.jobSummary.resultEntries && this.jobSummary.resultEntries.length) {
55
          this.jobSummary.resultEntries.forEach(
56
            entry => {
57
              if (entry.type === 'content') {
58
                this.contentResults.push(entry);
59
              } else if (entry.type === 'usage') {
60
                this.usageResults.push(entry);
61
              }
62
            }
63
          );
64
        }
65
      },
66
      error => {
67
        console.log(error);
68
        this.errorMessage = loadingJobSummaryError;
69
        this.loadingMessage = '';
70
      },
71
      () => {
72
        this.loadingMessage = '';
73
        if (!this.contentResults.length) {
74
          this.noContent = noContentRulesResults;
75
        }
76
        if (!this.usageResults.length) {
77
          this.noUsage = noUsageRulesResults;
78
        }
79
        /*if ( this.authService.activateFrontAuthorization && (this.authService.getUserEmail() !== this.jobSummary.userEmail.trim()) ) {
80
          this.router.navigateByUrl('/403-forbidden', { skipLocationChange: true });
81
        }*/
82
      }
83
    );
84
  }
85

    
86
  viewErrors(rule: JobResultEntry) {
87
    this.modalTitle = `Rule: ${rule.name}`;
88
    this.currentErrors = rule.errors;
89
    this.checkErrors.showModal();
90
  }
91

    
92
  linkToError(er: string) {
93
    return encodeURI(`${this.jobSummary.baseUrl}?verb=GetRecord&metadataPrefix=${this.jobSummary.metadataPrefix}&identifier=${er}`);
94
  }
95

    
96
}
(14-14/17)