mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-26 02:11:53 +00:00
collapsable config
This commit is contained in:
committed by
Aiden McClelland
parent
2a0425e968
commit
9dea6d292d
@@ -70,24 +70,44 @@
|
|||||||
<!-- object or union -->
|
<!-- object or union -->
|
||||||
<ng-container *ngIf="spec.type === 'object' || spec.type ==='union'">
|
<ng-container *ngIf="spec.type === 'object' || spec.type ==='union'">
|
||||||
<!-- label -->
|
<!-- label -->
|
||||||
<ion-item-divider>
|
<ion-item-divider (click)="toggleExpandObject(entry.key)" style="cursor: pointer;">
|
||||||
<form-label [data]="{
|
<form-label [data]="{
|
||||||
spec: spec,
|
spec: spec,
|
||||||
new: current && current[entry.key] === undefined,
|
new: current && current[entry.key] === undefined,
|
||||||
edited: entry.value.dirty
|
edited: entry.value.dirty
|
||||||
}"></form-label>
|
}"
|
||||||
|
></form-label>
|
||||||
|
<ion-icon
|
||||||
|
slot="end"
|
||||||
|
name="chevron-up"
|
||||||
|
[ngStyle]="{
|
||||||
|
'transform': objectDisplay[entry.key].expanded ? 'rotate(0deg)' : 'rotate(180deg)',
|
||||||
|
'transition': 'transform 0.4s ease-out'
|
||||||
|
}"
|
||||||
|
></ion-icon>
|
||||||
</ion-item-divider>
|
</ion-item-divider>
|
||||||
<!-- body -->
|
<!-- body -->
|
||||||
<div class="nested-wrapper">
|
<div
|
||||||
<form-object
|
[id]="entry.key"
|
||||||
[objectSpec]="
|
[ngStyle]="{
|
||||||
spec.type === 'union' ?
|
'max-height': objectDisplay[entry.key].height,
|
||||||
spec.variants[$any(entry.value).controls[spec.tag.id].value] :
|
'overflow': 'hidden',
|
||||||
spec.spec"
|
'transition-property': 'max-height',
|
||||||
[formGroup]="$any(entry.value)"
|
'transition-duration': '.5s',
|
||||||
[current]="current ? current[entry.key] : undefined"
|
'transition-delay': '.05s'
|
||||||
[unionSpec]="spec.type === 'union' ? spec : undefined"
|
}"
|
||||||
></form-object>
|
>
|
||||||
|
<div class="nested-wrapper">
|
||||||
|
<form-object
|
||||||
|
[objectSpec]="
|
||||||
|
spec.type === 'union' ?
|
||||||
|
spec.variants[$any(entry.value).controls[spec.tag.id].value] :
|
||||||
|
spec.spec"
|
||||||
|
[formGroup]="$any(entry.value)"
|
||||||
|
[current]="current ? current[entry.key] : undefined"
|
||||||
|
[unionSpec]="spec.type === 'union' ? spec : undefined"
|
||||||
|
></form-object>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
<!-- list (not enum) -->
|
<!-- list (not enum) -->
|
||||||
@@ -114,9 +134,9 @@
|
|||||||
<!-- nested -->
|
<!-- nested -->
|
||||||
<ng-container *ngIf="spec.subtype === 'object' || spec.subtype === 'union'">
|
<ng-container *ngIf="spec.subtype === 'object' || spec.subtype === 'union'">
|
||||||
<!-- nested label -->
|
<!-- nested label -->
|
||||||
<ion-item button (click)="toggleExpand(entry.key, i)">
|
<ion-item button (click)="toggleExpandListObject(entry.key, i)">
|
||||||
<form-label [data]="{
|
<form-label [data]="{
|
||||||
spec: $any({ name: objectListInfo[entry.key][i].displayAs || 'Entry ' + (i + 1) }),
|
spec: $any({ name: objectListDisplay[entry.key][i].displayAs || 'Entry ' + (i + 1) }),
|
||||||
new: false,
|
new: false,
|
||||||
edited: abstractControl.dirty,
|
edited: abstractControl.dirty,
|
||||||
invalid: abstractControl.invalid
|
invalid: abstractControl.invalid
|
||||||
@@ -125,7 +145,7 @@
|
|||||||
slot="end"
|
slot="end"
|
||||||
name="chevron-up"
|
name="chevron-up"
|
||||||
[ngStyle]="{
|
[ngStyle]="{
|
||||||
'transform': objectListInfo[entry.key][i].expanded ? 'rotate(0deg)' : 'rotate(180deg)',
|
'transform': objectListDisplay[entry.key][i].expanded ? 'rotate(0deg)' : 'rotate(180deg)',
|
||||||
'transition': 'transform 0.4s ease-out'
|
'transition': 'transform 0.4s ease-out'
|
||||||
}"
|
}"
|
||||||
></ion-icon>
|
></ion-icon>
|
||||||
@@ -134,15 +154,13 @@
|
|||||||
<div
|
<div
|
||||||
[id]="entry.key"
|
[id]="entry.key"
|
||||||
[ngStyle]="{
|
[ngStyle]="{
|
||||||
'max-height': objectListInfo[entry.key][i].height,
|
'max-height': objectListDisplay[entry.key][i].height,
|
||||||
'overflow': 'hidden',
|
'overflow': 'hidden',
|
||||||
'transition-property': 'max-height',
|
'transition-property': 'max-height',
|
||||||
'transition-duration': '.5s',
|
'transition-duration': '.5s',
|
||||||
'transition-delay': '.05s'
|
'transition-delay': '.05s'
|
||||||
}"
|
}"
|
||||||
>
|
>
|
||||||
<!-- [hidden]="objectListInfo[entry.key][i].expanded ? false : true" -->
|
|
||||||
|
|
||||||
<form-object
|
<form-object
|
||||||
[objectSpec]="
|
[objectSpec]="
|
||||||
spec.subtype === 'union' ?
|
spec.subtype === 'union' ?
|
||||||
|
|||||||
@@ -22,9 +22,8 @@ export class FormObjectComponent {
|
|||||||
@Output() onInputChange = new EventEmitter<void>()
|
@Output() onInputChange = new EventEmitter<void>()
|
||||||
warningAck: { [key: string]: boolean } = { }
|
warningAck: { [key: string]: boolean } = { }
|
||||||
unmasked: { [key: string]: boolean } = { }
|
unmasked: { [key: string]: boolean } = { }
|
||||||
// @TODO for when we want to expand/collapse normal objects/union in addition to list ones
|
objectDisplay: { [key: string]: { expanded: boolean, height: string } } = { }
|
||||||
// objectExpanded: { [key: string]: boolean } = { }
|
objectListDisplay: { [key: string]: { expanded: boolean, height: string, displayAs: string }[] } = { }
|
||||||
objectListInfo: { [key: string]: { expanded: boolean, height: string, displayAs: string }[] } = { }
|
|
||||||
Object = Object
|
Object = Object
|
||||||
|
|
||||||
constructor (
|
constructor (
|
||||||
@@ -33,20 +32,24 @@ export class FormObjectComponent {
|
|||||||
private readonly formService: FormService,
|
private readonly formService: FormService,
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
ngOnChanges (changes: { [propName: string]: SimpleChange }) {
|
ngOnInit () {
|
||||||
// Lists are automatically expanded, but their members are not
|
|
||||||
Object.keys(this.objectSpec).forEach(key => {
|
Object.keys(this.objectSpec).forEach(key => {
|
||||||
const spec = this.objectSpec[key]
|
const spec = this.objectSpec[key]
|
||||||
if (spec.type === 'list' && ['object', 'union'].includes(spec.subtype)) {
|
if (spec.type === 'list' && ['object', 'union'].includes(spec.subtype)) {
|
||||||
this.objectListInfo[key] = [];
|
this.objectListDisplay[key] = [];
|
||||||
(this.formGroup.get(key).value as any[]).forEach((obj, index) => {
|
(this.formGroup.get(key).value as any[]).forEach((obj, index) => {
|
||||||
const displayAs = (spec.spec as ListValueSpecOf<'object'>)['display-as']
|
const displayAs = (spec.spec as ListValueSpecOf<'object'>)['display-as']
|
||||||
this.objectListInfo[key][index] = {
|
this.objectListDisplay[key][index] = {
|
||||||
expanded: false,
|
expanded: false,
|
||||||
height: '0px',
|
height: '0px',
|
||||||
displayAs: displayAs ? (Mustache as any).render(displayAs, obj) : '',
|
displayAs: displayAs ? (Mustache as any).render(displayAs, obj) : '',
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
} else if (['object', 'union'].includes(spec.type)) {
|
||||||
|
this.objectDisplay[key] = {
|
||||||
|
expanded: false,
|
||||||
|
height: '0px',
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -85,25 +88,30 @@ export class FormObjectComponent {
|
|||||||
arr.insert(0, newItem)
|
arr.insert(0, newItem)
|
||||||
if (['object', 'union'].includes(listSpec.subtype)) {
|
if (['object', 'union'].includes(listSpec.subtype)) {
|
||||||
const displayAs = (listSpec.spec as ListValueSpecOf<'object'>)['display-as']
|
const displayAs = (listSpec.spec as ListValueSpecOf<'object'>)['display-as']
|
||||||
this.objectListInfo[key].unshift({
|
this.objectListDisplay[key].unshift({
|
||||||
height: '0px',
|
height: '0px',
|
||||||
expanded: true,
|
expanded: true,
|
||||||
displayAs: displayAs ? Mustache.render(displayAs, newItem.value) : '',
|
displayAs: displayAs ? Mustache.render(displayAs, newItem.value) : '',
|
||||||
})
|
})
|
||||||
|
|
||||||
pauseFor(200).then(() => {
|
pauseFor(200).then(() => {
|
||||||
this.objectListInfo[key][0].height = this.getDocSize(key)
|
this.objectListDisplay[key][0].height = this.getDocSize(key)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleExpand (key: string, i: number) {
|
toggleExpandObject (key: string) {
|
||||||
this.objectListInfo[key][i].expanded = !this.objectListInfo[key][i].expanded
|
this.objectDisplay[key].expanded = !this.objectDisplay[key].expanded
|
||||||
this.objectListInfo[key][i].height = this.objectListInfo[key][i].expanded ? this.getDocSize(key) : '0px'
|
this.objectDisplay[key].height = this.objectDisplay[key].expanded ? this.getDocSize(key) : '0px'
|
||||||
|
}
|
||||||
|
|
||||||
|
toggleExpandListObject (key: string, i: number) {
|
||||||
|
this.objectListDisplay[key][i].expanded = !this.objectListDisplay[key][i].expanded
|
||||||
|
this.objectListDisplay[key][i].height = this.objectListDisplay[key][i].expanded ? this.getDocSize(key) : '0px'
|
||||||
}
|
}
|
||||||
|
|
||||||
updateLabel (key: string, i: number, displayAs: string) {
|
updateLabel (key: string, i: number, displayAs: string) {
|
||||||
this.objectListInfo[key][i].displayAs = displayAs ? Mustache.render(displayAs, this.formGroup.get(key).value[i]) : ''
|
this.objectListDisplay[key][i].displayAs = displayAs ? Mustache.render(displayAs, this.formGroup.get(key).value[i]) : ''
|
||||||
}
|
}
|
||||||
|
|
||||||
getWarningText (text: string): IonicSafeString {
|
getWarningText (text: string): IonicSafeString {
|
||||||
@@ -195,11 +203,11 @@ export class FormObjectComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private deleteListItem (key: string, index: number, markDirty = true): void {
|
private deleteListItem (key: string, index: number, markDirty = true): void {
|
||||||
if (this.objectListInfo[key]) this.objectListInfo[key][index].height = '0px'
|
if (this.objectListDisplay[key]) this.objectListDisplay[key][index].height = '0px'
|
||||||
const arr = this.formGroup.get(key) as FormArray
|
const arr = this.formGroup.get(key) as FormArray
|
||||||
if (markDirty) arr.markAsDirty()
|
if (markDirty) arr.markAsDirty()
|
||||||
pauseFor(500).then(() => {
|
pauseFor(500).then(() => {
|
||||||
if (this.objectListInfo[key]) this.objectListInfo[key].splice(index, 1)
|
if (this.objectListDisplay[key]) this.objectListDisplay[key].splice(index, 1)
|
||||||
arr.removeAt(index)
|
arr.removeAt(index)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user