Skip to content
Snippets Groups Projects
Commit 703613c6 authored by Reiter, Christoph's avatar Reiter, Christoph :snake:
Browse files

Use json-ld expand/compact before accessing the properties

parent 243fac66
No related branches found
No related tags found
No related merge requests found
......@@ -12,6 +12,12 @@ import select2CSSPath from 'select2/dist/css/select2.min.css';
import * as errorUtils from "vpu-common/error";
const personContext = {
"@id": "@id",
"name": "http://schema.org/name",
"birthDate": "http://schema.org/Date"
};
select2(window, $);
class PersonSelect extends LitElement {
......@@ -110,12 +116,6 @@ class PersonSelect extends LitElement {
const apiUrl = this.jsonld.getApiUrlForIdentifier("http://schema.org/Person");
// const apiUrl = this.jsonld.getApiUrlForEntityName("Event");
// the mapping we need for Select2
const localContext = {
"id": "@id",
"text": "http://schema.org/name"
};
if (this.$select === null) {
return false;
}
......@@ -147,17 +147,12 @@ class PersonSelect extends LitElement {
};
},
processResults: function (data) {
// console.log(data);
that.lastResult = data;
const members = data["hydra:member"];
let results = [];
members.forEach((person) => {
let transformed = that.jsonld.transformMembers(data, personContext);
const results = [];
transformed.forEach((person) => {
results.push({id: person["@id"], text: that.generateOptionText(person)});
});
// console.log("results");
// console.log(results);
return {
results: results
};
......@@ -214,8 +209,10 @@ class PersonSelect extends LitElement {
})
.then((person) => {
that.object = person;
const identifier = person["@id"];
const option = new Option(that.generateOptionText(person), identifier, true, true);
const transformed = that.jsonld.compactMember(that.jsonld.expandMember(person), personContext);
const identifier = transformed["@id"];
const option = new Option(that.generateOptionText(transformed), identifier, true, true);
$this.attr("data-object", JSON.stringify(person));
$this.data("object", person);
that.$select.append(option).trigger('change');
......@@ -227,7 +224,8 @@ class PersonSelect extends LitElement {
},
bubbles: true
}));
}).catch(() => {
}).catch((e) => {
console.log(e);
that.clear();
});
}
......
common @ 5aa64ec4
Subproject commit 383f1a1f3b282a2f3924f503993861687a2b0ebb
Subproject commit 5aa64ec47e7b65d69327f4dec1102917fe33bd22
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment