Skip to content

Commit

Permalink
Add delete all projects button
Browse files Browse the repository at this point in the history
  • Loading branch information
michelelizzit committed Nov 7, 2023
1 parent e29eb87 commit c0f8bc2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@
},
{
"view": "iacAudit",
"contents": "Please open a workspace folder to use this extension.",
"contents": "In order to use PoiEx open a workspace folder.\n[Open Folder](command:vscode.openFolder)",
"when": "workspaceFolderCount == 0"
},
{
Expand All @@ -214,7 +214,7 @@
},
{
"view": "iacProjectManager",
"contents": "Please open a workspace folder to use this extension.",
"contents": "In order to use PoiEx open a workspace folder.\n[Open Folder](command:vscode.openFolder)",
"when": "workspaceFolderCount == 0"
},
{
Expand All @@ -224,7 +224,7 @@
},
{
"view": "iacProjectManager",
"contents": "Initialize a new project on current Workspace.\n[Init project](command:poiex.initProject)\nOpen existing project from remote database.\n[Open existing project](command:poiex.openProject)",
"contents": "Initialize a new project on current Workspace.\n[Init project](command:poiex.initProject)\nOpen existing project from remote database.\n[Open existing project](command:poiex.openProject)\nDrop project database.\n[Destroy all projects](command:poiex.destroyAllProjects)",
"when": "workspaceFolderCount == 1 && iacAudit.isProjectOpen == false"
},
{
Expand Down
15 changes: 15 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,21 @@ async function init1(context: vscode.ExtensionContext, iacPath: string) {
await cb();
}
}));

// Register command to destroy all projects and empty project database (destroyAllProjects)
context.subscriptions.push(vscode.commands.registerCommand(`${constants.EXT_NAME}.destroyAllProjects`, async () => {
console.log('[IaC Main] Destroy all projects button pressed');
vscode.window.showWarningMessage('Are you sure you want to destroy all projects (remove also on remote)?', 'Yes', 'No').then(async (choice) => {
if (choice === 'Yes') {
let plist = await pdb.listProjects();
if (plist === null) { return; }
for (let project of plist) {
let projectUuid = project.uuid;
await pdb.removeProject(projectUuid, rdb);
}
}
});
}));
}

async function openProject(context: vscode.ExtensionContext, storageUri: vscode.Uri, projectUuid: string, projectSecret: string | null = null) {
Expand Down
4 changes: 2 additions & 2 deletions src/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ export class IaCProjectDir {
)`);
}

async listProjects(): Promise<{}[]> {
async listProjects(): Promise<any[]> {
if (this.pdb === null) {
return [];
}
let stmt = await this.pdb.prepare('SELECT uuid, name, keys FROM projects WHERE deleted = 0');
let rows = await stmt.all({});
await stmt.finalize();
return rows as {}[];
return rows as any[];
}

async pushProject(uuid: string, name: string, keys: string | null, jwt: string | null = null) {
Expand Down

0 comments on commit c0f8bc2

Please sign in to comment.