From 5b4415eb78ecf8ada68df5c5b62acb4c20a861ae Mon Sep 17 00:00:00 2001
From: Patrizio Bekerle <patrizio@bekerle.com>
Date: Mon, 8 Mar 2021 08:30:04 +0100
Subject: [PATCH] Show email instead of birthday in person selector
 (dbp/apps/library#78)

---
 packages/person-select/README.md            |  6 +++---
 packages/person-select/src/person-select.js | 11 +++++------
 2 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/packages/person-select/README.md b/packages/person-select/README.md
index c9f31fe2..0a38edaa 100644
--- a/packages/person-select/README.md
+++ b/packages/person-select/README.md
@@ -24,9 +24,9 @@ npm i @dbp-toolkit/person-select
     - the `value` will also be set automatically when a person is chosen in the selector
 - `data-object` (read-only): when a person is selected the person object will be set as json string
     - example `<dbp-person-select data-object="{"@id":"/people/testuser", "@type":"http://schema.org/Person", "identifier":"testuser", "givenName":"Hans", "familyName":"Tester", "honorificSuffix":"Ing.", "telephone":"+43 (876) 123-4567", "phoneExtension":"4567", "email":"hans.tester@email.com", "name":"Hans Tester"}"></dbp-person-select>`
-- `show-birth-date` (optional): also shows the birth date of the persons to distinguish people with the same name
-    - the currently logged in user needs to have permissions to show the birth date of people
-    - example `<dbp-person-select show-birth-date></dbp-person-select>`
+- `show-details` (optional): also shows the email address of the persons to distinguish people with the same name
+    - the currently logged in user needs to have permissions to show the email address of people
+    - example `<dbp-person-select show-details></dbp-person-select>`
 - `show-reload-button` (optional): if set a reload button will be viewed next to the select box
     - the button triggers a `change` event on the web component
     - the button is disabled if no person is selected
diff --git a/packages/person-select/src/person-select.js b/packages/person-select/src/person-select.js
index 013c0e78..ff9e380c 100644
--- a/packages/person-select/src/person-select.js
+++ b/packages/person-select/src/person-select.js
@@ -18,7 +18,7 @@ import {AdapterLitElement} from "@dbp-toolkit/provider/src/adapter-lit-element";
 const personContext = {
     "@id": "@id",
     "name": "http://schema.org/name",
-    "birthDate": "http://schema.org/Date"
+    "email": "http://schema.org/email"
 };
 
 select2(window, $);
@@ -43,7 +43,7 @@ export class PersonSelect extends ScopedElementsMixin(AdapterLitElement) {
         this.lastResult = {};
         this.showReloadButton = false;
         this.reloadButtonTitle = '';
-        this.showBirthDate = false;
+        this.showDetails = false;
     }
 
     static get scopedElements() {
@@ -66,7 +66,7 @@ export class PersonSelect extends ScopedElementsMixin(AdapterLitElement) {
             object: { type: Object, attribute: false },
             showReloadButton: { type: Boolean, attribute: 'show-reload-button' },
             reloadButtonTitle: { type: String, attribute: 'reload-button-title' },
-            showBirthDate: { type: Boolean, attribute: 'show-birth-date' },
+            showDetails: { type: Boolean, attribute: 'show-details' },
             auth: { type: Object },
         };
     }
@@ -261,9 +261,8 @@ export class PersonSelect extends ScopedElementsMixin(AdapterLitElement) {
         let text = person["name"];
 
         // add birth date to name if present
-        if (this.showBirthDate && (person["birthDate"] !== undefined) && (person["birthDate"] !== null)) {
-            const date = new Date(person["birthDate"]);
-            text += ` (${date.toLocaleDateString("de-AT")})`;
+        if (this.showDetails && (person["email"] !== undefined) && (person["email"] !== null)) {
+            text += ` (${person["email"]})`;
         }
 
         return text;
-- 
GitLab