create tag and pick folder

This commit is contained in:
alexweininger 2021-05-29 10:08:32 -05:00
parent 83091e74bb
commit 1a115dfa68
4 changed files with 116 additions and 5 deletions

View file

@ -555,6 +555,11 @@
"command": "vscode-appwrite.openFunctionSettingsInBrowser",
"when": "viewItem =~ /^functionSettings$/",
"group": "inline"
},
{
"command": "vscode-appwrite.CreateTag",
"when": "viewItem =~ /^tags$/",
"group": "inline"
}
],
"explorer/context": [

View file

@ -1,10 +1,29 @@
import { Uri } from "vscode";
import { ProgressLocation, Uri, window } from "vscode";
import { functionsClient, storageClient } from "../../client";
import { getTarReadStream } from "../../utils/tar";
import { ext } from "../../extensionVariables";
import * as fs from "fs";
export async function createTag(folder: Uri): Promise<void> {
const tarFilePath = await getTarReadStream(folder);
import { TagsTreeItem } from "../../tree/functions/tags/TagsTreeItem";
import { selectWorkspaceFolder } from "../../utils/workspace";
export async function createTag(item: TagsTreeItem | Uri): Promise<void> {
if (item instanceof Uri) {
window.withProgress({ location: ProgressLocation.Notification, title: "Creating tag..." }, async (progress, token) => {
await createTagFromUri(item);
});
return;
}
if (item instanceof TagsTreeItem) {
const folder = await selectWorkspaceFolder("Select folder of your function code.");
console.log(folder);
window.withProgress({ location: ProgressLocation.Notification, title: "Creating tag..." }, async (progress, token) => {
await createTagFromUri(Uri.parse(folder));
});
}
}
async function createTagFromUri(uri: Uri): Promise<void> {
const tarFilePath = await getTarReadStream(uri);
if (functionsClient === undefined) {
return;
}

View file

@ -1,5 +1,6 @@
import { ThemeIcon, TreeItem } from "vscode";
import { MarkdownString, ThemeIcon, TreeItem } from "vscode";
import { Tag } from '../../../appwrite';
import { msToDate } from '../../../utils/date';
import { TagsTreeItem } from './TagsTreeItem';
export class TagTreeItem extends TreeItem {
@ -7,8 +8,10 @@ export class TagTreeItem extends TreeItem {
super(tag.$id);
const func = parent.parent.func;
const active = func.tag === tag.$id;
this.label = `${tag.$id}${active ? ' (Active)' : ''}`;
this.label = `${msToDate(tag.dateCreated)}${active ? ' (Active)' : ''}`;
this.description = tag.$id;
this.iconPath = new ThemeIcon(active ? 'circle-filled' : 'circle-outline');
this.contextValue = `tag${active ? '_active' : ''}`;
this.tooltip = new MarkdownString(`ID: ${tag.$id} \nCreated: ${msToDate(tag.dateCreated)} \nCommand: ${tag.command} \nSize: ${tag.size}B`);
}
}

84
src/utils/workspace.ts Normal file
View file

@ -0,0 +1,84 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as path from "path";
import * as vscode from "vscode";
import { QuickPickItem } from 'vscode';
export interface IAzureQuickPickItem<T = undefined> extends QuickPickItem {
/**
* An optional id to uniquely identify this item across sessions, used in persisting previous selections
* If not specified, a hash of the label will be used
*/
id?: string;
data: T;
/**
* Callback to use when this item is picked, instead of returning the pick
* Only applies when used as part of an `AzureWizard`
* This is not compatible with `canPickMany`
*/
onPicked?: () => void | Promise<void>;
/**
* The group that this pick belongs to. Set `IAzureQuickPickOptions.enableGrouping` for this property to take effect
* Only applies when used as part of an `AzureWizard`
*/
group?: string;
/**
* Optionally used to suppress persistence for this item, defaults to `false`
*/
suppressPersistence?: boolean;
}
export async function selectWorkspaceFolder(placeHolder: string): Promise<string> {
return await selectWorkspaceItem(placeHolder, {
canSelectFiles: false,
canSelectFolders: true,
canSelectMany: false,
defaultUri:
vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders.length > 0
? vscode.workspace.workspaceFolders[0].uri
: undefined,
openLabel: "Select",
});
}
export async function selectWorkspaceFile(placeHolder: string, fileExtensions?: string[]): Promise<string> {
const filters: { [name: string]: string[] } = {};
if (fileExtensions) {
filters.Artifacts = fileExtensions;
}
return await selectWorkspaceItem(placeHolder, {
canSelectFiles: true,
canSelectFolders: false,
canSelectMany: false,
openLabel: "Select",
filters: filters,
});
}
export async function selectWorkspaceItem(placeHolder: string, options: vscode.OpenDialogOptions): Promise<string> {
let folder: IAzureQuickPickItem<string | undefined> | undefined;
if (vscode.workspace.workspaceFolders) {
const folderPicks: IAzureQuickPickItem<string | undefined>[] = await Promise.all(
vscode.workspace.workspaceFolders.map((f: vscode.WorkspaceFolder) => {
return { label: path.basename(f.uri.fsPath), description: f.uri.fsPath, data: f.uri.fsPath };
})
);
folderPicks.push({ label: "$(file-directory) Browse...", description: "", data: undefined });
folder = await vscode.window.showQuickPick(folderPicks, { placeHolder });
}
if (folder?.data) {
return folder.data;
} else {
return (await vscode.window.showOpenDialog(options))?.[0].fsPath ?? '';
}
}