import { Component, Input, OnInit } from '@angular/core';
import { JsonSchemaFormService } from '../../json-schema-form.service';
@Component({
// tslint:disable-next-line:component-selector
selector: 'material-tabs-widget',
template: `
`,
styles: [` a { cursor: pointer; } `],
})
export class MaterialTabsComponent implements OnInit {
options: any;
itemCount: number;
selectedItem = 0;
showAddTab = true;
@Input() layoutNode: any;
@Input() layoutIndex: number[];
@Input() dataIndex: number[];
constructor(
private jsf: JsonSchemaFormService
) { }
ngOnInit() {
this.options = this.layoutNode.options || {};
this.itemCount = this.layoutNode.items.length - 1;
this.updateControl();
}
select(index) {
if (this.layoutNode.items[index].type === '$ref') {
this.jsf.addItem({
layoutNode: this.layoutNode.items[index],
layoutIndex: this.layoutIndex.concat(index),
dataIndex: this.dataIndex.concat(index)
});
this.updateControl();
}
this.selectedItem = index;
}
updateControl() {
this.itemCount = this.layoutNode.items.length - 1;
const lastItem = this.layoutNode.items[this.layoutNode.items.length - 1];
this.showAddTab = lastItem.type === '$ref' &&
this.itemCount < (lastItem.options.maxItems || 1000);
}
setTabTitle(item: any, index: number): string {
return this.jsf.setArrayItemTitle(this, item, index);
}
}