add chatbot
This commit is contained in:
parent
5a550e4594
commit
3de0e652b8
9 changed files with 497 additions and 3 deletions
|
|
@ -1,12 +1,12 @@
|
|||
import {Fetcher} from "openapi-typescript-fetch"
|
||||
import {type paths} from "../api/schema"
|
||||
import type {paths} from "../api/schema"
|
||||
|
||||
const fetcher = Fetcher.for<paths>()
|
||||
|
||||
const list: HTMLDivElement = document.querySelector("#list")!
|
||||
const template: HTMLTemplateElement = document.querySelector("#template-door")!
|
||||
|
||||
type DoorType = {
|
||||
export type DoorType = {
|
||||
id: string;
|
||||
label: string;
|
||||
state: "unlocked" | "locked" | "unknown" | "unlocking" | "locking";
|
||||
|
|
@ -15,7 +15,7 @@ type DoorType = {
|
|||
jammed: boolean;
|
||||
}
|
||||
|
||||
type AuthType = {
|
||||
export type AuthType = {
|
||||
username: string;
|
||||
authorized: boolean;
|
||||
authenticated: boolean;
|
||||
|
|
@ -23,6 +23,15 @@ type AuthType = {
|
|||
recentLogout: boolean;
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
lang: string;
|
||||
doors: Array<DoorType>;
|
||||
auth: AuthType;
|
||||
doorAction: (action: 'unlock' | 'lock', doorId: string) => void;
|
||||
}
|
||||
}
|
||||
|
||||
const auth: AuthType = {
|
||||
username: "user",
|
||||
authorized: true,
|
||||
|
|
@ -51,6 +60,9 @@ const timeouts: Record<string, number | null> = {
|
|||
|
||||
const doors: Array<DoorType> = []
|
||||
|
||||
window.doors = doors
|
||||
window.auth = auth
|
||||
|
||||
function triggerAuthTimeout() {
|
||||
const diff = auth.until ? (auth.until.getTime() - new Date().getTime()) : 0
|
||||
|
||||
|
|
@ -189,6 +201,8 @@ async function doorAction(action: "unlock" | "lock", doorId: string) {
|
|||
})
|
||||
}
|
||||
|
||||
window.doorAction = doorAction
|
||||
|
||||
function setDoorInfo(doorElement: HTMLDivElement, door: DoorType, initial: boolean = false) {
|
||||
const labelElement: HTMLDivElement = doorElement.querySelector("[data-label]")!
|
||||
const lockButton: HTMLButtonElement = doorElement.querySelector("[data-button='lock']")!
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue