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
import * as Highcharts from 'highcharts';
10
import {text} from '@angular/core/src/render3/instructions';
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
  index = 0;
33
  ruleName: string[] = [];
34
  unprocessedData: string[] = [];
35
  processedData: number[] = [];
36

    
37
  Highcharts: typeof Highcharts = Highcharts;
38
  chartOptions: Highcharts.Options;
39

    
40
  @ViewChild('checkErrors')
41
  public checkErrors: ConfirmationDialogComponent;
42

    
43
  constructor (private route: ActivatedRoute,
44
               private router: Router,
45
               private monitorService: MonitorService,
46
               private authService: AuthenticationService) {}
47

    
48
  ngOnInit () {
49
    if (this.authService.getIsUserLoggedIn()) {
50
        this.getJobInfo();
51
    } else {
52
      const id = this.route.snapshot.paramMap.get('id');
53
      this.authService.redirectUrl = '/compatibility/browseHistory/' + id;
54
      this.authService.loginWithState();
55
    }
56
    let body = document.getElementsByTagName('body')[0];
57
    body.classList.remove("top_bar_active");   //remove the class
58
    body.classList.remove("page_heading_active");
59
  }
60

    
61
  getJobInfo() {
62
    const id = this.route.snapshot.paramMap.get('id');
63
    this.loadingMessage = loadingJobSummary;
64
    this.monitorService.getJobSummary(id, 'all').subscribe(
65
      job => {
66
        this.jobSummary = job;
67
        if (this.jobSummary.resultEntries && this.jobSummary.resultEntries.length) {
68
          this.jobSummary.resultEntries.forEach(
69
            entry => {
70
              if (entry.type === 'content') {
71
                this.contentResults.push(entry);
72
                this.ruleName.push(entry.name);
73
                this.unprocessedData.push(entry.successes.split('/')[0]);
74
              } else if (entry.type === 'usage') {
75
                this.usageResults.push(entry);
76
              }
77
            }
78
          );
79
        }
80
      },
81
      error => {
82
        console.log(error);
83
        this.errorMessage = loadingJobSummaryError;
84
        this.loadingMessage = '';
85
      },
86
      () => {
87
        this.loadingMessage = '';
88
        if (!this.contentResults.length) {
89
          this.noContent = noContentRulesResults;
90
        } else {
91
          this.processedData = this.unprocessedData.map(Number);
92
          this.chartOptions = {
93
            title: { text: 'Number of records'},
94
            yAxis: { title: { text: 'Number of records' } },
95
            xAxis: { categories: this.ruleName },
96
            series: [{ name: 'For content', data: this.processedData, type: 'column' }]
97
          };
98
        }
99
        if (!this.usageResults.length) {
100
          this.noUsage = noUsageRulesResults;
101
        }
102
        /*if ( this.authService.activateFrontAuthorization && (this.authService.getUserEmail() !== this.jobSummary.userEmail.trim()) ) {
103
          this.router.navigateByUrl('/403-forbidden', { skipLocationChange: true });
104
        }*/
105
      }
106
    );
107
  }
108

    
109
  viewErrors(rule: JobResultEntry) {
110
    this.modalTitle = `Rule: ${rule.name}`;
111
    this.currentErrors = rule.errors;
112
    this.checkErrors.showModal();
113
  }
114

    
115
  linkToError(er: string) {
116
    return encodeURI(`${this.jobSummary.baseUrl}?verb=GetRecord&metadataPrefix=${this.jobSummary.metadataPrefix}&identifier=${er}`);
117
  }
118

    
119
}
(14-14/17)