import { gettext } from "django"; import { css, CSSResult, customElement, html, LitElement, property, TemplateResult } from "lit-element"; import { until } from "lit-html/directives/until"; import { Event, EventContext } from "../../api/Events"; import { Flow } from "../../api/Flows"; import { COMMON_STYLES } from "../../common/styles"; import "../../elements/Spinner"; import { SpinnerSize } from "../../elements/Spinner"; @customElement("ak-event-info") export class EventInfo extends LitElement { @property({attribute: false}) event?: Event; static get styles(): CSSResult[] { return COMMON_STYLES.concat( css` code { display: block; white-space: pre-wrap; } ` ); } getModelInfo(context: EventContext): TemplateResult { return html``; } defaultResponse(): TemplateResult { return html`

${gettext("Context")}

${JSON.stringify(this.event?.context)}

${gettext("User")}

${JSON.stringify(this.event?.user)}
`; } render(): TemplateResult { if (!this.event) { return html``; } switch (this.event?.action) { case "model_created": case "model_updated": case "model_deleted": return html`

${gettext("Affected model:")}


${this.getModelInfo(this.event.context.model as EventContext)} `; case "authorize_application": return html`

${gettext("Authorized application:")}


${this.getModelInfo(this.event.context.authorized_application as EventContext)}

${gettext("Using flow")}

${until(Flow.list({ flow_uuid: this.event.context.flow as string, }).then(resp => { return html`${resp.results[0].name}`; }), html``)}
`; case "login_failed": return html`

${gettext(`Attempted to log in as ${this.event.context.username}`)}

`; case "token_view": return html`

${gettext("Token:")}


${this.getModelInfo(this.event.context.token as EventContext)} `; case "property_mapping_exception": case "policy_exception": return html`

${gettext("Exception")}

${this.event.context.error}

${gettext("Expression")}

${this.event.context.expression}
`; case "policy_execution": return html`

${gettext("Request")}

${gettext("Result")}

`; case "configuration_error": return html`

${this.event.context.message}

`; case "update_available": return html`

${gettext("New version available!")}

${this.event.context.new_version} `; // Action types which typically don't record any extra context. // If context is not empty, we fall to the default response. case "login": case "logout": if (this.event.context === {}) { return html`${gettext("No additional data available.")}`; } return this.defaultResponse(); default: return this.defaultResponse(); } } }