// 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 { Table, Toolbar, ProgressBar } from "../util/widgets.js" import { create_indexer } from "../indexer/indexer.js" //////////////////////////////////////////////////////////////////////////////// export class Page extends ZenPage { constructor(...args) { super(...args); this._index_start = Number(this.get_param("start", 0)) || 0; this._index_count = Number(this.get_param("count", 50)) || 0; } async main() { const project = this.get_param("project"); const oplog = this.get_param("oplog"); var oplog_info = new Fetcher() .resource("prj", project, "oplog", oplog) .json(); this._indexer = this._load_indexer(project, oplog); this.set_title("oplog - " + oplog); var section = this.add_section(project + " - " + oplog); oplog_info = await oplog_info; this._index_max = oplog_info["opcount"]; this._build_nav(section, oplog_info); this._entry_table = section.add_widget(Table, ["key"]); await this._build_table(this._index_start); } async _load_indexer(project, oplog) { const progress_bar = this.add_widget(ProgressBar); progress_bar.set_progress("indexing"); var indexer = create_indexer(project, oplog, (...args) => { progress_bar.set_progress(...args); }); indexer = await indexer; progress_bar.destroy(); return indexer; } _build_nav(section, oplog_info) { const nav = section.add_widget(Toolbar); const left = nav.left(); left.add("|<") .on_click(() => this._on_next_prev(-10e10)); left.add("<<").on_click(() => this._on_next_prev(-10)); left.add("prev") .on_click(() => this._on_next_prev( -1)); left.add("next") .on_click(() => this._on_next_prev( 1)); left.add(">>").on_click(() => this._on_next_prev( 10)); left.add(">|") .on_click(() => this._on_next_prev( 10e10)); left.sep(); for (var count of [10, 25, 50, 100]) { var handler = (n) => this._on_change_count(n); left.add(count).on_click(handler, count); } left.sep(); left.add("tree").link("", { "page" : "tree", "project" : this.get_param("project"), "oplog" : this.get_param("oplog"), }); const right = nav.right(); right.add(Friendly.sep(oplog_info["opcount"])); right.add("(" + Friendly.kib(oplog_info["totalsize"]) + ")"); right.sep(); var search_input = right.add("search:", "label").tag("input") search_input.on("change", (x) => this._search(x.inner().value), search_input); } async _build_table(index) { this._index_count = Math.max(this._index_count, 1); index = Math.min(index, this._index_max - this._index_count); index = Math.max(index, 0); const project = this.get_param("project"); const oplog = this.get_param("oplog"); var entries = new Fetcher() .resource("prj", project, "oplog", oplog, "entries") .param("start", index) .param("count", this.set_param("count", this._index_count)) .json(); entries = (await entries)["entries"]; if (entries == undefined) return; if (entries.length == 0) return; this._entry_table.clear(index); for (const entry of entries) { var row = this._entry_table.add_row(entry["key"]); row.get_cell(0).link("", { "page" : "entry", "project" : project, "oplog" : oplog, "opkey" : entry["key"], }); } this.set_param("start", index); this._index_start = index; } _on_change_count(value) { this._index_count = parseInt(value); this._build_table(this._index_start); } _on_next_prev(direction) { var index = this._index_start + (this._index_count * direction); index = Math.max(0, index); this._build_table(index); } async _search(needle) { if (needle.length == 0) { this._build_table(this._index_start); return; } needle = needle.trim(); this._entry_table.clear(this._index_start); const project = this.get_param("project"); const oplog = this.get_param("oplog"); const indexer = await this._indexer; var added = 0; const truncate_at = this.get_param("searchmax") || 250; for (var name of indexer.search(needle)) { var row = this._entry_table.add_row(name); row.get_cell(0).link("", { "page" : "entry", "project" : project, "oplog" : oplog, "opkey" : name, }); if (++added >= truncate_at) { this._entry_table.add_row("...truncated"); break; } } } }