Merge branch 'ui-redesign' of gitlab.eudat.eu:dmp/OpenAIRE-EUDAT-DMP-service-pilot into ui-redesign

This commit is contained in:
apapachristou 2020-09-11 14:32:58 +03:00
commit 239b91480b
5 changed files with 64 additions and 49 deletions

View File

@ -52,6 +52,7 @@ import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph; import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRun; import org.apache.poi.xwpf.usermodel.XWPFRun;
import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -1018,15 +1019,12 @@ public class DatasetManager {
if (!tagNodes.isEmpty()) { if (!tagNodes.isEmpty()) {
tagNodes.forEach(node -> { tagNodes.forEach(node -> {
JsonNode value = node.get("value"); JsonNode value = node.get("value");
if (value.isArray()) { String stringValue = value.asText().replaceAll("=", ":");
value.elements().forEachRemaining(element -> { JSONArray values = new JSONArray(stringValue);
try { if (values != null) {
Map<String, String> data = mapper.readValue(element.asText(), HashMap.class); values.iterator().forEachRemaining(element -> {
this.addTag(tags, wizardModel.getTags(), data.get("id"), data.get("name")); Map<String, Object> data = ((JSONObject) element).toMap();
} catch (IOException e) { this.addTag(tags, wizardModel.getTags(), data.get("id").toString(), data.get("name").toString());
logger.error(e.getMessage(), e);
}
}); });
} else { } else {
this.addTag(tags, wizardModel.getTags(), "", value.asText()); this.addTag(tags, wizardModel.getTags(), "", value.asText());

View File

@ -297,7 +297,11 @@ public class RemoteFetcher {
} }
} }
} else { } else {
mapToMap(id, (Map<String, String>)obj, item, i == 1); if (obj instanceof Map) {
mapToMap(id, (Map<String, String>) obj, item, i == 1);
} else if (obj != null){
item.put(id, obj.toString());
}
} }
} }
} }
@ -502,14 +506,16 @@ public class RemoteFetcher {
} }
private void mapToMap(String key, Map<String, String> source, Map<String, String> destination, boolean isTitle) { private void mapToMap(String key, Map<String, String> source, Map<String, String> destination, boolean isTitle) {
String content = source.get("content"); if (source != null) {
if (isTitle) { String content = source.get("content");
String classId = source.get("classid"); if (isTitle) {
if (classId.equals("main title")) { String classId = source.get("classid");
if (classId.equals("main title")) {
destination.put(key, content);
}
} else {
destination.put(key, content); destination.put(key, content);
} }
} else {
destination.put(key, content);
} }
} }
} }

View File

