static: update ts formatting

This commit is contained in:
Jens Langhammer 2020-11-26 23:35:59 +01:00
parent 1e640fac76
commit 28980d932a
21 changed files with 119 additions and 271 deletions

View file

@ -1 +1,4 @@
{}
{
"printWidth": 100,
"jsxBracketSameLine": true
}

View file

@ -16,21 +16,10 @@
crossorigin
/>
<meta charset="UTF-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1, maximum-scale=1"
/>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<title>passbook</title>
<link
rel="icon"
type="image/png"
href="/static/dist/assets/images/logo.png"
/>
<link
rel="shortcut icon"
type="image/png"
href="/static/dist/assets/images/logo.png"
/>
<link rel="icon" type="image/png" href="/static/dist/assets/images/logo.png" />
<link rel="shortcut icon" type="image/png" href="/static/dist/assets/images/logo.png" />
<link
rel="stylesheet"
type="text/css"
@ -46,19 +35,13 @@
type="text/css"
href="/static/node_modules/%40fortawesome/fontawesome-free/css/fontawesome.min.css"
/>
<link
rel="stylesheet"
type="text/css"
href="/static/passbook/passbook.css"
/>
<link rel="stylesheet" type="text/css" href="/static/passbook/passbook.css" />
<script src="/static/dist/main.js" type="module"></script>
</head>
<body>
<pb-messages url="/api/v2beta/root/messages/"></pb-messages>
<div class="pf-c-page">
<a
class="pf-c-skip-to-content pf-c-button pf-m-primary"
href="#main-content"
<a class="pf-c-skip-to-content pf-c-button pf-m-primary" href="#main-content"
>Skip to content</a
>
<pb-sidebar class="pf-c-page__sidebar"> </pb-sidebar>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -13,9 +13,7 @@ export class Client {
if (r.status > 300) {
switch (r.status) {
case 404:
throw new NotFoundError(
`URL ${this.makeUrl(...url)} not found`
);
throw new NotFoundError(`URL ${this.makeUrl(...url)} not found`);
default:
throw new RequestError(r.statusText);
}

View file

@ -5,10 +5,7 @@ interface TokenResponse {
}
export function tokenByIdentifier(identifier: string): Promise<string> {
return DefaultClient.fetch<TokenResponse>(
"core",
"tokens",
identifier,
"view_key"
).then((r) => r.key);
return DefaultClient.fetch<TokenResponse>("core", "tokens", identifier, "view_key").then(
(r) => r.key
);
}

View file

@ -31,9 +31,7 @@ export class ActionButton extends LitElement {
css`
button {
/* Have to use !important here, as buttons with pf-m-progress have transition already */
transition: all
var(--pf-c-button--m-progress--TransitionDuration) ease
0s !important;
transition: all var(--pf-c-button--m-progress--TransitionDuration) ease 0s !important;
}
`,
];

View file

@ -43,9 +43,9 @@ export class AdminLoginsChart extends LitElement {
.then((r) => r.json())
.catch((e) => console.error(e))
.then((r) => {
let ctx = (<HTMLCanvasElement>(
this.shadowRoot?.querySelector("canvas")
)).getContext("2d")!;
let ctx = (<HTMLCanvasElement>this.shadowRoot?.querySelector("canvas")).getContext(
"2d"
)!;
this.chart = new Chart(ctx, {
type: "bar",
data: {
@ -77,19 +77,10 @@ export class AdminLoginsChart extends LitElement {
type: "time",
offset: true,
ticks: {
callback: function (
value,
index: number,
values
) {
const valueStamp = <TickValue>(
(<unknown>values[index])
);
const delta =
Date.now() - valueStamp.value;
const ago = Math.round(
delta / 1000 / 3600
);
callback: function (value, index: number, values) {
const valueStamp = <TickValue>(<unknown>values[index]);
const delta = Date.now() - valueStamp.value;
const ago = Math.round(delta / 1000 / 3600);
return `${ago} Hours ago`;
},
autoSkip: true,

View file

@ -53,9 +53,7 @@ export class Messages extends LitElement {
this.messageSocket.addEventListener("close", (e) => {
console.debug(`passbook/messages: closed ws connection: ${e}`);
setTimeout(() => {
console.debug(
`passbook/messages: reconnecting ws in ${this.retryDelay}ms`
);
console.debug(`passbook/messages: reconnecting ws in ${this.retryDelay}ms`);
this.connect();
}, this.retryDelay);
this.retryDelay = this.retryDelay * 2;

View file

@ -49,74 +49,60 @@ export class ModalButton extends LitElement {
updateHandlers() {
// Ensure links close the modal
this.querySelectorAll<HTMLAnchorElement>("[slot=modal] a").forEach(
(a) => {
// Make click on a close the modal
a.addEventListener("click", (e) => {
e.preventDefault();
this.open = false;
});
}
);
this.querySelectorAll<HTMLAnchorElement>("[slot=modal] a").forEach((a) => {
// Make click on a close the modal
a.addEventListener("click", (e) => {
e.preventDefault();
this.open = false;
});
});
// Make name field update slug field
this.querySelectorAll<HTMLInputElement>("input[name=name]").forEach(
(input) => {
input.addEventListener("input", (e) => {
const form = input.closest("form");
if (form === null) {
return;
}
const slugField = form.querySelector<HTMLInputElement>(
"input[name=slug]"
);
if (!slugField) {
return;
}
slugField.value = convertToSlug(input.value);
});
}
);
this.querySelectorAll<HTMLInputElement>("input[name=name]").forEach((input) => {
input.addEventListener("input", (e) => {
const form = input.closest("form");
if (form === null) {
return;
}
const slugField = form.querySelector<HTMLInputElement>("input[name=slug]");
if (!slugField) {
return;
}
slugField.value = convertToSlug(input.value);
});
});
// Ensure forms sends in AJAX
this.querySelectorAll<HTMLFormElement>("[slot=modal] form").forEach(
(form) => {
form.addEventListener("submit", (e) => {
e.preventDefault();
let formData = new FormData(form);
fetch(this.href ? this.href : form.action, {
method: form.method,
body: formData,
redirect: "manual",
this.querySelectorAll<HTMLFormElement>("[slot=modal] form").forEach((form) => {
form.addEventListener("submit", (e) => {
e.preventDefault();
let formData = new FormData(form);
fetch(this.href ? this.href : form.action, {
method: form.method,
body: formData,
redirect: "manual",
})
.then((response) => {
return response.text();
})
.then((response) => {
return response.text();
})
.then((data) => {
if (data.indexOf("csrfmiddlewaretoken") !== -1) {
this.querySelector(
"[slot=modal]"
)!.innerHTML = data;
console.debug(
`passbook/modalbutton: re-showing form`
);
this.updateHandlers();
} else {
this.open = false;
console.debug(
`passbook/modalbutton: successful submit`
);
this.dispatchEvent(
new CustomEvent("hashchange", {
bubbles: true,
})
);
}
})
.catch((e) => {
console.error(e);
});
});
}
);
.then((data) => {
if (data.indexOf("csrfmiddlewaretoken") !== -1) {
this.querySelector("[slot=modal]")!.innerHTML = data;
console.debug(`passbook/modalbutton: re-showing form`);
this.updateHandlers();
} else {
this.open = false;
console.debug(`passbook/modalbutton: successful submit`);
this.dispatchEvent(
new CustomEvent("hashchange", {
bubbles: true,
})
);
}
})
.catch((e) => {
console.error(e);
});
});
});
}
onClick(e: MouseEvent) {
@ -165,10 +151,7 @@ export class ModalButton extends LitElement {
}
render() {
return html` <slot
name="trigger"
@click=${(e: any) => this.onClick(e)}
></slot>
return html` <slot name="trigger" @click=${(e: any) => this.onClick(e)}></slot>
${this.open ? this.renderModal() : ""}`;
}
}

View file

@ -1,11 +1,4 @@
import {
css,
customElement,
html,
LitElement,
property,
TemplateResult,
} from "lit-element";
import { css, customElement, html, LitElement, property, TemplateResult } from "lit-element";
// @ts-ignore
import PageStyle from "@patternfly/patternfly/components/Page/page.css";
// @ts-ignore
@ -181,16 +174,12 @@ export class Sidebar extends LitElement {
}
}
return html` <li
class="pf-c-nav__item ${item.children
? "pf-m-expandable pf-m-expanded"
: ""}"
class="pf-c-nav__item ${item.children ? "pf-m-expandable pf-m-expanded" : ""}"
>
${item.path
? html`<a
href="#${item.path}"
class="pf-c-nav__link ${item.path.some(
(v) => v === this.activePath
)
class="pf-c-nav__link ${item.path.some((v) => v === this.activePath)
? "pf-m-current"
: ""}"
>
@ -199,10 +188,7 @@ export class Sidebar extends LitElement {
: html`<a class="pf-c-nav__link" aria-expanded="true"
>${item.name}
<span class="pf-c-nav__toggle">
<i
class="fas fa-angle-right"
aria-hidden="true"
></i>
<i class="fas fa-angle-right" aria-hidden="true"></i>
</span>
</a>
<section class="pf-c-nav__subnav">

View file

@ -46,11 +46,7 @@ export class SidebarBrand extends LitElement {
}
return html` <a href="" class="pf-c-page__header-brand-link">
<div class="pf-c-brand pb-brand">
<img
src="${this.config?.branding_logo}"
alt="passbook icon"
loading="lazy"
/>
<img src="${this.config?.branding_logo}" alt="passbook icon" loading="lazy" />
${this.config?.branding_title
? html`<span>${this.config.branding_title}</span>`
: ""}

View file

@ -49,19 +49,11 @@ export class SidebarUser extends LitElement {
return html``;
}
return html`
<a
href="#/-/user/"
class="pf-c-nav__link user-avatar"
id="user-settings"
>
<a href="#/-/user/" class="pf-c-nav__link user-avatar" id="user-settings">
<img class="pf-c-avatar" src="${this.user?.avatar}" alt="" />
<span>${this.user?.username}</span>
</a>
<a
href="/flows/-/default/invalidation/"
class="pf-c-nav__link user-logout"
id="logout"
>
<a href="/flows/-/default/invalidation/" class="pf-c-nav__link user-logout" id="logout">
<i class="fas fa-sign-out-alt" aria-hidden="true"></i>
</a>
`;

View file

@ -25,8 +25,7 @@ export class Tabs extends LitElement {
return html`<div class="pf-c-tabs">
<ul class="pf-c-tabs__list">
${pages.map((page) => {
const slot = page.attributes.getNamedItem("slot")
?.value;
const slot = page.attributes.getNamedItem("slot")?.value;
return html` <li
class="pf-c-tabs__item ${slot === this.currentPage
? CURRENT_CLASS
@ -39,8 +38,7 @@ export class Tabs extends LitElement {
}}
>
<span class="pf-c-tabs__item-text">
${page.attributes.getNamedItem("tab-title")
?.value}
${page.attributes.getNamedItem("tab-title")?.value}
</span>
</button>
</li>`;

View file

@ -4,12 +4,7 @@ import GlobalsStyle from "@patternfly/patternfly/base/patternfly-globals.css";
// @ts-ignore
import ButtonStyle from "@patternfly/patternfly/components/Button/button.css";
import { tokenByIdentifier } from "../api/token";
import {
ColorStyles,
ERROR_CLASS,
PRIMARY_CLASS,
SUCCESS_CLASS,
} from "../constants";
import { ColorStyles, ERROR_CLASS, PRIMARY_CLASS, SUCCESS_CLASS } from "../constants";
@customElement("pb-token-copy-button")
export class TokenCopyButton extends LitElement {
@ -51,10 +46,7 @@ export class TokenCopyButton extends LitElement {
}
render() {
return html`<button
@click=${() => this.onClick()}
class="pf-c-button ${this.buttonClass}"
>
return html`<button @click=${() => this.onClick()} class="pf-c-button ${this.buttonClass}">
<slot></slot>
</button>`;
}

View file

@ -16,21 +16,10 @@
crossorigin
/>
<meta charset="UTF-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1, maximum-scale=1"
/>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<title>passbook</title>
<link
rel="icon"
type="image/png"
href="/static/dist/assets/images/logo.png"
/>
<link
rel="shortcut icon"
type="image/png"
href="/static/dist/assets/images/logo.png"
/>
<link rel="icon" type="image/png" href="/static/dist/assets/images/logo.png" />
<link rel="shortcut icon" type="image/png" href="/static/dist/assets/images/logo.png" />
<link
rel="stylesheet"
type="text/css"
@ -46,19 +35,13 @@
type="text/css"
href="/static/node_modules/%40fortawesome/fontawesome-free/css/fontawesome.min.css"
/>
<link
rel="stylesheet"
type="text/css"
href="/static/passbook/passbook.css"
/>
<link rel="stylesheet" type="text/css" href="/static/passbook/passbook.css" />
<script src="/static/dist/main.js" type="module"></script>
</head>
<body>
<pb-messages url="/api/v2beta/root/messages/"></pb-messages>
<div class="pf-c-page">
<a
class="pf-c-skip-to-content pf-c-button pf-m-primary"
href="#main-content"
<a class="pf-c-skip-to-content pf-c-button pf-m-primary" href="#main-content"
>Skip to content</a
>
<pb-sidebar class="pf-c-page__sidebar"> </pb-sidebar>

View file

@ -56,9 +56,7 @@ export class FlowShellCard extends LitElement {
this.setFormSubmitHandlers();
break;
default:
console.debug(
`passbook/flows: unexpected data type ${data.type}`
);
console.debug(`passbook/flows: unexpected data type ${data.type}`);
break;
}
}
@ -89,9 +87,7 @@ export class FlowShellCard extends LitElement {
}
}
form.action = this.flowBodyUrl;
console.debug(
`passbook/flows: updated form.action ${this.flowBodyUrl}`
);
console.debug(`passbook/flows: updated form.action ${this.flowBodyUrl}`);
return true;
}
@ -103,9 +99,7 @@ export class FlowShellCard extends LitElement {
setFormSubmitHandlers() {
this.querySelectorAll("form").forEach((form) => {
console.debug(
`passbook/flows: Checking for autosubmit attribute ${form}`
);
console.debug(`passbook/flows: Checking for autosubmit attribute ${form}`);
this.checkAutosubmit(form);
console.debug(`passbook/flows: Setting action for form ${form}`);
this.updateFormAction(form);
@ -155,11 +149,7 @@ export class FlowShellCard extends LitElement {
loading() {
return html` <div class="pf-c-login__main-body pb-loading">
<span
class="pf-c-spinner"
role="progressbar"
aria-valuetext="Loading..."
>
<span class="pf-c-spinner" role="progressbar" aria-valuetext="Loading...">
<span class="pf-c-spinner__clipper"></span>
<span class="pf-c-spinner__lead-ball"></span>
<span class="pf-c-spinner__tail-ball"></span>

View file

@ -1,11 +1,4 @@
import {
css,
customElement,
html,
LitElement,
property,
TemplateResult,
} from "lit-element";
import { css, customElement, html, LitElement, property, TemplateResult } from "lit-element";
// @ts-ignore
import CodeMirrorStyle from "codemirror/lib/codemirror.css";
// @ts-ignore
@ -49,9 +42,7 @@ export class Route {
}
toString(): string {
return `<Route url=${this.url} callback=${
this.callback ? "true" : "false"
}>`;
return `<Route url=${this.url} callback=${this.callback ? "true" : "false"}>`;
}
}
@ -61,13 +52,9 @@ export const ROUTES: Route[] = [
new Route(new RegExp(`^/$`)).redirect("/-/overview/"),
new Route(new RegExp(`^#.*`)).redirect("/-/overview/"),
new Route(new RegExp(`^/applications/$`), html`<h1>test</h1>`),
new Route(new RegExp(`^/applications/(?<slug>${SLUG_REGEX})/$`)).then(
(args) => {
return html`<pb-application-view
.args=${args}
></pb-application-view>`;
}
),
new Route(new RegExp(`^/applications/(?<slug>${SLUG_REGEX})/$`)).then((args) => {
return html`<pb-application-view .args=${args}></pb-application-view>`;
}),
];
class RouteMatch {
@ -128,9 +115,7 @@ export class RouterOutlet extends LitElement {
}
let matchedRoute: RouteMatch | null = null;
ROUTES.forEach((route) => {
console.debug(
`passbook/router: matching ${activeUrl} against ${route.url}`
);
console.debug(`passbook/router: matching ${activeUrl} against ${route.url}`);
const match = route.url.exec(activeUrl);
if (match != null) {
matchedRoute = new RouteMatch(route);
@ -141,9 +126,7 @@ export class RouterOutlet extends LitElement {
}
});
if (!matchedRoute) {
console.debug(
`passbook/router: route "${activeUrl}" not defined, defaulting to shell`
);
console.debug(`passbook/router: route "${activeUrl}" not defined, defaulting to shell`);
const route = new Route(
RegExp(""),
html`<pb-site-shell url=${activeUrl}>

View file

@ -35,12 +35,7 @@ export class SiteShell extends LitElement {
z-index: 2000;
}
.pf-c-backdrop {
--pf-c-backdrop--BackgroundColor: rgba(
0,
0,
0,
0
) !important;
--pf-c-backdrop--BackgroundColor: rgba(0, 0, 0, 0) !important;
}
`,
BackdropStyle,
@ -59,9 +54,7 @@ export class SiteShell extends LitElement {
if (r.ok) {
return r;
}
console.debug(
`passbook/site-shell: Request failed ${this._url}`
);
console.debug(`passbook/site-shell: Request failed ${this._url}`);
window.location.hash = "#/";
throw new Error("Request failed");
})
@ -71,9 +64,7 @@ export class SiteShell extends LitElement {
})
.then(() => {
// Ensure anchors only change the hash
this.querySelectorAll<HTMLAnchorElement>(
"a:not(.pb-root-link)"
).forEach((a) => {
this.querySelectorAll<HTMLAnchorElement>("a:not(.pb-root-link)").forEach((a) => {
if (a.href === "") {
return;
}
@ -96,9 +87,7 @@ export class SiteShell extends LitElement {
f.addEventListener("submit", (e) => {
e.preventDefault();
const formData = new FormData(f);
const qs = new URLSearchParams(
<any>(<unknown>formData)
).toString();
const qs = new URLSearchParams(<any>(<unknown>formData)).toString();
window.location.hash = `#${this._url}?${qs}`;
});
});

View file

@ -31,29 +31,24 @@ export class ApplicationViewPage extends LitElement {
return html`<section class="pf-c-page__main-section pf-m-light">
<div class="pf-c-content">
<h1>
<img
class="pf-icon"
src="${this.application?.meta_icon || ""}"
/>
<img class="pf-icon" src="${this.application?.meta_icon || ""}" />
${this.application?.name}
</h1>
<p>${this.application?.meta_publisher}</p>
</div>
</section>
<section class="pf-c-page__main-section pf-m-no-padding-mobile">
<pb-tabs>
<div slot="page-1" tab-title="Users">users</div>
<div slot="page-2" tab-title="Containers">foo</div>
</pb-tabs>
<div class="pf-c-card">
<div class="pf-c-toolbar">
<div class="pf-c-toolbar__content">
<h1>test</h1>
<pb-tabs>
<section slot="page-1" tab-title="Users" class="pf-c-page__main-section pf-m-no-padding-mobile">
<div class="pf-c-card">
users
<h1>test</h1>
<span>${this.applicationSlug}</span>
</div>
<span>${this.application?.slug}</span>
</div>
</section>
<div slot="page-2" tab-title="Containers">
foo
</div>
</section>`;
</pb-tabs>`;
}
}

View file

@ -6,9 +6,7 @@ export function getCookie(name: string) {
const cookie = cookies[i].trim();
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) === name + "=") {
cookieValue = decodeURIComponent(
cookie.substring(name.length + 1)
);
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}