Skip to content

Commit

Permalink
Delete smart contracts package
Browse files Browse the repository at this point in the history
Closes IBM-Blockchain#9

Signed-off-by: Jakeeyturner <jaketurner25@live.com>
  • Loading branch information
Jakeeyturner committed Sep 12, 2018
1 parent ab9ada4 commit 40d75d6
Show file tree
Hide file tree
Showing 24 changed files with 538 additions and 121 deletions.
14 changes: 12 additions & 2 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
"blockchainExplorer.startFabricRuntime",
"blockchainExplorer.stopFabricRuntime",
"blockchainExplorer.restartFabricRuntime",
"blockchainExplorer.toggleFabricRuntimeDevMode"
"blockchainExplorer.toggleFabricRuntimeDevMode",
"blockchainAPackageExplorer.deleteSmartContractPackageEntry"
]
},
"main": "./out/src/extension",
Expand Down Expand Up @@ -185,6 +186,11 @@
"command": "blockchainExplorer.toggleFabricRuntimeDevMode",
"title": "Toggle Development Mode",
"category": "Blockchain"
},
{
"command": "blockchainAPackageExplorer.deleteSmartContractPackageEntry",
"title": "Delete Package",
"category": "Blockchain"
}
],
"menus": {
Expand Down Expand Up @@ -247,6 +253,10 @@
{
"command": "blockchainExplorer.toggleFabricRuntimeDevMode",
"when": "view == blockchainExplorer && viewItem == blockchain-runtime-item-stopped"
},
{
"command": "blockchainAPackageExplorer.deleteSmartContractPackageEntry",
"when": "view == blockchainAPackageExplorer && viewItem == blockchain-package-item"
}
]
}
Expand Down Expand Up @@ -382,4 +392,4 @@
}
}
}
}
}
10 changes: 5 additions & 5 deletions client/src/commands/addConnectionCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,30 @@
*/
'use strict';
import * as vscode from 'vscode';
import {CommandsUtil} from './commandsUtil';
import {UserInputUtil} from './userInputUtil';