@ -76,7 +76,7 @@ export class DatasetExternalReferencesEditorComponent extends BaseComponent impl
initialItems: (type) => this.searchDatasetExternalServices('', type), initialItems: (type) => this.searchDatasetExternalServices('', type),
displayFn: (item) => item ? item.label : null, displayFn: (item) => item ? item.label : null,
titleFn: (item) => item ? item.label : null, titleFn: (item) => item ? item.label : null,
subtitleFn: (item) => item.source ? this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.SOURCE:') + item.source : this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.NO-SOURCE') subtitleFn: (item) => item.source ? this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.SOURCE:') + item.source : item.tag ? this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.SOURCE:') + item.tag : this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.NO-SOURCE')
}; };
tagsAutoCompleteConfiguration: MultipleAutoCompleteConfiguration = { tagsAutoCompleteConfiguration: MultipleAutoCompleteConfiguration = {

View File

@ -190,18 +190,7 @@
<div *ngSwitchCase="datasetProfileFieldViewStyleEnum.Tags" class="col-12"> <div *ngSwitchCase="datasetProfileFieldViewStyleEnum.Tags" class="col-12">
<div class="row"> <div class="row">
<mat-form-field class="col-md-12"> <mat-form-field class="col-md-12">
<mat-chip-list #chipList> <app-multiple-auto-complete [configuration]="tagsAutoCompleteConfiguration" [formControl]="form.get('value')" placeholder="{{'DATASET-EDITOR.FIELDS.TAGS' | translate}}"></app-multiple-auto-complete>
<mat-chip *ngFor="let tag of getTags()"
[removable]="true" (removed)="removeTag(tag)">
{{tag.name}}
<mat-icon matChipRemove >cancel</mat-icon>
</mat-chip>
<input matInput placeholder="{{'DATASET-EDITOR.FIELDS.TAGS' | translate}}"
[matChipInputFor]="chipList"
[matChipInputSeparatorKeyCodes]="separatorKeysCodes"
[matChipInputAddOnBlur]="true"
(matChipInputTokenEnd)="addTag($event)">
</mat-chip-list>
</mat-form-field> </mat-form-field>
</div> </div>
</div> </div>

View File

@ -166,12 +166,19 @@ export class FormFieldComponent extends BaseComponent implements OnInit {
initialItems: () => this.searchDatasetExternalServices(''), initialItems: () => this.searchDatasetExternalServices(''),
displayFn: (item) => typeof (item) == 'string' ? JSON.parse(item)['name'] : item.name, displayFn: (item) => typeof (item) == 'string' ? JSON.parse(item)['name'] : item.name,
titleFn: (item) => typeof (item) == 'string' ? JSON.parse(item)['name'] : item.name, titleFn: (item) => typeof (item) == 'string' ? JSON.parse(item)['name'] : item.name,
subtitleFn: (item) => item.source ? this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.SOURCE:') + item.source : this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.NO-SOURCE'), subtitleFn: (item) => item.source ? this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.SOURCE:') + item.source : item.tag ? this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.SOURCE:') + item.tag : this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.NO-SOURCE'),
valueAssign: (item) => typeof (item) == 'string' ? item : JSON.stringify(item) valueAssign: (item) => typeof (item) == 'string' ? item : JSON.stringify(item)
}; };
break; break;
case DatasetProfileFieldViewStyle.Tags: case DatasetProfileFieldViewStyle.Tags:
this.setupTags(); this.tagsAutoCompleteConfiguration = {
filterFn: this.filterTags.bind(this),
initialItems: (excludedItems: any[]) => this.filterTags('').pipe(map(result => result.filter(resultItem => (excludedItems || []).map(x => x.id).indexOf(resultItem.id) === -1))),
displayFn: (item) => this.showTag(item),
titleFn: (item) => item['name'],
valueAssign: (item) => this.addTag(item)
};
this.parseTags();
break; break;
case DatasetProfileFieldViewStyle.Researchers: case DatasetProfileFieldViewStyle.Researchers:
this.researchersAutoCompleteConfiguration = { this.researchersAutoCompleteConfiguration = {
@ -337,28 +344,43 @@ export class FormFieldComponent extends BaseComponent implements OnInit {
return this.externalSourcesService.searchDatasetTags(requestItem); return this.externalSourcesService.searchDatasetTags(requestItem);
} }
private setupTags() { parseTags() {
this.tags = (this.form.get('value').value as string[]).map(string => JSON.parse(string)); let stringValue = this.form.get('value').value;
if (this.tags === null) { stringValue = (<string>stringValue).replace(new RegExp('{', 'g'), '{"').replace(new RegExp('=', 'g'), '":"').replace(new RegExp(',', 'g'), '",').replace(new RegExp(', ', 'g'), ', "').replace(new RegExp('}', 'g'), '"}');
this.tags = []; stringValue = stringValue.replace(new RegExp('}"', 'g'), '}').replace(new RegExp('"{', 'g'), '{');
console.log(stringValue);
const tagArray = JSON.parse(stringValue);
console.log(tagArray);
this.form.patchValue({'value': tagArray});
}
filterTags(value: string): Observable<ExternalSourceItemModel[]> {
const requestItem: RequestItem<TagCriteria> = new RequestItem();
const criteria: TagCriteria = new TagCriteria();
criteria.like = value;
requestItem.criteria = criteria;
return this.externalSourcesService.searchDatasetTags(requestItem);
}
showTag(ev: any) {
if (typeof ev === 'string') {
return ev;
} else {
return ev.name;
} }
} }
getTags() { addTag(ev: any) {
return this.tags; let item: ExternalTagEditorModel;
} //this.filteredTags = this.formGroup.get('tags').value;
if (typeof ev === 'string') {
removeTag(tag: any) { item = new ExternalTagEditorModel('', ev);
this.tags.splice(this.tags.indexOf(tag), 1); } else {
this.form.patchValue({ 'value': JSON.stringify(this.tags) }); item = ev;
} }
if (item.name !== '' ) {
addTag(ev: MatChipInputEvent) { return item;
if (ev.value !== '' && isNullOrUndefined((this.tags.find(tag => tag.name === ev.value)))) {
this.tags.push(new ExternalTagEditorModel('', ev.value));
} }
this.form.patchValue({ 'value': JSON.stringify(this.tags) });
ev.input.value = '';
} }
filterOrganisations(value: string): Observable<ExternalSourceItemModel[]> { filterOrganisations(value: string): Observable<ExternalSourceItemModel[]> {