-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrenderToolsIndex.js
More file actions
197 lines (181 loc) · 6.72 KB
/
renderToolsIndex.js
File metadata and controls
197 lines (181 loc) · 6.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
import { getToolRegistry } from "./toolRegistry.js";
import { escapeHtml } from "../src/shared/string/stringUtil.js";
const SAMPLES_INDEX_PATH = "/samples/index.html";
const SAMPLES_METADATA_PATH = "/samples/metadata/samples.index.metadata.json";
function toStandaloneHref(entryPoint) {
const normalized = String(entryPoint || "").replace(/^\.?\/*/, "");
return normalized ? `/tools/${normalized}` : "#";
}
function buildDocumentationLinks(tool) {
const folder = String(tool.folderName || tool.path || "").trim();
if (!folder) {
return [];
}
return [
{ label: "How To Use", path: `${folder}/how_to_use.html` },
{ label: "README", path: `${folder}/README.md` }
];
}
function buildCardLinks(tool, sampleCount) {
const docs = buildDocumentationLinks(tool);
const links = [...docs];
if (Number.isInteger(sampleCount) && sampleCount > 0) {
links.push({
label: `Samples (${sampleCount})`,
path: `${SAMPLES_INDEX_PATH}?tool=${encodeURIComponent(tool.id)}`
});
}
const seen = new Set();
return links.filter((entry) => {
const label = String(entry?.label || "").trim();
const path = String(entry?.path || "").trim();
if (!label || !path) {
return false;
}
const key = `${label.toLowerCase()}|${path.toLowerCase()}`;
if (seen.has(key)) {
return false;
}
seen.add(key);
return true;
});
}
function renderToolCard(tool, sampleCountByToolId) {
const standaloneHref = toStandaloneHref(tool.entryPoint);
const sampleCount = Number(sampleCountByToolId.get(tool.id) || 0);
const cardLinks = buildCardLinks(tool, sampleCount);
const sampleLinks = cardLinks.length > 0
? `
<div class="meta">
${cardLinks.map((entry) => `
<a class="tools-platform-card__action tools-platform-card__action--secondary" href="${escapeHtml(entry.path)}">${escapeHtml(entry.label)}</a>
`).join("")}
</div>
`
: "";
return `
<div class="card tools-platform-card">
<div class="meta">
<span class="pill live">${escapeHtml(tool.showcaseTag || "Active Tool")}</span>
<span class="pill planned">${escapeHtml(tool.showcaseStatus || "Engine Theme")}</span>
</div>
<h3><a href="${escapeHtml(standaloneHref)}">${escapeHtml(tool.displayName)}</a></h3>
<p>${escapeHtml(tool.description)}</p>
${sampleLinks}
</div>
`;
}
function classifyToolGroup(toolId) {
const viewerToolIds = new Set([
"3d-asset-viewer",
"replay-visualizer",
"performance-profiler"
]);
const utilityToolIds = new Set([
"asset-browser",
"asset-pipeline-tool",
"tile-model-converter",
"physics-sandbox",
"3d-json-payload-normalizer"
]);
if (viewerToolIds.has(toolId)) {
return "viewers";
}
if (utilityToolIds.has(toolId)) {
return "utilities";
}
return "editors";
}
function renderWorkspaceManagerCard() {
return `
<div class="card tools-platform-card">
<div class="meta">
<span class="pill live">Workspace</span>
<span class="pill planned">Manager</span>
</div>
<h3><a href="/tools/Workspace%20Manager/index.html">Workspace Manager</a></h3>
<p>Shared hosted launcher for opening tools inside a managed workspace container.</p>
<div class="meta">
<a class="tools-platform-card__action" href="/tools/Workspace%20Manager/index.html">Open Workspace Manager</a>
<a class="tools-platform-card__action tools-platform-card__action--secondary" href="Workspace Manager/how_to_use.html">How To Use</a>
<a class="tools-platform-card__action tools-platform-card__action--secondary" href="Workspace Manager/README.md">README</a>
</div>
</div>
`;
}
function renderWorkspaceManagerSection() {
const grid = document.querySelector("[data-workspace-manager-grid]");
if (!grid) {
return;
}
grid.innerHTML = renderWorkspaceManagerCard();
}
async function loadSampleCountByToolId() {
const counts = new Map();
try {
const response = await fetch(SAMPLES_METADATA_PATH, { cache: "no-store" });
if (!response.ok) {
return counts;
}
const metadata = await response.json();
const samples = Array.isArray(metadata?.samples) ? metadata.samples : [];
for (const sample of samples) {
if (String(sample?.phase || "").trim() === "20") {
continue;
}
const toolsUsed = Array.isArray(sample?.toolsUsed) && sample.toolsUsed.length > 0
? sample.toolsUsed
: (Array.isArray(sample?.toolHints) ? sample.toolHints : []);
for (const rawToolId of toolsUsed) {
const toolId = String(rawToolId || "").trim().toLowerCase();
if (!toolId || toolId === "workspace-manager") {
continue;
}
counts.set(toolId, Number(counts.get(toolId) || 0) + 1);
}
}
return counts;
} catch {
return counts;
}
}
function renderActiveToolsList(sampleCountByToolId) {
const editorsGrid = document.querySelector("[data-active-tools-editors-grid]");
const utilitiesGrid = document.querySelector("[data-active-tools-utilities-grid]");
const viewersGrid = document.querySelector("[data-active-tools-viewers-grid]");
if (!editorsGrid || !utilitiesGrid || !viewersGrid) {
return;
}
const tools = getToolRegistry()
.filter((entry) => entry.active === true)
.filter((entry) => entry.visibleInToolsList === true)
.filter((entry) => entry.id !== "state-inspector")
.sort((left, right) => String(left.displayName || "").localeCompare(String(right.displayName || "")));
const editors = tools.filter((tool) => classifyToolGroup(tool.id) === "editors").map((tool) => renderToolCard(tool, sampleCountByToolId));
const utilities = tools.filter((tool) => classifyToolGroup(tool.id) === "utilities").map((tool) => renderToolCard(tool, sampleCountByToolId));
const viewers = tools.filter((tool) => classifyToolGroup(tool.id) === "viewers").map((tool) => renderToolCard(tool, sampleCountByToolId));
editorsGrid.innerHTML = editors.join("\n");
utilitiesGrid.innerHTML = utilities.join("\n");
viewersGrid.innerHTML = viewers.join("\n");
}
function sortPlannedCardsAlphabetically() {
const grid = document.querySelector("[data-planned-tools-grid]");
if (!grid) {
return;
}
const cards = Array.from(grid.querySelectorAll(".card"));
cards
.sort((left, right) => {
const leftName = left.querySelector("h3")?.textContent?.trim() || "";
const rightName = right.querySelector("h3")?.textContent?.trim() || "";
return leftName.localeCompare(rightName);
})
.forEach((card) => grid.appendChild(card));
}
async function initToolsIndex() {
const sampleCountByToolId = await loadSampleCountByToolId();
renderWorkspaceManagerSection();
renderActiveToolsList(sampleCountByToolId);
sortPlannedCardsAlphabetically();
}
void initToolsIndex();