Skip to content

Commit

Permalink
Support full/partial submission
Browse files Browse the repository at this point in the history
  • Loading branch information
davebaol committed Jun 11, 2020
1 parent f135dda commit d91920e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
1 change: 1 addition & 0 deletions projects/formio-editor/src/lib/formio-editor-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export interface FormioEditorJsonOptions extends FormioEditorTabOptions, JsonEdi
export interface FormioEditorRendererOptions extends FormioEditorTabOptions {
submissionPanel?: {
disabled?: boolean;
fullSubmission: boolean;
resourceJsonEditor: JsonEditorInputOutputArguments;
schemaJsonEditor: JsonEditorInputOutputArguments & { enabled?: boolean };
};
Expand Down
11 changes: 8 additions & 3 deletions projects/formio-editor/src/lib/formio-editor.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,20 @@ <h5 class="modal-title" id="exampleModalLabel">Validation warning</h5>
<div *ngIf="submissionPanel" class="m-2 border-top border-primary">
<div class="row mx-0">
<div class="p-2" [ngClass]="{'col-6':showResourceSchema,'col-12':!showResourceSchema}">
<p class="font-weight-bold text-center mb-1">Resource</p>
<p class="font-weight-bold text-center mb-1">
Summission (
<label for="fullSubmitCheckbox" class="my-0">full</label>
<input id="fullSubmitCheckbox" class="mx-1" type="checkbox" [(ngModel)]="fullSubmission" (change)="showSubmissionPanel(submission)">
)
</p>
<json-editor #renderer_resource_jsoneditor
[options]="rendererResourceJsonEditorOptions"
(dataChange)="options?.renderer?.submissionPanel?.resourceJsonEditor?.output?.dataChange ? options.renderer.submissionPanel.resourceJsonEditor.output.dataChange($event) : undefined"
(dataError)="options?.renderer?.submissionPanel?.resourceJsonEditor?.output?.dataError ? options.renderer.submissionPanel.resourceJsonEditor.output.dataError($event) : undefined"
></json-editor>
</div>
<div class="p-2 col-6" [hidden]=!showResourceSchema>
<p class="font-weight-bold text-center mb-1">Resource Json Schema Validator</p>
<p class="font-weight-bold text-center mb-1">Json Schema Validator</p>
<json-editor #renderer_schema_jsoneditor
[options]="rendererSchemaJsonEditorOptions"
(dataChange)="options?.renderer?.submissionPanel?.schemaJsonEditor?.output?.dataChange ? options.renderer.submissionPanel.schemaJsonEditor.output.dataChange($event) : undefined"
Expand All @@ -144,7 +149,7 @@ <h5 class="modal-title" id="exampleModalLabel">Validation warning</h5>
</div>
<button class="mx-3 btn btn-primary" *ngIf="options?.renderer?.submissionPanel?.schemaJsonEditor?.enabled" (click)="showResourceSchema = !showResourceSchema">{{showResourceSchema? 'Hide Schema' : 'Show Schema'}}</button>
<button class="mx-2 btn btn-primary" *ngIf="options?.renderer?.submissionPanel?.schemaJsonEditor?.enabled && showResourceSchema" (click)="applyResourceJsonSchema()">Apply Schema</button>
<button class="mx-2 btn btn-primary" *ngIf="options?.renderer?.submissionPanel?.schemaJsonEditor?.enabled && showResourceSchema" (click)="showSubmissionPanel(undefined)">Regenerate Schema</button>
<button class="mx-2 btn btn-primary" *ngIf="options?.renderer?.submissionPanel?.schemaJsonEditor?.enabled && showResourceSchema" (click)="showSubmissionPanel(submission)">Regenerate Schema</button>
</div>
</div>
</div>
14 changes: 11 additions & 3 deletions projects/formio-editor/src/lib/formio-editor.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ export class FormioEditorComponent implements OnInit, AfterViewInit, OnDestroy
rendererSchemaJsonEditorOptions: JsonEditorOptions;
submissionPanel: boolean;
showResourceSchema: boolean;
submission: any;
fullSubmission: boolean;

// tslint:disable-next-line:variable-name
private _activeTab: FormioEditorTab;
Expand Down Expand Up @@ -130,6 +132,7 @@ export class FormioEditorComponent implements OnInit, AfterViewInit, OnDestroy
defaultRendererSchemaJsonEditorOptions,
options?.renderer?.submissionPanel?.schemaJsonEditor?.input?.options
);
this.fullSubmission = options?.renderer?.submissionPanel?.fullSubmission;
}

//
Expand Down Expand Up @@ -227,11 +230,16 @@ export class FormioEditorComponent implements OnInit, AfterViewInit, OnDestroy
showSubmissionPanel(submission: any) {
this.submissionPanel = !this.options.renderer?.submissionPanel?.disabled;
if (this.submissionPanel) {
const schema = generateFormJsonSchema(this.form);
if (submission) {
this.submission = submission;
}
setTimeout(() => {
if (submission) {
this.rendererResourceJsonEditor.set(submission.data);
let schema = generateFormJsonSchema(this.form);
if (this.fullSubmission) {
schema = { type: 'object', properties: { data: schema } };
}
this.rendererResourceJsonEditor.setSchema(undefined);
this.rendererResourceJsonEditor.set(this.fullSubmission ? this.submission : this.submission.data);
this.rendererSchemaJsonEditor.set(schema as JSON);
this.rendererResourceJsonEditor.setSchema(schema);
});
Expand Down
1 change: 1 addition & 0 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export class AppComponent {
},
submissionPanel: {
disabled: false,
fullSubmission: true,
resourceJsonEditor: {
input: {
options: {}
Expand Down

0 comments on commit d91920e

Please sign in to comment.