不再提供模板
This commit is contained in:
@@ -3,10 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ConfigPanel = void 0;
|
||||
// src/panels/ConfigPanel.ts
|
||||
const vscode = require("vscode");
|
||||
const ProjectManagementView_1 = require("./views/ProjectManagementView");
|
||||
const ProjectListView_1 = require("./views/ProjectListView");
|
||||
const AircraftConfigView_1 = require("./views/AircraftConfigView");
|
||||
const ContainerConfigView_1 = require("./views/ContainerConfigView");
|
||||
const ProjectView_1 = require("./views/ProjectView");
|
||||
const AircraftView_1 = require("./views/AircraftView");
|
||||
const ContainerView_1 = require("./views/ContainerView");
|
||||
const ConfigView_1 = require("./views/ConfigView");
|
||||
class ConfigPanel {
|
||||
static createOrShow(extensionUri) {
|
||||
const column = vscode.window.activeTextEditor?.viewColumn || vscode.ViewColumn.One;
|
||||
@@ -14,7 +14,7 @@ class ConfigPanel {
|
||||
ConfigPanel.currentPanel.panel.reveal(column);
|
||||
return;
|
||||
}
|
||||
const panel = vscode.window.createWebviewPanel('dockerConfigTest', 'Docker配置测试', column, {
|
||||
const panel = vscode.window.createWebviewPanel('DCSP', '数字卫星构建平台', column, {
|
||||
enableScripts: true,
|
||||
localResourceRoots: [extensionUri],
|
||||
retainContextWhenHidden: true
|
||||
@@ -22,39 +22,24 @@ class ConfigPanel {
|
||||
ConfigPanel.currentPanel = new ConfigPanel(panel, extensionUri);
|
||||
}
|
||||
constructor(panel, extensionUri) {
|
||||
this.currentView = 'management';
|
||||
this.currentView = 'projects';
|
||||
this.currentProjectId = '';
|
||||
this.currentAircraftId = '';
|
||||
this.currentContainerId = '';
|
||||
// 数据存储
|
||||
this.projects = [
|
||||
{ id: 'p1', name: '项目1' },
|
||||
{ id: 'p2', name: '项目2' }
|
||||
];
|
||||
this.aircrafts = [
|
||||
{ id: 'a1', name: '飞行器配置1', projectId: 'p1' },
|
||||
{ id: 'a2', name: '飞行器配置2', projectId: 'p2' }
|
||||
];
|
||||
this.containers = [
|
||||
{ id: 'c1', name: '容器1', aircraftId: 'a1' },
|
||||
{ id: 'c2', name: '容器2', aircraftId: 'a1' },
|
||||
{ id: 'c3', name: '容器1', aircraftId: 'a2' }
|
||||
];
|
||||
this.configs = [
|
||||
{ id: 'cfg1', name: '配置1', fileName: 'config.yaml', content: '# 配置1内容', containerId: 'c1' },
|
||||
{ id: 'cfg2', name: '配置2', fileName: 'settings.json', content: '# 配置2内容', containerId: 'c1' },
|
||||
{ id: 'cfg3', name: '配置1', fileName: 'docker-compose.yml', content: '# 配置1内容', containerId: 'c2' },
|
||||
{ id: 'cfg4', name: '配置1', fileName: 'config.yaml', content: '# 配置1内容', containerId: 'c3' }
|
||||
];
|
||||
this.projects = [];
|
||||
this.aircrafts = [];
|
||||
this.containers = [];
|
||||
this.configs = [];
|
||||
// 项目存储路径映射
|
||||
this.projectPaths = new Map();
|
||||
this.panel = panel;
|
||||
this.extensionUri = extensionUri;
|
||||
// 初始化各个视图
|
||||
this.projectManagementView = new ProjectManagementView_1.ProjectManagementView(extensionUri);
|
||||
this.projectListView = new ProjectListView_1.ProjectListView(extensionUri);
|
||||
this.aircraftConfigView = new AircraftConfigView_1.AircraftConfigView(extensionUri);
|
||||
this.containerConfigView = new ContainerConfigView_1.ContainerConfigView(extensionUri);
|
||||
this.projectView = new ProjectView_1.ProjectView(extensionUri);
|
||||
this.aircraftView = new AircraftView_1.AircraftView(extensionUri);
|
||||
this.containerView = new ContainerView_1.ContainerView(extensionUri);
|
||||
this.configView = new ConfigView_1.ConfigView(extensionUri);
|
||||
this.updateWebview();
|
||||
this.setupMessageListener();
|
||||
this.panel.onDidDispose(() => {
|
||||
@@ -67,50 +52,53 @@ class ConfigPanel {
|
||||
case 'configureProject':
|
||||
const selectedPath = await this.selectProjectPath(data.projectId, data.projectName);
|
||||
if (selectedPath) {
|
||||
this.currentView = 'projects';
|
||||
this.currentView = 'aircrafts';
|
||||
this.currentProjectId = data.projectId;
|
||||
this.updateWebview();
|
||||
}
|
||||
break;
|
||||
case 'openProject':
|
||||
// 已配置的项目直接打开
|
||||
this.currentView = 'projects';
|
||||
this.currentView = 'aircrafts';
|
||||
this.currentProjectId = data.projectId;
|
||||
this.updateWebview();
|
||||
break;
|
||||
case 'openAircraftConfig':
|
||||
this.currentView = 'aircrafts';
|
||||
this.currentView = 'containers';
|
||||
this.currentProjectId = data.projectId;
|
||||
// 找到对应的飞行器ID
|
||||
const aircraft = this.aircrafts.find(a => a.projectId === data.projectId);
|
||||
if (aircraft) {
|
||||
this.currentAircraftId = aircraft.id;
|
||||
}
|
||||
this.currentAircraftId = data.aircraftId;
|
||||
this.updateWebview();
|
||||
break;
|
||||
case 'openContainerConfig':
|
||||
this.currentView = 'container';
|
||||
this.currentView = 'configs';
|
||||
this.currentContainerId = data.containerId;
|
||||
this.updateWebview();
|
||||
break;
|
||||
case 'goBackToManagement':
|
||||
this.currentView = 'management';
|
||||
this.updateWebview();
|
||||
break;
|
||||
// 修复返回按钮的消息处理
|
||||
case 'goBackToProjects':
|
||||
this.currentView = 'projects';
|
||||
this.updateWebview();
|
||||
break;
|
||||
case 'goBackToAircraft':
|
||||
case 'goBackToAircrafts':
|
||||
this.currentView = 'aircrafts';
|
||||
this.updateWebview();
|
||||
break;
|
||||
case 'goBackToContainers':
|
||||
this.currentView = 'containers';
|
||||
this.updateWebview();
|
||||
break;
|
||||
case 'updateProjectName':
|
||||
this.updateProjectName(data.projectId, data.name);
|
||||
break;
|
||||
case 'createProject':
|
||||
this.createProject(data.name);
|
||||
break;
|
||||
case 'updateAircraftName':
|
||||
this.updateAircraftName(data.aircraftId, data.name);
|
||||
break;
|
||||
case 'createAircraft':
|
||||
this.createAircraft(data.name);
|
||||
break;
|
||||
case 'updateContainerName':
|
||||
this.updateContainerName(data.containerId, data.name);
|
||||
break;
|
||||
@@ -135,6 +123,9 @@ class ConfigPanel {
|
||||
case 'deleteProject':
|
||||
this.deleteProject(data.projectId);
|
||||
break;
|
||||
case 'deleteAircraft':
|
||||
this.deleteAircraft(data.aircraftId);
|
||||
break;
|
||||
case 'deleteContainer':
|
||||
this.deleteContainer(data.containerId);
|
||||
break;
|
||||
@@ -144,10 +135,11 @@ class ConfigPanel {
|
||||
}
|
||||
});
|
||||
}
|
||||
// ... 其余方法保持不变(selectProjectPath, updateProjectName, createProject等)
|
||||
// === 项目路径选择 ===
|
||||
async selectProjectPath(projectId, projectName) {
|
||||
try {
|
||||
// 提供两种方式:选择现有路径或输入新路径
|
||||
// 选择现有路径或输入新路径
|
||||
const choice = await vscode.window.showQuickPick([
|
||||
{
|
||||
label: '$(folder) 选择现有文件夹',
|
||||
@@ -215,7 +207,7 @@ class ConfigPanel {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
// === 项目相关方法 ===
|
||||
// 更新项目名
|
||||
updateProjectName(projectId, newName) {
|
||||
const project = this.projects.find(p => p.id === projectId);
|
||||
if (project) {
|
||||
@@ -224,6 +216,7 @@ class ConfigPanel {
|
||||
this.updateWebview();
|
||||
}
|
||||
}
|
||||
// 创建新项目
|
||||
createProject(name) {
|
||||
const newId = 'p' + (this.projects.length + 1);
|
||||
const newProject = {
|
||||
@@ -231,18 +224,14 @@ class ConfigPanel {
|
||||
name: name
|
||||
};
|
||||
this.projects.push(newProject);
|
||||
// 同时创建一个默认的飞行器配置
|
||||
const newAircraftId = 'a' + (this.aircrafts.length + 1);
|
||||
this.aircrafts.push({
|
||||
id: newAircraftId,
|
||||
name: `${name}配置`,
|
||||
projectId: newId
|
||||
});
|
||||
vscode.window.showInformationMessage(`新建项目: ${name}`);
|
||||
this.updateWebview();
|
||||
}
|
||||
// 删除项目
|
||||
deleteProject(projectId) {
|
||||
// 删除项目
|
||||
const project = this.projects.find(p => p.id === projectId);
|
||||
if (!project)
|
||||
return;
|
||||
this.projects = this.projects.filter(p => p.id !== projectId);
|
||||
// 删除相关的飞行器
|
||||
const relatedAircrafts = this.aircrafts.filter(a => a.projectId === projectId);
|
||||
@@ -255,10 +244,49 @@ class ConfigPanel {
|
||||
this.configs = this.configs.filter(cfg => !containerIds.includes(cfg.containerId));
|
||||
// 删除项目路径映射
|
||||
this.projectPaths.delete(projectId);
|
||||
vscode.window.showInformationMessage(`删除项目: ${projectId}`);
|
||||
vscode.window.showInformationMessage(`删除项目: ${project.name}`);
|
||||
this.updateWebview();
|
||||
}
|
||||
// === 容器相关方法 ===
|
||||
// 更新飞行器名
|
||||
updateAircraftName(aircraftId, newName) {
|
||||
const aircraft = this.aircrafts.find(a => a.id === aircraftId);
|
||||
if (aircraft) {
|
||||
aircraft.name = newName;
|
||||
vscode.window.showInformationMessage(`飞行器名称更新: ${newName}`);
|
||||
this.updateWebview();
|
||||
}
|
||||
}
|
||||
// 创建新飞行器
|
||||
createAircraft(name) {
|
||||
if (!this.currentProjectId) {
|
||||
vscode.window.showErrorMessage('无法创建飞行器:未找到当前项目');
|
||||
return;
|
||||
}
|
||||
const newId = 'a' + (this.aircrafts.length + 1);
|
||||
const newAircraft = {
|
||||
id: newId,
|
||||
name: name,
|
||||
projectId: this.currentProjectId
|
||||
};
|
||||
this.aircrafts.push(newAircraft);
|
||||
vscode.window.showInformationMessage(`新建飞行器: ${name}`);
|
||||
this.updateWebview();
|
||||
}
|
||||
// 删除飞行器
|
||||
deleteAircraft(aircraftId) {
|
||||
const aircraft = this.aircrafts.find(a => a.id === aircraftId);
|
||||
if (!aircraft)
|
||||
return;
|
||||
this.aircrafts = this.aircrafts.filter(a => a.id !== aircraftId);
|
||||
// 删除相关的容器
|
||||
this.containers = this.containers.filter(c => c.aircraftId !== aircraftId);
|
||||
// 删除相关的配置
|
||||
const containerIds = this.containers.filter(c => c.aircraftId === aircraftId).map(c => c.id);
|
||||
this.configs = this.configs.filter(cfg => !containerIds.includes(cfg.containerId));
|
||||
vscode.window.showInformationMessage(`删除飞行器: ${aircraft.name}`);
|
||||
this.updateWebview();
|
||||
}
|
||||
// 更新容器名
|
||||
updateContainerName(containerId, newName) {
|
||||
const container = this.containers.find(c => c.id === containerId);
|
||||
if (container) {
|
||||
@@ -267,6 +295,7 @@ class ConfigPanel {
|
||||
this.updateWebview();
|
||||
}
|
||||
}
|
||||
// 创建新容器
|
||||
createContainer(name) {
|
||||
console.log('创建容器,当前飞行器ID:', this.currentAircraftId);
|
||||
if (!this.currentAircraftId) {
|
||||
@@ -282,34 +311,38 @@ class ConfigPanel {
|
||||
this.containers.push(newContainer);
|
||||
// 创建两个默认配置文件
|
||||
const configCount = this.configs.length;
|
||||
// 第一个配置文件:Dockerfile
|
||||
// 第一个配置文件
|
||||
this.configs.push({
|
||||
id: 'cfg' + (configCount + 1),
|
||||
name: 'Docker配置',
|
||||
fileName: 'Dockerfile',
|
||||
name: '配置1',
|
||||
fileName: 'config.sh',
|
||||
content: `# ${name} 的 Dockerfile\nFROM ubuntu:20.04\n\n# 设置工作目录\nWORKDIR /app\n\n# 复制文件\nCOPY . .\n\n# 安装依赖\nRUN apt-get update && apt-get install -y \\\n python3 \\\n python3-pip\n\n# 暴露端口\nEXPOSE 8080\n\n# 启动命令\nCMD ["python3", "app.py"]`,
|
||||
containerId: newId
|
||||
});
|
||||
// 第二个配置文件:docker-compose.yml
|
||||
// 第二个配置文件
|
||||
this.configs.push({
|
||||
id: 'cfg' + (configCount + 2),
|
||||
name: '编排配置',
|
||||
fileName: 'docker-compose.yml',
|
||||
name: '配置2',
|
||||
fileName: 'config.sh',
|
||||
content: `# ${name} 的 Docker Compose 配置\nversion: '3.8'\n\nservices:\n ${name.toLowerCase().replace(/\\s+/g, '-')}:\n build: .\n container_name: ${name}\n ports:\n - "8080:8080"\n environment:\n - NODE_ENV=production\n volumes:\n - ./data:/app/data\n restart: unless-stopped`,
|
||||
containerId: newId
|
||||
});
|
||||
vscode.window.showInformationMessage(`新建容器: ${name} (包含2个默认配置文件)`);
|
||||
this.updateWebview();
|
||||
}
|
||||
// 删除容器
|
||||
deleteContainer(containerId) {
|
||||
const container = this.containers.find(c => c.id === containerId);
|
||||
if (!container)
|
||||
return;
|
||||
// 删除容器
|
||||
this.containers = this.containers.filter(c => c.id !== containerId);
|
||||
// 删除相关的配置
|
||||
this.configs = this.configs.filter(cfg => cfg.containerId !== containerId);
|
||||
vscode.window.showInformationMessage(`删除容器: ${containerId}`);
|
||||
vscode.window.showInformationMessage(`删除容器: ${container.name}`);
|
||||
this.updateWebview();
|
||||
}
|
||||
// === 配置相关方法 ===
|
||||
// 更新配置名
|
||||
updateConfigName(configId, newName) {
|
||||
const config = this.configs.find(c => c.id === configId);
|
||||
if (config) {
|
||||
@@ -318,6 +351,7 @@ class ConfigPanel {
|
||||
this.updateWebview();
|
||||
}
|
||||
}
|
||||
// 更新文件名
|
||||
async updateConfigFileName(configId, fileName) {
|
||||
const config = this.configs.find(c => c.id === configId);
|
||||
if (config) {
|
||||
@@ -326,7 +360,7 @@ class ConfigPanel {
|
||||
this.updateWebview();
|
||||
}
|
||||
}
|
||||
// 创建配置文件
|
||||
// 创建新配置文件
|
||||
createConfig(name) {
|
||||
const newId = 'cfg' + (this.configs.length + 1);
|
||||
const newConfig = {
|
||||
@@ -426,35 +460,32 @@ class ConfigPanel {
|
||||
}
|
||||
getWebviewContent() {
|
||||
switch (this.currentView) {
|
||||
case 'management':
|
||||
return this.projectManagementView.render({
|
||||
case 'projects':
|
||||
return this.projectView.render({
|
||||
projects: this.projects,
|
||||
projectPaths: this.projectPaths
|
||||
});
|
||||
case 'projects':
|
||||
return this.projectListView.render({
|
||||
projects: this.projects
|
||||
});
|
||||
case 'aircrafts':
|
||||
const projectAircrafts = this.aircrafts.filter(a => a.projectId === this.currentProjectId);
|
||||
return this.aircraftView.render({
|
||||
aircrafts: projectAircrafts
|
||||
});
|
||||
case 'containers':
|
||||
const currentProject = this.projects.find(p => p.id === this.currentProjectId);
|
||||
const projectAircraft = this.aircrafts.find(a => a.projectId === this.currentProjectId);
|
||||
if (projectAircraft) {
|
||||
this.currentAircraftId = projectAircraft.id;
|
||||
}
|
||||
const projectContainers = this.containers.filter(c => c.aircraftId === this.currentAircraftId);
|
||||
return this.aircraftConfigView.render({
|
||||
return this.containerView.render({
|
||||
project: currentProject,
|
||||
containers: projectContainers
|
||||
});
|
||||
case 'container':
|
||||
case 'configs':
|
||||
const currentContainer = this.containers.find(c => c.id === this.currentContainerId);
|
||||
const containerConfigs = this.configs.filter(cfg => cfg.containerId === this.currentContainerId);
|
||||
return this.containerConfigView.render({
|
||||
return this.configView.render({
|
||||
container: currentContainer,
|
||||
configs: containerConfigs
|
||||
});
|
||||
default:
|
||||
return this.projectManagementView.render({
|
||||
return this.projectView.render({
|
||||
projects: this.projects,
|
||||
projectPaths: this.projectPaths
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user