blob: 7dfa500618fab8687e5ceb45988f50902bec83dc [file] [log] [blame]
/********************************************************************************
* Copyright (c) 2015-2020 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
********************************************************************************/
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { LocalizationService } from '../localization/localization.service';
import { ContextService } from './context.service';
import { Context, Sensor } from './context';
import { Node } from '../navigator/node';
import { NavigatorService } from '../navigator/navigator.service';
import { MDMNotificationService } from '../core/mdm-notification.service';
import { TranslateService } from '@ngx-translate/core';
import { TRANSLATE } from '../core/mdm-core.module';
@Component({
selector: 'mdm-detail-context',
templateUrl: 'mdm-detail-descriptive-data.component.html',
})
export class MDMDescriptiveDataComponent implements OnInit {
readonly StatusLoading = TRANSLATE('details.mdm-detail-descriptive-data.status-loading');
readonly StatusNoNodes = TRANSLATE('details.mdm-detail-descriptive-data.status-no-nodes-available');
readonly StatusNoDescriptiveData = TRANSLATE('details.mdm-detail-descriptive-data.status-no-descriptive-data-available');
selectedNode: Node;
context: String;
_diff = false;
contexts: Context[];
sensors: Sensor[];
status: string;
msgsStatus: string;
constructor(private route: ActivatedRoute,
private localService: LocalizationService,
private _contextService: ContextService,
private navigatorService: NavigatorService,
private notificationService: MDMNotificationService,
private translateService: TranslateService) {}
ngOnInit() {
this.status = this.StatusLoading;
this.refreshDetailData(this.navigatorService.getSelectedNode());
this.route.params
.subscribe(
params => this.setContext(params['context']),
error => this.notificationService.notifyError(
this.translateService.instant('details.mdm-detail-descriptive-data.err-cannot-load-scope'), error));
this.navigatorService.selectedNodeChanged
.subscribe(
node => this.refreshDetailData(node),
error => this.notificationService.notifyError(
this.translateService.instant('details.mdm-detail-descriptive-data.err-cannot-load-data'), error));
}
setContext(context: string) {
this.context = context;
}
refreshDetailData(node: Node) {
if (node != undefined) {
this.selectedNode = node;
this.status = this.StatusLoading;
if (node.type.toLowerCase() === 'measurement' || node.type.toLowerCase() === 'teststep') {
this.loadContext(node);
} else {
this.status = this.StatusNoDescriptiveData;
}
} else {
this.status = this.StatusNoNodes;
}
}
private loadContext(node: Node) {
this.contexts = undefined;
this._contextService.getContext(node).subscribe(
contexts => {
if (contexts.hasOwnProperty('UNITUNDERTEST')
|| contexts.hasOwnProperty('TESTEQUIPMENT')
|| contexts.hasOwnProperty('TESTSEQUENCE')) {
this.contexts = <Context[]> contexts;
} else {
this.status = this.StatusNoDescriptiveData;
}
},
error => this.notificationService.notifyError(
this.translateService.instant('details.mdm-detail-descriptive-data.err-cannot-load-context'), error)
);
}
diffToggle() {
this._diff = !this._diff;
}
diff(attr1: string, attr2: string) {
if (attr1 !== attr2 && this._diff) {
return 'danger';
}
}
isUUT() {
return this.context.toLowerCase() === 'uut';
}
isTE() {
return this.context.toLowerCase() === 'te';
}
isTS() {
return this.context.toLowerCase() === 'ts';
}
}