ohayolibs
Version:
Ohayo is a set of essential modules for ohayojp.
55 lines (51 loc) • 1.78 kB
text/typescript
import { Component, OnInit, ViewEncapsulation } from '@angular/core';
import { ArrayProperty } from '../../model/array.property';
import { FormProperty } from '../../model/form.property';
import { SFGridSchema } from '../../schema/ui';
import { toBool } from '../../utils';
import { ObjectLayoutWidget } from '../../widget';
import { SFObjectWidgetRenderType } from './schema';
export class ObjectWidget extends ObjectLayoutWidget implements OnInit {
grid: SFGridSchema;
type: SFObjectWidgetRenderType = 'default';
list: Array<{}> = [];
title: string;
showExpand = true;
expand = true;
ngOnInit(): void {
const { formProperty, ui } = this;
const { grid, showTitle, type } = ui;
this.showExpand = toBool(ui.showExpand, true);
this.expand = toBool(ui.expand, true);
this.type = type ?? 'default';
if (this.type === 'card' || (!formProperty.isRoot() && !(formProperty.parent instanceof ArrayProperty) && showTitle === true)) {
this.title = this.schema.title as string;
}
this.grid = grid as SFGridSchema;
const list: Array<{}> = [];
for (const key of formProperty.propertiesId) {
const property = (formProperty.properties as { [key: string]: FormProperty })[key] as FormProperty;
const item = {
property,
grid: property.ui.grid || grid || {},
spanLabelFixed: property.ui.spanLabelFixed,
show: property.ui.hidden === false,
};
list.push(item);
}
this.list = list;
}
changeExpand(): void {
if (!this.showExpand) {
return;
}
this.expand = !this.expand;
this.detectChanges(true);
}
}