Changes to support better data extraction from answers when generating OpenXML document
This commit is contained in:
parent
b7193d2dda
commit
2c2133bb28
|
@ -1,9 +1,13 @@
|
|||
package eu.eudat.logic.utilities.documents.word;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import eu.eudat.logic.services.forms.VisibilityRuleService;
|
||||
import eu.eudat.logic.utilities.documents.types.ParagraphStyle;
|
||||
import eu.eudat.logic.utilities.documents.types.TextStyle;
|
||||
import eu.eudat.logic.utilities.interfaces.ApplierWithValue;
|
||||
import eu.eudat.models.data.components.commons.datafield.CheckBoxData;
|
||||
import eu.eudat.models.data.components.commons.datafield.ComboBoxData;
|
||||
import eu.eudat.models.data.user.components.datasetprofile.Field;
|
||||
import eu.eudat.models.data.user.components.datasetprofile.FieldSet;
|
||||
import eu.eudat.models.data.user.components.datasetprofile.Section;
|
||||
|
@ -139,9 +143,13 @@ public class WordBuilder {
|
|||
fields.forEach(field -> {
|
||||
if (visibilityRuleService.isElementVisible(field.getId())) {
|
||||
if (!createListing) {
|
||||
XWPFParagraph paragraph = addParagraphContent(field.getValue() == null ? "" : field.getValue(), mainDocumentPart, ParagraphStyle.TEXT, numId);
|
||||
CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
|
||||
number.setVal(BigInteger.valueOf(indent));
|
||||
try {
|
||||
XWPFParagraph paragraph = addParagraphContent(this.formatter(field), mainDocumentPart, ParagraphStyle.TEXT, numId);
|
||||
CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
|
||||
number.setVal(BigInteger.valueOf(indent));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -180,4 +188,38 @@ public class WordBuilder {
|
|||
}
|
||||
}
|
||||
|
||||
public String formatter(Field field) throws IOException {
|
||||
switch (field.getViewStyle().getRenderStyle()) {
|
||||
case "combobox": {
|
||||
String comboboxType = ((ComboBoxData) field.getData()).getType();
|
||||
if (comboboxType.equals("autocomplete")) {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
if (field.getValue() == null) return null;
|
||||
Map<String, String> map = mapper.readValue(field.getValue(), new TypeReference<Map<String, String>>() {
|
||||
});
|
||||
return map.get("label");
|
||||
} else if (comboboxType.equals("wordlist")) {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
if (field.getValue() == null) return null;
|
||||
Map<String, String> map = mapper.readValue(field.getValue(), new TypeReference<Map<String, String>>() {
|
||||
});
|
||||
return map.get("label");
|
||||
}
|
||||
}
|
||||
case "booleanDecision":
|
||||
if (field.getValue() != null && field.getValue().equals("true")) return "Yes";
|
||||
else return "No";
|
||||
case "radiobox":
|
||||
return field.getValue();
|
||||
case "checkBox":
|
||||
CheckBoxData data = (CheckBoxData) field.getData();
|
||||
return data.getLabel();
|
||||
case "freetext":
|
||||
return field.getValue();
|
||||
case "textarea":
|
||||
return field.getValue();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,4 +3,4 @@
|
|||
<!-- <input type="checkbox" formControlName="value"> -->
|
||||
</div>
|
||||
|
||||
<!-- label="{{field.data.label}}" formControlName="form.get('value').value"-->
|
||||
<!-- label="{{field.data.label}}" formControlName="form.get('value').value"-->
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
@CHARSET "UTF-8";
|
|
@ -1,9 +1,9 @@
|
|||
<div [formGroup]="form">
|
||||
<mat-form-field>
|
||||
<mat-select formControlName="value" [required]="field.validationRequired">
|
||||
<mat-option *ngFor="let opt of field.data.options" [value]="opt.value">{{opt.label}}</mat-option>
|
||||
</mat-select>
|
||||
<mat-error *ngIf="form.get('value').errors?.required">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
|
||||
</mat-form-field>
|
||||
<mat-form-field>
|
||||
<mat-select formControlName="value" [required]="field.validationRequired">
|
||||
<mat-option *ngFor="let opt of field.data.options" [value]="assign(opt)">{{opt.label}}</mat-option>
|
||||
</mat-select>
|
||||
<mat-error *ngIf="form.get('value').errors?.required">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
|
||||
</mat-form-field>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -17,4 +17,13 @@ export class DynamicFieldDropdownComponent implements OnInit {
|
|||
ngOnInit() {
|
||||
|
||||
}
|
||||
|
||||
assign(item: any) {
|
||||
if (!item) { return null; }
|
||||
return this.transform(item);
|
||||
}
|
||||
|
||||
transform(item: any) {
|
||||
if (typeof item === 'string') { return JSON.parse(item); } else { return JSON.stringify(item); }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,67 +1,71 @@
|
|||
<div *ngIf="form && field" [id]="field.id" [formGroup]="form" [ngSwitch]="field.viewStyle.renderStyle">
|
||||
|
||||
<!-- <h5 *ngIf="field.title">{{field.title}}</h5> -->
|
||||
<!-- <h5 *ngIf="field.title">{{field.title}}</h5> -->
|
||||
|
||||
|
||||
<div [class.content-left-margin]="field.title">
|
||||
<h5 *ngIf="field.description">{{field.description}}</h5>
|
||||
<h5 *ngIf="field.extendedDescription" class="field-extended-desc">
|
||||
<i>{{field.extendedDescription}}</i>
|
||||
</h5>
|
||||
<div [class.content-left-margin]="field.title">
|
||||
<h5 *ngIf="field.description">{{field.description}}</h5>
|
||||
<h5 *ngIf="field.extendedDescription" class="field-extended-desc">
|
||||
<i>{{field.extendedDescription}}</i>
|
||||
</h5>
|
||||
|
||||
<div *ngSwitchCase="'freetext'">
|
||||
<mat-form-field>
|
||||
<input matInput formControlName="value" placeholder="{{field.data.label}}" [required]="field.validationRequired">
|
||||
<mat-error *ngIf="form.get('value')['errors'] && form.get('value')['errors']['required']">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
|
||||
</mat-form-field>
|
||||
</div>
|
||||
<div *ngSwitchCase="'freetext'">
|
||||
<mat-form-field>
|
||||
<input matInput formControlName="value" placeholder="{{field.data.label}}" [required]="field.validationRequired">
|
||||
<mat-error *ngIf="form.get('value')['errors'] && form.get('value')['errors']['required']">{{'GENERAL.VALIDATION.REQUIRED'
|
||||
| translate}}</mat-error>
|
||||
</mat-form-field>
|
||||
</div>
|
||||
|
||||
<div *ngSwitchCase="'combobox'">
|
||||
<!--TODO-->
|
||||
<div *ngIf="this.field.data.type === 'autocomplete'">
|
||||
<app-df-autocomplete [form]="form" [field]="field"></app-df-autocomplete>
|
||||
</div>
|
||||
<div *ngIf="this.field.data.type === 'wordlist'">
|
||||
<app-df-dropdown [form]="form" [field]="field"></app-df-dropdown>
|
||||
</div>
|
||||
<div *ngSwitchCase="'combobox'">
|
||||
<!--TODO-->
|
||||
<div *ngIf="this.field.data.type === 'autocomplete'">
|
||||
<app-df-autocomplete [form]="form" [field]="field"></app-df-autocomplete>
|
||||
</div>
|
||||
<div *ngIf="this.field.data.type === 'wordlist'">
|
||||
<app-df-dropdown [form]="form" [field]="field"></app-df-dropdown>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div *ngSwitchCase="'checkBox'" class="checkbox">
|
||||
<app-df-checkbox [form]="form" [field]="field"></app-df-checkbox>
|
||||
</div>
|
||||
|
||||
<div *ngSwitchCase="'checkBox'" class="checkbox">
|
||||
<app-df-checkbox [form]="form" [field]="field"></app-df-checkbox>
|
||||
</div>
|
||||
<div *ngSwitchCase="'textarea'">
|
||||
<mat-form-field>
|
||||
<textarea matInput formControlName="value" matTextareaAutosize matAutosizeMinRows="2" matAutosizeMaxRows="10"
|
||||
[required]="field.validationRequired">
|
||||
|
||||
<div *ngSwitchCase="'textarea'">
|
||||
<mat-form-field>
|
||||
<textarea matInput formControlName="value" matTextareaAutosize matAutosizeMinRows="2" matAutosizeMaxRows="10" [required]="field.validationRequired">
|
||||
</textarea>
|
||||
<button mat-button *ngIf="!form.get('value').disabled && form.get('value').value" matSuffix mat-icon-button aria-label="Clear" (click)="this.form.patchValue({'value': ''})">
|
||||
<mat-icon>close</mat-icon>
|
||||
</button>
|
||||
<mat-error *ngIf="form.get('value')['errors'] && form.get('value')['errors']['required']">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
|
||||
</mat-form-field>
|
||||
<button mat-button *ngIf="!form.get('value').disabled && form.get('value').value" matSuffix mat-icon-button
|
||||
aria-label="Clear" (click)="this.form.patchValue({'value': ''})">
|
||||
<mat-icon>close</mat-icon>
|
||||
</button>
|
||||
<mat-error *ngIf="form.get('value')['errors'] && form.get('value')['errors']['required']">{{'GENERAL.VALIDATION.REQUIRED'
|
||||
| translate}}</mat-error>
|
||||
</mat-form-field>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div *ngSwitchCase="'booleanDecision'">
|
||||
<app-df-boolean-decision [form]="form" [field]="field"></app-df-boolean-decision>
|
||||
</div>
|
||||
<div *ngSwitchCase="'booleanDecision'">
|
||||
<app-df-boolean-decision [form]="form" [field]="field"></app-df-boolean-decision>
|
||||
</div>
|
||||
|
||||
<div *ngSwitchCase="'radiobox'">
|
||||
<app-df-radiobox [form]="form" [field]="field"></app-df-radiobox>
|
||||
</div>
|
||||
<div *ngSwitchCase="'radiobox'">
|
||||
<app-df-radiobox [form]="form" [field]="field"></app-df-radiobox>
|
||||
</div>
|
||||
|
||||
<div *ngSwitchCase="'label'"> </div>
|
||||
<div *ngSwitchCase="'label'"> </div>
|
||||
|
||||
|
||||
<!--<div [hidden]="isValid">
|
||||
<!--<div [hidden]="isValid">
|
||||
<mat-error *ngIf="isValidRequired">The field "{{field.data.label}}" <strong>required</strong></mat-error>
|
||||
<div class="invalid-feedbackCustom" *ngIf="isValidRequired">The field "{{field.label}}" is required</div>
|
||||
<div class="invalid-feedbackCustom" *ngIf="isValidPattern">The field {{field.label}} must match a regular expression {{field.regex}}</div>
|
||||
<div class="invalid-feedbackCustom" *ngIf="isValidCustom">The field {{field.label}} custom Validation</div>
|
||||
</div>-->
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- <div [formGroup]="form" class="form-group">
|
||||
|
|
Loading…
Reference in New Issue