blob: f8a9f044b769424bafe3cc9241a043d1899310c6 [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, OnDestroy } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { Node } from '@navigator/node';
import { NodeService } from '@navigator/node.service';
import { BasketService } from '@basket/basket.service';
import { NavigatorService } from '@navigator/navigator.service';
import { MDMNotificationService } from '@core/mdm-notification.service';
@Component({
selector: 'mdm-detail-view',
templateUrl: 'mdm-detail-view.component.html'
})
export class MDMDetailViewComponent implements OnInit, OnDestroy {
selectedNode: Node;
unit: Node;
quantity: Node;
subscription: any;
shoppable = false;
public status = 'file-explorer.file-explorer-nav-card.status-no-node-selected';
constructor(private basketService: BasketService,
private navigatorService: NavigatorService,
private notificationService: MDMNotificationService,
private translateService: TranslateService,
private nodeService: NodeService) {}
ngOnInit() {
this.onSelectedNodeChange(this.navigatorService.getSelectedNode());
this.subscription = this.navigatorService.selectedNodeChanged.subscribe(
node => this.onSelectedNodeChange(node),
error => this.notificationService.notifyError(this.translateService.instant('details.mdm-detail-view.cannot-update-node'), error)
);
}
ngOnDestroy() {
this.subscription.unsubscribe();
}
onSelectedNodeChange(node: Node) {
if (node != undefined) {
this.selectedNode = node;
if (node.type.toLowerCase() === 'channel') {
this.loadQuantity(node);
this.loadUnit(node);
} else {
this.quantity = undefined;
this.unit = undefined;
}
this.shoppable = this.isShoppable();
}
}
private loadUnit(node: Node) {
if (node.relations != undefined) {
node.relations
.filter(rel => rel.entityType.toLowerCase() === 'unit')
.filter(rel => rel.ids.length > 0)
.forEach(rel => this.nodeService.getNodeByRelation(node.sourceName, rel.entityType, rel.ids[0])
.subscribe(res => this.unit = res[0])
);
}
}
private loadQuantity(node: Node) {
if (node.relations != undefined) {
node.relations
.filter(rel => rel.entityType.toLowerCase() === 'quantity')
.filter(rel => rel.ids.length > 0)
.forEach(rel => this.nodeService.getNodeByRelation(node.sourceName, rel.entityType, rel.ids[0])
.subscribe(res => this.quantity = res[0])
);
}
}
isShoppable() {
if (this.selectedNode
&& this.selectedNode.name != undefined
&& this.selectedNode.type !== 'Environment'
&& this.selectedNode.type !== 'Unit'
&& this.selectedNode.type !== 'Channel') {
return false;
}
return true;
}
isReleasable() {
if (this.selectedNode && this.selectedNode.sourceType === 'TestStep') { return false; }
return true;
}
}