From cd0a1b547c6e0323d369003eab65ac6e3c474231 Mon Sep 17 00:00:00 2001
From: Patrizio Bekerle <patrizio@bekerle.com>
Date: Tue, 2 Feb 2021 14:37:01 +0100
Subject: [PATCH] Integrate auth property into dbp-check-in-place-select

---
 packages/check-in-place-select/README.md                    | 2 ++
 packages/check-in-place-select/assets/index.html            | 2 +-
 packages/check-in-place-select/src/check-in-place-select.js | 6 ++++--
 .../src/dbp-check-in-place-select-demo.js                   | 4 ++--
 4 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/packages/check-in-place-select/README.md b/packages/check-in-place-select/README.md
index b1ba6574..65a93300 100644
--- a/packages/check-in-place-select/README.md
+++ b/packages/check-in-place-select/README.md
@@ -32,6 +32,8 @@ npm i @dbp-toolkit/check-in-place-select
     - example `<dbp-check-in-place-select show-reload-button></dbp-check-in-place-select>`
 - `reload-button-title` (optional): sets a title text on the reload button
     - example `<dbp-check-in-place-select show-reload-button reload-button-text="Reload result list"></dbp-check-in-place-select>`
+- `auth` object: you need to set that object property for the auth token
+    - example auth property: `{token: "THE_BEARER_TOKEN"}`
 
 ## Local development
 
diff --git a/packages/check-in-place-select/assets/index.html b/packages/check-in-place-select/assets/index.html
index 14fc87c6..7aff3df6 100644
--- a/packages/check-in-place-select/assets/index.html
+++ b/packages/check-in-place-select/assets/index.html
@@ -8,6 +8,6 @@
 
 <body>
 
-<dbp-check-in-place-select-demo lang="de" entry-point-url="http://127.0.0.1:8000"></dbp-check-in-place-select-demo>
+<dbp-check-in-place-select-demo lang="de" entry-point-url="http://127.0.0.1:8000" auth></dbp-check-in-place-select-demo>
 </body>
 </html>
diff --git a/packages/check-in-place-select/src/check-in-place-select.js b/packages/check-in-place-select/src/check-in-place-select.js
index 27a84b80..9cff7832 100644
--- a/packages/check-in-place-select/src/check-in-place-select.js
+++ b/packages/check-in-place-select/src/check-in-place-select.js
@@ -39,6 +39,7 @@ export class CheckInPlaceSelect extends ScopedElementsMixin(AdapterLitElement) {
         this.showReloadButton = false;
         this.reloadButtonTitle = '';
         this.showCapacity = false;
+        this.auth = {};
 
         this._onDocumentClicked = this._onDocumentClicked.bind(this);
     }
@@ -67,6 +68,7 @@ export class CheckInPlaceSelect extends ScopedElementsMixin(AdapterLitElement) {
             showReloadButton: { type: Boolean, attribute: 'show-reload-button' },
             reloadButtonTitle: { type: String, attribute: 'reload-button-title' },
             showCapacity: { type: Boolean, attribute: 'show-capacity' },
+            auth: { type: Object },
         };
     }
 
@@ -163,7 +165,7 @@ export class CheckInPlaceSelect extends ScopedElementsMixin(AdapterLitElement) {
                 url: apiUrl,
                 contentType: "application/ld+json",
                 beforeSend: function (jqXHR) {
-                    jqXHR.setRequestHeader('Authorization', 'Bearer ' + window.DBPAuthToken);
+                    jqXHR.setRequestHeader('Authorization', 'Bearer ' + that.auth.token);
                     that.isSearching = true;
                 },
                 data: function (params) {
@@ -235,7 +237,7 @@ export class CheckInPlaceSelect extends ScopedElementsMixin(AdapterLitElement) {
             fetch(apiUrl, {
                 headers: {
                     'Content-Type': 'application/ld+json',
-                    'Authorization': 'Bearer ' + window.DBPAuthToken,
+                    'Authorization': 'Bearer ' + this.auth.token,
                 },
             })
             .then(result => {
diff --git a/packages/check-in-place-select/src/dbp-check-in-place-select-demo.js b/packages/check-in-place-select/src/dbp-check-in-place-select-demo.js
index 46002a3f..f4e58324 100644
--- a/packages/check-in-place-select/src/dbp-check-in-place-select-demo.js
+++ b/packages/check-in-place-select/src/dbp-check-in-place-select-demo.js
@@ -75,13 +75,13 @@ export class CheckInPlaceSelectDemo extends ScopedElementsMixin(DBPLitElement) {
                         <div class="field">
                             <label class="label">Check-In-Place 1</label>
                             <div class="control">
-                                <dbp-check-in-place-select lang="${this.lang}" entry-point-url="${this.entryPointUrl}"></dbp-check-in-place-select>
+                                <dbp-check-in-place-select lang="${this.lang}" entry-point-url="${this.entryPointUrl}" subscribe="auth:auth"></dbp-check-in-place-select>
                             </div>
                         </div>
                         <div class="field">
                             <label class="label">Check-In-Place 2</label>
                             <div class="control">
-                                <dbp-check-in-place-select lang="${this.lang}" entry-point-url="${this.entryPointUrl}" show-reload-button reload-button-title="Click me"></dbp-check-in-place-select>
+                                <dbp-check-in-place-select lang="${this.lang}" entry-point-url="${this.entryPointUrl}" subscribe="auth:auth" show-reload-button reload-button-title="Click me"></dbp-check-in-place-select>
                             </div>
                         </div>
                     </form>
-- 
GitLab