2020-05-25 21:30:55 -05:00
|
|
|
import * as ko from "knockout";
|
|
|
|
import * as ViewModels from "../Contracts/ViewModels";
|
|
|
|
import { TreeNodeMenuItem } from "./Controls/TreeComponent/TreeComponent";
|
|
|
|
import AddCollectionIcon from "../../images/AddCollection.svg";
|
|
|
|
import AddSqlQueryIcon from "../../images/AddSqlQuery_16x16.svg";
|
|
|
|
import HostedTerminalIcon from "../../images/Hosted-Terminal.svg";
|
|
|
|
import AddStoredProcedureIcon from "../../images/AddStoredProcedure.svg";
|
|
|
|
import DeleteCollectionIcon from "../../images/DeleteCollection.svg";
|
|
|
|
import DeleteDatabaseIcon from "../../images/DeleteDatabase.svg";
|
|
|
|
import AddUdfIcon from "../../images/AddUdf.svg";
|
|
|
|
import AddTriggerIcon from "../../images/AddTrigger.svg";
|
|
|
|
import DeleteTriggerIcon from "../../images/DeleteTrigger.svg";
|
|
|
|
import DeleteUDFIcon from "../../images/DeleteUDF.svg";
|
|
|
|
import DeleteSprocIcon from "../../images/DeleteSproc.svg";
|
2020-07-20 12:59:40 -05:00
|
|
|
import Explorer from "./Explorer";
|
2020-05-25 21:30:55 -05:00
|
|
|
|
|
|
|
export interface CollectionContextMenuButtonParams {
|
|
|
|
databaseId: string;
|
|
|
|
collectionId: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface DatabaseContextMenuButtonParams {
|
|
|
|
databaseId: string;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* New resource tree (in ReactJS)
|
|
|
|
*/
|
|
|
|
export class ResourceTreeContextMenuButtonFactory {
|
|
|
|
public static createDatabaseContextMenu(
|
2020-07-20 12:59:40 -05:00
|
|
|
container: Explorer,
|
2020-05-25 21:30:55 -05:00
|
|
|
selectedDatabase: ViewModels.Database
|
|
|
|
): TreeNodeMenuItem[] {
|
|
|
|
const newCollectionMenuItem: TreeNodeMenuItem = {
|
|
|
|
iconSrc: AddCollectionIcon,
|
|
|
|
onClick: () => container.onNewCollectionClicked(),
|
|
|
|
label: container.addCollectionText()
|
|
|
|
};
|
|
|
|
|
|
|
|
const deleteDatabaseMenuItem = {
|
|
|
|
iconSrc: DeleteDatabaseIcon,
|
|
|
|
onClick: () => container.deleteDatabaseConfirmationPane.open(),
|
|
|
|
label: container.deleteDatabaseText()
|
|
|
|
};
|
|
|
|
return [newCollectionMenuItem, deleteDatabaseMenuItem];
|
|
|
|
}
|
|
|
|
|
|
|
|
public static createCollectionContextMenuButton(
|
2020-07-20 12:59:40 -05:00
|
|
|
container: Explorer,
|
2020-05-25 21:30:55 -05:00
|
|
|
selectedCollection: ViewModels.Collection
|
|
|
|
): TreeNodeMenuItem[] {
|
|
|
|
const items: TreeNodeMenuItem[] = [];
|
|
|
|
if (container.isPreferredApiDocumentDB() || container.isPreferredApiGraph()) {
|
|
|
|
items.push({
|
|
|
|
iconSrc: AddSqlQueryIcon,
|
|
|
|
onClick: () => selectedCollection && selectedCollection.onNewQueryClick(selectedCollection, null),
|
|
|
|
label: "New SQL Query"
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (container.isPreferredApiMongoDB()) {
|
|
|
|
items.push({
|
|
|
|
iconSrc: AddSqlQueryIcon,
|
|
|
|
onClick: () => selectedCollection && selectedCollection.onNewMongoQueryClick(selectedCollection, null),
|
|
|
|
label: "New Query"
|
|
|
|
});
|
|
|
|
|
|
|
|
items.push({
|
|
|
|
iconSrc: HostedTerminalIcon,
|
|
|
|
onClick: () => {
|
|
|
|
const selectedCollection: ViewModels.Collection = container.findSelectedCollection();
|
|
|
|
selectedCollection && selectedCollection.onNewMongoShellClick();
|
|
|
|
},
|
|
|
|
label: "New Shell"
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (container.isPreferredApiDocumentDB() || container.isPreferredApiGraph()) {
|
|
|
|
items.push({
|
|
|
|
iconSrc: AddStoredProcedureIcon,
|
|
|
|
onClick: () => {
|
|
|
|
const selectedCollection: ViewModels.Collection = container.findSelectedCollection();
|
|
|
|
selectedCollection && selectedCollection.onNewStoredProcedureClick(selectedCollection, null);
|
|
|
|
},
|
|
|
|
label: "New Stored Procedure"
|
|
|
|
});
|
|
|
|
|
|
|
|
items.push({
|
|
|
|
iconSrc: AddUdfIcon,
|
|
|
|
onClick: () => {
|
|
|
|
const selectedCollection: ViewModels.Collection = container.findSelectedCollection();
|
|
|
|
selectedCollection && selectedCollection.onNewUserDefinedFunctionClick(selectedCollection, null);
|
|
|
|
},
|
|
|
|
label: "New UDF"
|
|
|
|
});
|
|
|
|
|
|
|
|
items.push({
|
|
|
|
iconSrc: AddTriggerIcon,
|
|
|
|
onClick: () => {
|
|
|
|
const selectedCollection: ViewModels.Collection = container.findSelectedCollection();
|
|
|
|
selectedCollection && selectedCollection.onNewTriggerClick(selectedCollection, null);
|
|
|
|
},
|
|
|
|
label: "New Trigger"
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
items.push({
|
|
|
|
iconSrc: DeleteCollectionIcon,
|
|
|
|
onClick: () => {
|
|
|
|
const selectedCollection: ViewModels.Collection = container.findSelectedCollection();
|
|
|
|
selectedCollection && selectedCollection.onDeleteCollectionContextMenuClick(selectedCollection, null);
|
|
|
|
},
|
|
|
|
label: container.deleteCollectionText()
|
|
|
|
});
|
|
|
|
|
|
|
|
return items;
|
|
|
|
}
|
|
|
|
|
2020-06-15 12:16:52 +02:00
|
|
|
public static createStoreProcedureContextMenuItems(
|
2020-07-20 12:59:40 -05:00
|
|
|
container: Explorer,
|
2020-06-15 12:16:52 +02:00
|
|
|
storedProcedure: ViewModels.StoredProcedure
|
|
|
|
): TreeNodeMenuItem[] {
|
2020-05-25 21:30:55 -05:00
|
|
|
if (container.isPreferredApiCassandra()) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
return [
|
|
|
|
{
|
|
|
|
iconSrc: DeleteSprocIcon,
|
2020-06-15 12:16:52 +02:00
|
|
|
onClick: () => storedProcedure.delete(),
|
2020-05-25 21:30:55 -05:00
|
|
|
label: "Delete Store Procedure"
|
|
|
|
}
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2020-07-20 12:59:40 -05:00
|
|
|
public static createTriggerContextMenuItems(container: Explorer, trigger: ViewModels.Trigger): TreeNodeMenuItem[] {
|
2020-05-25 21:30:55 -05:00
|
|
|
if (container.isPreferredApiCassandra()) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
return [
|
|
|
|
{
|
|
|
|
iconSrc: DeleteTriggerIcon,
|
2020-06-15 12:16:52 +02:00
|
|
|
onClick: () => trigger.delete(),
|
2020-05-25 21:30:55 -05:00
|
|
|
label: "Delete Trigger"
|
|
|
|
}
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2020-06-15 12:16:52 +02:00
|
|
|
public static createUserDefinedFunctionContextMenuItems(
|
2020-07-20 12:59:40 -05:00
|
|
|
container: Explorer,
|
2020-06-15 12:16:52 +02:00
|
|
|
userDefinedFunction: ViewModels.UserDefinedFunction
|
|
|
|
): TreeNodeMenuItem[] {
|
2020-05-25 21:30:55 -05:00
|
|
|
if (container.isPreferredApiCassandra()) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
return [
|
|
|
|
{
|
|
|
|
iconSrc: DeleteUDFIcon,
|
2020-06-15 12:16:52 +02:00
|
|
|
onClick: () => userDefinedFunction.delete(),
|
2020-05-25 21:30:55 -05:00
|
|
|
label: "Delete User Defined Function"
|
|
|
|
}
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|