182 files

This commit is contained in:
Home Assistant Version Control
2026-08-17 12:11:35 +00:00
parent 7dddf6bb13
commit ece15a1c1b
183 changed files with 11457 additions and 3092 deletions
@@ -11,10 +11,12 @@
import { LitElement, html, css, nothing } from "lit";
import { property, state } from "lit/decorators.js";
import { t, ensureLocale } from "../styles";
import { t, ensureLocale, langOf } from "../styles";
import { describeWsError } from "../ws-errors";
import { downloadUrl } from "../helpers/download";
import { downloadSignedDocument, openSignedDocument } from "../helpers/document-url";
import { formatBytes } from "../helpers/format-bytes";
import { CATEGORIES, CATEGORY_ICONS } from "../helpers/document-categories";
import type { HomeAssistant } from "../types";
interface Doc {
@@ -31,16 +33,6 @@ interface Doc {
part_ids?: string[];
}
const CATEGORIES = ["manual", "warranty", "invoice", "spare_parts", "photo", "other"] as const;
const CATEGORY_ICONS: Record<string, string> = {
manual: "mdi:book-open-variant",
warranty: "mdi:shield-check",
invoice: "mdi:receipt-text-outline",
spare_parts: "mdi:cog-outline",
photo: "mdi:image-outline",
other: "mdi:file-document-outline",
};
export class MaintenanceTaskDocuments extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant;
@property({ attribute: false }) public entryId!: string;
@@ -59,7 +51,7 @@ export class MaintenanceTaskDocuments extends LitElement {
private _localeReady = false;
private get _lang(): string {
return this.hass?.language || "en";
return langOf(this.hass);
}
/** The id linked docs reference — a task id or (part mode) a part id. */
@@ -158,19 +150,9 @@ export class MaintenanceTaskDocuments extends LitElement {
// A per-task page hint jumps straight to the relevant page via the PDF
// viewer's #page=N fragment (client-side, so it never breaks the signature).
const page = this._pageFor(doc);
const frag = page ? `#page=${page}` : "";
const win = window.open("about:blank", "_blank");
try {
const s = await this.hass.connection.sendMessagePromise<{ path: string }>({
type: "auth/sign_path",
path: `/api/maintenance_supporter/document/${doc.id}`,
expires: 300,
});
// Absolute URL: a fragment on a *root-relative* path won't resolve against
// the blank popup's about:blank base, so it would silently stay blank.
if (win) win.location.href = new URL(s.path + frag, window.location.origin).href;
await openSignedDocument(this.hass, doc.id, page ? `#page=${page}` : "");
} catch (e) {
if (win) win.close();
this._error = describeWsError(e, this._lang);
}
}
@@ -196,12 +178,7 @@ export class MaintenanceTaskDocuments extends LitElement {
private async _download(doc: Doc): Promise<void> {
try {
const s = await this.hass.connection.sendMessagePromise<{ path: string }>({
type: "auth/sign_path",
path: `/api/maintenance_supporter/document/${doc.id}`,
expires: 30,
});
downloadUrl(s.path, doc.filename || doc.title || "document");
await downloadSignedDocument(this.hass, doc.id, doc.filename || doc.title || "document");
} catch (e) {
this._error = describeWsError(e, this._lang);
}