From 703613c63aad6f191c9582a71df3278b46ec6b46 Mon Sep 17 00:00:00 2001 From: Christoph Reiter <reiter.christoph@gmail.com> Date: Wed, 15 Jan 2020 14:42:33 +0100 Subject: [PATCH] Use json-ld expand/compact before accessing the properties --- .../person-select/src/vpu-person-select.js | 32 +++++++++---------- packages/person-select/vendor/common | 2 +- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/packages/person-select/src/vpu-person-select.js b/packages/person-select/src/vpu-person-select.js index af3c2574..d4e963b7 100644 --- a/packages/person-select/src/vpu-person-select.js +++ b/packages/person-select/src/vpu-person-select.js @@ -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(); }); } diff --git a/packages/person-select/vendor/common b/packages/person-select/vendor/common index 383f1a1f..5aa64ec4 160000 --- a/packages/person-select/vendor/common +++ b/packages/person-select/vendor/common @@ -1 +1 @@ -Subproject commit 383f1a1f3b282a2f3924f503993861687a2b0ebb +Subproject commit 5aa64ec47e7b65d69327f4dec1102917fe33bd22 -- GitLab