重构代码结构并添加完整功能
主要改动: - 重构目录结构:合并子目录到根目录,简化项目结构 - 添加完整的查询 API:支持复杂条件查询、字段选择、游标模式 - 实现 LSM-Tree Compaction:7层结构、Score-based策略、后台异步合并 - 添加 Web UI:基于 Lit 的现代化管理界面,支持数据浏览和 Manifest 查看 - 完善文档:添加 README.md 和 examples/webui/README.md 新增功能: - Query Builder:链式查询 API,支持 Eq/Lt/Gt/In/Between/Contains 等操作符 - Web UI 组件:srdb-app、srdb-table-list、srdb-data-view、srdb-manifest-view 等 - 列选择持久化:自动保存到 localStorage - 刷新按钮:一键刷新当前视图 - 主题切换:深色/浅色主题支持 代码优化: - 使用 Go 1.24 新特性:range 7、min()、maps.Copy()、slices.Sort() - 统一组件命名:所有 Web Components 使用 srdb-* 前缀 - CSS 优化:提取共享样式,减少重复代码 - 清理遗留代码:删除未使用的方法和样式
This commit is contained in:
@@ -1,199 +1,110 @@
|
||||
// SRDB WebUI - htmx 版本
|
||||
import './components/app.js';
|
||||
import './components/table-list.js';
|
||||
import './components/table-view.js';
|
||||
import './components/modal-dialog.js';
|
||||
import './components/theme-toggle.js';
|
||||
import './components/badge.js';
|
||||
import './components/field-icon.js';
|
||||
import './components/data-view.js';
|
||||
import './components/manifest-view.js';
|
||||
import './components/page-header.js';
|
||||
|
||||
// 全局状态
|
||||
window.srdbState = {
|
||||
selectedTable: null,
|
||||
currentPage: 1,
|
||||
pageSize: 20,
|
||||
selectedColumns: [],
|
||||
expandedTables: new Set(),
|
||||
expandedLevels: new Set([0, 1]),
|
||||
};
|
||||
class App {
|
||||
constructor() {
|
||||
// 等待 srdb-app 组件渲染完成
|
||||
this.appContainer = document.querySelector('srdb-app');
|
||||
this.modal = document.querySelector('srdb-modal-dialog');
|
||||
|
||||
// 等待组件初始化
|
||||
if (this.appContainer) {
|
||||
// 使用 updateComplete 等待组件渲染完成
|
||||
this.appContainer.updateComplete.then(() => {
|
||||
this.tableList = this.appContainer.shadowRoot.querySelector('srdb-table-list');
|
||||
this.tableView = this.appContainer.shadowRoot.querySelector('srdb-table-view');
|
||||
this.pageHeader = this.appContainer.shadowRoot.querySelector('srdb-page-header');
|
||||
this.setupEventListeners();
|
||||
});
|
||||
} else {
|
||||
// 如果组件还未定义,等待它被定义
|
||||
customElements.whenDefined('srdb-app').then(() => {
|
||||
this.appContainer = document.querySelector('srdb-app');
|
||||
this.appContainer.updateComplete.then(() => {
|
||||
this.tableList = this.appContainer.shadowRoot.querySelector('srdb-table-list');
|
||||
this.tableView = this.appContainer.shadowRoot.querySelector('srdb-table-view');
|
||||
this.pageHeader = this.appContainer.shadowRoot.querySelector('srdb-page-header');
|
||||
this.setupEventListeners();
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 选择表格
|
||||
function selectTable(tableName) {
|
||||
window.srdbState.selectedTable = tableName;
|
||||
window.srdbState.currentPage = 1;
|
||||
|
||||
// 高亮选中的表
|
||||
document.querySelectorAll(".table-item").forEach((el) => {
|
||||
el.classList.toggle("selected", el.dataset.table === tableName);
|
||||
});
|
||||
|
||||
// 加载表数据
|
||||
loadTableData(tableName);
|
||||
}
|
||||
|
||||
// 加载表数据
|
||||
function loadTableData(tableName) {
|
||||
const mainContent = document.getElementById("main-content");
|
||||
mainContent.innerHTML = '<div class="loading">Loading...</div>';
|
||||
|
||||
fetch(
|
||||
`/api/tables-view/${tableName}?page=${window.srdbState.currentPage}&pageSize=${window.srdbState.pageSize}`,
|
||||
)
|
||||
.then((res) => res.text())
|
||||
.then((html) => {
|
||||
mainContent.innerHTML = html;
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error("Failed to load table data:", err);
|
||||
mainContent.innerHTML =
|
||||
'<div class="error">Failed to load table data</div>';
|
||||
setupEventListeners() {
|
||||
// Listen for table selection
|
||||
document.addEventListener('table-selected', (e) => {
|
||||
const tableName = e.detail.tableName;
|
||||
this.pageHeader.tableName = tableName;
|
||||
this.pageHeader.view = 'data';
|
||||
this.tableView.tableName = tableName;
|
||||
this.tableView.view = 'data';
|
||||
this.tableView.page = 1;
|
||||
});
|
||||
}
|
||||
|
||||
// 切换视图 (Data / Manifest)
|
||||
function switchView(tableName, mode) {
|
||||
const mainContent = document.getElementById("main-content");
|
||||
mainContent.innerHTML = '<div class="loading">Loading...</div>';
|
||||
|
||||
const endpoint =
|
||||
mode === "manifest"
|
||||
? `/api/tables-view/${tableName}/manifest`
|
||||
: `/api/tables-view/${tableName}?page=${window.srdbState.currentPage}&pageSize=${window.srdbState.pageSize}`;
|
||||
|
||||
fetch(endpoint)
|
||||
.then((res) => res.text())
|
||||
.then((html) => {
|
||||
mainContent.innerHTML = html;
|
||||
// Listen for view change from page-header
|
||||
document.addEventListener('view-changed', (e) => {
|
||||
this.tableView.view = e.detail.view;
|
||||
});
|
||||
}
|
||||
|
||||
// 分页
|
||||
function changePage(delta) {
|
||||
window.srdbState.currentPage += delta;
|
||||
if (window.srdbState.selectedTable) {
|
||||
loadTableData(window.srdbState.selectedTable);
|
||||
}
|
||||
}
|
||||
|
||||
function jumpToPage(page) {
|
||||
window.srdbState.currentPage = parseInt(page);
|
||||
if (window.srdbState.selectedTable) {
|
||||
loadTableData(window.srdbState.selectedTable);
|
||||
}
|
||||
}
|
||||
|
||||
function changePageSize(newSize) {
|
||||
window.srdbState.pageSize = parseInt(newSize);
|
||||
window.srdbState.currentPage = 1;
|
||||
if (window.srdbState.selectedTable) {
|
||||
loadTableData(window.srdbState.selectedTable);
|
||||
}
|
||||
}
|
||||
|
||||
// Modal 相关
|
||||
function showModal(title, content) {
|
||||
document.getElementById("modal-title").textContent = title;
|
||||
document.getElementById("modal-body-content").textContent = content;
|
||||
document.getElementById("modal").style.display = "flex";
|
||||
}
|
||||
|
||||
function closeModal() {
|
||||
document.getElementById("modal").style.display = "none";
|
||||
}
|
||||
|
||||
function showCellContent(content) {
|
||||
showModal("Cell Content", content);
|
||||
}
|
||||
|
||||
function showRowDetail(tableName, seq) {
|
||||
fetch(`/api/tables/${tableName}/data/${seq}`)
|
||||
.then((res) => res.json())
|
||||
.then((data) => {
|
||||
const formatted = JSON.stringify(data, null, 2);
|
||||
showModal(`Row Detail (Seq: ${seq})`, formatted);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error("Failed to load row detail:", err);
|
||||
alert("Failed to load row detail");
|
||||
// Listen for refresh request from page-header
|
||||
document.addEventListener('refresh-view', (e) => {
|
||||
this.tableView.loadData();
|
||||
});
|
||||
}
|
||||
|
||||
// 折叠展开
|
||||
function toggleExpand(tableName) {
|
||||
const item = document.querySelector(`[data-table="${tableName}"]`);
|
||||
const fieldsDiv = item.querySelector(".schema-fields");
|
||||
const icon = item.querySelector(".expand-icon");
|
||||
// Listen for row detail request
|
||||
document.addEventListener('show-row-detail', async (e) => {
|
||||
const { tableName, seq } = e.detail;
|
||||
await this.showRowDetail(tableName, seq);
|
||||
});
|
||||
|
||||
if (window.srdbState.expandedTables.has(tableName)) {
|
||||
window.srdbState.expandedTables.delete(tableName);
|
||||
fieldsDiv.style.display = "none";
|
||||
icon.classList.remove("expanded");
|
||||
} else {
|
||||
window.srdbState.expandedTables.add(tableName);
|
||||
fieldsDiv.style.display = "block";
|
||||
icon.classList.add("expanded");
|
||||
// Listen for cell content request
|
||||
document.addEventListener('show-cell-content', (e) => {
|
||||
this.showCellContent(e.detail.content);
|
||||
});
|
||||
|
||||
// Close modal on backdrop click
|
||||
this.modal.addEventListener('click', () => {
|
||||
this.modal.open = false;
|
||||
});
|
||||
}
|
||||
|
||||
async showRowDetail(tableName, seq) {
|
||||
try {
|
||||
const response = await fetch(`/api/tables/${tableName}/data/${seq}`);
|
||||
if (!response.ok) throw new Error('Failed to load row detail');
|
||||
|
||||
const data = await response.json();
|
||||
const content = JSON.stringify(data, null, 2);
|
||||
|
||||
this.modal.title = `Row Detail - Seq: ${seq}`;
|
||||
this.modal.content = content;
|
||||
this.modal.open = true;
|
||||
} catch (error) {
|
||||
console.error('Error loading row detail:', error);
|
||||
this.modal.title = 'Error';
|
||||
this.modal.content = `Failed to load row detail: ${error.message}`;
|
||||
this.modal.open = true;
|
||||
}
|
||||
}
|
||||
|
||||
showCellContent(content) {
|
||||
this.modal.title = 'Cell Content';
|
||||
this.modal.content = String(content);
|
||||
this.modal.open = true;
|
||||
}
|
||||
}
|
||||
|
||||
function toggleLevel(level) {
|
||||
const levelCard = document.querySelector(`[data-level="${level}"]`);
|
||||
const fileList = levelCard.querySelector(".file-list");
|
||||
const icon = levelCard.querySelector(".expand-icon");
|
||||
|
||||
if (window.srdbState.expandedLevels.has(level)) {
|
||||
window.srdbState.expandedLevels.delete(level);
|
||||
fileList.style.display = "none";
|
||||
icon.classList.remove("expanded");
|
||||
} else {
|
||||
window.srdbState.expandedLevels.add(level);
|
||||
fileList.style.display = "grid";
|
||||
icon.classList.add("expanded");
|
||||
}
|
||||
}
|
||||
|
||||
// 格式化工具
|
||||
function formatBytes(bytes) {
|
||||
if (bytes === 0) return "0 B";
|
||||
const k = 1024;
|
||||
const sizes = ["B", "KB", "MB", "GB"];
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
||||
return (bytes / Math.pow(k, i)).toFixed(2) + " " + sizes[i];
|
||||
}
|
||||
|
||||
function formatCount(count) {
|
||||
if (count >= 1000000) return (count / 1000000).toFixed(1) + "M";
|
||||
if (count >= 1000) return (count / 1000).toFixed(1) + "K";
|
||||
return count.toString();
|
||||
}
|
||||
|
||||
// 点击 modal 外部关闭
|
||||
document.addEventListener("click", (e) => {
|
||||
const modal = document.getElementById("modal");
|
||||
if (e.target === modal) {
|
||||
closeModal();
|
||||
}
|
||||
});
|
||||
|
||||
// ESC 键关闭 modal
|
||||
document.addEventListener("keydown", (e) => {
|
||||
if (e.key === "Escape") {
|
||||
closeModal();
|
||||
}
|
||||
});
|
||||
|
||||
// 切换列显示
|
||||
function toggleColumn(columnName) {
|
||||
// 切换 schema-field-card 的选中状态
|
||||
const card = document.querySelector(
|
||||
`.schema-field-card[data-column="${columnName}"]`,
|
||||
);
|
||||
if (!card) return;
|
||||
|
||||
card.classList.toggle("selected");
|
||||
const isSelected = card.classList.contains("selected");
|
||||
|
||||
// 切换表格列的显示/隐藏
|
||||
const headers = document.querySelectorAll(`th[data-column="${columnName}"]`);
|
||||
const cells = document.querySelectorAll(`td[data-column="${columnName}"]`);
|
||||
|
||||
headers.forEach((header) => {
|
||||
header.style.display = isSelected ? "" : "none";
|
||||
});
|
||||
|
||||
cells.forEach((cell) => {
|
||||
cell.style.display = isSelected ? "" : "none";
|
||||
});
|
||||
// Initialize app when DOM is ready
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', () => new App());
|
||||
} else {
|
||||
new App();
|
||||
}
|
||||
|
||||
145
webui/static/js/components/app.js
Normal file
145
webui/static/js/components/app.js
Normal file
@@ -0,0 +1,145 @@
|
||||
import { LitElement, html, css } from 'https://cdn.jsdelivr.net/gh/lit/dist@3/core/lit-core.min.js';
|
||||
import { sharedStyles, cssVariables } from '../styles/shared-styles.js';
|
||||
|
||||
export class AppContainer extends LitElement {
|
||||
static properties = {
|
||||
mobileMenuOpen: { type: Boolean }
|
||||
};
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this.mobileMenuOpen = false;
|
||||
}
|
||||
|
||||
toggleMobileMenu() {
|
||||
this.mobileMenuOpen = !this.mobileMenuOpen;
|
||||
}
|
||||
|
||||
static styles = [
|
||||
sharedStyles,
|
||||
cssVariables,
|
||||
css`
|
||||
:host {
|
||||
display: block;
|
||||
height: 100vh;
|
||||
}
|
||||
|
||||
.container {
|
||||
display: flex;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.sidebar {
|
||||
width: 280px;
|
||||
background: var(--bg-surface);
|
||||
border-right: 1px solid var(--border-color);
|
||||
overflow-y: auto;
|
||||
overflow-x: hidden;
|
||||
padding: 16px 12px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.sidebar::-webkit-scrollbar {
|
||||
width: 6px;
|
||||
}
|
||||
|
||||
.sidebar-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.sidebar h1 {
|
||||
font-size: 18px;
|
||||
font-weight: 700;
|
||||
letter-spacing: -0.02em;
|
||||
background: linear-gradient(135deg, var(--primary-light), var(--primary));
|
||||
-webkit-background-clip: text;
|
||||
-webkit-text-fill-color: transparent;
|
||||
}
|
||||
|
||||
.main {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
overflow-x: hidden;
|
||||
background: var(--bg-main);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
|
||||
/* 移动端遮罩 */
|
||||
.mobile-overlay {
|
||||
display: none;
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
z-index: 999;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.mobile-overlay.show {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.container {
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.sidebar {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 280px;
|
||||
height: 100vh;
|
||||
border-right: 1px solid var(--border-color);
|
||||
border-bottom: none;
|
||||
transform: translateX(-100%);
|
||||
transition: transform 0.3s ease;
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
.sidebar.open {
|
||||
transform: translateX(0);
|
||||
}
|
||||
|
||||
.main {
|
||||
padding-top: 0;
|
||||
}
|
||||
}
|
||||
`
|
||||
];
|
||||
|
||||
render() {
|
||||
return html`
|
||||
<!-- 移动端遮罩 -->
|
||||
<div class="mobile-overlay ${this.mobileMenuOpen ? 'show' : ''}" @click=${this.toggleMobileMenu}></div>
|
||||
|
||||
<div class="container">
|
||||
<!-- 左侧表列表 -->
|
||||
<div class="sidebar ${this.mobileMenuOpen ? 'open' : ''}">
|
||||
<div class="sidebar-header">
|
||||
<h1>SRDB Tables</h1>
|
||||
<srdb-theme-toggle></srdb-theme-toggle>
|
||||
</div>
|
||||
<srdb-table-list @table-selected=${this.toggleMobileMenu}></srdb-table-list>
|
||||
</div>
|
||||
|
||||
<!-- 右侧主内容区 -->
|
||||
<div class="main">
|
||||
<srdb-page-header @toggle-mobile-menu=${this.toggleMobileMenu}></srdb-page-header>
|
||||
<srdb-table-view></srdb-table-view>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
}
|
||||
|
||||
customElements.define('srdb-app', AppContainer);
|
||||
106
webui/static/js/components/badge.js
Normal file
106
webui/static/js/components/badge.js
Normal file
@@ -0,0 +1,106 @@
|
||||
import { LitElement, html, css } from 'https://cdn.jsdelivr.net/gh/lit/dist@3/core/lit-core.min.js';
|
||||
import { sharedStyles, cssVariables } from '../styles/shared-styles.js';
|
||||
|
||||
export class Badge extends LitElement {
|
||||
static properties = {
|
||||
variant: { type: String }, // 'primary', 'success', 'warning', 'danger', 'info'
|
||||
icon: { type: String },
|
||||
size: { type: String } // 'sm', 'md'
|
||||
};
|
||||
|
||||
static styles = [
|
||||
sharedStyles,
|
||||
cssVariables,
|
||||
css`
|
||||
:host {
|
||||
display: inline-flex;
|
||||
}
|
||||
|
||||
.badge {
|
||||
position: relative;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
padding: 2px 8px;
|
||||
font-size: 11px;
|
||||
font-weight: 600;
|
||||
border-radius: var(--radius-sm);
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.badge.size-md {
|
||||
padding: 4px 10px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
/* Primary variant */
|
||||
.badge.variant-primary {
|
||||
--badge-border-color: rgba(99, 102, 241, 0.2);
|
||||
background: rgba(99, 102, 241, 0.15);
|
||||
color: var(--primary);
|
||||
}
|
||||
|
||||
/* Success variant */
|
||||
.badge.variant-success {
|
||||
--badge-border-color: rgba(16, 185, 129, 0.2);
|
||||
background: rgba(16, 185, 129, 0.15);
|
||||
color: var(--success);
|
||||
}
|
||||
|
||||
/* Warning variant */
|
||||
.badge.variant-warning {
|
||||
--badge-border-color: rgba(245, 158, 11, 0.2);
|
||||
background: rgba(245, 158, 11, 0.15);
|
||||
color: var(--warning);
|
||||
}
|
||||
|
||||
/* Danger variant */
|
||||
.badge.variant-danger {
|
||||
--badge-border-color: rgba(239, 68, 68, 0.2);
|
||||
background: rgba(239, 68, 68, 0.15);
|
||||
color: var(--danger);
|
||||
}
|
||||
|
||||
/* Info variant */
|
||||
.badge.variant-info {
|
||||
--badge-border-color: rgba(59, 130, 246, 0.2);
|
||||
background: rgba(59, 130, 246, 0.15);
|
||||
color: var(--info);
|
||||
}
|
||||
|
||||
/* Secondary variant */
|
||||
.badge.variant-secondary {
|
||||
--badge-border-color: rgba(160, 160, 176, 0.2);
|
||||
background: rgba(160, 160, 176, 0.15);
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.icon {
|
||||
font-size: 12px;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.badge.size-md .icon {
|
||||
font-size: 14px;
|
||||
}
|
||||
`
|
||||
];
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this.variant = 'primary';
|
||||
this.icon = '';
|
||||
this.size = 'sm';
|
||||
}
|
||||
|
||||
render() {
|
||||
return html`
|
||||
<span class="badge variant-${this.variant} size-${this.size}">
|
||||
${this.icon ? html`<span class="icon">${this.icon}</span>` : ''}
|
||||
<slot></slot>
|
||||
</span>
|
||||
`;
|
||||
}
|
||||
}
|
||||
|
||||
customElements.define('srdb-badge', Badge);
|
||||
351
webui/static/js/components/data-view.js
Normal file
351
webui/static/js/components/data-view.js
Normal file
@@ -0,0 +1,351 @@
|
||||
import { LitElement, html, css } from 'https://cdn.jsdelivr.net/gh/lit/dist@3/core/lit-core.min.js';
|
||||
import { sharedStyles, cssVariables } from '../styles/shared-styles.js';
|
||||
|
||||
export class DataView extends LitElement {
|
||||
static properties = {
|
||||
tableName: { type: String },
|
||||
schema: { type: Object },
|
||||
tableData: { type: Object },
|
||||
selectedColumns: { type: Array },
|
||||
loading: { type: Boolean }
|
||||
};
|
||||
|
||||
static styles = [
|
||||
sharedStyles,
|
||||
cssVariables,
|
||||
css`
|
||||
:host {
|
||||
display: block;
|
||||
}
|
||||
|
||||
h3 {
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
margin: 20px 0 12px 0;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.schema-section {
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.schema-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.schema-field-card {
|
||||
padding: 12px;
|
||||
background: var(--bg-elevated);
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: var(--radius-md);
|
||||
cursor: pointer;
|
||||
transition: var(--transition);
|
||||
}
|
||||
|
||||
.schema-field-card:hover {
|
||||
background: var(--bg-hover);
|
||||
}
|
||||
|
||||
.schema-field-card.selected {
|
||||
border-color: var(--primary);
|
||||
background: var(--primary-bg);
|
||||
}
|
||||
|
||||
.field-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.field-item-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.field-index-icon {
|
||||
font-size: 14px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.field-name {
|
||||
font-weight: 500;
|
||||
color: var(--text-primary);
|
||||
font-size: 13px;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.field-type {
|
||||
font-family: 'Courier New', monospace;
|
||||
}
|
||||
|
||||
.field-comment {
|
||||
color: var(--text-tertiary);
|
||||
font-size: 11px;
|
||||
margin-top: 4px;
|
||||
font-style: italic;
|
||||
min-height: 16px;
|
||||
}
|
||||
|
||||
.field-comment:empty::before {
|
||||
content: "No comment";
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
.table-wrapper {
|
||||
overflow-x: auto;
|
||||
background: var(--bg-elevated);
|
||||
border-radius: var(--radius-md);
|
||||
border: 1px solid var(--border-color);
|
||||
}
|
||||
|
||||
.data-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.data-table th {
|
||||
background: var(--bg-surface);
|
||||
color: var(--text-secondary);
|
||||
font-weight: 600;
|
||||
text-align: left;
|
||||
padding: 12px;
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.data-table td {
|
||||
padding: 10px 12px;
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
color: var(--text-primary);
|
||||
max-width: 300px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.data-table td:hover {
|
||||
white-space: normal;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.data-table tr:hover {
|
||||
background: var(--bg-hover);
|
||||
}
|
||||
|
||||
.truncated-icon {
|
||||
margin-left: 4px;
|
||||
font-size: 10px;
|
||||
}
|
||||
|
||||
.row-detail-btn {
|
||||
padding: 4px 12px;
|
||||
background: var(--primary);
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: var(--radius-sm);
|
||||
cursor: pointer;
|
||||
font-size: 12px;
|
||||
transition: var(--transition);
|
||||
}
|
||||
|
||||
.row-detail-btn:hover {
|
||||
background: var(--primary-dark);
|
||||
}
|
||||
`
|
||||
];
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this.tableName = '';
|
||||
this.schema = null;
|
||||
this.tableData = null;
|
||||
this.selectedColumns = [];
|
||||
this.loading = false;
|
||||
}
|
||||
|
||||
updated(changedProperties) {
|
||||
// 当 tableName 或 schema 改变时,尝试加载保存的列选择
|
||||
if ((changedProperties.has('tableName') || changedProperties.has('schema')) && this.tableName && this.schema) {
|
||||
const saved = this.loadSelectedColumns();
|
||||
if (saved && saved.length > 0) {
|
||||
// 验证保存的列是否仍然存在于当前 schema 中
|
||||
const validColumns = saved.filter(col =>
|
||||
this.schema.fields.some(field => field.name === col)
|
||||
);
|
||||
if (validColumns.length > 0) {
|
||||
this.selectedColumns = validColumns;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
toggleColumn(columnName) {
|
||||
const index = this.selectedColumns.indexOf(columnName);
|
||||
if (index > -1) {
|
||||
this.selectedColumns = this.selectedColumns.filter(c => c !== columnName);
|
||||
} else {
|
||||
this.selectedColumns = [...this.selectedColumns, columnName];
|
||||
}
|
||||
|
||||
// 持久化到 localStorage
|
||||
this.saveSelectedColumns();
|
||||
|
||||
this.dispatchEvent(new CustomEvent('columns-changed', {
|
||||
detail: { columns: this.selectedColumns },
|
||||
bubbles: true,
|
||||
composed: true
|
||||
}));
|
||||
}
|
||||
|
||||
saveSelectedColumns() {
|
||||
if (!this.tableName) return;
|
||||
const key = `srdb_columns_${this.tableName}`;
|
||||
localStorage.setItem(key, JSON.stringify(this.selectedColumns));
|
||||
}
|
||||
|
||||
loadSelectedColumns() {
|
||||
if (!this.tableName) return null;
|
||||
const key = `srdb_columns_${this.tableName}`;
|
||||
const saved = localStorage.getItem(key);
|
||||
return saved ? JSON.parse(saved) : null;
|
||||
}
|
||||
|
||||
showRowDetail(seq) {
|
||||
this.dispatchEvent(new CustomEvent('show-row-detail', {
|
||||
detail: { tableName: this.tableName, seq },
|
||||
bubbles: true,
|
||||
composed: true
|
||||
}));
|
||||
}
|
||||
|
||||
formatCount(count) {
|
||||
if (count >= 1000000) return (count / 1000000).toFixed(1) + 'M';
|
||||
if (count >= 1000) return (count / 1000).toFixed(1) + 'K';
|
||||
return count.toString();
|
||||
}
|
||||
|
||||
formatTime(nanoTime) {
|
||||
if (!nanoTime) return '';
|
||||
// 将纳秒转换为毫秒
|
||||
const date = new Date(nanoTime / 1000000);
|
||||
// 格式化为 YYYY-MM-DD HH:mm:ss
|
||||
const year = date.getFullYear();
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(date.getDate()).padStart(2, '0');
|
||||
const hours = String(date.getHours()).padStart(2, '0');
|
||||
const minutes = String(date.getMinutes()).padStart(2, '0');
|
||||
const seconds = String(date.getSeconds()).padStart(2, '0');
|
||||
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
|
||||
}
|
||||
|
||||
getColumns() {
|
||||
let columns = [];
|
||||
|
||||
if (this.selectedColumns.length > 0) {
|
||||
columns = [...this.selectedColumns];
|
||||
} else {
|
||||
columns = this.schema?.fields?.map(f => f.name) || [];
|
||||
}
|
||||
|
||||
// 确保系统字段的顺序:_seq 在开头,_time 在倒数第二
|
||||
const filtered = columns.filter(c => c !== '_seq' && c !== '_time');
|
||||
|
||||
// _seq 放开头
|
||||
const result = ['_seq', ...filtered];
|
||||
|
||||
// _time 放倒数第二(Actions 列之前)
|
||||
result.push('_time');
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
render() {
|
||||
if (this.loading || !this.schema || !this.tableData) {
|
||||
return html`<div class="loading">Loading data...</div>`;
|
||||
}
|
||||
|
||||
const columns = this.getColumns();
|
||||
|
||||
return html`
|
||||
${this.renderSchemaSection()}
|
||||
|
||||
<h3>Data (${this.formatCount(this.tableData.totalRows)} rows)</h3>
|
||||
|
||||
${this.tableData.data.length === 0 ? html`
|
||||
<div class="empty"><p>No data available</p></div>
|
||||
` : html`
|
||||
<div class="table-wrapper">
|
||||
<table class="data-table">
|
||||
<thead>
|
||||
<tr>
|
||||
${columns.map(col => html`<th>${col}</th>`)}
|
||||
<th style="text-align: center;">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
${this.tableData.data.map(row => html`
|
||||
<tr>
|
||||
${columns.map(col => html`
|
||||
<td>
|
||||
${col === '_time' ? this.formatTime(row[col]) : row[col]}
|
||||
${row[col + '_truncated'] ? html`<span class="truncated-icon">✂️</span>` : ''}
|
||||
</td>
|
||||
`)}
|
||||
<td style="text-align: center;">
|
||||
<button
|
||||
class="row-detail-btn"
|
||||
@click=${() => this.showRowDetail(row._seq)}
|
||||
>
|
||||
Detail
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
`)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
`}
|
||||
`;
|
||||
}
|
||||
|
||||
renderSchemaSection() {
|
||||
if (!this.schema || !this.schema.fields) return '';
|
||||
|
||||
return html`
|
||||
<div class="schema-section">
|
||||
<h3>Schema <span style="font-size: 12px; font-weight: 400; color: var(--text-secondary);">(点击字段卡片选择要显示的列)</span></h3>
|
||||
<div class="schema-grid">
|
||||
${this.schema.fields.map(field => html`
|
||||
<div
|
||||
class="schema-field-card ${this.selectedColumns.includes(field.name) ? 'selected' : ''}"
|
||||
@click=${() => this.toggleColumn(field.name)}
|
||||
>
|
||||
<div class="field-item">
|
||||
<div class="field-item-row">
|
||||
<srdb-field-icon
|
||||
?indexed=${field.indexed}
|
||||
class="field-index-icon"
|
||||
title="${field.indexed ? 'Indexed field (fast)' : 'Not indexed (slow)'}"
|
||||
></srdb-field-icon>
|
||||
<span class="field-name">${field.name}</span>
|
||||
<srdb-badge variant="primary" class="field-type">
|
||||
${field.type}
|
||||
</srdb-badge>
|
||||
</div>
|
||||
<div class="field-comment">${field.comment || ''}</div>
|
||||
</div>
|
||||
</div>
|
||||
`)}
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
}
|
||||
|
||||
customElements.define('srdb-data-view', DataView);
|
||||
59
webui/static/js/components/field-icon.js
Normal file
59
webui/static/js/components/field-icon.js
Normal file
@@ -0,0 +1,59 @@
|
||||
import { LitElement, html, css, svg } from 'https://cdn.jsdelivr.net/gh/lit/dist@3/core/lit-core.min.js';
|
||||
|
||||
export class FieldIcon extends LitElement {
|
||||
static properties = {
|
||||
indexed: { type: Boolean }
|
||||
};
|
||||
|
||||
static styles = css`
|
||||
:host {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
}
|
||||
|
||||
svg {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
}
|
||||
|
||||
.indexed {
|
||||
fill: var(--success);
|
||||
color: var(--success);
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.not-indexed {
|
||||
fill: var(--text-secondary);
|
||||
color: var(--text-secondary);
|
||||
opacity: 0.6;
|
||||
}
|
||||
`;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this.indexed = false;
|
||||
}
|
||||
|
||||
render() {
|
||||
if (this.indexed) {
|
||||
// 闪电图标 - 已索引(快速)
|
||||
return html`
|
||||
<svg viewBox="0 0 24 24" class="indexed" xmlns="http://www.w3.org/2000/svg" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<polygon points="13 2 3 14 12 14 11 22 21 10 12 10 13 2" fill="currentColor" stroke="none"/>
|
||||
</svg>
|
||||
`;
|
||||
} else {
|
||||
// 圆点图标 - 未索引
|
||||
return html`
|
||||
<svg viewBox="0 0 24 24" class="not-indexed" xmlns="http://www.w3.org/2000/svg">
|
||||
<circle cx="12" cy="12" r="4" fill="currentColor"/>
|
||||
</svg>
|
||||
`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
customElements.define('srdb-field-icon', FieldIcon);
|
||||
301
webui/static/js/components/manifest-view.js
Normal file
301
webui/static/js/components/manifest-view.js
Normal file
@@ -0,0 +1,301 @@
|
||||
import { LitElement, html, css } from 'https://cdn.jsdelivr.net/gh/lit/dist@3/core/lit-core.min.js';
|
||||
import { sharedStyles, cssVariables } from '../styles/shared-styles.js';
|
||||
|
||||
export class ManifestView extends LitElement {
|
||||
static properties = {
|
||||
manifestData: { type: Object },
|
||||
loading: { type: Boolean },
|
||||
expandedLevels: { type: Set }
|
||||
};
|
||||
|
||||
static styles = [
|
||||
sharedStyles,
|
||||
cssVariables,
|
||||
css`
|
||||
:host {
|
||||
display: block;
|
||||
}
|
||||
|
||||
h3 {
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
margin: 20px 0 12px 0;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.manifest-stats {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
||||
gap: 16px;
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.stat-card {
|
||||
padding: 16px;
|
||||
background: var(--bg-elevated);
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: var(--radius-md);
|
||||
}
|
||||
|
||||
.stat-label {
|
||||
font-size: 12px;
|
||||
color: var(--text-tertiary);
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.stat-value {
|
||||
font-size: 20px;
|
||||
font-weight: 600;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.level-card {
|
||||
margin-bottom: 12px;
|
||||
background: var(--bg-elevated);
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: var(--radius-md);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.level-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 16px;
|
||||
cursor: pointer;
|
||||
transition: var(--transition);
|
||||
}
|
||||
|
||||
.level-header:hover {
|
||||
background: var(--bg-hover);
|
||||
}
|
||||
|
||||
.level-header-left {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.expand-icon {
|
||||
font-size: 12px;
|
||||
color: var(--text-secondary);
|
||||
transition: transform 0.2s ease;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.expand-icon.expanded {
|
||||
transform: rotate(90deg);
|
||||
}
|
||||
|
||||
.level-title {
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.level-stats {
|
||||
display: flex;
|
||||
gap: 16px;
|
||||
font-size: 13px;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.level-files {
|
||||
padding: 16px;
|
||||
background: var(--bg-surface);
|
||||
border-top: 1px solid var(--border-color);
|
||||
display: none;
|
||||
}
|
||||
|
||||
.level-files.expanded {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.file-list {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.file-item {
|
||||
padding: 12px;
|
||||
background: var(--bg-elevated);
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: var(--radius-sm);
|
||||
transition: var(--transition);
|
||||
}
|
||||
|
||||
.file-item:hover {
|
||||
border-color: var(--primary);
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.file-name {
|
||||
font-family: 'Courier New', monospace;
|
||||
font-size: 13px;
|
||||
color: var(--text-primary);
|
||||
font-weight: 500;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.file-detail {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
font-size: 12px;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.file-detail-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.file-list {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
.empty {
|
||||
background: var(--bg-elevated);
|
||||
border-radius: var(--radius-md);
|
||||
border: 1px dashed var(--border-color);
|
||||
margin-top: 24px;
|
||||
}
|
||||
|
||||
.empty p {
|
||||
margin: 0;
|
||||
}
|
||||
`
|
||||
];
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this.manifestData = null;
|
||||
this.loading = false;
|
||||
this.expandedLevels = new Set();
|
||||
}
|
||||
|
||||
toggleLevel(levelNum) {
|
||||
if (this.expandedLevels.has(levelNum)) {
|
||||
this.expandedLevels.delete(levelNum);
|
||||
} else {
|
||||
this.expandedLevels.add(levelNum);
|
||||
}
|
||||
this.requestUpdate();
|
||||
}
|
||||
|
||||
formatSize(bytes) {
|
||||
if (bytes >= 1024 * 1024 * 1024) return (bytes / (1024 * 1024 * 1024)).toFixed(2) + ' GB';
|
||||
if (bytes >= 1024 * 1024) return (bytes / (1024 * 1024)).toFixed(2) + ' MB';
|
||||
if (bytes >= 1024) return (bytes / 1024).toFixed(2) + ' KB';
|
||||
return bytes + ' B';
|
||||
}
|
||||
|
||||
getScoreVariant(score) {
|
||||
if (score >= 0.8) return 'danger'; // 高分 = 需要紧急 compaction
|
||||
if (score >= 0.5) return 'warning'; // 中分 = 需要关注
|
||||
return 'success'; // 低分 = 健康状态
|
||||
}
|
||||
|
||||
render() {
|
||||
if (this.loading || !this.manifestData) {
|
||||
return html`<div class="loading">Loading manifest...</div>`;
|
||||
}
|
||||
|
||||
const totalFiles = this.manifestData.levels.reduce((sum, l) => sum + l.file_count, 0);
|
||||
const totalSize = this.manifestData.levels.reduce((sum, l) => sum + l.total_size, 0);
|
||||
const totalCompactions = this.manifestData.compaction_stats?.total_compactions || 0;
|
||||
|
||||
return html`
|
||||
<h3>LSM-Tree Structure</h3>
|
||||
|
||||
<div class="manifest-stats">
|
||||
<div class="stat-card">
|
||||
<div class="stat-label">Active Levels</div>
|
||||
<div class="stat-value">${this.manifestData.levels.filter(l => l.file_count > 0).length}</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-label">Total Files</div>
|
||||
<div class="stat-value">${totalFiles}</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-label">Total Size</div>
|
||||
<div class="stat-value">${this.formatSize(totalSize)}</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-label">Compactions</div>
|
||||
<div class="stat-value">${totalCompactions}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
${this.manifestData.levels && this.manifestData.levels.length > 0
|
||||
? this.manifestData.levels.map(level => this.renderLevelCard(level))
|
||||
: html`
|
||||
<div class="empty">
|
||||
<p>No SSTable files in this table yet.</p>
|
||||
<p style="font-size: 14px; margin-top: 8px;">Insert some data to see the LSM-Tree structure.</p>
|
||||
</div>
|
||||
`
|
||||
}
|
||||
`;
|
||||
}
|
||||
|
||||
renderLevelCard(level) {
|
||||
if (level.file_count === 0) return '';
|
||||
|
||||
const isExpanded = this.expandedLevels.has(level.level);
|
||||
|
||||
return html`
|
||||
<div class="level-card">
|
||||
<div class="level-header" @click=${() => this.toggleLevel(level.level)}>
|
||||
<div class="level-header-left">
|
||||
<span class="expand-icon ${isExpanded ? 'expanded' : ''}">▶</span>
|
||||
<div>
|
||||
<div class="level-title">Level ${level.level}</div>
|
||||
<div class="level-stats">
|
||||
<span>${level.file_count} files</span>
|
||||
<span>${this.formatSize(level.total_size)}</span>
|
||||
${level.score !== undefined ? html`
|
||||
<srdb-badge variant="${this.getScoreVariant(level.score)}">
|
||||
Score: ${(level.score * 100).toFixed(0)}%
|
||||
</srdb-badge>
|
||||
` : ''}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
${level.files && level.files.length > 0 ? html`
|
||||
<div class="level-files ${isExpanded ? 'expanded' : ''}">
|
||||
<div class="file-list">
|
||||
${level.files.map(file => html`
|
||||
<div class="file-item">
|
||||
<div class="file-name">${file.file_number}.sst</div>
|
||||
<div class="file-detail">
|
||||
<div class="file-detail-row">
|
||||
<span>Size:</span>
|
||||
<span>${this.formatSize(file.file_size)}</span>
|
||||
</div>
|
||||
<div class="file-detail-row">
|
||||
<span>Rows:</span>
|
||||
<span>${file.row_count || 0}</span>
|
||||
</div>
|
||||
<div class="file-detail-row">
|
||||
<span>Seq Range:</span>
|
||||
<span>${file.min_key} - ${file.max_key}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`)}
|
||||
</div>
|
||||
</div>
|
||||
` : ''}
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
}
|
||||
|
||||
customElements.define('srdb-manifest-view', ManifestView);
|
||||
179
webui/static/js/components/modal-dialog.js
Normal file
179
webui/static/js/components/modal-dialog.js
Normal file
@@ -0,0 +1,179 @@
|
||||
import { LitElement, html, css } from 'https://cdn.jsdelivr.net/gh/lit/dist@3/core/lit-core.min.js';
|
||||
import { sharedStyles, cssVariables } from '../styles/shared-styles.js';
|
||||
|
||||
export class ModalDialog extends LitElement {
|
||||
static properties = {
|
||||
open: { type: Boolean },
|
||||
title: { type: String },
|
||||
content: { type: String }
|
||||
};
|
||||
|
||||
static styles = [
|
||||
sharedStyles,
|
||||
cssVariables,
|
||||
css`
|
||||
:host {
|
||||
display: none;
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: rgba(0, 0, 0, 0.7);
|
||||
z-index: 1000;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
:host([open]) {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.modal-content {
|
||||
background: var(--bg-surface);
|
||||
border-radius: var(--radius-lg);
|
||||
box-shadow: var(--shadow-xl);
|
||||
min-width: 324px;
|
||||
max-width: 90vw;
|
||||
max-height: 80vh;
|
||||
width: fit-content;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
border: 1px solid var(--border-color);
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.modal-content {
|
||||
min-width: 300px;
|
||||
max-width: 95vw;
|
||||
}
|
||||
}
|
||||
|
||||
.modal-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 20px 24px;
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
}
|
||||
|
||||
.modal-header h3 {
|
||||
margin: 0;
|
||||
font-size: 18px;
|
||||
font-weight: 600;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.modal-close {
|
||||
background: transparent;
|
||||
border: none;
|
||||
color: var(--text-secondary);
|
||||
cursor: pointer;
|
||||
padding: 4px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border-radius: var(--radius-sm);
|
||||
transition: var(--transition);
|
||||
}
|
||||
|
||||
.modal-close:hover {
|
||||
background: var(--bg-hover);
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.modal-body {
|
||||
padding: 24px;
|
||||
overflow-y: auto;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
pre {
|
||||
/*background: var(--bg-elevated);*/
|
||||
padding: 16px;
|
||||
border-radius: var(--radius-md);
|
||||
overflow-x: auto;
|
||||
color: var(--text-primary);
|
||||
font-family: 'Courier New', monospace;
|
||||
font-size: 13px;
|
||||
line-height: 1.5;
|
||||
margin: 0;
|
||||
white-space: pre-wrap;
|
||||
word-wrap: break-word;
|
||||
}
|
||||
`
|
||||
];
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this.open = false;
|
||||
this.title = 'Content';
|
||||
this.content = '';
|
||||
this._handleKeyDown = this._handleKeyDown.bind(this);
|
||||
}
|
||||
|
||||
connectedCallback() {
|
||||
super.connectedCallback();
|
||||
document.addEventListener('keydown', this._handleKeyDown);
|
||||
}
|
||||
|
||||
disconnectedCallback() {
|
||||
super.disconnectedCallback();
|
||||
document.removeEventListener('keydown', this._handleKeyDown);
|
||||
}
|
||||
|
||||
updated(changedProperties) {
|
||||
if (changedProperties.has('open')) {
|
||||
if (this.open) {
|
||||
this.setAttribute('open', '');
|
||||
} else {
|
||||
this.removeAttribute('open');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_handleKeyDown(e) {
|
||||
if (this.open && e.key === 'Escape') {
|
||||
this.close();
|
||||
}
|
||||
}
|
||||
|
||||
close() {
|
||||
this.open = false;
|
||||
this.dispatchEvent(new CustomEvent('modal-close', {
|
||||
bubbles: true,
|
||||
composed: true
|
||||
}));
|
||||
}
|
||||
|
||||
render() {
|
||||
return html`
|
||||
<div class="modal-content" @click=${(e) => e.stopPropagation()}>
|
||||
<div class="modal-header">
|
||||
<h3>${this.title}</h3>
|
||||
<button class="modal-close" @click=${this.close}>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="20"
|
||||
height="20"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<line x1="18" y1="6" x2="6" y2="18"></line>
|
||||
<line x1="6" y1="6" x2="18" y2="18"></line>
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<pre>${this.content}</pre>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
}
|
||||
|
||||
customElements.define('srdb-modal-dialog', ModalDialog);
|
||||
267
webui/static/js/components/page-header.js
Normal file
267
webui/static/js/components/page-header.js
Normal file
@@ -0,0 +1,267 @@
|
||||
import { LitElement, html, css } from 'https://cdn.jsdelivr.net/gh/lit/dist@3/core/lit-core.min.js';
|
||||
import { sharedStyles, cssVariables } from '../styles/shared-styles.js';
|
||||
|
||||
export class PageHeader extends LitElement {
|
||||
static properties = {
|
||||
tableName: { type: String },
|
||||
view: { type: String }
|
||||
};
|
||||
|
||||
static styles = [
|
||||
sharedStyles,
|
||||
cssVariables,
|
||||
css`
|
||||
:host {
|
||||
display: block;
|
||||
background: var(--bg-surface);
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 10;
|
||||
}
|
||||
|
||||
.header-content {
|
||||
padding: 16px 24px;
|
||||
}
|
||||
|
||||
.header-top {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.mobile-menu-btn {
|
||||
display: none;
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
background: var(--primary);
|
||||
border: none;
|
||||
border-radius: var(--radius-md);
|
||||
color: white;
|
||||
cursor: pointer;
|
||||
flex-shrink: 0;
|
||||
transition: var(--transition);
|
||||
}
|
||||
|
||||
.mobile-menu-btn:hover {
|
||||
background: var(--primary-dark);
|
||||
}
|
||||
|
||||
.mobile-menu-btn svg {
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
}
|
||||
|
||||
h2 {
|
||||
font-size: 24px;
|
||||
font-weight: 600;
|
||||
margin: 0;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
text-align: center;
|
||||
padding: 20px;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.view-tabs {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
margin: 0 -12px;
|
||||
padding: 0 24px;
|
||||
}
|
||||
|
||||
.refresh-btn {
|
||||
margin-left: auto;
|
||||
padding: 8px 12px;
|
||||
background: transparent;
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: var(--radius-sm);
|
||||
color: var(--text-secondary);
|
||||
cursor: pointer;
|
||||
transition: var(--transition);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.refresh-btn:hover {
|
||||
background: var(--bg-hover);
|
||||
border-color: var(--border-hover);
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.refresh-btn svg {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
}
|
||||
|
||||
.view-tab {
|
||||
position: relative;
|
||||
padding: 16px 20px;
|
||||
background: transparent;
|
||||
border: none;
|
||||
color: var(--text-secondary);
|
||||
cursor: pointer;
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
transition: var(--transition);
|
||||
}
|
||||
|
||||
.view-tab:hover {
|
||||
color: var(--text-primary);
|
||||
/*background: var(--bg-hover);*/
|
||||
}
|
||||
|
||||
.view-tab.active {
|
||||
color: var(--primary);
|
||||
}
|
||||
|
||||
.view-tab::before,
|
||||
.view-tab::after {
|
||||
position: absolute;
|
||||
display: block;
|
||||
content: "";
|
||||
z-index: 0;
|
||||
opacity: 0;
|
||||
inset-inline: 8px;
|
||||
}
|
||||
|
||||
.view-tab::before {
|
||||
inset-block: 8px;
|
||||
border-radius: var(--radius-md);
|
||||
background: var(--bg-elevated);
|
||||
}
|
||||
|
||||
.view-tab::after {
|
||||
border-radius: var(--radius-md);
|
||||
background: var(--primary);
|
||||
bottom: -2px;
|
||||
height: 4px;
|
||||
}
|
||||
|
||||
.view-tab.active::before,
|
||||
.view-tab.active::after,
|
||||
.view-tab:hover::before {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.view-tab span {
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.mobile-menu-btn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.header-content {
|
||||
padding: 12px 16px;
|
||||
}
|
||||
|
||||
h2 {
|
||||
font-size: 18px;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.view-tabs {
|
||||
margin: 0 -16px;
|
||||
padding: 0 16px;
|
||||
}
|
||||
|
||||
.view-tab {
|
||||
padding: 8px 16px;
|
||||
font-size: 13px;
|
||||
}
|
||||
}
|
||||
`
|
||||
];
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this.tableName = '';
|
||||
this.view = 'data';
|
||||
}
|
||||
|
||||
switchView(newView) {
|
||||
this.view = newView;
|
||||
this.dispatchEvent(new CustomEvent('view-changed', {
|
||||
detail: { view: newView },
|
||||
bubbles: true,
|
||||
composed: true
|
||||
}));
|
||||
}
|
||||
|
||||
toggleMobileMenu() {
|
||||
this.dispatchEvent(new CustomEvent('toggle-mobile-menu', {
|
||||
bubbles: true,
|
||||
composed: true
|
||||
}));
|
||||
}
|
||||
|
||||
refreshView() {
|
||||
this.dispatchEvent(new CustomEvent('refresh-view', {
|
||||
detail: { view: this.view },
|
||||
bubbles: true,
|
||||
composed: true
|
||||
}));
|
||||
}
|
||||
|
||||
render() {
|
||||
if (!this.tableName) {
|
||||
return html`
|
||||
<div class="header-content">
|
||||
<div class="empty-state">
|
||||
<p>Select a table from the sidebar</p>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
return html`
|
||||
<div class="header-content">
|
||||
<div class="header-top">
|
||||
<button class="mobile-menu-btn" @click=${this.toggleMobileMenu}>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
||||
<line x1="3" y1="12" x2="21" y2="12"></line>
|
||||
<line x1="3" y1="6" x2="21" y2="6"></line>
|
||||
<line x1="3" y1="18" x2="21" y2="18"></line>
|
||||
</svg>
|
||||
</button>
|
||||
<h2>${this.tableName}</h2>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="view-tabs">
|
||||
<button
|
||||
class="view-tab ${this.view === 'data' ? 'active' : ''}"
|
||||
@click=${() => this.switchView('data')}
|
||||
>
|
||||
<span>Data</span>
|
||||
</button>
|
||||
<button
|
||||
class="view-tab ${this.view === 'manifest' ? 'active' : ''}"
|
||||
@click=${() => this.switchView('manifest')}
|
||||
>
|
||||
<span>Manifest / LSM-Tree</span>
|
||||
</button>
|
||||
<button class="refresh-btn" @click=${this.refreshView} title="Refresh current view">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path d="M21.5 2v6h-6M2.5 22v-6h6M2 11.5a10 10 0 0 1 18.8-4.3M22 12.5a10 10 0 0 1-18.8 4.2"/>
|
||||
</svg>
|
||||
<span>Refresh</span>
|
||||
</button>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
}
|
||||
|
||||
customElements.define('srdb-page-header', PageHeader);
|
||||
284
webui/static/js/components/table-list.js
Normal file
284
webui/static/js/components/table-list.js
Normal file
@@ -0,0 +1,284 @@
|
||||
import { LitElement, html, css } from 'https://cdn.jsdelivr.net/gh/lit/dist@3/core/lit-core.min.js';
|
||||
import { sharedStyles, cssVariables } from '../styles/shared-styles.js';
|
||||
|
||||
export class TableList extends LitElement {
|
||||
static properties = {
|
||||
tables: { type: Array },
|
||||
selectedTable: { type: String },
|
||||
expandedTables: { type: Set }
|
||||
};
|
||||
|
||||
static styles = [
|
||||
sharedStyles,
|
||||
cssVariables,
|
||||
css`
|
||||
:host {
|
||||
display: block;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.table-item {
|
||||
margin-bottom: 8px;
|
||||
background: var(--bg-elevated);
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: var(--radius-md);
|
||||
overflow: hidden;
|
||||
transition: var(--transition);
|
||||
}
|
||||
|
||||
.table-item:hover {
|
||||
border-color: var(--border-hover);
|
||||
}
|
||||
|
||||
.table-item.selected {
|
||||
border-color: var(--primary);
|
||||
box-shadow: 0 0 0 1px var(--primary);
|
||||
}
|
||||
|
||||
.table-item.selected .table-header {
|
||||
background: var(--primary-bg);
|
||||
}
|
||||
|
||||
.table-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 10px 12px;
|
||||
cursor: pointer;
|
||||
transition: var(--transition);
|
||||
}
|
||||
|
||||
.table-header:hover {
|
||||
background: var(--bg-hover);
|
||||
}
|
||||
|
||||
.table-item.has-expanded .table-header {
|
||||
border-bottom-color: var(--border-color);
|
||||
}
|
||||
|
||||
.table-header-left {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.expand-icon {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
font-size: 12px;
|
||||
transition: var(--transition);
|
||||
flex-shrink: 0;
|
||||
border-radius: var(--radius-sm);
|
||||
cursor: pointer;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.expand-icon:hover {
|
||||
background: var(--bg-hover);
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.expand-icon.expanded {
|
||||
transform: rotate(90deg);
|
||||
color: var(--primary);
|
||||
}
|
||||
|
||||
.table-name {
|
||||
font-weight: 500;
|
||||
color: var(--text-primary);
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
.table-count {
|
||||
font-size: 12px;
|
||||
color: var(--text-tertiary);
|
||||
white-space: nowrap;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
/* Schema 字段列表 */
|
||||
.schema-fields {
|
||||
display: none;
|
||||
flex-direction: column;
|
||||
border-top: 1px solid transparent;
|
||||
transition: var(--transition);
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.schema-fields.expanded {
|
||||
display: block;
|
||||
border-top-color: var(--border-color);
|
||||
}
|
||||
|
||||
/* 共享的垂直线 */
|
||||
.schema-fields.expanded::before {
|
||||
z-index: 2;
|
||||
content: "";
|
||||
position: absolute;
|
||||
left: 24px;
|
||||
top: 0;
|
||||
bottom: 24px;
|
||||
width: 1px;
|
||||
background: var(--border-color);
|
||||
}
|
||||
|
||||
.field-item {
|
||||
z-index: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 8px 12px 8px 24px;
|
||||
font-size: 12px;
|
||||
transition: var(--transition);
|
||||
position: relative;
|
||||
}
|
||||
|
||||
/* 每个字段的水平线 */
|
||||
.field-item::before {
|
||||
content: "";
|
||||
width: 8px;
|
||||
height: 1px;
|
||||
background: var(--border-color);
|
||||
}
|
||||
|
||||
.field-item:hover {
|
||||
background: var(--bg-hover);
|
||||
}
|
||||
|
||||
.field-item:last-child {
|
||||
padding-bottom: 12px;
|
||||
}
|
||||
|
||||
.field-index-icon {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
font-size: 14px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.field-index-icon.indexed {
|
||||
color: var(--success);
|
||||
}
|
||||
|
||||
.field-index-icon.not-indexed {
|
||||
color: var(--text-tertiary);
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
.field-name {
|
||||
font-weight: 500;
|
||||
color: var(--text-secondary);
|
||||
flex: 1;
|
||||
}
|
||||
.field-type {
|
||||
font-family: 'Courier New', monospace;
|
||||
}
|
||||
|
||||
.loading {
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.error {
|
||||
text-align: center;
|
||||
padding: 20px;
|
||||
color: var(--danger);
|
||||
}
|
||||
`
|
||||
];
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this.tables = [];
|
||||
this.selectedTable = '';
|
||||
this.expandedTables = new Set();
|
||||
}
|
||||
|
||||
connectedCallback() {
|
||||
super.connectedCallback();
|
||||
this.loadTables();
|
||||
}
|
||||
|
||||
async loadTables() {
|
||||
try {
|
||||
const response = await fetch('/api/tables');
|
||||
if (!response.ok) throw new Error('Failed to load tables');
|
||||
this.tables = await response.json();
|
||||
} catch (error) {
|
||||
console.error('Error loading tables:', error);
|
||||
}
|
||||
}
|
||||
|
||||
toggleExpand(tableName, event) {
|
||||
event.stopPropagation();
|
||||
if (this.expandedTables.has(tableName)) {
|
||||
this.expandedTables.delete(tableName);
|
||||
} else {
|
||||
this.expandedTables.add(tableName);
|
||||
}
|
||||
this.requestUpdate();
|
||||
}
|
||||
|
||||
selectTable(tableName) {
|
||||
this.selectedTable = tableName;
|
||||
this.dispatchEvent(new CustomEvent('table-selected', {
|
||||
detail: { tableName },
|
||||
bubbles: true,
|
||||
composed: true
|
||||
}));
|
||||
}
|
||||
|
||||
render() {
|
||||
if (this.tables.length === 0) {
|
||||
return html`<div class="loading">Loading tables...</div>`;
|
||||
}
|
||||
|
||||
return html`
|
||||
${this.tables.map(table => html`
|
||||
<div class="table-item ${this.expandedTables.has(table.name) ? 'has-expanded' : ''} ${this.selectedTable === table.name ? 'selected' : ''}">
|
||||
<div
|
||||
class="table-header"
|
||||
@click=${() => this.selectTable(table.name)}
|
||||
>
|
||||
<div class="table-header-left">
|
||||
<span
|
||||
class="expand-icon ${this.expandedTables.has(table.name) ? 'expanded' : ''}"
|
||||
@click=${(e) => this.toggleExpand(table.name, e)}
|
||||
>
|
||||
▶
|
||||
</span>
|
||||
<span class="table-name">${table.name}</span>
|
||||
</div>
|
||||
<span class="table-count">${table.fields.length} fields</span>
|
||||
</div>
|
||||
|
||||
<div class="schema-fields ${this.expandedTables.has(table.name) ? 'expanded' : ''}">
|
||||
${table.fields.map(field => html`
|
||||
<div class="field-item">
|
||||
<srdb-field-icon
|
||||
?indexed=${field.indexed}
|
||||
class="field-index-icon"
|
||||
title="${field.indexed ? 'Indexed field (fast)' : 'Not indexed (slow)'}"
|
||||
></srdb-field-icon>
|
||||
<span class="field-name">${field.name}</span>
|
||||
<srdb-badge variant="primary" class="field-type">
|
||||
${field.type}
|
||||
</srdb-badge>
|
||||
</div>
|
||||
`)}
|
||||
</div>
|
||||
</div>
|
||||
`)}
|
||||
`;
|
||||
}
|
||||
}
|
||||
|
||||
customElements.define('srdb-table-list', TableList);
|
||||
364
webui/static/js/components/table-view.js
Normal file
364
webui/static/js/components/table-view.js
Normal file
@@ -0,0 +1,364 @@
|
||||
import { LitElement, html, css } from 'https://cdn.jsdelivr.net/gh/lit/dist@3/core/lit-core.min.js';
|
||||
import { sharedStyles, cssVariables } from '../styles/shared-styles.js';
|
||||
|
||||
export class TableView extends LitElement {
|
||||
static properties = {
|
||||
tableName: { type: String },
|
||||
view: { type: String }, // 'data' or 'manifest'
|
||||
schema: { type: Object },
|
||||
tableData: { type: Object },
|
||||
manifestData: { type: Object },
|
||||
selectedColumns: { type: Array },
|
||||
page: { type: Number },
|
||||
pageSize: { type: Number },
|
||||
loading: { type: Boolean }
|
||||
};
|
||||
|
||||
static styles = [
|
||||
sharedStyles,
|
||||
cssVariables,
|
||||
css`
|
||||
:host {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: 100%;
|
||||
flex: 1;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.content-wrapper {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
padding: 24px;
|
||||
padding-bottom: 80px;
|
||||
}
|
||||
|
||||
.pagination {
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
left: 280px;
|
||||
right: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 12px;
|
||||
padding: 16px 24px;
|
||||
background: var(--bg-elevated);
|
||||
border-top: 1px solid var(--border-color);
|
||||
z-index: 10;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.pagination {
|
||||
left: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.pagination button {
|
||||
padding: 8px 16px;
|
||||
background: var(--bg-surface);
|
||||
color: var(--text-primary);
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: var(--radius-sm);
|
||||
cursor: pointer;
|
||||
transition: var(--transition);
|
||||
}
|
||||
|
||||
.pagination button:hover:not(:disabled) {
|
||||
background: var(--bg-hover);
|
||||
border-color: var(--border-hover);
|
||||
}
|
||||
|
||||
.pagination button:disabled {
|
||||
opacity: 0.5;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.pagination select,
|
||||
.pagination input {
|
||||
padding: 8px 12px;
|
||||
background: var(--bg-surface);
|
||||
color: var(--text-primary);
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: var(--radius-sm);
|
||||
}
|
||||
|
||||
.pagination input {
|
||||
width: 80px;
|
||||
}
|
||||
|
||||
.pagination span {
|
||||
color: var(--text-primary);
|
||||
font-size: 14px;
|
||||
}
|
||||
`
|
||||
];
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this.tableName = '';
|
||||
this.view = 'data';
|
||||
this.schema = null;
|
||||
this.tableData = null;
|
||||
this.manifestData = null;
|
||||
this.selectedColumns = [];
|
||||
this.page = 1;
|
||||
this.pageSize = 20;
|
||||
this.loading = false;
|
||||
}
|
||||
|
||||
updated(changedProperties) {
|
||||
if (changedProperties.has('tableName') && this.tableName) {
|
||||
// 切换表时重置选中的列
|
||||
this.selectedColumns = [];
|
||||
this.page = 1;
|
||||
this.loadData();
|
||||
}
|
||||
if (changedProperties.has('view') && this.tableName) {
|
||||
this.loadData();
|
||||
}
|
||||
}
|
||||
|
||||
async loadData() {
|
||||
if (!this.tableName) return;
|
||||
|
||||
this.loading = true;
|
||||
|
||||
try {
|
||||
// Load schema
|
||||
const schemaResponse = await fetch(`/api/tables/${this.tableName}/schema`);
|
||||
if (!schemaResponse.ok) throw new Error('Failed to load schema');
|
||||
this.schema = await schemaResponse.json();
|
||||
|
||||
// Initialize selected columns (all by default)
|
||||
if (this.schema.fields) {
|
||||
this.selectedColumns = this.schema.fields.map(f => f.name);
|
||||
}
|
||||
|
||||
if (this.view === 'data') {
|
||||
await this.loadTableData();
|
||||
} else if (this.view === 'manifest') {
|
||||
await this.loadManifestData();
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error loading data:', error);
|
||||
} finally {
|
||||
this.loading = false;
|
||||
}
|
||||
}
|
||||
|
||||
async loadTableData() {
|
||||
const selectParam = this.selectedColumns.join(',');
|
||||
const url = `/api/tables/${this.tableName}/data?page=${this.page}&pageSize=${this.pageSize}&select=${selectParam}`;
|
||||
|
||||
const response = await fetch(url);
|
||||
if (!response.ok) throw new Error('Failed to load table data');
|
||||
this.tableData = await response.json();
|
||||
}
|
||||
|
||||
async loadManifestData() {
|
||||
const response = await fetch(`/api/tables/${this.tableName}/manifest`);
|
||||
if (!response.ok) throw new Error('Failed to load manifest data');
|
||||
this.manifestData = await response.json();
|
||||
}
|
||||
|
||||
switchView(newView) {
|
||||
this.view = newView;
|
||||
}
|
||||
|
||||
toggleColumn(columnName) {
|
||||
const index = this.selectedColumns.indexOf(columnName);
|
||||
if (index > -1) {
|
||||
this.selectedColumns = this.selectedColumns.filter(c => c !== columnName);
|
||||
} else {
|
||||
this.selectedColumns = [...this.selectedColumns, columnName];
|
||||
}
|
||||
this.loadTableData();
|
||||
}
|
||||
|
||||
changePage(delta) {
|
||||
this.page = Math.max(1, this.page + delta);
|
||||
this.loadTableData();
|
||||
}
|
||||
|
||||
changePageSize(newSize) {
|
||||
this.pageSize = parseInt(newSize);
|
||||
this.page = 1;
|
||||
this.loadTableData();
|
||||
}
|
||||
|
||||
jumpToPage(pageNum) {
|
||||
const num = parseInt(pageNum);
|
||||
if (num > 0 && this.tableData && num <= this.tableData.totalPages) {
|
||||
this.page = num;
|
||||
this.loadTableData();
|
||||
}
|
||||
}
|
||||
|
||||
showRowDetail(seq) {
|
||||
this.dispatchEvent(new CustomEvent('show-row-detail', {
|
||||
detail: { tableName: this.tableName, seq },
|
||||
bubbles: true,
|
||||
composed: true
|
||||
}));
|
||||
}
|
||||
|
||||
toggleLevel(level) {
|
||||
const levelCard = this.shadowRoot.querySelector(`[data-level="${level}"]`);
|
||||
if (levelCard) {
|
||||
const fileList = levelCard.querySelector('.file-list');
|
||||
const icon = levelCard.querySelector('.expand-icon');
|
||||
if (fileList.classList.contains('expanded')) {
|
||||
fileList.classList.remove('expanded');
|
||||
icon.style.transform = 'rotate(0deg)';
|
||||
} else {
|
||||
fileList.classList.add('expanded');
|
||||
icon.style.transform = 'rotate(90deg)';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
formatBytes(bytes) {
|
||||
if (bytes === 0) return '0 B';
|
||||
const k = 1024;
|
||||
const sizes = ['B', 'KB', 'MB', 'GB', 'TB'];
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
||||
return (bytes / Math.pow(k, i)).toFixed(2) + ' ' + sizes[i];
|
||||
}
|
||||
|
||||
formatCount(count) {
|
||||
if (count >= 1000000) return (count / 1000000).toFixed(1) + 'M';
|
||||
if (count >= 1000) return (count / 1000).toFixed(1) + 'K';
|
||||
return count.toString();
|
||||
}
|
||||
|
||||
render() {
|
||||
if (!this.tableName) {
|
||||
return html`
|
||||
<div class="empty">
|
||||
<h2>Select a table to view data</h2>
|
||||
<p>Choose a table from the sidebar to get started</p>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
if (this.loading) {
|
||||
return html`<div class="loading">Loading...</div>`;
|
||||
}
|
||||
|
||||
return html`
|
||||
<div class="content-wrapper">
|
||||
${this.view === 'data' ? html`
|
||||
<srdb-data-view
|
||||
.tableName=${this.tableName}
|
||||
.schema=${this.schema}
|
||||
.tableData=${this.tableData}
|
||||
.selectedColumns=${this.selectedColumns}
|
||||
.loading=${this.loading}
|
||||
@columns-changed=${(e) => {
|
||||
this.selectedColumns = e.detail.columns;
|
||||
this.loadTableData();
|
||||
}}
|
||||
@show-row-detail=${(e) => this.showRowDetail(e.detail.seq)}
|
||||
></srdb-data-view>
|
||||
` : html`
|
||||
<srdb-manifest-view
|
||||
.manifestData=${this.manifestData}
|
||||
.loading=${this.loading}
|
||||
></srdb-manifest-view>
|
||||
`}
|
||||
</div>
|
||||
|
||||
${this.view === 'data' && this.tableData ? this.renderPagination() : ''}
|
||||
`;
|
||||
}
|
||||
|
||||
renderPagination() {
|
||||
return html`
|
||||
<div class="pagination">
|
||||
<select @change=${(e) => this.changePageSize(e.target.value)}>
|
||||
${[10, 20, 50, 100].map(size => html`
|
||||
<option value="${size}" ?selected=${size === this.pageSize}>
|
||||
${size} / page
|
||||
</option>
|
||||
`)}
|
||||
</select>
|
||||
|
||||
<button
|
||||
@click=${() => this.changePage(-1)}
|
||||
?disabled=${this.page <= 1}
|
||||
>
|
||||
Previous
|
||||
</button>
|
||||
|
||||
<span>
|
||||
Page ${this.page} of ${this.tableData.totalPages}
|
||||
(${this.formatCount(this.tableData.totalRows)} rows)
|
||||
</span>
|
||||
|
||||
<input
|
||||
type="number"
|
||||
min="1"
|
||||
max="${this.tableData.totalPages}"
|
||||
placeholder="Jump to"
|
||||
@keydown=${(e) => e.key === 'Enter' && this.jumpToPage(e.target.value)}
|
||||
/>
|
||||
|
||||
<button @click=${(e) => this.jumpToPage(e.target.previousElementSibling.value)}>
|
||||
Go
|
||||
</button>
|
||||
|
||||
<button
|
||||
@click=${() => this.changePage(1)}
|
||||
?disabled=${this.page >= this.tableData.totalPages}
|
||||
>
|
||||
Next
|
||||
</button>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
formatCount(count) {
|
||||
if (count >= 1000000) return (count / 1000000).toFixed(1) + 'M';
|
||||
if (count >= 1000) return (count / 1000).toFixed(1) + 'K';
|
||||
return count.toString();
|
||||
}
|
||||
|
||||
changePage(delta) {
|
||||
this.page = Math.max(1, this.page + delta);
|
||||
this.loadTableData();
|
||||
}
|
||||
|
||||
changePageSize(newSize) {
|
||||
this.pageSize = parseInt(newSize);
|
||||
this.page = 1;
|
||||
this.loadTableData();
|
||||
}
|
||||
|
||||
jumpToPage(pageNum) {
|
||||
const num = parseInt(pageNum);
|
||||
if (num > 0 && this.tableData && num <= this.tableData.totalPages) {
|
||||
this.page = num;
|
||||
this.loadTableData();
|
||||
}
|
||||
}
|
||||
|
||||
showRowDetail(seq) {
|
||||
this.dispatchEvent(new CustomEvent('show-row-detail', {
|
||||
detail: { tableName: this.tableName, seq },
|
||||
bubbles: true,
|
||||
composed: true
|
||||
}));
|
||||
}
|
||||
|
||||
showCellContent(content) {
|
||||
this.dispatchEvent(new CustomEvent('show-cell-content', {
|
||||
detail: { content },
|
||||
bubbles: true,
|
||||
composed: true
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
customElements.define('srdb-table-view', TableView);
|
||||
123
webui/static/js/components/theme-toggle.js
Normal file
123
webui/static/js/components/theme-toggle.js
Normal file
@@ -0,0 +1,123 @@
|
||||
import { LitElement, html, css } from 'https://cdn.jsdelivr.net/gh/lit/dist@3/core/lit-core.min.js';
|
||||
import { sharedStyles } from '../styles/shared-styles.js';
|
||||
|
||||
export class ThemeToggle extends LitElement {
|
||||
static properties = {
|
||||
theme: { type: String }
|
||||
};
|
||||
|
||||
static styles = [
|
||||
sharedStyles,
|
||||
css`
|
||||
:host {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.theme-toggle {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 8px 12px;
|
||||
background: var(--bg-elevated);
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: var(--radius-md);
|
||||
cursor: pointer;
|
||||
transition: var(--transition);
|
||||
font-size: 14px;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.theme-toggle:hover {
|
||||
background: var(--bg-hover);
|
||||
border-color: var(--border-hover);
|
||||
}
|
||||
|
||||
.icon {
|
||||
font-size: 18px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.label {
|
||||
font-weight: 500;
|
||||
}
|
||||
`
|
||||
];
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
// 从 localStorage 读取主题,默认为 dark
|
||||
this.theme = localStorage.getItem('srdb-theme') || 'dark';
|
||||
this.applyTheme();
|
||||
}
|
||||
|
||||
toggleTheme() {
|
||||
this.theme = this.theme === 'dark' ? 'light' : 'dark';
|
||||
localStorage.setItem('srdb-theme', this.theme);
|
||||
this.applyTheme();
|
||||
|
||||
// 触发主题变化事件
|
||||
this.dispatchEvent(new CustomEvent('theme-changed', {
|
||||
detail: { theme: this.theme },
|
||||
bubbles: true,
|
||||
composed: true
|
||||
}));
|
||||
}
|
||||
|
||||
applyTheme() {
|
||||
const root = document.documentElement;
|
||||
|
||||
if (this.theme === 'light') {
|
||||
// 浅色主题
|
||||
root.style.setProperty('--srdb-bg-main', '#ffffff');
|
||||
root.style.setProperty('--srdb-bg-surface', '#f5f5f5');
|
||||
root.style.setProperty('--srdb-bg-elevated', '#e5e5e5');
|
||||
root.style.setProperty('--srdb-bg-hover', '#d4d4d4');
|
||||
|
||||
root.style.setProperty('--srdb-text-primary', '#1a1a1a');
|
||||
root.style.setProperty('--srdb-text-secondary', '#666666');
|
||||
root.style.setProperty('--srdb-text-tertiary', '#999999');
|
||||
|
||||
root.style.setProperty('--srdb-border-color', 'rgba(0, 0, 0, 0.1)');
|
||||
root.style.setProperty('--srdb-border-hover', 'rgba(0, 0, 0, 0.2)');
|
||||
|
||||
root.style.setProperty('--srdb-shadow-sm', '0 1px 2px 0 rgba(0, 0, 0, 0.05)');
|
||||
root.style.setProperty('--srdb-shadow-md', '0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06)');
|
||||
root.style.setProperty('--srdb-shadow-lg', '0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05)');
|
||||
root.style.setProperty('--srdb-shadow-xl', '0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04)');
|
||||
} else {
|
||||
// 深色主题(默认值)
|
||||
root.style.setProperty('--srdb-bg-main', '#0f0f1a');
|
||||
root.style.setProperty('--srdb-bg-surface', '#1a1a2e');
|
||||
root.style.setProperty('--srdb-bg-elevated', '#222236');
|
||||
root.style.setProperty('--srdb-bg-hover', '#2a2a3e');
|
||||
|
||||
root.style.setProperty('--srdb-text-primary', '#ffffff');
|
||||
root.style.setProperty('--srdb-text-secondary', '#a0a0b0');
|
||||
root.style.setProperty('--srdb-text-tertiary', '#6b6b7b');
|
||||
|
||||
root.style.setProperty('--srdb-border-color', 'rgba(255, 255, 255, 0.1)');
|
||||
root.style.setProperty('--srdb-border-hover', 'rgba(255, 255, 255, 0.2)');
|
||||
|
||||
root.style.setProperty('--srdb-shadow-sm', '0 1px 2px 0 rgba(0, 0, 0, 0.3)');
|
||||
root.style.setProperty('--srdb-shadow-md', '0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -1px rgba(0, 0, 0, 0.3)');
|
||||
root.style.setProperty('--srdb-shadow-lg', '0 10px 15px -3px rgba(0, 0, 0, 0.5), 0 4px 6px -2px rgba(0, 0, 0, 0.3)');
|
||||
root.style.setProperty('--srdb-shadow-xl', '0 20px 25px -5px rgba(0, 0, 0, 0.5), 0 10px 10px -5px rgba(0, 0, 0, 0.3)');
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
return html`
|
||||
<button class="theme-toggle" @click=${this.toggleTheme}>
|
||||
<span class="icon">
|
||||
${this.theme === 'dark' ? '🌙' : '☀️'}
|
||||
</span>
|
||||
<span class="label">
|
||||
${this.theme === 'dark' ? 'Dark' : 'Light'}
|
||||
</span>
|
||||
</button>
|
||||
`;
|
||||
}
|
||||
}
|
||||
|
||||
customElements.define('srdb-theme-toggle', ThemeToggle);
|
||||
89
webui/static/js/styles/shared-styles.js
Normal file
89
webui/static/js/styles/shared-styles.js
Normal file
@@ -0,0 +1,89 @@
|
||||
import { css } from 'https://cdn.jsdelivr.net/gh/lit/dist@3/core/lit-core.min.js';
|
||||
|
||||
// 共享的基础样式
|
||||
export const sharedStyles = css`
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
/* 自定义滚动条样式 */
|
||||
*::-webkit-scrollbar {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
}
|
||||
|
||||
*::-webkit-scrollbar-track {
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
*::-webkit-scrollbar-thumb {
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
*::-webkit-scrollbar-thumb:hover {
|
||||
background: rgba(255, 255, 255, 0.15);
|
||||
}
|
||||
|
||||
/* 通用状态样式 */
|
||||
.empty {
|
||||
text-align: center;
|
||||
padding: 60px 20px;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.loading {
|
||||
text-align: center;
|
||||
padding: 60px 20px;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
`;
|
||||
|
||||
// CSS 变量(可以在组件中使用,优先使用外部定义的变量)
|
||||
export const cssVariables = css`
|
||||
:host {
|
||||
/* 主色调 - 优雅的紫蓝色 */
|
||||
--primary: var(--srdb-primary, #6366f1);
|
||||
--primary-dark: var(--srdb-primary-dark, #4f46e5);
|
||||
--primary-light: var(--srdb-primary-light, #818cf8);
|
||||
--primary-bg: var(--srdb-primary-bg, rgba(99, 102, 241, 0.1));
|
||||
|
||||
/* 背景色 */
|
||||
--bg-main: var(--srdb-bg-main, #0f0f1a);
|
||||
--bg-surface: var(--srdb-bg-surface, #1a1a2e);
|
||||
--bg-elevated: var(--srdb-bg-elevated, #222236);
|
||||
--bg-hover: var(--srdb-bg-hover, #2a2a3e);
|
||||
|
||||
/* 文字颜色 */
|
||||
--text-primary: var(--srdb-text-primary, #ffffff);
|
||||
--text-secondary: var(--srdb-text-secondary, #a0a0b0);
|
||||
--text-tertiary: var(--srdb-text-tertiary, #6b6b7b);
|
||||
|
||||
/* 边框和分隔线 */
|
||||
--border-color: var(--srdb-border-color, rgba(255, 255, 255, 0.1));
|
||||
--border-hover: var(--srdb-border-hover, rgba(255, 255, 255, 0.2));
|
||||
|
||||
/* 状态颜色 */
|
||||
--success: var(--srdb-success, #10b981);
|
||||
--warning: var(--srdb-warning, #f59e0b);
|
||||
--danger: var(--srdb-danger, #ef4444);
|
||||
--info: var(--srdb-info, #3b82f6);
|
||||
|
||||
/* 阴影 */
|
||||
--shadow-sm: var(--srdb-shadow-sm, 0 1px 2px 0 rgba(0, 0, 0, 0.3));
|
||||
--shadow-md: var(--srdb-shadow-md, 0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -1px rgba(0, 0, 0, 0.3));
|
||||
--shadow-lg: var(--srdb-shadow-lg, 0 10px 15px -3px rgba(0, 0, 0, 0.5), 0 4px 6px -2px rgba(0, 0, 0, 0.3));
|
||||
--shadow-xl: var(--srdb-shadow-xl, 0 20px 25px -5px rgba(0, 0, 0, 0.5), 0 10px 10px -5px rgba(0, 0, 0, 0.3));
|
||||
|
||||
/* 圆角 */
|
||||
--radius-sm: var(--srdb-radius-sm, 6px);
|
||||
--radius-md: var(--srdb-radius-md, 8px);
|
||||
--radius-lg: var(--srdb-radius-lg, 12px);
|
||||
--radius-xl: var(--srdb-radius-xl, 16px);
|
||||
|
||||
/* 过渡 */
|
||||
--transition: var(--srdb-transition, all 0.2s cubic-bezier(0.4, 0, 0.2, 1));
|
||||
}
|
||||
`;
|
||||
Reference in New Issue
Block a user