Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision

Target

Select target project
  • 987FCF504483CBC8/toolkit
1 result
Select Git revision
Show changes
Commits on Source (10)
......@@ -73,7 +73,7 @@ export class AppShell extends ScopedElementsMixin(DBPLitElement) {
this.boundCloseMenuHandler = this.hideMenu.bind(this);
this.initateOpenMenu = false;
this.auth = {};
this.auth = null;
this.langDir = '';
}
......@@ -332,6 +332,11 @@ export class AppShell extends ScopedElementsMixin(DBPLitElement) {
break;
case 'auth':
{
// kill event if auth gets default
if (this.auth === null) {
break;
}
if (this.auth.person) {
this._roles = this.auth.person['roles'];
} else {
......@@ -340,11 +345,14 @@ export class AppShell extends ScopedElementsMixin(DBPLitElement) {
this._updateVisibleRoutes();
const loginStatus = this.auth['login-status'];
if (loginStatus !== this._loginStatus) {
console.log('Login status: ' + loginStatus);
}
this._loginStatus = loginStatus;
if (loginStatus !== undefined) {
this._loginStatus = loginStatus;
}
// Clear the session storage when the user logs out
if (this._loginStatus === 'logging-out') {
......@@ -943,13 +951,9 @@ export class AppShell extends ScopedElementsMixin(DBPLitElement) {
// if app is loaded correctly, remove spinner
this.updateComplete.then(() => {
const slot = this.shadowRoot.querySelector('slot:not([name])');
if (slot) slot.style.display = 'none';
});
} else {
// if app is not loaded correctly, show spinner
this.updateComplete.then(() => {
const slot = this.shadowRoot.querySelector('slot:not([name])');
if (slot) slot.style.display = '';
// remove for safari 12 support. safari 13+ supports display: none on slots.
if (slot) slot.remove();
});
}
......
......@@ -44,6 +44,13 @@ Or directly via CDN:
- example auth property: `{token: "THE_BEARER_TOKEN"}`
- note: most often this should be an attribute that is not set directly, but subscribed at a provider
## Override Properties
- `buildUrlData` - A function which gets passed the select and the current search context and
should return the query parameters used for searching.
- `formatPerson` - A function which takes the select and a person object and should
return the text representation displayed to the user.
## Local development
```bash
......
<html>
<body>
<script>
parent.postMessage(location.href, location.origin)
</script>
</body>
</html>
\ No newline at end of file
......@@ -48,6 +48,7 @@ export default (async () => {
build !== 'local' && build !== 'test' ? terser() : false,
copy({
targets: [
{src: 'assets/silent-check-sso.html', dest: 'dist'},
{src: 'assets/index.html', dest: 'dist'},
{
src: await getPackagePath('@dbp-toolkit/common', 'assets/icons/*.svg'),
......
......@@ -67,7 +67,7 @@ export class PersonSelectDemo extends ScopedElementsMixin(DBPLitElement) {
subscribe="requested-login-status"
lang="${this.lang}"
entry-point-url="${this.entryPointUrl}"
silent-check-sso-redirect-uri="/dist/silent-check-sso.html"
silent-check-sso-redirect-uri="/silent-check-sso.html"
url="https://auth-dev.tugraz.at/auth"
realm="tugraz-vpu"
client-id="auth-dev-mw-frontend-local"
......
......@@ -14,15 +14,6 @@ import select2CSSPath from 'select2/dist/css/select2.min.css';
import * as errorUtils from '@dbp-toolkit/common/error';
import {AdapterLitElement} from '@dbp-toolkit/common';
const personContext = {
'@id': '@id',
givenName: 'http://schema.org/givenName',
familyName: 'http://schema.org/familyName',
email: 'http://schema.org/email',
};
select2(window, $);
export class PersonSelect extends ScopedElementsMixin(AdapterLitElement) {
constructor() {
super();
......@@ -46,6 +37,8 @@ export class PersonSelect extends ScopedElementsMixin(AdapterLitElement) {
this.showDetails = false;
this._onDocumentClicked = this._onDocumentClicked.bind(this);
select2(window, $);
}
static get scopedElements() {
......@@ -178,21 +171,19 @@ export class PersonSelect extends ScopedElementsMixin(AdapterLitElement) {
jqXHR.setRequestHeader('Authorization', 'Bearer ' + that.auth.token);
that.isSearching = true;
},
data: function (params) {
return {
search: params.term.trim(),
};
data: (params) => {
return this.buildUrlData(this, params);
},
processResults: function (data) {
that.$('#person-select-dropdown').addClass('select2-bug');
that.lastResult = data;
let transformed = that.jsonld.transformMembers(data, personContext);
let members = data['hydra:member'];
const results = [];
transformed.forEach((person) => {
members.forEach((person) => {
results.push({
id: person['@id'],
text: that.generateOptionText(person),
text: that.formatPerson(that, person),
});
});
......@@ -260,14 +251,10 @@ export class PersonSelect extends ScopedElementsMixin(AdapterLitElement) {
})
.then((person) => {
that.object = person;
const transformed = that.jsonld.compactMember(
that.jsonld.expandMember(person),
personContext
);
const identifier = transformed['@id'];
const identifier = person['@id'];
const option = new Option(
that.generateOptionText(transformed),
that.formatPerson(this, person),
identifier,
true,
true
......@@ -295,7 +282,29 @@ export class PersonSelect extends ScopedElementsMixin(AdapterLitElement) {
return true;
}
generateOptionText(person) {
/**
* Gets passed the select2 params (https://select2.org/data-sources/ajax#jquery-ajax-options)
* and should return an object containing the query parameters send to the server.
*
* @param {object} select
* @param {object} params
* @returns {object}
*/
buildUrlData(select, params) {
return {
search: params.term.trim(),
};
}
/**
* Gets passed a person object and should return a string representation that will
* will be shown to the user.
*
* @param {object} select
* @param {object} person
* @returns {string}
*/
formatPerson(select, person) {
let text = person['givenName'] ?? '';
if (person['familyName']) {
text += ` ${person['familyName']}`;
......
......@@ -4184,9 +4184,9 @@ escape-string-regexp@^1.0.5:
integrity sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==
eslint-plugin-jsdoc@^39.0.0:
version "39.7.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-39.7.0.tgz#887c8996fcad5c9d2ac7835018f81278706464e5"
integrity sha512-4gWAJABzWzfu/LBNLo5cdZph8Ce8QY/Og3FvzU2TsBz50hDB3gBlMJulrmFvPHFXnSxmB6mzMf3dpi4yxdFKfQ==
version "39.7.4"
resolved "https://registry.yarnpkg.com/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-39.7.4.tgz#fec1b5a3cfcbb706980e98e0dbb60ae1f31777d7"
integrity sha512-2eJcWGKRyNQFa37UIpGcAdOp3wtES8vV3mlnFmEmJCuBNyFhK6cMhbZgMkLoLjKnipoxsN9GbfZZ+8nPY8ETZQ==
dependencies:
"@es-joy/jsdoccomment" "~0.36.1"
comment-parser "1.3.1"
......