// Copyright Epic Games, Inc. All Rights Reserved. "use strict"; import { ZenPage } from "./page.js" import { Fetcher } from "../util/fetcher.js" import { Friendly } from "../util/friendly.js" import { Modal } from "../util/modal.js" import { Table, Toolbar } from "../util/widgets.js" //////////////////////////////////////////////////////////////////////////////// export class Page extends ZenPage { async main() { var section = this.add_section("projects"); // project list var columns = [ "name", "project_dir", "engine_dir", "actions", ]; var table = section.add_widget(Table, columns); for (const project of await new Fetcher().resource("/prj/list").json()) { var row = table.add_row( "", project.ProjectRootDir, project.EngineRootDir, ); var cell = row.get_cell(0); cell.tag().text(project.Id).on_click((x) => this.view_project(x), project.Id); var cell = row.get_cell(-1); var action_tb = new Toolbar(cell, true); action_tb.left().add("view").on_click((x) => this.view_project(x), project.Id); action_tb.left().add("drop").on_click((x) => this.drop_project(x), project.Id); } // cache var section = this.add_section("z$"); columns = [ "namespace", "dir", "buckets", "entries", "size disk", "size mem", "actions", ] var zcache_info = new Fetcher().resource("/z$/").json(); const cache_table = section.add_widget(Table, columns, Table.Flag_FitLeft|Table.Flag_PackRight); for (const namespace of (await zcache_info)["Namespaces"]) { new Fetcher().resource(`/z$/${namespace}/`).json().then((data) => { const row = cache_table.add_row( "", data["Configuration"]["RootDir"], data["Buckets"].length, data["EntryCount"], Friendly.kib(data["StorageSize"].DiskSize), Friendly.kib(data["StorageSize"].MemorySize) ); var cell = row.get_cell(0); cell.tag().text(namespace).on_click(() => this.view_zcache(namespace)); row.get_cell(1).tag().text(namespace); cell = row.get_cell(-1); const action_tb = new Toolbar(cell, true); action_tb.left().add("view").on_click(() => this.view_zcache(namespace)); action_tb.left().add("drop").on_click(() => this.drop_zcache(namespace)); }); } // stats section = this.add_section("stats"); columns = [ "name", "req count", "size disk", "size mem", "cid total", ]; const stats_table = section.add_widget(Table, columns, Table.Flag_PackRight); var providers = new Fetcher().resource("stats").json(); for (var provider of (await providers)["providers"]) { var stats = await new Fetcher().resource("stats", provider).json(); var values = [""]; try { values.push(stats.requests.count); const size_stat = (stats.store || stats.cache).size; values.push(Friendly.kib(size_stat.disk)); values.push(Friendly.kib(size_stat.memory)); values.push(stats.cid.size.total); } catch {} row = stats_table.add_row(...values); row.get_cell(0).tag().text(provider).on_click((x) => this.view_stat(x), provider); } } view_stat(provider) { window.location = "?page=stat&provider=" + provider; } view_project(project_id) { window.location = "?page=project&project=" + project_id; } drop_project(project_id) { const drop = async () => { await new Fetcher().resource("prj", project_id).delete(); this.reload(); }; new Modal() .title("Confirmation") .message(`Drop project '${project_id}'?`) .option("Yes", () => drop()) .option("No"); } view_zcache(namespace) { window.location = "?page=zcache&namespace=" + namespace; } drop_zcache(namespace) { const drop = async () => { await new Fetcher().resource("z$", namespace).delete(); this.reload(); }; new Modal() .title("Confirmation") .message(`Drop zcache '${namespace}'?`) .option("Yes", () => drop()) .option("No"); } }