不再提供模板
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
// src/panels/ConfigPanel.ts
|
||||
import * as vscode from 'vscode';
|
||||
import { ProjectManagementView } from './views/ProjectManagementView';
|
||||
import { ProjectListView } from './views/ProjectListView';
|
||||
import { AircraftConfigView } from './views/AircraftConfigView';
|
||||
import { ContainerConfigView } from './views/ContainerConfigView';
|
||||
import { ProjectView } from './views/ProjectView';
|
||||
import { AircraftView } from './views/AircraftView';
|
||||
import { ContainerView } from './views/ContainerView';
|
||||
import { ConfigView } from './views/ConfigView';
|
||||
|
||||
// 数据模型接口
|
||||
interface Project {
|
||||
@@ -36,43 +36,25 @@ export class ConfigPanel {
|
||||
private readonly panel: vscode.WebviewPanel;
|
||||
private readonly extensionUri: vscode.Uri;
|
||||
|
||||
private currentView: 'management' | 'projects' | 'aircrafts' | 'container' = 'management';
|
||||
private currentView: 'projects' | 'aircrafts' | 'containers' | 'configs' = 'projects';
|
||||
private currentProjectId: string = '';
|
||||
private currentAircraftId: string = '';
|
||||
private currentContainerId: string = '';
|
||||
|
||||
// 数据存储
|
||||
private projects: Project[] = [
|
||||
{ id: 'p1', name: '项目1' },
|
||||
{ id: 'p2', name: '项目2' }
|
||||
];
|
||||
|
||||
private aircrafts: Aircraft[] = [
|
||||
{ id: 'a1', name: '飞行器配置1', projectId: 'p1' },
|
||||
{ id: 'a2', name: '飞行器配置2', projectId: 'p2' }
|
||||
];
|
||||
|
||||
private containers: Container[] = [
|
||||
{ id: 'c1', name: '容器1', aircraftId: 'a1' },
|
||||
{ id: 'c2', name: '容器2', aircraftId: 'a1' },
|
||||
{ id: 'c3', name: '容器1', aircraftId: 'a2' }
|
||||
];
|
||||
|
||||
private configs: Config[] = [
|
||||
{ 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' }
|
||||
];
|
||||
private projects: Project[] = [];
|
||||
private aircrafts: Aircraft[] = [];
|
||||
private containers: Container[] = [];
|
||||
private configs: Config[] = [];
|
||||
|
||||
// 项目存储路径映射
|
||||
private projectPaths: Map<string, string> = new Map();
|
||||
|
||||
// 视图实例
|
||||
private readonly projectManagementView: ProjectManagementView;
|
||||
private readonly projectListView: ProjectListView;
|
||||
private readonly aircraftConfigView: AircraftConfigView;
|
||||
private readonly containerConfigView: ContainerConfigView;
|
||||
private readonly projectView: ProjectView;
|
||||
private readonly aircraftView: AircraftView;
|
||||
private readonly containerView: ContainerView;
|
||||
private readonly configView: ConfigView;
|
||||
|
||||
public static createOrShow(extensionUri: vscode.Uri) {
|
||||
const column = vscode.window.activeTextEditor?.viewColumn || vscode.ViewColumn.One;
|
||||
@@ -83,8 +65,8 @@ export class ConfigPanel {
|
||||
}
|
||||
|
||||
const panel = vscode.window.createWebviewPanel(
|
||||
'dockerConfigTest',
|
||||
'Docker配置测试',
|
||||
'DCSP',
|
||||
'数字卫星构建平台',
|
||||
column,
|
||||
{
|
||||
enableScripts: true,
|
||||
@@ -101,10 +83,10 @@ export class ConfigPanel {
|
||||
this.extensionUri = extensionUri;
|
||||
|
||||
// 初始化各个视图
|
||||
this.projectManagementView = new ProjectManagementView(extensionUri);
|
||||
this.projectListView = new ProjectListView(extensionUri);
|
||||
this.aircraftConfigView = new AircraftConfigView(extensionUri);
|
||||
this.containerConfigView = new ContainerConfigView(extensionUri);
|
||||
this.projectView = new ProjectView(extensionUri);
|
||||
this.aircraftView = new AircraftView(extensionUri);
|
||||
this.containerView = new ContainerView(extensionUri);
|
||||
this.configView = new ConfigView(extensionUri);
|
||||
|
||||
this.updateWebview();
|
||||
this.setupMessageListener();
|
||||
@@ -120,7 +102,7 @@ export 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();
|
||||
}
|
||||
@@ -128,43 +110,40 @@ export class ConfigPanel {
|
||||
|
||||
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;
|
||||
@@ -173,6 +152,14 @@ export class ConfigPanel {
|
||||
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;
|
||||
@@ -205,6 +192,10 @@ export class ConfigPanel {
|
||||
this.deleteProject(data.projectId);
|
||||
break;
|
||||
|
||||
case 'deleteAircraft':
|
||||
this.deleteAircraft(data.aircraftId);
|
||||
break;
|
||||
|
||||
case 'deleteContainer':
|
||||
this.deleteContainer(data.containerId);
|
||||
break;
|
||||
@@ -216,10 +207,11 @@ export class ConfigPanel {
|
||||
});
|
||||
}
|
||||
|
||||
// ... 其余方法保持不变(selectProjectPath, updateProjectName, createProject等)
|
||||
// === 项目路径选择 ===
|
||||
private async selectProjectPath(projectId: string, projectName: string): Promise<string | null> {
|
||||
try {
|
||||
// 提供两种方式:选择现有路径或输入新路径
|
||||
// 选择现有路径或输入新路径
|
||||
const choice = await vscode.window.showQuickPick(
|
||||
[
|
||||
{
|
||||
@@ -294,7 +286,7 @@ export class ConfigPanel {
|
||||
}
|
||||
}
|
||||
|
||||
// === 项目相关方法 ===
|
||||
// 更新项目名
|
||||
private updateProjectName(projectId: string, newName: string) {
|
||||
const project = this.projects.find(p => p.id === projectId);
|
||||
if (project) {
|
||||
@@ -304,6 +296,7 @@ export class ConfigPanel {
|
||||
}
|
||||
}
|
||||
|
||||
// 创建新项目
|
||||
private createProject(name: string) {
|
||||
const newId = 'p' + (this.projects.length + 1);
|
||||
const newProject: Project = {
|
||||
@@ -311,43 +304,79 @@ export 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();
|
||||
}
|
||||
|
||||
// 删除项目
|
||||
private deleteProject(projectId: string) {
|
||||
// 删除项目
|
||||
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);
|
||||
const aircraftIds = relatedAircrafts.map(a => a.id);
|
||||
this.aircrafts = this.aircrafts.filter(a => a.projectId !== projectId);
|
||||
|
||||
// 删除相关的容器
|
||||
this.containers = this.containers.filter(c => !aircraftIds.includes(c.aircraftId));
|
||||
|
||||
// 删除相关的配置
|
||||
const containerIds = this.containers.filter(c => aircraftIds.includes(c.aircraftId)).map(c => c.id);
|
||||
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();
|
||||
}
|
||||
|
||||
// === 容器相关方法 ===
|
||||
// 更新飞行器名
|
||||
private updateAircraftName(aircraftId: string, newName: string) {
|
||||
const aircraft = this.aircrafts.find(a => a.id === aircraftId);
|
||||
if (aircraft) {
|
||||
aircraft.name = newName;
|
||||
vscode.window.showInformationMessage(`飞行器名称更新: ${newName}`);
|
||||
this.updateWebview();
|
||||
}
|
||||
}
|
||||
|
||||
// 创建新飞行器
|
||||
private createAircraft(name: string) {
|
||||
if (!this.currentProjectId) {
|
||||
vscode.window.showErrorMessage('无法创建飞行器:未找到当前项目');
|
||||
return;
|
||||
}
|
||||
|
||||
const newId = 'a' + (this.aircrafts.length + 1);
|
||||
const newAircraft: Aircraft = {
|
||||
id: newId,
|
||||
name: name,
|
||||
projectId: this.currentProjectId
|
||||
};
|
||||
this.aircrafts.push(newAircraft);
|
||||
|
||||
vscode.window.showInformationMessage(`新建飞行器: ${name}`);
|
||||
this.updateWebview();
|
||||
}
|
||||
|
||||
// 删除飞行器
|
||||
private deleteAircraft(aircraftId: string) {
|
||||
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();
|
||||
}
|
||||
|
||||
// 更新容器名
|
||||
private updateContainerName(containerId: string, newName: string) {
|
||||
const container = this.containers.find(c => c.id === containerId);
|
||||
if (container) {
|
||||
@@ -357,6 +386,7 @@ export class ConfigPanel {
|
||||
}
|
||||
}
|
||||
|
||||
// 创建新容器
|
||||
private createContainer(name: string) {
|
||||
console.log('创建容器,当前飞行器ID:', this.currentAircraftId);
|
||||
|
||||
@@ -377,20 +407,20 @@ export class ConfigPanel {
|
||||
// 创建两个默认配置文件
|
||||
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
|
||||
});
|
||||
@@ -399,18 +429,22 @@ export class ConfigPanel {
|
||||
this.updateWebview();
|
||||
}
|
||||
|
||||
// 删除容器
|
||||
private deleteContainer(containerId: string) {
|
||||
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();
|
||||
}
|
||||
|
||||
// === 配置相关方法 ===
|
||||
// 更新配置名
|
||||
private updateConfigName(configId: string, newName: string) {
|
||||
const config = this.configs.find(c => c.id === configId);
|
||||
if (config) {
|
||||
@@ -420,6 +454,7 @@ export class ConfigPanel {
|
||||
}
|
||||
}
|
||||
|
||||
// 更新文件名
|
||||
private async updateConfigFileName(configId: string, fileName: string): Promise<void> {
|
||||
const config = this.configs.find(c => c.id === configId);
|
||||
if (config) {
|
||||
@@ -429,7 +464,7 @@ export class ConfigPanel {
|
||||
}
|
||||
}
|
||||
|
||||
// 创建配置文件
|
||||
// 创建新配置文件
|
||||
private createConfig(name: string) {
|
||||
const newId = 'cfg' + (this.configs.length + 1);
|
||||
const newConfig: Config = {
|
||||
@@ -540,39 +575,34 @@ export class ConfigPanel {
|
||||
|
||||
private getWebviewContent(): string {
|
||||
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