Project

General

Profile

1
import { Component, OnInit, ViewChild } from '@angular/core';
2
import { ActivatedRoute } 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

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

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

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

    
28
  modalTitle: string;
29
  isModalShown: boolean;
30

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

    
34
  constructor (private route: ActivatedRoute,
35
               private monitorService: MonitorService) {}
36

    
37
  ngOnInit () {
38
    setTimeout(() => {
39
      this.getJobInfo();
40
    }, 500 );
41
  }
42

    
43
  getJobInfo() {
44
    let id = this.route.snapshot.paramMap.get('id');
45
    this.loadingMessage = loadingJobSummary;
46
    this.monitorService.getJobSummary(id,'all').subscribe(
47
      job => {
48
        this.jobSummary = job;
49
        if (this.jobSummary.resultEntries && this.jobSummary.resultEntries.length) {
50
          this.jobSummary.resultEntries.forEach(
51
            entry => {
52
              if (entry.type == 'content') {
53
                this.contentResults.push(entry);
54
              } else if (entry.type == 'usage') {
55
                this.usageResults.push(entry);
56
              }
57
            }
58
          );
59
        }
60
      },
61
      error => {
62
        console.log(error);
63
        this.errorMessage = loadingJobSummaryError;
64
        this.loadingMessage = '';
65
      },
66
      () => {
67
        this.loadingMessage = '';
68
        if (!this.contentResults.length) {
69
          this.noContent = noContentRulesResults;
70
        }
71
        if (!this.usageResults.length) {
72
          this.noUsage = noUsageRulesResults;
73
        }
74
      }
75
    );
76
  }
77

    
78
  viewErrors(rule: JobResultEntry) {
79
    this.modalTitle = `Rule: ${rule.name}`;
80
    this.currentErrors = rule.errors;
81
    this.checkErrors.showModal();
82
  }
83

    
84
  linkToError(er: string) {
85
    return encodeURI(`${this.jobSummary.baseUrl}?verb=GetRecord&metadataPrefix=${this.jobSummary.metadataPrefix}&identifier=${er}`);
86
  }
87

    
88
}
(12-12/15)