// TODO: make it save where have got up to
export async function addConnection(): Promise<{} | void> {
console.log('addConnection');
const connectionName: string = await CommandsUtil.showInputBox('Enter a name for the connection');
const connectionName: string = await UserInputUtil.showInputBox('Enter a name for the connection');

if (!connectionName) {
return Promise.resolve();
}

const connectionProfilePath: string = await CommandsUtil.showInputBox('Enter a file path to the connection profile json file');
const connectionProfilePath: string = await UserInputUtil.showInputBox('Enter a file path to the connection profile json file');

if (!connectionProfilePath) {
return Promise.resolve();
}

const certificatePath: string = await CommandsUtil.showInputBox('Enter a file path to the certificate file');
const certificatePath: string = await UserInputUtil.showInputBox('Enter a file path to the certificate file');

if (!certificatePath) {
return Promise.resolve();
}

const privateKeyPath: string = await CommandsUtil.showInputBox('Enter a file path to the private key file');
const privateKeyPath: string = await UserInputUtil.showInputBox('Enter a file path to the private key file');

if (!privateKeyPath) {
return Promise.resolve();
Expand Down
8 changes: 4 additions & 4 deletions client/src/commands/addConnectionIdentityCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
'use strict';
import * as vscode from 'vscode';
import { CommandsUtil } from './commandsUtil';
import { UserInputUtil } from './userInputUtil';
import { ConnectionTreeItem } from '../explorer/model/ConnectionTreeItem';

export async function addConnectionIdentity(connectionItem: ConnectionTreeItem): Promise<{} | void> {
Expand All @@ -23,20 +23,20 @@ export async function addConnectionIdentity(connectionItem: ConnectionTreeItem):
if (connectionItem) {
connectionName = connectionItem.connection.name;
} else {
connectionName = await CommandsUtil.showConnectionQuickPickBox('Choose a connection to add an identity to');
connectionName = await UserInputUtil.showConnectionQuickPickBox('Choose a connection to add an identity to');
}

if (!connectionName) {
return Promise.resolve();
}

const certificatePath: string = await CommandsUtil.showInputBox('Enter a file path to the certificate file');
const certificatePath: string = await UserInputUtil.showInputBox('Enter a file path to the certificate file');

if (!certificatePath) {
return Promise.resolve();
}

const privateKeyPath: string = await CommandsUtil.showInputBox('Enter a file path to the private key file');
const privateKeyPath: string = await UserInputUtil.showInputBox('Enter a file path to the private key file');

if (!privateKeyPath) {
return Promise.resolve();
Expand Down
6 changes: 3 additions & 3 deletions client/src/commands/connectCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
'use strict';
import * as vscode from 'vscode';
import { CommandsUtil } from './commandsUtil';
import { UserInputUtil } from './userInputUtil';
import { IFabricConnection } from '../fabric/IFabricConnection';
import { ParsedCertificate } from '../fabric/ParsedCertificate';
import { FabricConnectionFactory } from '../fabric/FabricConnectionFactory';
Expand All @@ -27,7 +27,7 @@ export async function connect(connectionName: string, identityName?: string): Pr
console.log('connect', connectionName, identityName);

if (!connectionName) {
connectionName = await CommandsUtil.showConnectionQuickPickBox('Choose a connection to connect with');
connectionName = await UserInputUtil.showConnectionQuickPickBox('Choose a connection to connect with');
if (!connectionName) {
return;
}
Expand Down Expand Up @@ -59,7 +59,7 @@ export async function connect(connectionName: string, identityName?: string): Pr
if (connectionRegistryEntry.identities.length > 1) {

if (!identityName) {
identityName = await CommandsUtil.showIdentityConnectionQuickPickBox('Choose an identity to connect with', connectionRegistryEntry);
identityName = await UserInputUtil.showIdentityConnectionQuickPickBox('Choose an identity to connect with', connectionRegistryEntry);
if (!identityName) {
return;
}
Expand Down
4 changes: 2 additions & 2 deletions client/src/commands/deleteConnectionCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
'use strict';
import * as vscode from 'vscode';
import {CommandsUtil} from './commandsUtil';
import {UserInputUtil} from './userInputUtil';
import { ConnectionTreeItem } from '../explorer/model/ConnectionTreeItem';

export async function deleteConnection(connectionItem: ConnectionTreeItem): Promise<{} | void> {
Expand All @@ -24,7 +24,7 @@ export async function deleteConnection(connectionItem: ConnectionTreeItem): Prom
if (connectionItem) {
connectionToDelete = connectionItem.connection.name;
} else {
connectionToDelete = await CommandsUtil.showConnectionQuickPickBox('Choose the connection that you want to delete');
connectionToDelete = await UserInputUtil.showConnectionQuickPickBox('Choose the connection that you want to delete');
}

const connections: Array<any> = vscode.workspace.getConfiguration().get('fabric.connections');
Expand Down
82 changes: 82 additions & 0 deletions client/src/commands/deleteSmartContractPackageCommand.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'use strict';
import * as vscode from 'vscode';
import { UserInputUtil } from './userInputUtil';
import { PackageTreeItem } from '../explorer/model/PackageTreeItem';
import * as myExtension from '../extension';
import * as fs from 'fs-extra';
import * as homeDir from 'home-dir';
import { CommandUtil } from '../util/CommandUtil';

export async function deleteSmartContractPackage(packageTreeItem: PackageTreeItem): Promise<{} | void> {
console.log('deleteSmartContractPackage');

let packageToDelete: string | string[];

let index: number;
let deleteObject: object; // Used for mapping packages to their deletion status
let objectKeys: string[] = []; // Array of deleteObject keys

if (packageTreeItem) {
packageToDelete = packageTreeItem.name;
} else {
packageToDelete = await UserInputUtil.showSmartContractPackagesQuickPickBox('Choose the smart contract package that you want to delete');
}

const packages: string[] = await CommandUtil.getPackages();

if (packageToDelete === undefined) {
return;
}

if (typeof packageToDelete === 'string') {
index = packages.findIndex((_package) => {
return _package === packageToDelete;
});
} else {
deleteObject = {}; // tslint:disable-line

for (let x = 0; x < packages.length; x++) {
deleteObject[x] = packageToDelete.indexOf(packages[x]);
}

objectKeys = Object.keys(deleteObject);

}

let packageDir: string = vscode.workspace.getConfiguration().get('fabric.package.directory');

if (packageDir.startsWith('~')) {
// Remove tilda and replace with home dir
packageDir = homeDir(packageDir.replace('~', ''));
}

if (objectKeys.length > 0) {
for (const key of objectKeys) {
if (deleteObject[key] > -1) {
console.log('Deleting', packageDir + '/' + packages[key]);
await fs.remove(packageDir + '/' + packages[key]);
}
}
}

if (index > -1) {
console.log('Deleting', packageDir + '/' + packages[index]);

await fs.remove(packageDir + '/' + packages[index]);
}

return vscode.commands.executeCommand('blockchainAPackageExplorer.refreshEntry');
}
4 changes: 2 additions & 2 deletions client/src/commands/restartFabricRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import * as vscode from 'vscode';
import { FabricRuntimeManager } from '../fabric/FabricRuntimeManager';
import { CommandsUtil } from './commandsUtil';
import { UserInputUtil } from './userInputUtil';
import { RuntimeTreeItem } from '../explorer/model/RuntimeTreeItem';
import { VSCodeOutputAdapter } from '../logging/VSCodeOutputAdapter';
import { FabricRuntime } from '../fabric/FabricRuntime';
Expand All @@ -23,7 +23,7 @@ export async function restartFabricRuntime(runtimeTreeItem?: RuntimeTreeItem): P
const runtimeManager: FabricRuntimeManager = FabricRuntimeManager.instance();
let runtimeName: string;
if (!runtimeTreeItem) {
runtimeName = await CommandsUtil.showRuntimeQuickPickBox('Select the Fabric runtime to restart');
runtimeName = await UserInputUtil.showRuntimeQuickPickBox('Select the Fabric runtime to restart');
} else {
runtimeName = runtimeTreeItem.getName();
}
Expand Down
4 changes: 2 additions & 2 deletions client/src/commands/startFabricRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import * as vscode from 'vscode';
import { FabricRuntimeManager } from '../fabric/FabricRuntimeManager';
import { CommandsUtil } from './commandsUtil';
import { UserInputUtil } from './userInputUtil';
import { RuntimeTreeItem } from '../explorer/model/RuntimeTreeItem';
import { VSCodeOutputAdapter } from '../logging/VSCodeOutputAdapter';
import { FabricRuntime } from '../fabric/FabricRuntime';
Expand All @@ -23,7 +23,7 @@ export async function startFabricRuntime(runtimeTreeItem?: RuntimeTreeItem): Pro
const runtimeManager: FabricRuntimeManager = FabricRuntimeManager.instance();
let runtimeName: string;
if (!runtimeTreeItem) {
runtimeName = await CommandsUtil.showRuntimeQuickPickBox('Select the Fabric runtime to start');
runtimeName = await UserInputUtil.showRuntimeQuickPickBox('Select the Fabric runtime to start');
} else {
runtimeName = runtimeTreeItem.getName();
}
Expand Down
4 changes: 2 additions & 2 deletions client/src/commands/stopFabricRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import * as vscode from 'vscode';
import { FabricRuntimeManager } from '../fabric/FabricRuntimeManager';
import { CommandsUtil } from './commandsUtil';
import { UserInputUtil } from './userInputUtil';
import { RuntimeTreeItem } from '../explorer/model/RuntimeTreeItem';
import { VSCodeOutputAdapter } from '../logging/VSCodeOutputAdapter';
import { FabricRuntime } from '../fabric/FabricRuntime';
Expand All @@ -23,7 +23,7 @@ export async function stopFabricRuntime(runtimeTreeItem?: RuntimeTreeItem): Prom
const runtimeManager: FabricRuntimeManager = FabricRuntimeManager.instance();
let runtimeName: string;
if (!runtimeTreeItem) {
runtimeName = await CommandsUtil.showRuntimeQuickPickBox('Select the Fabric runtime to stop');
runtimeName = await UserInputUtil.showRuntimeQuickPickBox('Select the Fabric runtime to stop');
} else {
runtimeName = runtimeTreeItem.getName();
}
Expand Down
4 changes: 2 additions & 2 deletions client/src/commands/toggleFabricRuntimeDevMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import * as vscode from 'vscode';
import { FabricRuntimeManager } from '../fabric/FabricRuntimeManager';
import { CommandsUtil } from './commandsUtil';
import { UserInputUtil } from './userInputUtil';
import { RuntimeTreeItem } from '../explorer/model/RuntimeTreeItem';
import { VSCodeOutputAdapter } from '../logging/VSCodeOutputAdapter';
import { FabricRuntime } from '../fabric/FabricRuntime';
Expand All @@ -23,7 +23,7 @@ export async function toggleFabricRuntimeDevMode(runtimeTreeItem?: RuntimeTreeIt
const runtimeManager: FabricRuntimeManager = FabricRuntimeManager.instance();
let runtimeName: string;
if (!runtimeTreeItem) {
runtimeName = await CommandsUtil.showRuntimeQuickPickBox('Select the Fabric runtime to toggle development mode');
runtimeName = await UserInputUtil.showRuntimeQuickPickBox('Select the Fabric runtime to toggle development mode');
} else {
runtimeName = runtimeTreeItem.getName();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ import * as vscode from 'vscode';
import { ParsedCertificate } from '../fabric/ParsedCertificate';
import { FabricRuntimeRegistry } from '../fabric/FabricRuntimeRegistry';
import { FabricRuntimeRegistryEntry } from '../fabric/FabricRuntimeRegistryEntry';
import * as myExtension from '../extension';
import { PackageTreeItem } from '../explorer/model/PackageTreeItem';
import { CommandUtil } from '../util/CommandUtil';

export class CommandsUtil {
export class UserInputUtil {

static showConnectionQuickPickBox(prompt: string): Thenable<string | undefined> {
const connections: Array<any> = vscode.workspace.getConfiguration().get('fabric.connections');
Expand Down Expand Up @@ -75,4 +78,17 @@ export class CommandsUtil {
return vscode.window.showQuickPick(runtimeNames, quickPickOptions);
}

static async showSmartContractPackagesQuickPickBox(prompt: string): Promise<string | undefined | string[]> {

const packages: string[] = await CommandUtil.getPackages();

const quickPickOptions = {
ignoreFocusOut: false,
canPickMany: true,
placeHolder: prompt
};

return vscode.window.showQuickPick(packages, quickPickOptions);
}

}
Loading

0 comments on commit 40d75d6

Please sign in to comment.