static: start implementing Application View page

This commit is contained in:
Jens Langhammer 2020-11-27 18:37:56 +01:00
parent 47fe867803
commit 55f2ae5d08
7 changed files with 157 additions and 24 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -3,7 +3,7 @@ import { NotFoundError, RequestError } from "./errors";
export const VERSION = "v2beta"; export const VERSION = "v2beta";
export class Client { export class Client {
private makeUrl(...url: string[]): string { makeUrl(...url: string[]): string {
return `/api/${VERSION}/${url.join("/")}/`; return `/api/${VERSION}/${url.join("/")}/`;
} }
@ -26,3 +26,10 @@ export class Client {
} }
export const DefaultClient = new Client(); export const DefaultClient = new Client();
export interface PBResponse {
count: number;
next: string;
previous: string;
results: Array<any>;
}

View file

@ -29,9 +29,6 @@ export const SIDEBAR_ITEMS: SidebarItem[] = [
}, },
{ {
name: "Administration", name: "Administration",
children: [
{
name: "General",
children: [ children: [
{ {
name: "Overview", name: "Overview",
@ -41,8 +38,6 @@ export const SIDEBAR_ITEMS: SidebarItem[] = [
name: "System Tasks", name: "System Tasks",
path: ["/administration/tasks/"], path: ["/administration/tasks/"],
}, },
],
},
{ {
name: "Applications", name: "Applications",
path: ["/administration/applications/"], path: ["/administration/applications/"],

View file

@ -0,0 +1,58 @@
import { css, html, LitElement, TemplateResult } from "lit-element";
import { until } from "lit-html/directives/until.js";
import { DefaultClient, PBResponse } from "../api/client";
export abstract class Table extends LitElement {
abstract apiEndpoint(): string[];
abstract columns(): Array<string>;
abstract row(item: any): Array<TemplateResult>;
private data: PBResponse = <PBResponse>{};
public static get styles() {
return css`
table {
width: 100%;
}
table,
tr,
td {
border: 1px inset white;
border-collapse: collapse;
}
td,
th {
padding: 0.5rem;
}
td:hover {
border: 1px solid red;
}
`;
}
private renderRows() {
return DefaultClient.fetch<PBResponse>(...this.apiEndpoint())
.then((r) => (this.data = r))
.then(() => {
return this.data.results.map((item) => {
return this.row(item).map((col) => {
// let t = <TemplateStringsArray>[];
return col;
});
});
});
}
render() {
return html`<table>
<thead>
<tr>
${this.columns().map((col) => html`<th>${col}</th>`)}
</tr>
</thead>
<tbody>
${until(this.renderRows(), html`<tr><td>loading...</tr></td>`)}
</tbody>
</table>`;
}
}

View file

@ -26,7 +26,10 @@ export class FlowShellCard extends LitElement {
firstUpdated() { firstUpdated() {
fetch(this.flowBodyUrl) fetch(this.flowBodyUrl)
.then((r) => { .then((r) => {
if (!r.ok) { if (r.status === 404) {
// Fallback when the flow does not exist, just redirect to the root
window.location.pathname = "/";
} else if (!r.ok) {
throw Error(r.statusText); throw Error(r.statusText);
} }
return r; return r;

View file

@ -1,6 +1,26 @@
import { css, customElement, html, LitElement, property } from "lit-element"; import { css, customElement, html, LitElement, property, TemplateResult } from "lit-element";
import { Application } from "../../api/application"; import { Application } from "../../api/application";
import { DefaultClient } from "../../api/client";
import { COMMON_STYLES } from "../../common/styles"; import { COMMON_STYLES } from "../../common/styles";
import { Table } from "../../elements/Table";
@customElement("pb-bound-policies-list")
export class BoundPoliciesList extends Table {
@property()
target?: string;
apiEndpoint(): string[] {
return ["policies", "bindings", `?target=${this.target}`];
}
columns(): string[] {
return ["Foo"];
}
row(item: any): TemplateResult[] {
return [html`${item}`];
}
}
@customElement("pb-application-view") @customElement("pb-application-view")
export class ApplicationViewPage extends LitElement { export class ApplicationViewPage extends LitElement {
@ -28,6 +48,9 @@ export class ApplicationViewPage extends LitElement {
} }
render() { render() {
if (!this.application) {
return html``;
}
return html`<section class="pf-c-page__main-section pf-m-light"> return html`<section class="pf-c-page__main-section pf-m-light">
<div class="pf-c-content"> <div class="pf-c-content">
<h1> <h1>
@ -38,16 +61,50 @@ export class ApplicationViewPage extends LitElement {
</div> </div>
</section> </section>
<pb-tabs> <pb-tabs>
<section slot="page-1" tab-title="Users" class="pf-c-page__main-section pf-m-no-padding-mobile"> <section
<div class="pf-c-card"> slot="page-1"
users tab-title="Users"
<h1>test</h1> class="pf-c-page__main-section pf-m-no-padding-mobile"
>
<span>${this.application?.slug}</span> <div class="pf-l-gallery pf-m-gutter">
<div
class="pf-c-card pf-c-card-aggregate pf-l-gallery__item pf-m-4-col"
style="grid-column-end: span 3;grid-row-end: span 2;"
>
<div class="pf-c-card__header">
<div class="pf-c-card__header-main">
<i class="pf-icon pf-icon-server"></i> Logins over the last 24
hours
</div>
</div>
<div class="pf-c-card__body">
<pb-admin-logins-chart
url="${DefaultClient.makeUrl(
"core",
"applications",
this.application?.slug!,
"metrics"
)}"
></pb-admin-logins-chart>
</div>
</div>
</div> </div>
</section> </section>
<div slot="page-2" tab-title="Containers"> <div
foo slot="page-2"
tab-title="Policy Bindings"
class="pf-c-page__main-section pf-m-no-padding-mobile"
>
<div class="pf-l-gallery pf-m-gutter">
<div
class="pf-c-card pf-c-card-aggregate pf-l-gallery__item pf-m-4-col"
style="grid-column-end: span 3;grid-row-end: span 2;"
>
<pb-bound-policies-list
.target=${this.application.pk}
></pb-bound-policies-list>
</div>
</div>
</div> </div>
</pb-tabs>`; </pb-tabs>`;
} }