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
  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 monitorService: MonitorService) {}
35

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

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

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

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

    
87
}
(12-12/15)