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'; ...@@ -12,6 +12,12 @@ import select2CSSPath from 'select2/dist/css/select2.min.css';
import * as errorUtils from "vpu-common/error"; import * as errorUtils from "vpu-common/error";
const personContext = {
"@id": "@id",
"name": "http://schema.org/name",
"birthDate": "http://schema.org/Date"
};
select2(window, $); select2(window, $);
class PersonSelect extends LitElement { class PersonSelect extends LitElement {
...@@ -110,12 +116,6 @@ 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.getApiUrlForIdentifier("http://schema.org/Person");
// const apiUrl = this.jsonld.getApiUrlForEntityName("Event"); // 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) { if (this.$select === null) {
return false; return false;
} }
...@@ -147,17 +147,12 @@ class PersonSelect extends LitElement { ...@@ -147,17 +147,12 @@ class PersonSelect extends LitElement {
}; };
}, },
processResults: function (data) { processResults: function (data) {
// console.log(data); let transformed = that.jsonld.transformMembers(data, personContext);
that.lastResult = data; const results = [];
const members = data["hydra:member"]; transformed.forEach((person) => {
let results = [];
members.forEach((person) => {
results.push({id: person["@id"], text: that.generateOptionText(person)}); results.push({id: person["@id"], text: that.generateOptionText(person)});
}); });
// console.log("results");
// console.log(results);
return { return {
results: results results: results
}; };
...@@ -214,8 +209,10 @@ class PersonSelect extends LitElement { ...@@ -214,8 +209,10 @@ class PersonSelect extends LitElement {
}) })
.then((person) => { .then((person) => {
that.object = person; that.object = person;
const identifier = person["@id"]; const transformed = that.jsonld.compactMember(that.jsonld.expandMember(person), personContext);
const option = new Option(that.generateOptionText(person), identifier, true, true); const identifier = transformed["@id"];
const option = new Option(that.generateOptionText(transformed), identifier, true, true);
$this.attr("data-object", JSON.stringify(person)); $this.attr("data-object", JSON.stringify(person));
$this.data("object", person); $this.data("object", person);
that.$select.append(option).trigger('change'); that.$select.append(option).trigger('change');
...@@ -227,7 +224,8 @@ class PersonSelect extends LitElement { ...@@ -227,7 +224,8 @@ class PersonSelect extends LitElement {
}, },
bubbles: true bubbles: true
})); }));
}).catch(() => { }).catch((e) => {
console.log(e);
that.clear(); 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