Merge branch 'ui-redesign' of gitlab.eudat.eu:dmp/OpenAIRE-EUDAT-DMP-service-pilot into ui-redesign
This commit is contained in:
commit
239b91480b
|
@ -52,6 +52,7 @@ import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
|
|||
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFRun;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -1018,15 +1019,12 @@ public class DatasetManager {
|
|||
if (!tagNodes.isEmpty()) {
|
||||
tagNodes.forEach(node -> {
|
||||
JsonNode value = node.get("value");
|
||||
if (value.isArray()) {
|
||||
value.elements().forEachRemaining(element -> {
|
||||
try {
|
||||
Map<String, String> data = mapper.readValue(element.asText(), HashMap.class);
|
||||
this.addTag(tags, wizardModel.getTags(), data.get("id"), data.get("name"));
|
||||
} catch (IOException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
|
||||
String stringValue = value.asText().replaceAll("=", ":");
|
||||
JSONArray values = new JSONArray(stringValue);
|
||||
if (values != null) {
|
||||
values.iterator().forEachRemaining(element -> {
|
||||
Map<String, Object> data = ((JSONObject) element).toMap();
|
||||
this.addTag(tags, wizardModel.getTags(), data.get("id").toString(), data.get("name").toString());
|
||||
});
|
||||
} else {
|
||||
this.addTag(tags, wizardModel.getTags(), "", value.asText());
|
||||
|
|
|
@ -297,7 +297,11 @@ public class RemoteFetcher {
|
|||
}
|
||||
}
|
||||
} 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) {
|
||||
String content = source.get("content");
|
||||
if (isTitle) {
|
||||
String classId = source.get("classid");
|
||||
if (classId.equals("main title")) {
|
||||
if (source != null) {
|
||||
String content = source.get("content");
|
||||
if (isTitle) {
|
||||
String classId = source.get("classid");
|
||||
if (classId.equals("main title")) {
|
||||
destination.put(key, content);
|
||||
}
|
||||
} else {
|
||||
destination.put(key, content);
|
||||
}
|
||||
} else {
|
||||
destination.put(key, content);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -76,7 +76,7 @@ export class DatasetExternalReferencesEditorComponent extends BaseComponent impl
|
|||
initialItems: (type) => this.searchDatasetExternalServices('', type),
|
||||
displayFn: (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 = {
|
||||
|
|
|
@ -190,18 +190,7 @@
|
|||
<div *ngSwitchCase="datasetProfileFieldViewStyleEnum.Tags" class="col-12">
|
||||
<div class="row">
|
||||
<mat-form-field class="col-md-12">
|
||||
<mat-chip-list #chipList>
|
||||
<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>
|
||||
<app-multiple-auto-complete [configuration]="tagsAutoCompleteConfiguration" [formControl]="form.get('value')" placeholder="{{'DATASET-EDITOR.FIELDS.TAGS' | translate}}"></app-multiple-auto-complete>
|
||||
</mat-form-field>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -166,12 +166,19 @@ export class FormFieldComponent extends BaseComponent implements OnInit {
|
|||
initialItems: () => this.searchDatasetExternalServices(''),
|
||||
displayFn: (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)
|
||||
};
|
||||
break;
|
||||
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;
|
||||
case DatasetProfileFieldViewStyle.Researchers:
|
||||
this.researchersAutoCompleteConfiguration = {
|
||||
|
@ -337,28 +344,43 @@ export class FormFieldComponent extends BaseComponent implements OnInit {
|
|||
return this.externalSourcesService.searchDatasetTags(requestItem);
|
||||
}
|
||||
|
||||
private setupTags() {
|
||||
this.tags = (this.form.get('value').value as string[]).map(string => JSON.parse(string));
|
||||
if (this.tags === null) {
|
||||
this.tags = [];
|
||||
parseTags() {
|
||||
let stringValue = this.form.get('value').value;
|
||||
stringValue = (<string>stringValue).replace(new RegExp('{', 'g'), '{"').replace(new RegExp('=', 'g'), '":"').replace(new RegExp(',', 'g'), '",').replace(new RegExp(', ', 'g'), ', "').replace(new RegExp('}', 'g'), '"}');
|
||||
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() {
|
||||
return this.tags;
|
||||
}
|
||||
|
||||
removeTag(tag: any) {
|
||||
this.tags.splice(this.tags.indexOf(tag), 1);
|
||||
this.form.patchValue({ 'value': JSON.stringify(this.tags) });
|
||||
}
|
||||
|
||||
addTag(ev: MatChipInputEvent) {
|
||||
if (ev.value !== '' && isNullOrUndefined((this.tags.find(tag => tag.name === ev.value)))) {
|
||||
this.tags.push(new ExternalTagEditorModel('', ev.value));
|
||||
addTag(ev: any) {
|
||||
let item: ExternalTagEditorModel;
|
||||
//this.filteredTags = this.formGroup.get('tags').value;
|
||||
if (typeof ev === 'string') {
|
||||
item = new ExternalTagEditorModel('', ev);
|
||||
} else {
|
||||
item = ev;
|
||||
}
|
||||
if (item.name !== '' ) {
|
||||
return item;
|
||||
}
|
||||
this.form.patchValue({ 'value': JSON.stringify(this.tags) });
|
||||
ev.input.value = '';
|
||||
}
|
||||
|
||||
filterOrganisations(value: string): Observable<ExternalSourceItemModel[]> {
|
||||
|
|
Loading…
Reference in New Issue