mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-19 17:01:13 +00:00
Split all script data access methods (#197)
* Split all script data access methods * More cleanup * Fix Typo
This commit is contained in:
@@ -1,15 +1,14 @@
|
||||
import * as Constants from "../../Common/Constants";
|
||||
import * as ko from "knockout";
|
||||
import * as monaco from "monaco-editor";
|
||||
import Q from "q";
|
||||
|
||||
import DiscardIcon from "../../../images/discard.svg";
|
||||
import SaveIcon from "../../../images/save-cosmos.svg";
|
||||
import * as Constants from "../../Common/Constants";
|
||||
import editable from "../../Common/EditableUtility";
|
||||
import * as DataModels from "../../Contracts/DataModels";
|
||||
import * as ViewModels from "../../Contracts/ViewModels";
|
||||
import TabsBase from "./TabsBase";
|
||||
import editable from "../../Common/EditableUtility";
|
||||
import * as monaco from "monaco-editor";
|
||||
import SaveIcon from "../../../images/save-cosmos.svg";
|
||||
import DiscardIcon from "../../../images/discard.svg";
|
||||
import { CommandButtonComponentProps } from "../Controls/CommandButton/CommandButtonComponent";
|
||||
import TabsBase from "./TabsBase";
|
||||
|
||||
export default abstract class ScriptTabBase extends TabsBase implements ViewModels.WaitsForTemplate {
|
||||
public ariaLabel: ko.Observable<string>;
|
||||
@@ -30,7 +29,8 @@ export default abstract class ScriptTabBase extends TabsBase implements ViewMode
|
||||
public formIsValid: ko.Computed<boolean>;
|
||||
public formIsDirty: ko.Computed<boolean>;
|
||||
public isNew: ko.Observable<boolean>;
|
||||
public resource: ko.Observable<DataModels.Script>;
|
||||
// TODO: Remove any. The SDK types for all the script.body are slightly incorrect which makes this REALLY hard to type correct.
|
||||
public resource: ko.Observable<any>;
|
||||
public isTemplateReady: ko.Observable<boolean>;
|
||||
protected _partitionKey: DataModels.PartitionKey;
|
||||
|
||||
@@ -194,8 +194,8 @@ export default abstract class ScriptTabBase extends TabsBase implements ViewMode
|
||||
});
|
||||
}
|
||||
|
||||
public abstract onSaveClick: () => Q.Promise<any>;
|
||||
public abstract onUpdateClick: () => Q.Promise<any>;
|
||||
public abstract onSaveClick: () => Promise<any>;
|
||||
public abstract onUpdateClick: () => Promise<any>;
|
||||
|
||||
public onDiscard = (): Q.Promise<any> => {
|
||||
this.setBaselines();
|
||||
@@ -206,14 +206,14 @@ export default abstract class ScriptTabBase extends TabsBase implements ViewMode
|
||||
return Q();
|
||||
};
|
||||
|
||||
public onSaveOrUpdateClick(): Q.Promise<any> {
|
||||
public onSaveOrUpdateClick(): Promise<any> {
|
||||
if (this.saveButton.visible()) {
|
||||
return this.onSaveClick();
|
||||
} else if (this.updateButton.visible()) {
|
||||
return this.onUpdateClick();
|
||||
}
|
||||
|
||||
return Q();
|
||||
return undefined;
|
||||
}
|
||||
|
||||
protected getTabsButtons(): CommandButtonComponentProps[] {
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
import { Resource, StoredProcedureDefinition } from "@azure/cosmos";
|
||||
import * as ko from "knockout";
|
||||
import * as _ from "underscore";
|
||||
import Q from "q";
|
||||
import * as _ from "underscore";
|
||||
import ExecuteQueryIcon from "../../../images/ExecuteQuery.svg";
|
||||
import * as Constants from "../../Common/Constants";
|
||||
import * as DataModels from "../../Contracts/DataModels";
|
||||
import { createStoredProcedure } from "../../Common/dataAccess/createStoredProcedure";
|
||||
import { updateStoredProcedure } from "../../Common/dataAccess/updateStoredProcedure";
|
||||
import editable from "../../Common/EditableUtility";
|
||||
import * as ViewModels from "../../Contracts/ViewModels";
|
||||
import { Action } from "../../Shared/Telemetry/TelemetryConstants";
|
||||
import editable from "../../Common/EditableUtility";
|
||||
import ScriptTabBase from "./ScriptTabBase";
|
||||
import * as TelemetryProcessor from "../../Shared/Telemetry/TelemetryProcessor";
|
||||
import ExecuteQueryIcon from "../../../images/ExecuteQuery.svg";
|
||||
import StoredProcedure from "../Tree/StoredProcedure";
|
||||
import { createStoredProcedure, updateStoredProcedure } from "../../Common/DocumentClientUtilityBase";
|
||||
import { CommandButtonComponentProps } from "../Controls/CommandButton/CommandButtonComponent";
|
||||
import StoredProcedure from "../Tree/StoredProcedure";
|
||||
import ScriptTabBase from "./ScriptTabBase";
|
||||
|
||||
enum ToggleState {
|
||||
Result = "result",
|
||||
@@ -24,7 +25,6 @@ export default class StoredProcedureTab extends ScriptTabBase {
|
||||
public executeResultsEditorId: string;
|
||||
public executeLogsEditorId: string;
|
||||
public toggleState: ko.Observable<ToggleState>;
|
||||
|
||||
public originalSprocBody: ViewModels.Editable<string>;
|
||||
public resultsData: ko.Observable<string>;
|
||||
public logsData: ko.Observable<string>;
|
||||
@@ -54,13 +54,11 @@ export default class StoredProcedureTab extends ScriptTabBase {
|
||||
this.buildCommandBarOptions();
|
||||
}
|
||||
|
||||
public onSaveClick = (): Q.Promise<DataModels.StoredProcedure> => {
|
||||
const resource: DataModels.StoredProcedure = <DataModels.StoredProcedure>{
|
||||
public onSaveClick = (): Promise<StoredProcedureDefinition & Resource> => {
|
||||
return this._createStoredProcedure({
|
||||
id: this.id(),
|
||||
body: this.editorContent()
|
||||
};
|
||||
|
||||
return this._createStoredProcedure(resource);
|
||||
});
|
||||
};
|
||||
|
||||
public onDiscard = (): Q.Promise<any> => {
|
||||
@@ -72,8 +70,8 @@ export default class StoredProcedureTab extends ScriptTabBase {
|
||||
return Q();
|
||||
};
|
||||
|
||||
public onUpdateClick = (): Q.Promise<any> => {
|
||||
const data: DataModels.StoredProcedure = this._getResource();
|
||||
public onUpdateClick = (): Promise<any> => {
|
||||
const data = this._getResource();
|
||||
|
||||
this.isExecutionError(false);
|
||||
this.isExecuting(true);
|
||||
@@ -83,18 +81,18 @@ export default class StoredProcedureTab extends ScriptTabBase {
|
||||
dataExplorerArea: Constants.Areas.Tab,
|
||||
tabTitle: this.tabTitle()
|
||||
});
|
||||
return updateStoredProcedure(this.collection, data)
|
||||
return updateStoredProcedure(this.collection.databaseId, this.collection.id(), data)
|
||||
.then(
|
||||
(updatedResource: DataModels.StoredProcedure) => {
|
||||
updatedResource => {
|
||||
this.resource(updatedResource);
|
||||
this.tabTitle(updatedResource.id);
|
||||
this.node.id(updatedResource.id);
|
||||
this.node.body(updatedResource.body);
|
||||
this.node.body(updatedResource.body as string);
|
||||
this.setBaselines();
|
||||
|
||||
const editorModel = this.editor() && this.editor().getModel();
|
||||
editorModel && editorModel.setValue(updatedResource.body);
|
||||
this.editorContent.setBaseline(updatedResource.body);
|
||||
editorModel && editorModel.setValue(updatedResource.body as string);
|
||||
this.editorContent.setBaseline(updatedResource.body as string);
|
||||
TelemetryProcessor.traceSuccess(
|
||||
Action.UpdateStoredProcedure,
|
||||
{
|
||||
@@ -220,18 +218,14 @@ export default class StoredProcedureTab extends ScriptTabBase {
|
||||
});
|
||||
}
|
||||
|
||||
private _getResource(): DataModels.StoredProcedure {
|
||||
const resource: DataModels.StoredProcedure = <DataModels.StoredProcedure>{
|
||||
_rid: this.resource()._rid,
|
||||
_self: this.resource()._self,
|
||||
private _getResource() {
|
||||
return {
|
||||
id: this.id(),
|
||||
body: this.editorContent()
|
||||
};
|
||||
|
||||
return resource;
|
||||
}
|
||||
|
||||
private _createStoredProcedure(resource: DataModels.StoredProcedure): Q.Promise<DataModels.StoredProcedure> {
|
||||
private _createStoredProcedure(resource: StoredProcedureDefinition): Promise<StoredProcedureDefinition & Resource> {
|
||||
this.isExecutionError(false);
|
||||
this.isExecuting(true);
|
||||
const startKey: number = TelemetryProcessor.traceStart(Action.CreateStoredProcedure, {
|
||||
@@ -241,7 +235,7 @@ export default class StoredProcedureTab extends ScriptTabBase {
|
||||
tabTitle: this.tabTitle()
|
||||
});
|
||||
|
||||
return createStoredProcedure(this.collection, resource)
|
||||
return createStoredProcedure(this.collection.databaseId, this.collection.id(), resource)
|
||||
.then(
|
||||
createdResource => {
|
||||
this.tabTitle(createdResource.id);
|
||||
@@ -256,8 +250,8 @@ export default class StoredProcedureTab extends ScriptTabBase {
|
||||
this.setBaselines();
|
||||
|
||||
const editorModel = this.editor() && this.editor().getModel();
|
||||
editorModel && editorModel.setValue(createdResource.body);
|
||||
this.editorContent.setBaseline(createdResource.body);
|
||||
editorModel && editorModel.setValue(createdResource.body as string);
|
||||
this.editorContent.setBaseline(createdResource.body as string);
|
||||
this.node = this.collection.createStoredProcedureNode(createdResource);
|
||||
TelemetryProcessor.traceSuccess(
|
||||
Action.CreateStoredProcedure,
|
||||
@@ -284,7 +278,7 @@ export default class StoredProcedureTab extends ScriptTabBase {
|
||||
},
|
||||
startKey
|
||||
);
|
||||
return Q.reject(createError);
|
||||
return Promise.reject(createError);
|
||||
}
|
||||
)
|
||||
.finally(() => this.isExecuting(false));
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import Q from "q";
|
||||
import { Resource, TriggerDefinition, TriggerOperation, TriggerType } from "@azure/cosmos";
|
||||
import * as Constants from "../../Common/Constants";
|
||||
import * as DataModels from "../../Contracts/DataModels";
|
||||
import { createTrigger } from "../../Common/dataAccess/createTrigger";
|
||||
import { updateTrigger } from "../../Common/dataAccess/updateTrigger";
|
||||
import editable from "../../Common/EditableUtility";
|
||||
import * as ViewModels from "../../Contracts/ViewModels";
|
||||
import { Action } from "../../Shared/Telemetry/TelemetryConstants";
|
||||
import ScriptTabBase from "./ScriptTabBase";
|
||||
import editable from "../../Common/EditableUtility";
|
||||
import * as TelemetryProcessor from "../../Shared/Telemetry/TelemetryProcessor";
|
||||
import Trigger from "../Tree/Trigger";
|
||||
import { createTrigger, updateTrigger } from "../../Common/DocumentClientUtilityBase";
|
||||
import ScriptTabBase from "./ScriptTabBase";
|
||||
|
||||
export default class TriggerTab extends ScriptTabBase {
|
||||
public collection: ViewModels.Collection;
|
||||
@@ -27,13 +27,17 @@ export default class TriggerTab extends ScriptTabBase {
|
||||
super.buildCommandBarOptions();
|
||||
}
|
||||
|
||||
public onSaveClick = (): Q.Promise<DataModels.Trigger> => {
|
||||
const data: DataModels.Trigger = this._getResource();
|
||||
return this._createTrigger(data);
|
||||
public onSaveClick = (): Promise<TriggerDefinition & Resource> => {
|
||||
return this._createTrigger({
|
||||
id: this.id(),
|
||||
body: this.editorContent(),
|
||||
triggerOperation: this.triggerOperation() as TriggerOperation,
|
||||
triggerType: this.triggerType() as TriggerType
|
||||
});
|
||||
};
|
||||
|
||||
public onUpdateClick = (): Q.Promise<any> => {
|
||||
const data: DataModels.Trigger = this._getResource();
|
||||
public onUpdateClick = (): Promise<any> => {
|
||||
const data = this._getResource();
|
||||
this.isExecutionError(false);
|
||||
this.isExecuting(true);
|
||||
const startKey: number = TelemetryProcessor.traceStart(Action.UpdateTrigger, {
|
||||
@@ -42,14 +46,19 @@ export default class TriggerTab extends ScriptTabBase {
|
||||
tabTitle: this.tabTitle()
|
||||
});
|
||||
|
||||
return updateTrigger(this.collection, data)
|
||||
return updateTrigger(this.collection.databaseId, this.collection.id(), {
|
||||
id: this.id(),
|
||||
body: this.editorContent(),
|
||||
triggerOperation: this.triggerOperation() as TriggerOperation,
|
||||
triggerType: this.triggerType() as TriggerType
|
||||
})
|
||||
.then(
|
||||
(createdResource: DataModels.Trigger) => {
|
||||
createdResource => {
|
||||
this.resource(createdResource);
|
||||
this.tabTitle(createdResource.id);
|
||||
|
||||
this.node.id(createdResource.id);
|
||||
this.node.body(createdResource.body);
|
||||
this.node.body(createdResource.body as string);
|
||||
this.node.triggerType(createdResource.triggerOperation);
|
||||
this.node.triggerOperation(createdResource.triggerOperation);
|
||||
TelemetryProcessor.traceSuccess(
|
||||
@@ -66,8 +75,8 @@ export default class TriggerTab extends ScriptTabBase {
|
||||
this.setBaselines();
|
||||
|
||||
const editorModel = this.editor().getModel();
|
||||
editorModel.setValue(createdResource.body);
|
||||
this.editorContent.setBaseline(createdResource.body);
|
||||
editorModel.setValue(createdResource.body as string);
|
||||
this.editorContent.setBaseline(createdResource.body as string);
|
||||
},
|
||||
(createError: any) => {
|
||||
this.isExecutionError(true);
|
||||
@@ -89,7 +98,7 @@ export default class TriggerTab extends ScriptTabBase {
|
||||
public setBaselines() {
|
||||
super.setBaselines();
|
||||
|
||||
const resource = <DataModels.Trigger>this.resource();
|
||||
const resource = this.resource();
|
||||
this.triggerOperation.setBaseline(resource.triggerOperation);
|
||||
this.triggerType.setBaseline(resource.triggerType);
|
||||
}
|
||||
@@ -109,7 +118,7 @@ export default class TriggerTab extends ScriptTabBase {
|
||||
}
|
||||
}
|
||||
|
||||
private _createTrigger(resource: DataModels.Trigger): Q.Promise<DataModels.Trigger> {
|
||||
private _createTrigger(resource: TriggerDefinition): Promise<TriggerDefinition & Resource> {
|
||||
this.isExecutionError(false);
|
||||
this.isExecuting(true);
|
||||
const startKey: number = TelemetryProcessor.traceStart(Action.CreateTrigger, {
|
||||
@@ -119,9 +128,9 @@ export default class TriggerTab extends ScriptTabBase {
|
||||
tabTitle: this.tabTitle()
|
||||
});
|
||||
|
||||
return createTrigger(this.collection, resource)
|
||||
return createTrigger(this.collection.databaseId, this.collection.id(), resource)
|
||||
.then(
|
||||
(createdResource: DataModels.Trigger) => {
|
||||
createdResource => {
|
||||
this.tabTitle(createdResource.id);
|
||||
this.isNew(false);
|
||||
this.resource(createdResource);
|
||||
@@ -134,8 +143,8 @@ export default class TriggerTab extends ScriptTabBase {
|
||||
this.setBaselines();
|
||||
|
||||
const editorModel = this.editor().getModel();
|
||||
editorModel.setValue(createdResource.body);
|
||||
this.editorContent.setBaseline(createdResource.body);
|
||||
editorModel.setValue(createdResource.body as string);
|
||||
this.editorContent.setBaseline(createdResource.body as string);
|
||||
|
||||
this.node = this.collection.createTriggerNode(createdResource);
|
||||
TelemetryProcessor.traceSuccess(
|
||||
@@ -163,22 +172,18 @@ export default class TriggerTab extends ScriptTabBase {
|
||||
},
|
||||
startKey
|
||||
);
|
||||
return Q.reject(createError);
|
||||
return Promise.reject(createError);
|
||||
}
|
||||
)
|
||||
.finally(() => this.isExecuting(false));
|
||||
}
|
||||
|
||||
private _getResource(): DataModels.Trigger {
|
||||
const resource: DataModels.Trigger = <DataModels.Trigger>{
|
||||
_rid: this.resource()._rid,
|
||||
_self: this.resource()._self,
|
||||
private _getResource() {
|
||||
return {
|
||||
id: this.id(),
|
||||
body: this.editorContent(),
|
||||
triggerOperation: this.triggerOperation(),
|
||||
triggerType: this.triggerType()
|
||||
};
|
||||
|
||||
return resource;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import Q from "q";
|
||||
import { Resource, UserDefinedFunctionDefinition } from "@azure/cosmos";
|
||||
import * as Constants from "../../Common/Constants";
|
||||
import * as DataModels from "../../Contracts/DataModels";
|
||||
import { createUserDefinedFunction } from "../../Common/dataAccess/createUserDefinedFunction";
|
||||
import { updateUserDefinedFunction } from "../../Common/dataAccess/updateUserDefinedFunction";
|
||||
import * as ViewModels from "../../Contracts/ViewModels";
|
||||
import { Action } from "../../Shared/Telemetry/TelemetryConstants";
|
||||
import ScriptTabBase from "./ScriptTabBase";
|
||||
import * as TelemetryProcessor from "../../Shared/Telemetry/TelemetryProcessor";
|
||||
import UserDefinedFunction from "../Tree/UserDefinedFunction";
|
||||
import { createUserDefinedFunction, updateUserDefinedFunction } from "../../Common/DocumentClientUtilityBase";
|
||||
import ScriptTabBase from "./ScriptTabBase";
|
||||
|
||||
export default class UserDefinedFunctionTab extends ScriptTabBase {
|
||||
public collection: ViewModels.Collection;
|
||||
@@ -19,13 +19,13 @@ export default class UserDefinedFunctionTab extends ScriptTabBase {
|
||||
super.buildCommandBarOptions();
|
||||
}
|
||||
|
||||
public onSaveClick = (): Q.Promise<DataModels.UserDefinedFunction> => {
|
||||
const data: DataModels.UserDefinedFunction = this._getResource();
|
||||
public onSaveClick = (): Promise<UserDefinedFunctionDefinition & Resource> => {
|
||||
const data = this._getResource();
|
||||
return this._createUserDefinedFunction(data);
|
||||
};
|
||||
|
||||
public onUpdateClick = (): Q.Promise<any> => {
|
||||
const data: DataModels.UserDefinedFunction = this._getResource();
|
||||
public onUpdateClick = (): Promise<any> => {
|
||||
const data = this._getResource();
|
||||
this.isExecutionError(false);
|
||||
this.isExecuting(true);
|
||||
const startKey: number = TelemetryProcessor.traceStart(Action.UpdateUDF, {
|
||||
@@ -35,14 +35,14 @@ export default class UserDefinedFunctionTab extends ScriptTabBase {
|
||||
tabTitle: this.tabTitle()
|
||||
});
|
||||
|
||||
return updateUserDefinedFunction(this.collection, data)
|
||||
return updateUserDefinedFunction(this.collection.databaseId, this.collection.id(), data)
|
||||
.then(
|
||||
(createdResource: DataModels.UserDefinedFunction) => {
|
||||
createdResource => {
|
||||
this.resource(createdResource);
|
||||
this.tabTitle(createdResource.id);
|
||||
|
||||
this.node.id(createdResource.id);
|
||||
this.node.body(createdResource.body);
|
||||
this.node.body(createdResource.body as string);
|
||||
TelemetryProcessor.traceSuccess(
|
||||
Action.UpdateUDF,
|
||||
{
|
||||
@@ -57,8 +57,8 @@ export default class UserDefinedFunctionTab extends ScriptTabBase {
|
||||
this.setBaselines();
|
||||
|
||||
const editorModel = this.editor().getModel();
|
||||
editorModel.setValue(createdResource.body);
|
||||
this.editorContent.setBaseline(createdResource.body);
|
||||
editorModel.setValue(createdResource.body as string);
|
||||
this.editorContent.setBaseline(createdResource.body as string);
|
||||
},
|
||||
(createError: any) => {
|
||||
this.isExecutionError(true);
|
||||
@@ -93,8 +93,8 @@ export default class UserDefinedFunctionTab extends ScriptTabBase {
|
||||
}
|
||||
|
||||
private _createUserDefinedFunction(
|
||||
resource: DataModels.UserDefinedFunction
|
||||
): Q.Promise<DataModels.UserDefinedFunction> {
|
||||
resource: UserDefinedFunctionDefinition
|
||||
): Promise<UserDefinedFunctionDefinition & Resource> {
|
||||
this.isExecutionError(false);
|
||||
this.isExecuting(true);
|
||||
const startKey: number = TelemetryProcessor.traceStart(Action.CreateUDF, {
|
||||
@@ -104,9 +104,9 @@ export default class UserDefinedFunctionTab extends ScriptTabBase {
|
||||
tabTitle: this.tabTitle()
|
||||
});
|
||||
|
||||
return createUserDefinedFunction(this.collection, resource)
|
||||
return createUserDefinedFunction(this.collection.databaseId, this.collection.id(), resource)
|
||||
.then(
|
||||
(createdResource: DataModels.UserDefinedFunction) => {
|
||||
createdResource => {
|
||||
this.tabTitle(createdResource.id);
|
||||
this.isNew(false);
|
||||
this.resource(createdResource);
|
||||
@@ -118,8 +118,8 @@ export default class UserDefinedFunctionTab extends ScriptTabBase {
|
||||
this.setBaselines();
|
||||
|
||||
const editorModel = this.editor().getModel();
|
||||
editorModel.setValue(createdResource.body);
|
||||
this.editorContent.setBaseline(createdResource.body);
|
||||
editorModel.setValue(createdResource.body as string);
|
||||
this.editorContent.setBaseline(createdResource.body as string);
|
||||
|
||||
this.node = this.collection.createUserDefinedFunctionNode(createdResource);
|
||||
TelemetryProcessor.traceSuccess(
|
||||
@@ -147,14 +147,14 @@ export default class UserDefinedFunctionTab extends ScriptTabBase {
|
||||
},
|
||||
startKey
|
||||
);
|
||||
return Q.reject(createError);
|
||||
return Promise.reject(createError);
|
||||
}
|
||||
)
|
||||
.finally(() => this.isExecuting(false));
|
||||
}
|
||||
|
||||
private _getResource() {
|
||||
const resource: DataModels.UserDefinedFunction = <DataModels.UserDefinedFunction>{
|
||||
const resource = {
|
||||
_rid: this.resource()._rid,
|
||||
_self: this.resource()._self,
|
||||
id: this.id(),
|
||||
|
||||
@@ -1,23 +1,28 @@
|
||||
import { Resource, StoredProcedureDefinition, TriggerDefinition, UserDefinedFunctionDefinition } from "@azure/cosmos";
|
||||
import * as ko from "knockout";
|
||||
import Q from "q";
|
||||
import * as _ from "underscore";
|
||||
import UploadWorker from "worker-loader!../../workers/upload";
|
||||
import { AuthType } from "../../AuthType";
|
||||
import * as Constants from "../../Common/Constants";
|
||||
import { readStoredProcedures } from "../../Common/dataAccess/readStoredProcedures";
|
||||
import { readTriggers } from "../../Common/dataAccess/readTriggers";
|
||||
import { readUserDefinedFunctions } from "../../Common/dataAccess/readUserDefinedFunctions";
|
||||
import { createDocument, readCollectionQuotaInfo, readOffer, readOffers } from "../../Common/DocumentClientUtilityBase";
|
||||
import * as Logger from "../../Common/Logger";
|
||||
import { configContext } from "../../ConfigContext";
|
||||
import * as DataModels from "../../Contracts/DataModels";
|
||||
import * as ViewModels from "../../Contracts/ViewModels";
|
||||
import { PlatformType } from "../../PlatformType";
|
||||
import { Action, ActionModifiers } from "../../Shared/Telemetry/TelemetryConstants";
|
||||
import * as TelemetryProcessor from "../../Shared/Telemetry/TelemetryProcessor";
|
||||
import { userContext } from "../../UserContext";
|
||||
import * as NotificationConsoleUtils from "../../Utils/NotificationConsoleUtils";
|
||||
import { OfferUtils } from "../../Utils/OfferUtils";
|
||||
import { StartUploadMessageParams, UploadDetails, UploadDetailsRecord } from "../../workers/upload/definitions";
|
||||
import Explorer from "../Explorer";
|
||||
import { ConsoleDataType } from "../Menus/NotificationConsole/NotificationConsoleComponent";
|
||||
import { CassandraAPIDataClient, CassandraTableKey, CassandraTableKeys } from "../Tables/TableDataClient";
|
||||
import ConflictId from "./ConflictId";
|
||||
|
||||
import DocumentId from "./DocumentId";
|
||||
import ConflictsTab from "../Tabs/ConflictsTab";
|
||||
import DocumentsTab from "../Tabs/DocumentsTab";
|
||||
import GraphTab from "../Tabs/GraphTab";
|
||||
@@ -27,21 +32,11 @@ import MongoShellTab from "../Tabs/MongoShellTab";
|
||||
import QueryTab from "../Tabs/QueryTab";
|
||||
import QueryTablesTab from "../Tabs/QueryTablesTab";
|
||||
import SettingsTab from "../Tabs/SettingsTab";
|
||||
import ConflictId from "./ConflictId";
|
||||
import DocumentId from "./DocumentId";
|
||||
import StoredProcedure from "./StoredProcedure";
|
||||
import Trigger from "./Trigger";
|
||||
import UserDefinedFunction from "./UserDefinedFunction";
|
||||
import { configContext } from "../../ConfigContext";
|
||||
import Explorer from "../Explorer";
|
||||
import {
|
||||
createDocument,
|
||||
readTriggers,
|
||||
readUserDefinedFunctions,
|
||||
readStoredProcedures,
|
||||
readCollectionQuotaInfo,
|
||||
readOffer,
|
||||
readOffers
|
||||
} from "../../Common/DocumentClientUtilityBase";
|
||||
import { userContext } from "../../UserContext";
|
||||
|
||||
export default class Collection implements ViewModels.Collection {
|
||||
public nodeKind: string;
|
||||
@@ -854,21 +849,21 @@ export default class Collection implements ViewModels.Collection {
|
||||
Trigger.create(source, event);
|
||||
}
|
||||
|
||||
public createStoredProcedureNode(data: DataModels.StoredProcedure): StoredProcedure {
|
||||
public createStoredProcedureNode(data: StoredProcedureDefinition & Resource): StoredProcedure {
|
||||
const node = new StoredProcedure(this.container, this, data);
|
||||
this.container.selectedNode(node);
|
||||
this.children.push(node);
|
||||
return node;
|
||||
}
|
||||
|
||||
public createUserDefinedFunctionNode(data: DataModels.UserDefinedFunction): UserDefinedFunction {
|
||||
public createUserDefinedFunctionNode(data: UserDefinedFunctionDefinition & Resource): UserDefinedFunction {
|
||||
const node = new UserDefinedFunction(this.container, this, data);
|
||||
this.container.selectedNode(node);
|
||||
this.children.push(node);
|
||||
return node;
|
||||
}
|
||||
|
||||
public createTriggerNode(data: DataModels.Trigger): Trigger {
|
||||
public createTriggerNode(data: TriggerDefinition & Resource): Trigger {
|
||||
const node = new Trigger(this.container, this, data);
|
||||
this.container.selectedNode(node);
|
||||
this.children.push(node);
|
||||
@@ -1062,8 +1057,8 @@ export default class Collection implements ViewModels.Collection {
|
||||
});
|
||||
}
|
||||
|
||||
public loadStoredProcedures(): Q.Promise<any> {
|
||||
return readStoredProcedures(this).then((storedProcedures: DataModels.StoredProcedure[]) => {
|
||||
public loadStoredProcedures(): Promise<any> {
|
||||
return readStoredProcedures(this.databaseId, this.id()).then(storedProcedures => {
|
||||
const storedProceduresNodes: ViewModels.TreeNode[] = storedProcedures.map(
|
||||
storedProcedure => new StoredProcedure(this.container, this, storedProcedure)
|
||||
);
|
||||
@@ -1073,8 +1068,8 @@ export default class Collection implements ViewModels.Collection {
|
||||
});
|
||||
}
|
||||
|
||||
public loadUserDefinedFunctions(): Q.Promise<any> {
|
||||
return readUserDefinedFunctions(this).then((userDefinedFunctions: DataModels.UserDefinedFunction[]) => {
|
||||
public loadUserDefinedFunctions(): Promise<any> {
|
||||
return readUserDefinedFunctions(this.databaseId, this.id()).then(userDefinedFunctions => {
|
||||
const userDefinedFunctionsNodes: ViewModels.TreeNode[] = userDefinedFunctions.map(
|
||||
udf => new UserDefinedFunction(this.container, this, udf)
|
||||
);
|
||||
@@ -1084,8 +1079,8 @@ export default class Collection implements ViewModels.Collection {
|
||||
});
|
||||
}
|
||||
|
||||
public loadTriggers(): Q.Promise<any> {
|
||||
return readTriggers(this, null /*options*/).then((triggers: DataModels.Trigger[]) => {
|
||||
public loadTriggers(): Promise<any> {
|
||||
return readTriggers(this.databaseId, this.id()).then(triggers => {
|
||||
const triggerNodes: ViewModels.TreeNode[] = triggers.map(trigger => new Trigger(this.container, this, trigger));
|
||||
const otherNodes = this.children().filter(node => node.nodeKind !== "Trigger");
|
||||
const allNodes = otherNodes.concat(triggerNodes);
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { Resource, StoredProcedureDefinition } from "@azure/cosmos";
|
||||
import * as ko from "knockout";
|
||||
import * as ViewModels from "../../Contracts/ViewModels";
|
||||
import * as Constants from "../../Common/Constants";
|
||||
import * as DataModels from "../../Contracts/DataModels";
|
||||
import { deleteStoredProcedure } from "../../Common/dataAccess/deleteStoredProcedure";
|
||||
import { executeStoredProcedure } from "../../Common/DocumentClientUtilityBase";
|
||||
import * as ViewModels from "../../Contracts/ViewModels";
|
||||
import { Action, ActionModifiers } from "../../Shared/Telemetry/TelemetryConstants";
|
||||
|
||||
import StoredProcedureTab from "../Tabs/StoredProcedureTab";
|
||||
import * as TelemetryProcessor from "../../Shared/Telemetry/TelemetryProcessor";
|
||||
import Explorer from "../Explorer";
|
||||
import { deleteStoredProcedure, executeStoredProcedure } from "../../Common/DocumentClientUtilityBase";
|
||||
import StoredProcedureTab from "../Tabs/StoredProcedureTab";
|
||||
import TabsBase from "../Tabs/TabsBase";
|
||||
|
||||
const sampleStoredProcedureBody: string = `// SAMPLE STORED PROCEDURE
|
||||
@@ -47,20 +47,20 @@ export default class StoredProcedure {
|
||||
public body: ko.Observable<string>;
|
||||
public isExecuteEnabled: boolean;
|
||||
|
||||
constructor(container: Explorer, collection: ViewModels.Collection, data: DataModels.StoredProcedure) {
|
||||
constructor(container: Explorer, collection: ViewModels.Collection, data: StoredProcedureDefinition & Resource) {
|
||||
this.nodeKind = "StoredProcedure";
|
||||
this.container = container;
|
||||
this.collection = collection;
|
||||
this.self = data._self;
|
||||
this.rid = data._rid;
|
||||
this.id = ko.observable(data.id);
|
||||
this.body = ko.observable(data.body);
|
||||
this.body = ko.observable(data.body as string);
|
||||
this.isExecuteEnabled = this.container.isFeatureEnabled(Constants.Features.executeSproc);
|
||||
}
|
||||
|
||||
public static create(source: ViewModels.Collection, event: MouseEvent) {
|
||||
const id = source.container.tabsManager.getTabs(ViewModels.CollectionTabKind.StoredProcedures).length + 1;
|
||||
const storedProcedure = <DataModels.StoredProcedure>{
|
||||
const storedProcedure = <StoredProcedureDefinition>{
|
||||
id: "",
|
||||
body: sampleStoredProcedureBody
|
||||
};
|
||||
@@ -104,7 +104,7 @@ export default class StoredProcedure {
|
||||
if (storedProcedureTab) {
|
||||
this.container.tabsManager.activateTab(storedProcedureTab);
|
||||
} else {
|
||||
const storedProcedureData = <DataModels.StoredProcedure>{
|
||||
const storedProcedureData = <StoredProcedureDefinition>{
|
||||
_rid: this.rid,
|
||||
_self: this.self,
|
||||
id: this.id(),
|
||||
@@ -137,14 +137,7 @@ export default class StoredProcedure {
|
||||
return;
|
||||
}
|
||||
|
||||
const storedProcedureData = <DataModels.StoredProcedure>{
|
||||
_rid: this.rid,
|
||||
_self: this.self,
|
||||
id: this.id(),
|
||||
body: this.body()
|
||||
};
|
||||
|
||||
deleteStoredProcedure(this.collection, storedProcedureData).then(
|
||||
deleteStoredProcedure(this.collection.databaseId, this.collection.id(), this.id()).then(
|
||||
() => {
|
||||
this.container.tabsManager.removeTabByComparator((tab: TabsBase) => tab.node && tab.node.rid === this.rid);
|
||||
this.collection.children.remove(this);
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { StoredProcedureDefinition } from "@azure/cosmos";
|
||||
import * as ko from "knockout";
|
||||
import * as ViewModels from "../../Contracts/ViewModels";
|
||||
import * as Constants from "../../Common/Constants";
|
||||
import * as DataModels from "../../Contracts/DataModels";
|
||||
import { deleteTrigger } from "../../Common/dataAccess/deleteTrigger";
|
||||
import * as ViewModels from "../../Contracts/ViewModels";
|
||||
import { Action, ActionModifiers } from "../../Shared/Telemetry/TelemetryConstants";
|
||||
import TriggerTab from "../Tabs/TriggerTab";
|
||||
import * as TelemetryProcessor from "../../Shared/Telemetry/TelemetryProcessor";
|
||||
import Explorer from "../Explorer";
|
||||
import { deleteTrigger } from "../../Common/DocumentClientUtilityBase";
|
||||
import TriggerTab from "../Tabs/TriggerTab";
|
||||
|
||||
export default class Trigger {
|
||||
public nodeKind: string;
|
||||
@@ -43,7 +43,7 @@ export default class Trigger {
|
||||
|
||||
public static create(source: ViewModels.Collection, event: MouseEvent) {
|
||||
const id = source.container.tabsManager.getTabs(ViewModels.CollectionTabKind.Triggers).length + 1;
|
||||
const trigger = <DataModels.Trigger>{
|
||||
const trigger = <StoredProcedureDefinition>{
|
||||
id: "",
|
||||
body: "function trigger(){}",
|
||||
triggerOperation: "All",
|
||||
@@ -79,7 +79,7 @@ export default class Trigger {
|
||||
if (triggerTab) {
|
||||
this.container.tabsManager.activateTab(triggerTab);
|
||||
} else {
|
||||
const triggerData = <DataModels.Trigger>{
|
||||
const triggerData = <StoredProcedureDefinition>{
|
||||
_rid: this.rid,
|
||||
_self: this.self,
|
||||
id: this.id(),
|
||||
@@ -114,16 +114,7 @@ export default class Trigger {
|
||||
return;
|
||||
}
|
||||
|
||||
const triggerData = <DataModels.Trigger>{
|
||||
_rid: this.rid,
|
||||
_self: this.self,
|
||||
id: this.id(),
|
||||
body: this.body(),
|
||||
triggerOperation: this.triggerOperation(),
|
||||
triggerType: this.triggerType()
|
||||
};
|
||||
|
||||
deleteTrigger(this.collection, triggerData).then(
|
||||
deleteTrigger(this.collection.databaseId, this.collection.id(), this.id()).then(
|
||||
() => {
|
||||
this.container.tabsManager.removeTabByComparator(tab => tab.node && tab.node.rid === this.rid);
|
||||
this.collection.children.remove(this);
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { Resource, UserDefinedFunctionDefinition } from "@azure/cosmos";
|
||||
import * as ko from "knockout";
|
||||
import * as ViewModels from "../../Contracts/ViewModels";
|
||||
import * as Constants from "../../Common/Constants";
|
||||
import * as DataModels from "../../Contracts/DataModels";
|
||||
import { deleteUserDefinedFunction } from "../../Common/dataAccess/deleteUserDefinedFunction";
|
||||
import * as ViewModels from "../../Contracts/ViewModels";
|
||||
import { Action, ActionModifiers } from "../../Shared/Telemetry/TelemetryConstants";
|
||||
import UserDefinedFunctionTab from "../Tabs/UserDefinedFunctionTab";
|
||||
import * as TelemetryProcessor from "../../Shared/Telemetry/TelemetryProcessor";
|
||||
import Explorer from "../Explorer";
|
||||
import { deleteUserDefinedFunction } from "../../Common/DocumentClientUtilityBase";
|
||||
import UserDefinedFunctionTab from "../Tabs/UserDefinedFunctionTab";
|
||||
|
||||
export default class UserDefinedFunction {
|
||||
public nodeKind: string;
|
||||
@@ -17,7 +17,7 @@ export default class UserDefinedFunction {
|
||||
public id: ko.Observable<string>;
|
||||
public body: ko.Observable<string>;
|
||||
|
||||
constructor(container: Explorer, collection: ViewModels.Collection, data: DataModels.UserDefinedFunction) {
|
||||
constructor(container: Explorer, collection: ViewModels.Collection, data: UserDefinedFunctionDefinition & Resource) {
|
||||
this.nodeKind = "UserDefinedFunction";
|
||||
this.container = container;
|
||||
|
||||
@@ -25,12 +25,12 @@ export default class UserDefinedFunction {
|
||||
this.self = data._self;
|
||||
this.rid = data._rid;
|
||||
this.id = ko.observable(data.id);
|
||||
this.body = ko.observable(data.body);
|
||||
this.body = ko.observable(data.body as string);
|
||||
}
|
||||
|
||||
public static create(source: ViewModels.Collection, event: MouseEvent) {
|
||||
const id = source.container.tabsManager.getTabs(ViewModels.CollectionTabKind.UserDefinedFunctions).length + 1;
|
||||
const userDefinedFunction = <DataModels.UserDefinedFunction>{
|
||||
const userDefinedFunction = {
|
||||
id: "",
|
||||
body: "function userDefinedFunction(){}"
|
||||
};
|
||||
@@ -64,7 +64,7 @@ export default class UserDefinedFunction {
|
||||
if (userDefinedFunctionTab) {
|
||||
this.container.tabsManager.activateTab(userDefinedFunctionTab);
|
||||
} else {
|
||||
const userDefinedFunctionData = <DataModels.UserDefinedFunction>{
|
||||
const userDefinedFunctionData = {
|
||||
_rid: this.rid,
|
||||
_self: this.self,
|
||||
id: this.id(),
|
||||
@@ -107,13 +107,7 @@ export default class UserDefinedFunction {
|
||||
return;
|
||||
}
|
||||
|
||||
const userDefinedFunctionData = <DataModels.UserDefinedFunction>{
|
||||
_rid: this.rid,
|
||||
_self: this.self,
|
||||
id: this.id(),
|
||||
body: this.body()
|
||||
};
|
||||
deleteUserDefinedFunction(this.collection, userDefinedFunctionData).then(
|
||||
deleteUserDefinedFunction(this.collection.databaseId, this.collection.id(), this.id()).then(
|
||||
() => {
|
||||
this.container.tabsManager.removeTabByComparator(tab => tab.node && tab.node.rid === this.rid);
|
||||
this.collection.children.remove(this);
|
||||
|
||||
Reference in New Issue
Block a user