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
  ruleNameForContent: string[] = [];
33
  ruleNameForUsage: string[] = [];
34
  unprocessedDataForContent: string[] = [];
35
  unprocessedDataForUsage: string[] = [];
36
  processedDataForContent: number[] = [];
37
  processedDataForUsage: number[] = [];
38

    
39
  HighchartsForContent: typeof Highcharts = Highcharts;
40
  HighchartsForUsage: typeof Highcharts = Highcharts;
41
  chartOptionsForContent: Highcharts.Options;
42
  chartOptionsForUsage: Highcharts.Options;
43

    
44
  @ViewChild('checkErrors')
45
  public checkErrors: ConfirmationDialogComponent;
46

    
47
  constructor (private route: ActivatedRoute,
48
               private router: Router,
49
               private monitorService: MonitorService,
50
               private authService: AuthenticationService) {}
51

    
52
  ngOnInit () {
53
    if (this.authService.getIsUserLoggedIn()) {
54
        this.getJobInfo();
55
    } else {
56
      const id = this.route.snapshot.paramMap.get('id');
57
      this.authService.redirectUrl = '/compatibility/browseHistory/' + id;
58
      this.authService.loginWithState();
59
    }
60
    let body = document.getElementsByTagName('body')[0];
61
    body.classList.remove("top_bar_active");   //remove the class
62
    body.classList.remove("page_heading_active");
63
    body.classList.remove("landing");
64
    body.classList.add("dashboard");
65
  }
66

    
67
  getJobInfo() {
68
    const id = this.route.snapshot.paramMap.get('id');
69
    this.loadingMessage = loadingJobSummary;
70
    this.monitorService.getJobSummary(id, 'all').subscribe(
71
      job => {
72
        this.jobSummary = job;
73
        if (this.jobSummary.resultEntries && this.jobSummary.resultEntries.length) {
74
          this.jobSummary.resultEntries.forEach(
75
            entry => {
76
              if (entry.type === 'content') {
77
                this.contentResults.push(entry);
78
                this.ruleNameForContent.push(entry.name);
79
                this.unprocessedDataForContent.push(entry.successes.split('/')[0]);
80
              } else if (entry.type === 'usage') {
81
                this.usageResults.push(entry);
82
                this.ruleNameForUsage.push(entry.name);
83
                this.unprocessedDataForUsage.push(entry.successes.split('/')[0]);
84
              }
85
            }
86
          );
87
        }
88
      },
89
      error => {
90
        console.log(error);
91
        this.errorMessage = loadingJobSummaryError;
92
        this.loadingMessage = '';
93
      },
94
      () => {
95
        this.loadingMessage = '';
96
        if (!this.contentResults.length) {
97
          this.noContent = noContentRulesResults;
98
        } else {
99
          this.processedDataForContent = this.unprocessedDataForContent.map(Number);
100
          this.chartOptionsForContent = {
101
            title: { text: ''},
102
            yAxis: { title: { text: 'Number of records' } },
103
            xAxis: { categories: this.ruleNameForContent },
104
            series: [{ name: 'For content', data: this.processedDataForContent, type: 'column' }]
105
          };
106
        }
107
        if (!this.usageResults.length) {
108
          this.noUsage = noUsageRulesResults;
109
        } else {
110
          this.processedDataForUsage = this.unprocessedDataForUsage.map(Number);
111
          this.chartOptionsForUsage = {
112
            title: { text: ''},
113
            yAxis: { title: { text: 'Number of records' } },
114
            xAxis: { categories: this.ruleNameForUsage },
115
            series: [{ name: 'For usage', data: this.processedDataForUsage, type: 'column' }]
116
          };
117
        }
118
        /*if ( this.authService.activateFrontAuthorization && (this.authService.getUserEmail() !== this.jobSummary.userEmail.trim()) ) {
119
          this.router.navigateByUrl('/403-forbidden', { skipLocationChange: true });
120
        }*/
121
      }
122
    );
123
  }
124

    
125
  viewErrors(rule: JobResultEntry) {
126
    this.modalTitle = `Rule: ${rule.name}`;
127
    this.currentErrors = rule.errors;
128
    this.checkErrors.showModal();
129
  }
130

    
131
  linkToError(er: string) {
132
    return encodeURI(`${this.jobSummary.baseUrl}?verb=GetRecord&metadataPrefix=${this.jobSummary.metadataPrefix}&identifier=${er}`);
133
  }
134

    
135
}
(8-8/11)