blob: 0ce9774d87b031b6bb8edd8ca951e95ac3d19b41 [file] [log] [blame]
/********************************************************************************
* Copyright (c) 2015-2018 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 { TranslateService } from '@ngx-translate/core';
import { Node} from '@navigator/node';
import { NavigatorService } from '@navigator/navigator.service';
import { LocalizationService } from '@localization/localization.service';
import { MDMNotificationService } from '@core/mdm-notification.service';
import { TRANSLATE } from '@core/mdm-core.module';
import { ContextService } from '../../services/context.service';
import { Sensor, Context } from '../../model/details.model';
@Component({
selector: 'sensors',
templateUrl: 'sensor.component.html',
})
export class SensorComponent implements OnInit {
readonly StatusLoading = TRANSLATE('details.sensor.status-loading');
readonly StatusNoNodes = TRANSLATE('details.sensor.status-no-nodes-available');
readonly StatusNoDescriptiveData = TRANSLATE('details.sensor.status-no-descriptive-data-available');
selectedNode: Node;
context: String;
_diff = false;
contexts: Context[];
sensors: Sensor[];
errorMessage: string;
status: string;
uut = 'Prüfling';
ts = 'Testablauf';
te = 'Messgerät';
s = 'Sensoren';
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.route.params
.subscribe(
params => this.setContext(params['context']),
error => this.notificationService.notifyError(this.translateService.instant('details.sensor.err-cannot-load-scope'), error)
);
this.navigatorService.selectedNodeChanged
.subscribe(node => this.loadContext(node),
error => this.notificationService.notifyError(this.translateService.instant('details.sensor.err-cannot-load-data'), error)
);
}
setContext(context: string) {
this.context = context;
this.loadContext(this.navigatorService.getSelectedNode());
}
loadContext(node: Node) {
if (node != undefined) {
this.selectedNode = node;
this.contexts = undefined;
if (node.name != undefined && (node.type.toLowerCase() === 'measurement' || node.type.toLowerCase() === 'teststep')) {
this.status = this.StatusLoading;
this._contextService.getSensors(node).subscribe(
sensors => this.sensors = <Sensor[]> sensors,
error => this.notificationService.notifyError(
this.translateService.instant('details.sensor.err-cannot-load-descriptive-data'), error)
);
} else {
this.status = this.StatusNoDescriptiveData;
}
} else {
this.status = this.StatusNoNodes;
}
}
diffToggle() {
this._diff = !this._diff;
}
diff(attr1: string, attr2: string) {
if (attr1 !== attr2 && this._diff) {
return 'danger';
}
}
}