mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-29 22:02:01 +00:00
Initial Move from Azure DevOps to GitHub
This commit is contained in:
96
src/Platform/Portal/DataAccessUtility.ts
Normal file
96
src/Platform/Portal/DataAccessUtility.ts
Normal file
@@ -0,0 +1,96 @@
|
||||
import "jquery";
|
||||
import * as _ from "underscore";
|
||||
import Q from "q";
|
||||
|
||||
import { getAuthorizationHeader } from "../../Utils/AuthorizationUtils";
|
||||
import * as DataModels from "../../Contracts/DataModels";
|
||||
import * as ViewModels from "../../Contracts/ViewModels";
|
||||
import * as Constants from "../../Common/Constants";
|
||||
import { DataAccessUtilityBase } from "../../Common/DataAccessUtilityBase";
|
||||
import { MessageHandler } from "../../Common/MessageHandler";
|
||||
import { MessageTypes } from "../../Contracts/ExplorerContracts";
|
||||
|
||||
export class DataAccessUtility extends DataAccessUtilityBase {
|
||||
public readDatabases(options: any): Q.Promise<DataModels.Database[]> {
|
||||
return MessageHandler.sendCachedDataMessage<DataModels.Database[]>(MessageTypes.AllDatabases, [
|
||||
(<any>window).dataExplorer.databaseAccount().id,
|
||||
Constants.ClientDefaults.portalCacheTimeoutMs
|
||||
]).catch(error => {
|
||||
return super.readDatabases(options);
|
||||
});
|
||||
}
|
||||
|
||||
// public readCollections(database: ViewModels.Database, options: any): Q.Promise<DataModels.Collection[]> {
|
||||
// return MessageHandler.sendCachedDataMessage<DataModels.Collection[]>(MessageTypes.CollectionsForDatabase, [
|
||||
// (<any>window).dataExplorer.databaseAccount().id,
|
||||
// database.id()
|
||||
// ]);
|
||||
// }
|
||||
|
||||
public readOffers(options: any): Q.Promise<DataModels.Offer[]> {
|
||||
return MessageHandler.sendCachedDataMessage<DataModels.Offer[]>(MessageTypes.AllOffers, [
|
||||
(<any>window).dataExplorer.databaseAccount().id,
|
||||
Constants.ClientDefaults.portalCacheTimeoutMs
|
||||
]).catch(error => {
|
||||
return super.readOffers(options);
|
||||
});
|
||||
}
|
||||
|
||||
public readOffer(requestedResource: DataModels.Offer, options: any): Q.Promise<DataModels.OfferWithHeaders> {
|
||||
const deferred: Q.Deferred<DataModels.OfferWithHeaders> = Q.defer<DataModels.OfferWithHeaders>();
|
||||
super.readOffer(requestedResource, options).then(
|
||||
(offer: DataModels.OfferWithHeaders) => deferred.resolve(offer),
|
||||
(reason: any) => {
|
||||
const isThrottled: boolean =
|
||||
!!reason &&
|
||||
!!reason.error &&
|
||||
!!reason.error.code &&
|
||||
reason.error.code == Constants.HttpStatusCodes.TooManyRequests;
|
||||
if (isThrottled && MessageHandler.canSendMessage()) {
|
||||
MessageHandler.sendCachedDataMessage<DataModels.OfferWithHeaders>(MessageTypes.SingleOffer, [
|
||||
(<any>window).dataExplorer.databaseAccount().id,
|
||||
requestedResource._self,
|
||||
requestedResource.offerVersion
|
||||
]).then(
|
||||
(offer: DataModels.OfferWithHeaders) => deferred.resolve(offer),
|
||||
(reason: any) => deferred.reject(reason)
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
deferred.reject(reason);
|
||||
}
|
||||
);
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
public updateOfferThroughputBeyondLimit(
|
||||
updateThroughputRequestPayload: DataModels.UpdateOfferThroughputRequest,
|
||||
options: any
|
||||
): Q.Promise<void> {
|
||||
const deferred: Q.Deferred<void> = Q.defer<void>();
|
||||
const explorer: ViewModels.Explorer = (<any>window).dataExplorer;
|
||||
const url: string = `${explorer.extensionEndpoint()}/api/offerthroughputrequest/updatebeyondspecifiedlimit`;
|
||||
const authorizationHeader: ViewModels.AuthorizationTokenHeaderMetadata = getAuthorizationHeader();
|
||||
const requestOptions: any = _.extend({}, options, {});
|
||||
requestOptions[authorizationHeader.header] = authorizationHeader.token;
|
||||
const requestSettings: JQueryAjaxSettings<any> = {
|
||||
type: "POST",
|
||||
contentType: "application/json",
|
||||
headers: requestOptions,
|
||||
data: JSON.stringify(updateThroughputRequestPayload)
|
||||
};
|
||||
|
||||
$.ajax(url, requestSettings).then(
|
||||
(data: any, textStatus: string, xhr: JQueryXHR<any>) => {
|
||||
deferred.resolve();
|
||||
},
|
||||
(xhr: JQueryXHR<any>, textStatus: string, error: any) => {
|
||||
deferred.reject(xhr.responseText);
|
||||
}
|
||||
);
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
}
|
||||
20
src/Platform/Portal/ExplorerFactory.ts
Normal file
20
src/Platform/Portal/ExplorerFactory.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import * as ViewModels from "../../Contracts/ViewModels";
|
||||
import Explorer from "../../Explorer/Explorer";
|
||||
|
||||
import { NotificationsClient } from "./NotificationsClient";
|
||||
import DocumentClientUtilityBase from "../../Common/DocumentClientUtilityBase";
|
||||
import { DataAccessUtility } from "./DataAccessUtility";
|
||||
|
||||
export default class PortalExplorerFactory {
|
||||
public createExplorer(): ViewModels.Explorer {
|
||||
var documentClientUtility = new DocumentClientUtilityBase(new DataAccessUtility());
|
||||
|
||||
var explorer = new Explorer({
|
||||
documentClientUtility: documentClientUtility,
|
||||
notificationsClient: new NotificationsClient(),
|
||||
isEmulator: false
|
||||
});
|
||||
|
||||
return explorer;
|
||||
}
|
||||
}
|
||||
11
src/Platform/Portal/Main.ts
Normal file
11
src/Platform/Portal/Main.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import * as ViewModels from "../../Contracts/ViewModels";
|
||||
import PortalExplorerFactory from "./ExplorerFactory";
|
||||
import "../../Explorer/Tables/DataTable/DataTableBindingManager";
|
||||
|
||||
export function initializeExplorer(): ViewModels.Explorer {
|
||||
const portalExplorerFactory = new PortalExplorerFactory();
|
||||
const explorer = portalExplorerFactory.createExplorer();
|
||||
|
||||
window.addEventListener("message", explorer.handleMessage.bind(explorer), false);
|
||||
return explorer;
|
||||
}
|
||||
9
src/Platform/Portal/NotificationsClient.ts
Normal file
9
src/Platform/Portal/NotificationsClient.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { NotificationsClientBase } from "../../Common/NotificationsClientBase";
|
||||
|
||||
export class NotificationsClient extends NotificationsClientBase {
|
||||
private static readonly _notificationsApiSuffix: string = "/api/notifications";
|
||||
|
||||
public constructor() {
|
||||
super(NotificationsClient._notificationsApiSuffix);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user