angular2-json-schema-form
Version:
Angular 2 JSON Schema Form builder
79 lines (68 loc) • 2.49 kB
text/typescript
import { Component, Input, OnInit } from '@angular/core';
import { JsonSchemaFormService } from '../../library/json-schema-form.service';
import { JsonPointer } from '../../library/utilities/index';
export class MaterialTabsComponent implements OnInit {
private options: any;
private itemCount: number;
private selectedItem: number = 0;
private showAddTab: boolean = true;
formID: number;
layoutNode: any;
layoutIndex: number[];
dataIndex: number[];
constructor(
private jsf: JsonSchemaFormService
) { }
ngOnInit() {
this.options = this.layoutNode.options;
this.itemCount = this.layoutNode.items.length - 1;
this.updateControl();
}
private select(index) {
if (this.layoutNode.items[index].type === '$ref') {
this.itemCount = this.layoutNode.items.length;
this.jsf.addItem({
formID: this.formID,
layoutNode: this.layoutNode.items[index],
layoutIndex: this.layoutIndex.concat(index),
dataIndex: this.dataIndex.concat(index)
});
this.updateControl();
};
this.selectedItem = index;
}
private updateControl() {
const lastItem = this.layoutNode.items[this.layoutNode.items.length - 1];
if (lastItem.type === '$ref' &&
this.itemCount >= (lastItem.options.maxItems || 1000000)
) {
this.showAddTab = false;
}
}
private setTitle(item: any = null, index: number = null): string {
return this.jsf.setTitle(this, item, index);
}
}