Skip to content
Snippets Groups Projects
Commit 57ca9a16 authored by Reiter, Christoph's avatar Reiter, Christoph :snake:
Browse files

Move the base element into its own file

parent d32a9ece
No related branches found
No related tags found
No related merge requests found
import {AdapterLitElement} from "@dbp-toolkit/provider/src/adapter-lit-element";
export class BaseLitElement extends AdapterLitElement {
constructor() {
super();
this.auth = {};
}
static get properties() {
return {
...super.properties,
auth: { type: Object },
};
}
_(selector) {
return this.shadowRoot === null ? this.querySelector(selector) : this.shadowRoot.querySelector(selector);
}
_hasSignaturePermissions(roleName) {
return (this.auth.person && Array.isArray(this.auth.person.roles) && this.auth.person.roles.indexOf(roleName) !== -1);
}
_updateAuth() {
this._loginStatus = this.auth['login-status'];
// Every time isLoggedIn()/isLoading() return something different we request a re-render
let newLoginState = [this.isLoggedIn(), this.isLoading()];
if (this._loginState.toString() !== newLoginState.toString()) {
this.requestUpdate();
}
this._loginState = newLoginState;
}
update(changedProperties) {
changedProperties.forEach((oldValue, propName) => {
switch (propName) {
case "auth":
this._updateAuth();
break;
}
});
super.update(changedProperties);
}
connectedCallback() {
super.connectedCallback();
this._loginStatus = '';
this._loginState = [];
}
isLoggedIn() {
return (this.auth.person !== undefined && this.auth.person !== null);
}
isLoading() {
if (this._loginStatus === "logged-out")
return false;
return (!this.isLoggedIn() && this.auth.token !== undefined);
}
}
import * as utils from "./utils"; import * as utils from "./utils";
import {AdapterLitElement} from "@dbp-toolkit/provider/src/adapter-lit-element";
import * as commonUtils from "@dbp-toolkit/common/utils"; import * as commonUtils from "@dbp-toolkit/common/utils";
import {BaseLitElement} from './base-element.js';
export class DBPSignatureBaseLitElement extends AdapterLitElement { export default class DBPSignatureLitElement extends BaseLitElement {
constructor() {
super();
this.auth = {};
}
static get properties() {
return {
...super.properties,
auth: { type: Object },
};
}
_(selector) {
return this.shadowRoot === null ? this.querySelector(selector) : this.shadowRoot.querySelector(selector);
}
_hasSignaturePermissions(roleName) {
return (this.auth.person && Array.isArray(this.auth.person.roles) && this.auth.person.roles.indexOf(roleName) !== -1);
}
_updateAuth() {
this._loginStatus = this.auth['login-status'];
// Every time isLoggedIn()/isLoading() return something different we request a re-render
let newLoginState = [this.isLoggedIn(), this.isLoading()];
if (this._loginState.toString() !== newLoginState.toString()) {
this.requestUpdate();
}
this._loginState = newLoginState;
}
update(changedProperties) {
changedProperties.forEach((oldValue, propName) => {
switch (propName) {
case "auth":
this._updateAuth();
break;
}
});
super.update(changedProperties);
}
connectedCallback() {
super.connectedCallback();
this._loginStatus = '';
this._loginState = [];
}
isLoggedIn() {
return (this.auth.person !== undefined && this.auth.person !== null);
}
isLoading() {
if (this._loginStatus === "logged-out")
return false;
return (!this.isLoggedIn() && this.auth.token !== undefined);
}
}
export default class DBPSignatureLitElement extends DBPSignatureBaseLitElement {
constructor() { constructor() {
super(); super();
this.queuedFiles = []; this.queuedFiles = [];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment