diff --git a/frontend/src/index.ts b/frontend/src/index.ts index 57951a97..edc3066e 100644 --- a/frontend/src/index.ts +++ b/frontend/src/index.ts @@ -430,6 +430,7 @@ export class App extends LiteElement { case "archiveAddMember": case "archiveNewResourceTab": case "archiveCrawl": + case "browserProfile": case "crawlTemplate": case "crawlTemplateEdit": return html` + * ``` + */ +@localized() +export class BrowserProfilesDetail extends LiteElement { + @property({ type: Object }) + authState!: AuthState; + + @property({ type: String }) + archiveId!: string; + + @property({ type: String }) + profileId!: string; + + @state() + private profile: Partial = { + id: "2", + name: "Twitter Webrecorder", + description: "Et netus et malesuada fames.", + created: new Date().toUTCString(), + origins: ["https://twitter.com", "https://twitter.com/webrecorder_io"], + }; + + render() { + return html` + +
+

${this.profile.name}

+
`; + } +} + +customElements.define("btrix-browser-profiles-detail", BrowserProfilesDetail); diff --git a/frontend/src/pages/archive/browser-profiles-list.ts b/frontend/src/pages/archive/browser-profiles-list.ts new file mode 100644 index 00000000..10ab580e --- /dev/null +++ b/frontend/src/pages/archive/browser-profiles-list.ts @@ -0,0 +1,124 @@ +import { state, property } from "lit/decorators.js"; +import { msg, localized, str } from "@lit/localize"; + +import type { AuthState } from "../../utils/AuthService"; +import LiteElement, { html } from "../../utils/LiteElement"; +import { Profile } from "./types"; + +/** + * Usage: + * ```ts + * + * ``` + */ +@localized() +export class BrowserProfilesList extends LiteElement { + @property({ type: Object }) + authState!: AuthState; + + @property({ type: String }) + archiveId?: string; + + @state() + browserProfiles?: Profile[]; + + firstUpdated() { + this.fetchCrawls(); + } + + render() { + return html` ${this.renderTable()} `; + } + + renderTable() { + return html` +
+
+ +
+ ${this.browserProfiles + ? this.browserProfiles.length + ? html`
+ ${this.browserProfiles.map(this.renderItem.bind(this))} +
` + : html` +
+

+ ${msg("No browser profiles yet.")} +

+
+ ` + : ""} +
+ `; + } + + private renderItem(data: Profile) { + return html` + +
+
+
${data.name}
+
+ ${data.description} +
+
+
+ ${new Date(data.created).toLocaleDateString()} +
+
+ ${data.origins.join(", ")} +
+
+
+ `; + } + + /** + * Fetch browser profiles and update internal state + */ + private async fetchCrawls(): Promise { + try { + const data = await this.getProfiles(); + + this.browserProfiles = data; + } catch (e) { + this.notify({ + message: msg("Sorry, couldn't retrieve browser profiles at this time."), + type: "danger", + icon: "exclamation-octagon", + }); + } + } + + private async getProfiles(): Promise { + if (!this.archiveId) { + throw new Error(`Archive ID ${typeof this.archiveId}`); + } + + const data = await this.apiFetch( + `/archives/${this.archiveId}/profiles`, + this.authState! + ); + + return data; + } +} + +customElements.define("btrix-browser-profiles-list", BrowserProfilesList); diff --git a/frontend/src/pages/archive/index.ts b/frontend/src/pages/archive/index.ts index 1e92eacd..f51078ac 100644 --- a/frontend/src/pages/archive/index.ts +++ b/frontend/src/pages/archive/index.ts @@ -13,8 +13,14 @@ import "./crawl-templates-list"; import "./crawl-templates-new"; import "./crawl-detail"; import "./crawls-list"; +import "./browser-profiles-detail"; +import "./browser-profiles-list"; -export type ArchiveTab = "crawls" | "crawl-templates" | "members"; +export type ArchiveTab = + | "crawls" + | "crawl-templates" + | "browser-profiles" + | "members"; const defaultTab = "crawls"; @@ -36,6 +42,9 @@ export class Archive extends LiteElement { @property({ type: String }) archiveTab: ArchiveTab = defaultTab; + @property({ type: String }) + browserProfileId?: string; + @property({ type: String }) crawlId?: string; @@ -114,6 +123,9 @@ export class Archive extends LiteElement { case "crawl-templates": tabPanelContent = this.renderCrawlTemplates(); break; + case "browser-profiles": + tabPanelContent = this.renderBrowserProfiles(); + break; case "members": if (this.isAddingMember) { tabPanelContent = this.renderAddMember(); @@ -149,6 +161,10 @@ export class Archive extends LiteElement { tabName: "crawl-templates", label: msg("Crawl Templates"), })} + ${this.renderNavTab({ + tabName: "browser-profiles", + label: msg("Browser Profiles"), + })} ${showMembersTab ? this.renderNavTab({ tabName: "members", label: msg("Members") }) : ""} @@ -245,6 +261,21 @@ export class Archive extends LiteElement { >`; } + private renderBrowserProfiles() { + if (this.browserProfileId) { + return html``; + } + + return html``; + } + private renderMembers() { if (!this.archive!.users) return; diff --git a/frontend/src/pages/archive/types.ts b/frontend/src/pages/archive/types.ts index a282d84a..1fd54822 100644 --- a/frontend/src/pages/archive/types.ts +++ b/frontend/src/pages/archive/types.ts @@ -55,3 +55,19 @@ export type CrawlTemplate = { config: CrawlConfig; scale: number; }; + +export type Profile = { + id: string; + name: string; + description: string; + created: string; + origins: string[]; + baseId: string; + baseProfileName: string; + aid: string; + resource: { + filename: string; + hash: string; + size: number; + }; +}; diff --git a/frontend/src/routes.ts b/frontend/src/routes.ts index ef695c3b..d0490039 100644 --- a/frontend/src/routes.ts +++ b/frontend/src/routes.ts @@ -15,6 +15,7 @@ export const ROUTES = { archiveNewResourceTab: "/archives/:id/:tab/new", archiveAddMember: "/archives/:id/:tab/add-member", archiveCrawl: "/archives/:id/:tab/crawl/:crawlId", + browserProfile: "/archives/:id/:tab/profile/:browserProfileId", crawlTemplate: "/archives/:id/:tab/config/:crawlConfigId", crawlTemplateEdit: "/archives/:id/:tab/config/:crawlConfigId?edit", users: "/users",