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