blob: ed4e1c6e8591c92392291181489ef2d4b71d5006 [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, Input, OnChanges, SimpleChanges } from '@angular/core';
import { DetailViewService } from '../../services/detail-view.service';
import { BasketService } from '@basket/basket.service';
import { Node, Attribute} from '@navigator/node';
import { MDMItem } from '@core/mdm-item';
@Component({
selector: 'mdm-detail-panel',
templateUrl: './detail-panel.component.html',
styleUrls: ['./detail-panel.component.css']
})
export class DetailPanelComponent implements OnChanges {
// node to display
@Input() node: Node;
// handles pannel expansion state
@Input() collapsed: boolean;
// handles shopping button disabled state
@Input() shoppable = false;
// handles shopping button visible state
@Input() showButton = false;
// attributes of display node
displayAttributes: Attribute[];
constructor(
private detailViewService: DetailViewService,
private basketService: BasketService) { }
// change detection for display node
ngOnChanges(changes: SimpleChanges): void {
if (changes['node'] && this.node != undefined) {
this.refreshAttributes(this.node);
}
}
// refresh display attributes
private refreshAttributes(node: Node) {
if (node != undefined) {
this.displayAttributes = this.detailViewService.getAttributesToDisplay(this.node);
}
}
// button listener for shopping button
public add2Basket() {
if (this.node != undefined) {
this.basketService.add(new MDMItem(this.node.sourceName, this.node.type, this.node.id));
}
}
// provides style class for panel header (+ icon)
public getClass() {
let style = this.showButton ? 'margin5 ' : '';
return style + this.node.getClass();
}
}