From 0b3fb8f52e2a02e4a376ee4d38c5e5deb4d1b159 Mon Sep 17 00:00:00 2001 From: Chris Dias Date: Fri, 2 Feb 2018 10:09:03 -0800 Subject: [PATCH] Chrisdias/201 (#208) * fixes #201, #207 --- commands/docker-compose.ts | 15 +++++++++------ explorer/models/azureRegistryNodes.ts | 17 +++++++++++------ explorer/models/dockerHubNodes.ts | 12 ++++++++---- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/commands/docker-compose.ts b/commands/docker-compose.ts index a24898e3a2..8fdc85ac60 100644 --- a/commands/docker-compose.ts +++ b/commands/docker-compose.ts @@ -34,18 +34,19 @@ function computeItems(folder: vscode.WorkspaceFolder, uris: vscode.Uri[]): vscod async function compose(command: string, message: string, dockerComposeFileUri?: vscode.Uri) { let folder: vscode.WorkspaceFolder; - if (vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders.length === 1) { + + if (!vscode.workspace.workspaceFolders) { + vscode.window.showErrorMessage('Docker compose can only run if VS Code is opened on a folder.'); + return; + } + + if (vscode.workspace.workspaceFolders.length === 1) { folder = vscode.workspace.workspaceFolders[0]; } else { folder = await (vscode).window.showWorkspaceFolderPick(); } if (!folder) { - if (!vscode.workspace.workspaceFolders) { - vscode.window.showErrorMessage('Docker compose can only run if VS Code is opened on a folder.'); - } else { - vscode.window.showErrorMessage('Docker compose can only run if a workspace folder is picked in VS Code.'); - } return; } @@ -69,6 +70,8 @@ async function compose(command: string, message: string, dockerComposeFileUri?: const build: string = configOptions.get('dockerComposeBuild', true) ? '--build': ''; const detached: string = configOptions.get('dockerComposeDetached', true) ? '-d' : ''; + + terminal.sendText(`cd ${folder.uri.fsPath}`); terminal.sendText(command.toLowerCase() === 'up' ? `docker-compose -f ${selectedItem.file} ${command} ${detached} ${build}` : `docker-compose -f ${selectedItem.file} ${command}`); terminal.show(); if (reporter) { diff --git a/explorer/models/azureRegistryNodes.ts b/explorer/models/azureRegistryNodes.ts index bd9721c6e7..7d25f9b415 100644 --- a/explorer/models/azureRegistryNodes.ts +++ b/explorer/models/azureRegistryNodes.ts @@ -201,19 +201,19 @@ export class AzureRepositoryNode extends NodeBase { }); for (let i = 0; i < tags.length; i++) { - created = ''; + let manifest = JSON.parse(await request.get('https://' + element.repository + '/v2/' + element.label + '/manifests/latest', { auth: { bearer: accessTokenARC } })); - created = moment(new Date(JSON.parse(manifest.history[0].v1Compatibility).created)).fromNow(); - node = new AzureImageNode(`${element.label}:${tags[i]} (${created})`, 'azureImageNode'); + node = new AzureImageNode(`${element.label}:${tags[i]}`, 'azureImageNode'); node.azureAccount = element.azureAccount; node.password = element.password; node.registry = element.registry; node.serverUrl = element.repository; node.subscription = element.subscription; node.userName = element.userName; + node.created = moment(new Date(JSON.parse(manifest.history[0].v1Compatibility).created)).fromNow(); imageNodes.push(node); } @@ -230,8 +230,9 @@ export class AzureImageNode extends NodeBase { ) { super(label); } - + public azureAccount: AzureAccount + public created: string; public password: string; public registry: ContainerModels.Registry; public serverUrl: string; @@ -239,8 +240,12 @@ export class AzureImageNode extends NodeBase { public userName: string; getTreeItem(): vscode.TreeItem { + let displayName: string = this.label; + + displayName = `${displayName} (${this.created})`; + return { - label: this.label, + label: `${displayName}`, collapsibleState: vscode.TreeItemCollapsibleState.None, contextValue: this.contextValue } @@ -249,7 +254,7 @@ export class AzureImageNode extends NodeBase { export class AzureNotSignedInNode extends NodeBase { constructor() { - super('Sign in to Azure...'); + super('Click here to sign in to Azure...'); } getTreeItem(): vscode.TreeItem { diff --git a/explorer/models/dockerHubNodes.ts b/explorer/models/dockerHubNodes.ts index 01fde7673f..2c00e736a4 100644 --- a/explorer/models/dockerHubNodes.ts +++ b/explorer/models/dockerHubNodes.ts @@ -79,15 +79,14 @@ export class DockerHubRepositoryNode extends NodeBase { async getChildren(element: DockerHubRepositoryNode): Promise { const imageNodes: DockerHubImageNode[] = []; let node: DockerHubImageNode; - let created: string = ''; const myTags: dockerHub.Tag[] = await dockerHub.getRepositoryTags({namespace: element.repository.namespace, name: element.repository.name}); for (let i = 0; i < myTags.length; i++) { - created = moment(new Date(myTags[i].last_updated)).fromNow(); - node = new DockerHubImageNode(`${element.repository.name}:${myTags[i].name} (${created})`, 'dockerHubImageTag'); + node = new DockerHubImageNode(`${element.repository.name}:${myTags[i].name}`, 'dockerHubImageTag'); node.password = element.password; node.userName = element.userName; node.repository = element.repository; + node.created = moment(new Date(myTags[i].last_updated)).fromNow();; imageNodes.push(node); } @@ -109,10 +108,15 @@ export class DockerHubImageNode extends NodeBase { public userName: string; public password: string; public repository: any; + public created: string; getTreeItem(): vscode.TreeItem { + let displayName: string = this.label; + + displayName = `${displayName} (${this.created})`; + return { - label: this.label, + label: `${displayName}`, collapsibleState: vscode.TreeItemCollapsibleState.None, contextValue: this.contextValue }