import { Component, OnInit, Input, Output, EventEmitter, ViewEncapsulation, OnChanges, SimpleChanges, Inject } from '@angular/core';
import { Subscription } from 'rxjs/Subscription';
import { MatTree, MatTreeModel } from './mat-tree';
import { MatTreeController } from './mat-tree-controller';
import { NodeEvent } from './mat-tree.events';
import { MatTreeService } from './mat-tree.service';
@Component({
selector: 'mat-tree',
encapsulation: ViewEncapsulation.None,
template: `
`,
styleUrls: ['./mat-tree.component.less'],
})
export class MatTreeComponent implements OnInit, OnChanges {
// tslint:disable-next-line:no-input-rename
@Input('tree') treeModel: MatTreeModel;
@Input() direction: string = 'left';
@Output() nodeChecked: EventEmitter = new EventEmitter();
@Output() nodeUnchecked: EventEmitter = new EventEmitter();
@Output() nodeExpanded: EventEmitter = new EventEmitter();
@Output() nodeCollapsed: EventEmitter = new EventEmitter();
@Output() nodeSelected: EventEmitter = new EventEmitter();
tree: MatTree;
private subscriptions: Subscription[] = [];
public constructor(
private treeService: MatTreeService
) {}
public ngOnChanges(changes: SimpleChanges): void {
if (!this.treeModel) {
// this.tree = MatTreeComponent.EMPTY_TREE;
} else {
this.tree = new MatTree(this.treeModel);
}
}
moveToRight() {
this.treeService.moveNode(this.tree);
}
ngOnInit() {
this.subscriptions.push(
this.treeService.nodeChecked$.subscribe((e: NodeEvent) => {
this.nodeChecked.emit(this.tree);
})
);
this.subscriptions.push(
this.treeService.nodeUnchecked$.subscribe((e: NodeEvent) => {
this.nodeUnchecked.emit(this.tree);
})
);
this.subscriptions.push(
this.treeService.nodeExpanded$.subscribe((e: NodeEvent) => {
this.nodeExpanded.emit(e);
})
);
this.subscriptions.push(
this.treeService.nodeCollapsed$.subscribe((e: NodeEvent) => {
this.nodeCollapsed.emit(e);
})
);
}
}