// Copyright Epic Games, Inc. All Rights Reserved. "use strict"; import { WidgetHost } from "../util/widgets.js" //////////////////////////////////////////////////////////////////////////////// export class PageBase extends WidgetHost { constructor(parent, params) { super(parent) this._params = params; } set_title(name) { var value = document.title; if (name.length && value.length) name = value + " - " + name; document.title = name; } get_param(name, fallback=undefined) { var ret = this._params.get(name); if (ret != undefined) return ret; if (fallback != undefined) this.set_param(name, fallback); return fallback; } set_param(name, value, update=true) { this._params.set(name, value); if (!update) return value; const url = new URL(window.location); for (var [key, xfer] of this._params) url.searchParams.set(key, xfer); history.replaceState(null, "", url); return value; } reload() { window.location.reload(); } } //////////////////////////////////////////////////////////////////////////////// export class ZenPage extends PageBase { constructor(parent, ...args) { super(parent, ...args); super.set_title("zen"); this.add_branding(parent); this.generate_crumbs(); } add_branding(parent) { var root = parent.tag().id("branding"); const logo_container = root.tag("div").id("logo"); logo_container.tag("img").attr("src", "favicon.ico").id("zen_icon"); logo_container.tag("span").id("zen_text").text("zenserver"); logo_container.tag().id("go_home").on_click(() => window.location.search = ""); root.tag("img").attr("src", "epicgames.ico").id("epic_logo"); } set_title(...args) { super.set_title(...args); } generate_crumbs() { var auto_name = this.get_param("page") || "start"; if (auto_name == "start") return; const crumbs = this.tag().id("crumbs"); const new_crumb = function(name, search=undefined) { crumbs.tag(); var crumb = crumbs.tag().text(name); if (search != undefined) crumb.on_click((x) => window.location.search = x, search); }; new_crumb("home", ""); var project = this.get_param("project"); if (project != undefined) { auto_name = project; var oplog = this.get_param("oplog"); if (oplog != undefined) { new_crumb(auto_name, `?page=project&project=${project}`); auto_name = oplog; var opkey = this.get_param("opkey") if (opkey != undefined) { new_crumb(auto_name, `?page=oplog&project=${project}&oplog=${oplog}`); auto_name = opkey.split("/").pop().split("\\").pop(); // Check if we're viewing cook artifacts var page = this.get_param("page"); var hash = this.get_param("hash"); if (hash != undefined && page == "cookartifacts") { new_crumb(auto_name, `?page=entry&project=${project}&oplog=${oplog}&opkey=${opkey}`); auto_name = "cook artifacts"; } } } } new_crumb(auto_name); } }