* Delete stored procedures

* Optimize tree picking

* fix

* fix
This commit is contained in:
Stephen Weatherford (MSFT) 2018-04-02 17:31:22 -07:00 коммит произвёл GitHub
Родитель 0ca7e6320f
Коммит be4bb373a4
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
5 изменённых файлов: 55 добавлений и 10 удалений

Просмотреть файл

@ -243,6 +243,11 @@
"command": "cosmosDB.deleteDocDBDocument",
"title": "Delete Document"
},
{
"category": "Cosmos DB",
"command": "cosmosDB.deleteStoredProcedure",
"title": "Delete Stored Procedure"
},
{
"category": "Cosmos DB",
"command": "cosmosDB.newMongoScrapbook",
@ -475,6 +480,10 @@
"command": "cosmosDB.deleteDocDBDocument",
"when": "view == cosmosDBExplorer && viewItem == cosmosDBDocument"
},
{
"command": "cosmosDB.deleteStoredProcedure",
"when": "view == cosmosDBExplorer && viewItem == cosmosDBStoredProcedure"
},
{
"command": "cosmosDB.deleteDocDBDatabase",
"when": "view == cosmosDBExplorer && viewItem == cosmosDBDocumentDatabase"

Просмотреть файл

@ -9,6 +9,7 @@ import { DocDBAccountTreeItem } from "./tree/DocDBAccountTreeItem";
import { DocDBCollectionTreeItem } from "./tree/DocDBCollectionTreeItem";
import { DocDBDocumentTreeItem } from "./tree/DocDBDocumentTreeItem";
import { DocDBDocumentsTreeItem } from "./tree/DocDBDocumentsTreeItem";
import { DocDBStoredProcedureTreeItem } from "./tree/DocDBStoredProcedureTreeItem";
export function registerDocDBCommands(actionHandler: AzureActionHandler, tree: AzureTreeDataProvider): void {
actionHandler.registerCommand('cosmosDB.createDocDBDatabase', async (node?: IAzureParentNode) => {
@ -48,4 +49,10 @@ export function registerDocDBCommands(actionHandler: AzureActionHandler, tree: A
}
await node.deleteNode();
});
actionHandler.registerCommand('cosmosDB.deleteStoredProcedure', async (node?: IAzureNode) => {
if (!node) {
node = await tree.showNodePicker(DocDBStoredProcedureTreeItem.contextValue);
}
await node.deleteNode();
});
}

Просмотреть файл

@ -11,6 +11,8 @@ import { getDocumentClient } from "../getDocumentClient";
import { DocDBDocumentsTreeItem } from './DocDBDocumentsTreeItem';
import * as path from "path";
import { DialogBoxResponses } from '../../constants';
import { DocDBStoredProcedureTreeItem } from './DocDBStoredProcedureTreeItem';
import { DocDBDocumentTreeItem } from './DocDBDocumentTreeItem';
/**
* Represents a DocumentDB collection
@ -19,7 +21,8 @@ export class DocDBCollectionTreeItem implements IAzureParentTreeItem {
public static contextValue: string = "cosmosDBDocumentCollection";
public readonly contextValue: string = DocDBCollectionTreeItem.contextValue;
private readonly _children: IAzureTreeItem[];
private readonly _documentsTreeItem: DocDBDocumentsTreeItem;
private readonly _storedProceduresTreeItem: DocDBStoredProceduresTreeItem;
constructor(
private _documentEndpoint: string,
@ -27,10 +30,8 @@ export class DocDBCollectionTreeItem implements IAzureParentTreeItem {
private _collection: CollectionMeta,
private _isEmulator: boolean) {
this._children = [
new DocDBDocumentsTreeItem(this._documentEndpoint, this._masterKey, this, this._isEmulator),
new DocDBStoredProceduresTreeItem(this._documentEndpoint, this._masterKey, this._collection, this._isEmulator)
];
this._documentsTreeItem = new DocDBDocumentsTreeItem(this._documentEndpoint, this._masterKey, this, this._isEmulator);
this._storedProceduresTreeItem = new DocDBStoredProceduresTreeItem(this._documentEndpoint, this._masterKey, this._collection, this._isEmulator);
}
public get id(): string {
@ -49,7 +50,7 @@ export class DocDBCollectionTreeItem implements IAzureParentTreeItem {
}
public async loadMoreChildren(node: IAzureNode<IAzureTreeItem>, clearCache: boolean): Promise<IAzureTreeItem[]> {
return this._children;
return [this._documentsTreeItem, this._storedProceduresTreeItem];
}
public hasMoreChildren(): boolean {
@ -84,6 +85,17 @@ export class DocDBCollectionTreeItem implements IAzureParentTreeItem {
}
public pickTreeItem?(expectedContextValue: string): IAzureTreeItem | undefined {
return this._children.find(node => node.contextValue === expectedContextValue);
switch (expectedContextValue) {
case DocDBDocumentsTreeItem.contextValue:
case DocDBDocumentTreeItem.contextValue:
return this._documentsTreeItem;
case DocDBStoredProceduresTreeItem.contextValue:
case DocDBStoredProcedureTreeItem.contextValue:
return this._storedProceduresTreeItem;
default:
return undefined;
}
}
}

Просмотреть файл

@ -5,8 +5,10 @@
import * as path from 'path';
import * as vscode from "vscode";
import { IAzureTreeItem } from 'vscode-azureextensionui';
import { IAzureTreeItem, IAzureNode, UserCancelledError } from 'vscode-azureextensionui';
import { ProcedureMeta } from 'documentdb';
import { DialogBoxResponses } from '../../constants';
import { getDocumentClient } from '../getDocumentClient';
/**
* Represents a Cosmos DB DocumentDB (SQL) stored procedure
@ -15,7 +17,7 @@ export class DocDBStoredProcedureTreeItem implements IAzureTreeItem {
public static contextValue: string = "cosmosDBStoredProcedure";
public readonly contextValue: string = DocDBStoredProcedureTreeItem.contextValue;
constructor(private _procedure: ProcedureMeta) {
constructor(private _documentEndpoint: string, private _masterKey: string, private _isEmulator: boolean, private _procedure: ProcedureMeta) {
}
public get id(): string {
@ -36,4 +38,19 @@ export class DocDBStoredProcedureTreeItem implements IAzureTreeItem {
dark: path.join(__filename, '..', '..', '..', '..', '..', 'resources', 'icons', 'dark', 'Process_16x.svg')
};
}
public async deleteTreeItem(_node: IAzureNode): Promise<void> {
const message: string = `Are you sure you want to delete stored procedure '${this.label}'?`;
const result = await vscode.window.showWarningMessage(message, DialogBoxResponses.Yes, DialogBoxResponses.Cancel);
if (result === DialogBoxResponses.Yes) {
const client = getDocumentClient(this._documentEndpoint, this._masterKey, this._isEmulator);
await new Promise((resolve, reject) => {
client.deleteStoredProcedure(this.link, function (err) {
err ? reject(err) : resolve();
});
});
} else {
throw new UserCancelledError();
}
}
}

Просмотреть файл

@ -23,7 +23,7 @@ export class DocDBStoredProceduresTreeItem extends DocDBTreeItemBase<ProcedureMe
}
public initChild(resource: ProcedureMeta): IAzureTreeItem {
return new DocDBStoredProcedureTreeItem(resource);
return new DocDBStoredProcedureTreeItem(this.documentEndpoint, this.masterKey, this.isEmulator, resource);
}
public get iconPath(): string | vscode.Uri | { light: string | vscode.Uri; dark: string | vscode.Uri } {