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 {
6
  loadingJobSummary, loadingJobSummaryError, noContentRulesResults,
7
  noUsageRulesResults
8
} from '../../domain/shared-messages';
9
import { ConfirmationDialogComponent } from '../../shared/reusablecomponents/confirmation-dialog.component';
10
import {AuthenticationService} from "../../services/authentication.service";
11

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

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

    
24
  jobSummary: StoredJob;
25
  contentResults: JobResultEntry[] = [];
26
  usageResults: JobResultEntry[] = [];
27
  currentErrors: string[] = [];
28

    
29
  modalTitle: string;
30
  isModalShown: boolean;
31

    
32
  @ViewChild('checkErrors')
33
  public checkErrors: ConfirmationDialogComponent;
34

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

    
40
  ngOnInit () {
41
    setTimeout(() => {
42
      this.getJobInfo();
43
    }, 500 );
44
  }
45

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

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

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

    
94
}
(14-14/17)