0
0

将git和配置文件合并,增加了配置文件永久删除的功能

This commit is contained in:
xubing
2025-11-25 14:30:54 +08:00
parent d3ef13de42
commit 056f98fd25
6 changed files with 1117 additions and 1258 deletions

View File

@@ -1,7 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConfigView = void 0;
// src/panels/views/ConfigView.ts
const BaseView_1 = require("./BaseView");
class ConfigView extends BaseView_1.BaseView {
render(data) {
@@ -13,7 +12,7 @@ class ConfigView extends BaseView_1.BaseView {
const gitLoading = data?.gitLoading || false;
const gitBranches = data?.gitBranches || [];
const gitRepoUrl = data?.gitRepoUrl || '';
// 生成配置列表的 HTML
// 生成配置列表的 HTML - 包含配置文件和 Git 仓库
const configsHtml = configs.map((config) => `
<tr>
<td>
@@ -27,21 +26,17 @@ class ConfigView extends BaseView_1.BaseView {
</td>
</tr>
`).join('');
// 生成 Git 仓库列表的 HTML
// 生成 Git 仓库列表的 HTML - 以配置文件形式显示
const gitReposHtml = gitRepos.map(repo => `
<tr>
<td>
<span class="repo-name" data-repo-id="${repo.id}">📁 ${repo.name}</span>
<span class="editable">📁 ${repo.name}</span>
<div style="font-size: 12px; color: var(--vscode-descriptionForeground); margin-top: 4px;">
${repo.url}
</div>
<div style="font-size: 11px; color: var(--vscode-descriptionForeground);">
分支: ${repo.branch} | 最后同步: ${repo.lastSync}
模型1、模型2
</div>
</td>
<td>
<span class="clickable" onclick="loadGitRepo('${repo.id}')">打开</span>
<span class="clickable" onclick="syncGitRepo('${repo.id}')" style="margin-left: 10px;">同步</span>
<span class="clickable" onclick="loadGitRepo('${repo.id}')">${repo.url.split('/').pop()}</span>
</td>
<td>
<button class="btn-delete" onclick="deleteGitRepo('${repo.id}')">删除</button>
@@ -50,8 +45,6 @@ class ConfigView extends BaseView_1.BaseView {
`).join('');
// 生成分支选择的 HTML
const branchesHtml = gitBranches.length > 0 ? this.generateBranchesHtml(gitBranches) : '';
// 生成文件树的 HTML
const fileTreeHtml = gitFileTree.length > 0 ? this.renderFileTree(gitFileTree) : '<div style="text-align: center; padding: 20px; color: var(--vscode-descriptionForeground);">选择仓库以浏览文件</div>';
return `<!DOCTYPE html>
<html lang="zh-CN">
<head>
@@ -60,77 +53,6 @@ class ConfigView extends BaseView_1.BaseView {
<title>配置管理</title>
${this.getStyles()}
<style>
.git-container {
display: flex;
gap: 20px;
margin-top: 20px;
}
.repo-list {
flex: 1;
min-width: 300px;
}
.file-tree {
flex: 2;
min-width: 400px;
border: 1px solid var(--vscode-panel-border);
border-radius: 4px;
padding: 15px;
background: var(--vscode-panel-background);
max-height: 400px;
overflow-y: auto;
}
.tree-item {
margin: 2px 0;
}
.tree-folder {
cursor: pointer;
padding: 2px 4px;
border-radius: 2px;
display: inline-block;
}
.tree-folder:hover {
background: var(--vscode-list-hoverBackground);
}
.tree-file {
padding: 2px 4px;
border-radius: 2px;
display: inline-block;
}
.tree-file:hover {
background: var(--vscode-list-hoverBackground);
}
.tree-children {
margin-left: 10px;
}
.current-repo {
background: var(--vscode-badge-background);
padding: 10px;
border-radius: 4px;
margin-bottom: 15px;
}
.loading {
text-align: center;
padding: 20px;
color: var(--vscode-descriptionForeground);
}
.btn-sync {
background: var(--vscode-button-background);
color: var(--vscode-button-foreground);
border: none;
padding: 6px 12px;
border-radius: 4px;
cursor: pointer;
margin-left: 10px;
}
.btn-sync:hover {
background: var(--vscode-button-hoverBackground);
}
.branch-selection {
border: 1px solid var(--vscode-input-border);
}
.branch-item:hover {
background: var(--vscode-list-hoverBackground);
}
.url-input-section {
background: var(--vscode-panel-background);
padding: 15px;
@@ -138,24 +60,21 @@ class ConfigView extends BaseView_1.BaseView {
margin-bottom: 15px;
border: 1px solid var(--vscode-input-border);
}
.debug-panel {
background: var(--vscode-inputValidation-infoBackground);
padding: 10px;
margin-bottom: 15px;
border-radius: 4px;
border: 1px solid var(--vscode-inputValidation-infoBorder);
}
.debug-info {
font-size: 12px;
color: var(--vscode-input-foreground);
font-family: 'Courier New', monospace;
}
.section-title {
margin: 30px 0 15px 0;
padding-bottom: 10px;
border-bottom: 2px solid var(--vscode-panel-border);
color: var(--vscode-titleBar-activeForeground);
}
.config-section {
margin-bottom: 30px;
}
.branch-selection {
border: 1px solid var(--vscode-input-border);
}
.branch-item:hover {
background: var(--vscode-list-hoverBackground);
}
</style>
</head>
<body>
@@ -164,72 +83,55 @@ class ConfigView extends BaseView_1.BaseView {
<button class="back-btn" onclick="goBackToContainers()">← 返回容器管理</button>
</div>
<!-- 配置管理部分 -->
<h3 class="section-title">📋 配置文件管理</h3>
<table class="table">
<thead>
<tr>
<th width="30%">配置</th>
<th width="40%">文件</th>
<th width="30%">操作</th>
</tr>
</thead>
<tbody>
${configsHtml}
<tr>
<td colspan="3" style="text-align: center; padding: 20px;">
<button class="btn-new" onclick="createNewConfig()">+ 新建配置</button>
</td>
</tr>
</tbody>
</table>
<!-- 配置文件管理部分 -->
<div class="config-section">
<h3 class="section-title">📋 配置文件管理</h3>
<table class="table">
<thead>
<tr>
<th width="30%">配置</th>
<th width="40%">文件</th>
<th width="30%">操作</th>
</tr>
</thead>
<tbody>
${configsHtml}
${gitReposHtml}
<tr>
<td colspan="3" style="text-align: center; padding: 20px;">
<button class="btn-new" onclick="createNewConfig()">+ 新建配置</button>
</td>
</tr>
</tbody>
</table>
</div>
<!-- Git 仓库管理部分 -->
<h3 class="section-title">📚 Git 仓库管理</h3>
<!-- URL 输入区域 -->
<div class="url-input-section">
<h4>🔗 添加 Git 仓库</h4>
<div style="display: flex; gap: 10px; margin-top: 10px;">
<input type="text" id="repoUrlInput"
placeholder="请输入 Git 仓库 URL例如: https://github.com/username/repo.git"
value="${gitRepoUrl}"
style="flex: 1; padding: 8px; background: var(--vscode-input-background); color: var(--vscode-input-foreground); border: 1px solid var(--vscode-input-border); border-radius: 4px;">
<button class="btn-new" onclick="fetchBranches()">获取分支</button>
</div>
<div id="branchSelectionContainer">
${branchesHtml}
</div>
</div>
<div style="margin-bottom: 20px;">
${currentGitRepo ? `
<div class="current-repo">
<strong>当前仓库:</strong> ${currentGitRepo.name} (${currentGitRepo.url})
<button class="btn-sync" onclick="syncGitRepo('${currentGitRepo.id}')">同步</button>
<div class="config-section">
<h3 class="section-title">📚 Git 仓库管理</h3>
<!-- URL 输入区域 -->
<div class="url-input-section">
<h4>🔗 添加 Git 仓库</h4>
<div style="display: flex; gap: 10px; margin-top: 10px;">
<input type="text" id="repoUrlInput"
placeholder="请输入 Git 仓库 URL例如: https://github.com/username/repo.git"
value="${gitRepoUrl}"
style="flex: 1; padding: 8px; background: var(--vscode-input-background); color: var(--vscode-input-foreground); border: 1px solid var(--vscode-input-border); border-radius: 4px;">
<button class="btn-new" onclick="fetchBranches()">获取分支</button>
</div>
<div id="branchSelectionContainer">
${branchesHtml}
</div>
` : ''}
</div>
<div class="git-container">
<div class="repo-list">
<table class="table">
<thead>
<tr>
<th width="60%">仓库</th>
<th width="20%">操作</th>
<th width="20%">管理</th>
</tr>
</thead>
<tbody>
${gitReposHtml}
</tbody>
</table>
</div>
<div class="file-tree">
<h4>📂 文件浏览器</h4>
${gitLoading ? '<div class="loading">🔄 加载中...</div>' : fileTreeHtml}
<div style="margin-bottom: 20px;">
${currentGitRepo ? `
<div style="background: var(--vscode-badge-background); padding: 10px; border-radius: 4px; margin-bottom: 15px;">
<strong>当前仓库:</strong> ${currentGitRepo.name} (${currentGitRepo.url})
<button class="btn-sync" onclick="syncGitRepo('${currentGitRepo.id}')" style="background: var(--vscode-button-background); color: var(--vscode-button-foreground); border: none; padding: 6px 12px; border-radius: 4px; cursor: pointer; margin-left: 10px;">同步</button>
</div>
` : ''}
</div>
</div>
@@ -329,14 +231,6 @@ class ConfigView extends BaseView_1.BaseView {
}
// Git 仓库管理功能
function updateDebugInfo(message) {
const debugElement = document.getElementById('debugInfo');
if (debugElement) {
debugElement.innerHTML = message;
console.log('🔍 调试信息:', message);
}
}
function fetchBranches() {
const urlInput = document.getElementById('repoUrlInput');
const repoUrl = urlInput.value.trim();
@@ -353,7 +247,6 @@ class ConfigView extends BaseView_1.BaseView {
currentRepoUrl = repoUrl;
console.log('🌿 获取分支列表:', repoUrl);
updateDebugInfo('🌿 正在获取分支列表...');
vscode.postMessage({
type: 'fetchBranches',
@@ -369,7 +262,6 @@ class ConfigView extends BaseView_1.BaseView {
selectedBranches.delete(branchName);
}
console.log('选中的分支:', Array.from(selectedBranches));
updateDebugInfo('选中的分支: ' + Array.from(selectedBranches).join(', '));
}
function cloneSelectedBranches() {
@@ -379,7 +271,6 @@ class ConfigView extends BaseView_1.BaseView {
}
console.log('🚀 开始克隆选中的分支:', Array.from(selectedBranches));
updateDebugInfo('🚀 开始克隆分支: ' + Array.from(selectedBranches).join(', '));
vscode.postMessage({
type: 'cloneBranches',
@@ -394,7 +285,6 @@ class ConfigView extends BaseView_1.BaseView {
// 隐藏分支选择区域
document.getElementById('branchSelectionContainer').innerHTML = '';
updateDebugInfo('✅ 分支克隆请求已发送');
}
function cancelBranchSelection() {
@@ -405,8 +295,6 @@ class ConfigView extends BaseView_1.BaseView {
// 隐藏分支选择区域
document.getElementById('branchSelectionContainer').innerHTML = '';
updateDebugInfo('❌ 已取消分支选择');
vscode.postMessage({
type: 'cancelBranchSelection'
});
@@ -414,7 +302,6 @@ class ConfigView extends BaseView_1.BaseView {
function loadGitRepo(repoId) {
console.log('📂 加载仓库:', repoId);
updateDebugInfo('📂 正在加载仓库...');
vscode.postMessage({
type: 'loadGitRepo',
repoId: repoId
@@ -423,7 +310,6 @@ class ConfigView extends BaseView_1.BaseView {
function syncGitRepo(repoId) {
console.log('🔄 同步仓库:', repoId);
updateDebugInfo('🔄 正在同步仓库...');
vscode.postMessage({
type: 'syncGitRepo',
repoId: repoId
@@ -433,7 +319,6 @@ class ConfigView extends BaseView_1.BaseView {
function deleteGitRepo(repoId) {
if (confirm('确定删除这个 Git 仓库吗?')) {
console.log('🗑️ 删除仓库:', repoId);
updateDebugInfo('🗑️ 正在删除仓库...');
vscode.postMessage({
type: 'deleteGitRepo',
repoId: repoId
@@ -441,24 +326,6 @@ class ConfigView extends BaseView_1.BaseView {
}
}
function importFile(filePath) {
if (confirm('确定要将此文件导入到当前容器吗?')) {
console.log('📥 导入文件:', filePath);
updateDebugInfo('📥 正在导入文件...');
vscode.postMessage({
type: 'importGitFile',
filePath: filePath
});
}
}
function toggleFolder(folderPath) {
const folderElement = document.getElementById('folder-' + folderPath.replace(/[^a-zA-Z0-9]/g, '-'));
if (folderElement) {
folderElement.style.display = folderElement.style.display === 'none' ? 'block' : 'none';
}
}
// 动态渲染分支选择区域
function renderBranchSelection(branches, repoUrl) {
const container = document.getElementById('branchSelectionContainer');
@@ -577,29 +444,17 @@ class ConfigView extends BaseView_1.BaseView {
if (message.type === 'branchesFetched') {
console.log('🌿 收到分支数据:', message.branches);
updateDebugInfo('✅ 获取到 ' + message.branches.length + ' 个分支');
renderBranchSelection(message.branches, message.repoUrl);
}
if (message.type === 'configFileLoaded') {
document.getElementById('configContent').value = message.content;
}
if (message.type === 'gitRepoLoading') {
updateDebugInfo(message.loading ? '🔄 后端正在加载仓库文件树...' : '✅ 后端文件树加载完成');
}
});
// 初始化
document.addEventListener('DOMContentLoaded', function() {
console.log('📄 ConfigView 页面加载完成');
updateDebugInfo('📄 页面加载完成 - 等待用户操作');
setTimeout(() => {
document.querySelectorAll('.tree-children').forEach(el => {
el.style.display = 'block';
});
}, 100);
});
</script>
</body>
@@ -627,32 +482,6 @@ class ConfigView extends BaseView_1.BaseView {
html += '</div></div>';
return html;
}
renderFileTree(nodes, level = 0) {
return nodes.map(node => {
const paddingLeft = level * 20;
if (node.type === 'folder') {
return `
<div class="tree-item" style="padding-left: ${paddingLeft}px;">
<span class="tree-folder" onclick="toggleFolder('${node.path}')">
📁 ${node.name}
</span>
<div id="folder-${node.path.replace(/[^a-zA-Z0-9]/g, '-')}" class="tree-children">
${this.renderFileTree(node.children || [], level + 1)}
</div>
</div>
`;
}
else {
return `
<div class="tree-item" style="padding-left: ${paddingLeft}px;">
<span class="tree-file clickable" onclick="importFile('${node.path}')">
📄 ${node.name}
</span>
</div>
`;
}
}).join('');
}
}
exports.ConfigView = ConfigView;
//# sourceMappingURL=ConfigView.js.map