-
Notifications
You must be signed in to change notification settings - Fork 374
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add singular plug-in label (#1458) * Document the default port/address that you can access the UI in your web browser (#1252) * Improve translations (#1459) * Fix capitalization (#1496) * Update zh-CN.json (#1503) * Fixed nested arrays settings (#1504) * Fixed nested arrays settings #2 (#1510) * Fixed nested arrays; Fixed lint; * Removed console.log() * Fixed nested arrays #3 (#1511) * Wait for custom UI (#1522) * Wait for custom UI (#1523) --------- Co-authored-by: Dave Nicolson <david.nicolson@gmail.com> Co-authored-by: Adam Coulombe <adamcoulombe187@hotmail.com> Co-authored-by: Aiden <9078877+aiden0w0@users.noreply.github.com> Co-authored-by: Artem Kononenko <slonick2012@gmail.com>
- Loading branch information
1 parent
8f4674d
commit 1a9d76d
Showing
39 changed files
with
1,197 additions
and
1,027 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
ui/src/app/core/components/schema-form/schema-form.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<ng-container> | ||
<json-schema-form *ngIf="configSchema.schema" [options]="jsonFormOptions" [schema]="configSchema.schema" | ||
<json-schema-form *ngIf="configSchema.schema" [jsfPatch]="configSchema.fixArrays" [options]="jsonFormOptions" [schema]="configSchema.schema" | ||
[layout]="configSchema.layout" [form]="configSchema.form" [data]="currentData" framework="bootstrap-4" | ||
(onChanges)="onChanges($event)" (isValid)="validChange($event)" class="ng-bs4-validate"> | ||
</json-schema-form> | ||
</ng-container> | ||
</ng-container> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
ui/src/app/core/directives/json-schema-form-patch.directive.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
import {Directive, Host, Input, Optional, Self} from '@angular/core'; | ||
import {JsonSchemaFormComponent} from '@oznu/ngx-bs4-jsonform'; | ||
import {cloneDeep, merge, uniqueId} from 'lodash-es'; | ||
|
||
@Directive({ | ||
selector: '[jsfPatch]', | ||
}) | ||
export class JsonSchemaFormPatchDirective { | ||
@Input() jsfPatch = false; | ||
|
||
constructor( | ||
@Host() @Self() @Optional() public jsonSchemaForm: JsonSchemaFormComponent) { | ||
|
||
const buildLayoutOriginal = jsonSchemaForm.jsf.buildLayout.bind(jsonSchemaForm.jsf); | ||
|
||
jsonSchemaForm.jsf.buildLayout = (widgetLibrary: any) => { | ||
|
||
buildLayoutOriginal(widgetLibrary); | ||
if (jsonSchemaForm.jsf.formValues && this.jsfPatch) { | ||
return this.fixNestedArrayLayout( | ||
jsonSchemaForm.jsf.layout, | ||
jsonSchemaForm.jsf.formValues, | ||
); | ||
} | ||
}; | ||
|
||
} | ||
|
||
private fixNestedArrayLayout(builtLayout: any[], formData: any) { | ||
this.fixArray(builtLayout, formData, ''); | ||
return builtLayout; | ||
} | ||
|
||
private fixArray(items: any | any[], formData: any, refPointer: string) { | ||
if (Array.isArray(items)) { | ||
const configItems = items.filter(x => x.name !== '_bridge'); | ||
const nestedItems = configItems | ||
.filter(x => x.items && Array.isArray(x.items)) | ||
.flatMap(x => x.items) | ||
.filter(x => x.dataType === 'array' || x.arrayItem); | ||
|
||
const allItems = configItems.concat(nestedItems); | ||
allItems.filter(x => x.dataType === 'array' || x.arrayItem).forEach(item => { | ||
this.fixNestedArray(item, formData, refPointer); | ||
}); | ||
} else { | ||
this.fixNestedArray(items, formData, refPointer); | ||
} | ||
} | ||
|
||
private fixNestedArray(item: any, formData: any, refPointer: string) { | ||
if (item.items && Array.isArray(item.items)) { | ||
|
||
const ref = item.items.find(x => x.type === '$ref'); | ||
if (ref) { | ||
|
||
const dataItems = item.items.filter(x => x.type === 'section' || x.type === 'div'); | ||
|
||
const template = dataItems.length > 0 | ||
? dataItems.reduce((a, b) => a.id > b.id ? a : b) | ||
: this.getItemTemplateFromRef(ref); | ||
|
||
const data = this.getDataFromPointer(formData, ref.dataPointer.replace(refPointer, '')); | ||
|
||
if (data === null) { | ||
return; | ||
} | ||
|
||
if (Array.isArray(data)) { | ||
// add missing items | ||
while (item.items.length - 1 < data.length) { | ||
const newItem = cloneDeep(template); | ||
newItem._id = uniqueId('new_'); | ||
|
||
item.items.unshift(newItem); | ||
} | ||
|
||
data.forEach((d: any, index: number) => { | ||
this.fixArray(item.items[index], d, ref.dataPointer); | ||
}); | ||
} else { | ||
this.fixArray(item.items, formData, ref.dataPointer); | ||
} | ||
} else { | ||
this.fixArray(item.items, formData, refPointer); | ||
} | ||
|
||
item.items.filter(i => i.items && Array.isArray(i.items)).forEach(i => { | ||
this.fixArray(i.items, formData, refPointer); | ||
}); | ||
} | ||
} | ||
|
||
private getDataFromPointer(data: any, dataPointer: string) { | ||
let value = data; | ||
|
||
dataPointer.substring(1).split(/\//).filter(x => x !== '-') | ||
.forEach((key: string) => { | ||
try { | ||
value = value[key]; | ||
} catch { | ||
value = null; | ||
} | ||
}); | ||
|
||
return value; | ||
} | ||
|
||
private getItemTemplateFromRef(ref: any) { | ||
const templateNode: { type: string; items: any[] } = { | ||
type: 'section', | ||
items: [], | ||
}; | ||
|
||
const item = cloneDeep(ref); | ||
merge(item, templateNode); | ||
return item; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.