mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-23 10:51:30 +00:00
Compare commits
2 Commits
fix_eslint
...
eslint/fix
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2cfa0b04c9 | ||
|
|
3c72351040 |
@@ -80,19 +80,15 @@ src/Explorer/Tables/DataTable/CacheBase.ts
|
||||
src/Explorer/Tables/DataTable/DataTableBindingManager.ts
|
||||
src/Explorer/Tables/DataTable/DataTableBuilder.ts
|
||||
src/Explorer/Tables/DataTable/DataTableContextMenu.ts
|
||||
# src/Explorer/Tables/DataTable/DataTableOperationManager.ts
|
||||
src/Explorer/Tables/DataTable/DataTableOperationManager.ts
|
||||
src/Explorer/Tables/DataTable/DataTableViewModel.ts
|
||||
src/Explorer/Tables/DataTable/TableEntityListViewModel.ts
|
||||
# src/Explorer/Tables/QueryBuilder/CustomTimestampHelper.ts
|
||||
src/Explorer/Tables/QueryBuilder/CustomTimestampHelper.ts
|
||||
src/Explorer/Tables/TableDataClient.ts
|
||||
src/Explorer/Tables/TableEntityProcessor.ts
|
||||
src/Explorer/Tables/Utilities.ts
|
||||
src/Explorer/Tabs/ConflictsTab.ts
|
||||
src/Explorer/Tabs/DatabaseSettingsTab.ts
|
||||
src/Explorer/Tabs/DocumentsTab.test.ts
|
||||
src/Explorer/Tabs/DocumentsTab.ts
|
||||
src/Explorer/Tabs/GraphTab.ts
|
||||
src/Explorer/Tabs/MongoDocumentsTab.ts
|
||||
src/Explorer/Tabs/NotebookV2Tab.ts
|
||||
src/Explorer/Tabs/ScriptTabBase.ts
|
||||
src/Explorer/Tabs/TabComponents.ts
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import ko from "knockout";
|
||||
import * as Constants from "../Constants";
|
||||
import * as Entities from "../Entities";
|
||||
import * as Utilities from "../Utilities";
|
||||
|
||||
import * as DataTableOperations from "./DataTableOperations";
|
||||
import * as Constants from "../Constants";
|
||||
import TableCommands from "./TableCommands";
|
||||
import TableEntityListViewModel from "./TableEntityListViewModel";
|
||||
import * as Utilities from "../Utilities";
|
||||
import * as Entities from "../Entities";
|
||||
|
||||
/*
|
||||
* Base class for data table row selection.
|
||||
@@ -24,7 +25,7 @@ export default class DataTableOperationManager {
|
||||
}
|
||||
|
||||
private click = (event: JQueryEventObject) => {
|
||||
const elem: JQuery = $(event.currentTarget);
|
||||
var elem: JQuery = $(event.currentTarget);
|
||||
this.updateLastSelectedItem(elem, event.shiftKey);
|
||||
|
||||
if (Utilities.isEnvironmentCtrlPressed(event)) {
|
||||
@@ -36,30 +37,30 @@ export default class DataTableOperationManager {
|
||||
}
|
||||
};
|
||||
|
||||
private doubleClick = () => {
|
||||
private doubleClick = (event: JQueryEventObject) => {
|
||||
this.tryOpenEditor();
|
||||
};
|
||||
|
||||
private keyDown = (event: JQueryEventObject): boolean => {
|
||||
const isUpArrowKey: boolean = event.keyCode === Constants.keyCodes.UpArrow,
|
||||
isDownArrowKey: boolean = event.keyCode === Constants.keyCodes.DownArrow;
|
||||
let handled = false;
|
||||
var isUpArrowKey: boolean = event.keyCode === Constants.keyCodes.UpArrow,
|
||||
isDownArrowKey: boolean = event.keyCode === Constants.keyCodes.DownArrow,
|
||||
handled: boolean = false;
|
||||
|
||||
if (isUpArrowKey || isDownArrowKey) {
|
||||
const lastSelectedItem: Entities.ITableEntity = this._tableEntityListViewModel.lastSelectedItem;
|
||||
const dataTableRows: JQuery = $(Constants.htmlSelectors.dataTableAllRowsSelector);
|
||||
const maximumIndex = dataTableRows.length - 1;
|
||||
var lastSelectedItem: Entities.ITableEntity = this._tableEntityListViewModel.lastSelectedItem;
|
||||
var dataTableRows: JQuery = $(Constants.htmlSelectors.dataTableAllRowsSelector);
|
||||
var maximumIndex = dataTableRows.length - 1;
|
||||
|
||||
// If can't find an index for lastSelectedItem, then either no item is previously selected or it goes across page.
|
||||
// Simply select the first item in this case.
|
||||
const lastSelectedItemIndex = lastSelectedItem
|
||||
var lastSelectedItemIndex = lastSelectedItem
|
||||
? this._tableEntityListViewModel.getItemIndexFromCurrentPage(
|
||||
this._tableEntityListViewModel.getTableEntityKeys(lastSelectedItem.RowKey._)
|
||||
)
|
||||
: -1;
|
||||
const nextIndex: number = isUpArrowKey ? lastSelectedItemIndex - 1 : lastSelectedItemIndex + 1;
|
||||
const safeIndex: number = Utilities.ensureBetweenBounds(nextIndex, 0, maximumIndex);
|
||||
const selectedRowElement: JQuery = dataTableRows.eq(safeIndex);
|
||||
var nextIndex: number = isUpArrowKey ? lastSelectedItemIndex - 1 : lastSelectedItemIndex + 1;
|
||||
var safeIndex: number = Utilities.ensureBetweenBounds(nextIndex, 0, maximumIndex);
|
||||
var selectedRowElement: JQuery = dataTableRows.eq(safeIndex);
|
||||
|
||||
if (selectedRowElement) {
|
||||
if (event.shiftKey) {
|
||||
@@ -89,7 +90,7 @@ export default class DataTableOperationManager {
|
||||
// in contrast, there may be more than one key down and key
|
||||
// pressed events.
|
||||
private keyUp = (event: JQueryEventObject): boolean => {
|
||||
let handled = false;
|
||||
var handled: boolean = false;
|
||||
|
||||
switch (event.keyCode) {
|
||||
case Constants.keyCodes.Enter:
|
||||
@@ -104,9 +105,8 @@ export default class DataTableOperationManager {
|
||||
};
|
||||
|
||||
private itemDropped = (event: JQueryEventObject): boolean => {
|
||||
const handled = false;
|
||||
//eslint-disable-next-line
|
||||
const items = (<any>event.originalEvent).dataTransfer.items;
|
||||
var handled: boolean = false;
|
||||
var items = (<any>event.originalEvent).dataTransfer.items;
|
||||
|
||||
if (!items) {
|
||||
// On browsers outside of Chromium
|
||||
@@ -115,9 +115,9 @@ export default class DataTableOperationManager {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
const item = items[i];
|
||||
const entry = item.webkitGetAsEntry();
|
||||
for (var i = 0; i < items.length; i++) {
|
||||
var item = items[i];
|
||||
var entry = item.webkitGetAsEntry();
|
||||
|
||||
if (entry.isFile) {
|
||||
// TODO: parse the file and insert content as entities
|
||||
@@ -132,8 +132,8 @@ export default class DataTableOperationManager {
|
||||
}
|
||||
|
||||
private tryHandleDeleteSelected(): boolean {
|
||||
const selectedEntities: Entities.ITableEntity[] = this._tableEntityListViewModel.selected();
|
||||
let handled = false;
|
||||
var selectedEntities: Entities.ITableEntity[] = this._tableEntityListViewModel.selected();
|
||||
var handled: boolean = false;
|
||||
|
||||
if (selectedEntities && selectedEntities.length) {
|
||||
this._tableCommands.deleteEntitiesCommand(this._tableEntityListViewModel);
|
||||
@@ -150,8 +150,8 @@ export default class DataTableOperationManager {
|
||||
}
|
||||
|
||||
private updateLastSelectedItem($elem: JQuery, isShiftSelect: boolean) {
|
||||
const entityIdentity: Entities.ITableEntityIdentity = this.getEntityIdentity($elem);
|
||||
const entity = this._tableEntityListViewModel.getItemFromCurrentPage(
|
||||
var entityIdentity: Entities.ITableEntityIdentity = this.getEntityIdentity($elem);
|
||||
var entity = this._tableEntityListViewModel.getItemFromCurrentPage(
|
||||
this._tableEntityListViewModel.getTableEntityKeys(entityIdentity.RowKey)
|
||||
);
|
||||
|
||||
@@ -164,7 +164,7 @@ export default class DataTableOperationManager {
|
||||
|
||||
private applySingleSelection($elem: JQuery) {
|
||||
if ($elem) {
|
||||
const entityIdentity: Entities.ITableEntityIdentity = this.getEntityIdentity($elem);
|
||||
var entityIdentity: Entities.ITableEntityIdentity = this.getEntityIdentity($elem);
|
||||
|
||||
this._tableEntityListViewModel.clearSelection();
|
||||
this.addToSelection(entityIdentity.RowKey);
|
||||
@@ -180,12 +180,12 @@ export default class DataTableOperationManager {
|
||||
}
|
||||
|
||||
private applyCtrlSelection($elem: JQuery): void {
|
||||
const koSelected: ko.ObservableArray<Entities.ITableEntity> = this._tableEntityListViewModel
|
||||
var koSelected: ko.ObservableArray<Entities.ITableEntity> = this._tableEntityListViewModel
|
||||
? this._tableEntityListViewModel.selected
|
||||
: null;
|
||||
|
||||
if (koSelected) {
|
||||
const entityIdentity: Entities.ITableEntityIdentity = this.getEntityIdentity($elem);
|
||||
var entityIdentity: Entities.ITableEntityIdentity = this.getEntityIdentity($elem);
|
||||
|
||||
if (
|
||||
!this._tableEntityListViewModel.isItemSelected(
|
||||
@@ -201,7 +201,7 @@ export default class DataTableOperationManager {
|
||||
}
|
||||
|
||||
private applyShiftSelection($elem: JQuery): void {
|
||||
let anchorItem = this._tableEntityListViewModel.lastSelectedAnchorItem;
|
||||
var anchorItem = this._tableEntityListViewModel.lastSelectedAnchorItem;
|
||||
|
||||
// If anchor item doesn't exist, use the first available item of current page instead
|
||||
if (!anchorItem && this._tableEntityListViewModel.items().length > 0) {
|
||||
@@ -209,16 +209,16 @@ export default class DataTableOperationManager {
|
||||
}
|
||||
|
||||
if (anchorItem) {
|
||||
const entityIdentity: Entities.ITableEntityIdentity = this.getEntityIdentity($elem);
|
||||
const elementIndex = this._tableEntityListViewModel.getItemIndexFromAllPages(
|
||||
var entityIdentity: Entities.ITableEntityIdentity = this.getEntityIdentity($elem);
|
||||
var elementIndex = this._tableEntityListViewModel.getItemIndexFromAllPages(
|
||||
this._tableEntityListViewModel.getTableEntityKeys(entityIdentity.RowKey)
|
||||
);
|
||||
const anchorIndex = this._tableEntityListViewModel.getItemIndexFromAllPages(
|
||||
var anchorIndex = this._tableEntityListViewModel.getItemIndexFromAllPages(
|
||||
this._tableEntityListViewModel.getTableEntityKeys(anchorItem.RowKey._)
|
||||
);
|
||||
|
||||
const startIndex = Math.min(elementIndex, anchorIndex);
|
||||
const endIndex = Math.max(elementIndex, anchorIndex);
|
||||
var startIndex = Math.min(elementIndex, anchorIndex);
|
||||
var endIndex = Math.max(elementIndex, anchorIndex);
|
||||
|
||||
this._tableEntityListViewModel.clearSelection();
|
||||
ko.utils.arrayPushAll<Entities.ITableEntity>(
|
||||
@@ -229,7 +229,7 @@ export default class DataTableOperationManager {
|
||||
}
|
||||
|
||||
private applyContextMenuSelection($elem: JQuery) {
|
||||
const entityIdentity: Entities.ITableEntityIdentity = this.getEntityIdentity($elem);
|
||||
var entityIdentity: Entities.ITableEntityIdentity = this.getEntityIdentity($elem);
|
||||
|
||||
if (
|
||||
!this._tableEntityListViewModel.isItemSelected(
|
||||
@@ -244,26 +244,26 @@ export default class DataTableOperationManager {
|
||||
}
|
||||
|
||||
private addToSelection(rowKey: string) {
|
||||
const selectedEntity: Entities.ITableEntity = this._tableEntityListViewModel.getItemFromCurrentPage(
|
||||
var selectedEntity: Entities.ITableEntity = this._tableEntityListViewModel.getItemFromCurrentPage(
|
||||
this._tableEntityListViewModel.getTableEntityKeys(rowKey)
|
||||
);
|
||||
|
||||
if (selectedEntity !== null) {
|
||||
if (selectedEntity != null) {
|
||||
this._tableEntityListViewModel.selected.push(selectedEntity);
|
||||
}
|
||||
}
|
||||
|
||||
// Selecting first row if the selection is empty.
|
||||
public selectFirstIfNeeded(): void {
|
||||
const koSelected: ko.ObservableArray<Entities.ITableEntity> = this._tableEntityListViewModel
|
||||
var koSelected: ko.ObservableArray<Entities.ITableEntity> = this._tableEntityListViewModel
|
||||
? this._tableEntityListViewModel.selected
|
||||
: null;
|
||||
const koEntities: ko.ObservableArray<Entities.ITableEntity> = this._tableEntityListViewModel
|
||||
var koEntities: ko.ObservableArray<Entities.ITableEntity> = this._tableEntityListViewModel
|
||||
? this._tableEntityListViewModel.items
|
||||
: null;
|
||||
|
||||
if (!koSelected().length && koEntities().length) {
|
||||
const firstEntity: Entities.ITableEntity = koEntities()[0];
|
||||
var firstEntity: Entities.ITableEntity = koEntities()[0];
|
||||
|
||||
// Clear last selection: lastSelectedItem and lastSelectedAnchorItem
|
||||
this._tableEntityListViewModel.clearLastSelected();
|
||||
@@ -278,7 +278,7 @@ export default class DataTableOperationManager {
|
||||
}
|
||||
}
|
||||
|
||||
public bind(): void {
|
||||
public bind() {
|
||||
this.dataTable.on("click", "tr", this.click);
|
||||
this.dataTable.on("dblclick", "tr", this.doubleClick);
|
||||
this.dataTable.on("keydown", "td", this.keyDown);
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import * as DateTimeUtilities from "./DateTimeUtilities";
|
||||
import QueryBuilderViewModel from "./QueryBuilderViewModel";
|
||||
import QueryClauseViewModel from "./QueryClauseViewModel";
|
||||
import * as DateTimeUtilities from "./DateTimeUtilities";
|
||||
|
||||
/**
|
||||
* Constants
|
||||
*/
|
||||
export const utc = "utc";
|
||||
export const local = "local";
|
||||
export var utc = "utc";
|
||||
export var local = "local";
|
||||
|
||||
export interface ITimestampQuery {
|
||||
queryType: string; // valid values are "last" and "range"
|
||||
@@ -41,11 +41,11 @@ export function addRangeTimestamp(
|
||||
queryBuilderViewModel.addCustomRange(timestamp, queryClauseViewModel);
|
||||
}
|
||||
|
||||
export function getDefaultStart(localTime: boolean, durationHours = 24): string {
|
||||
let startTimestamp: string;
|
||||
export function getDefaultStart(localTime: boolean, durationHours: number = 24): string {
|
||||
var startTimestamp: string;
|
||||
|
||||
const utcNowString: string = new Date().toISOString();
|
||||
const yesterday: Date = new Date(utcNowString);
|
||||
var utcNowString: string = new Date().toISOString();
|
||||
var yesterday: Date = new Date(utcNowString);
|
||||
|
||||
yesterday.setHours(yesterday.getHours() - durationHours);
|
||||
startTimestamp = yesterday.toISOString();
|
||||
@@ -58,9 +58,9 @@ export function getDefaultStart(localTime: boolean, durationHours = 24): string
|
||||
}
|
||||
|
||||
export function getDefaultEnd(localTime: boolean): string {
|
||||
let endTimestamp: string;
|
||||
var endTimestamp: string;
|
||||
|
||||
const utcNowString: string = new Date().toISOString();
|
||||
var utcNowString: string = new Date().toISOString();
|
||||
|
||||
endTimestamp = utcNowString;
|
||||
|
||||
@@ -73,14 +73,14 @@ export function getDefaultEnd(localTime: boolean): string {
|
||||
|
||||
export function parseDate(dateString: string, isUTC: boolean): Date {
|
||||
// TODO validate dateString
|
||||
let date: Date = null;
|
||||
var date: Date = null;
|
||||
|
||||
if (dateString) {
|
||||
try {
|
||||
// Date string is assumed to be UTC in Storage Explorer Standalone.
|
||||
// Behavior may vary in other browsers.
|
||||
// Here's an example of how the string looks like "2015-10-24T21:44:12"
|
||||
const millisecondTime = Date.parse(dateString),
|
||||
var millisecondTime = Date.parse(dateString),
|
||||
parsed: Date = new Date(millisecondTime);
|
||||
|
||||
if (isUTC) {
|
||||
@@ -89,7 +89,7 @@ export function parseDate(dateString: string, isUTC: boolean): Date {
|
||||
// Since we parsed in UTC, accessors are flipped - we get local time from the getUTC* group
|
||||
// Reinstating, the date is parsed above as UTC, and here we are creating a new date object
|
||||
// in local time.
|
||||
const year = parsed.getUTCFullYear(),
|
||||
var year = parsed.getUTCFullYear(),
|
||||
month = parsed.getUTCMonth(),
|
||||
day = parsed.getUTCDate(),
|
||||
hours = parsed.getUTCHours(),
|
||||
@@ -109,8 +109,8 @@ export function parseDate(dateString: string, isUTC: boolean): Date {
|
||||
|
||||
export function utcFromLocalDateString(localDateString: string): string {
|
||||
// TODO validate localDateString
|
||||
const localDate = parseDate(localDateString, false);
|
||||
let utcDateString: string = null;
|
||||
var localDate = parseDate(localDateString, false),
|
||||
utcDateString: string = null;
|
||||
|
||||
if (localDate) {
|
||||
utcDateString = localDate.toISOString();
|
||||
@@ -120,7 +120,7 @@ export function utcFromLocalDateString(localDateString: string): string {
|
||||
}
|
||||
|
||||
function padIfNeeded(value: number): string {
|
||||
let padded = String(value);
|
||||
var padded: string = String(value);
|
||||
|
||||
if (0 <= value && value < 10) {
|
||||
padded = "0" + padded;
|
||||
@@ -130,7 +130,7 @@ function padIfNeeded(value: number): string {
|
||||
}
|
||||
|
||||
function toLocalDateString(date: Date): string {
|
||||
let localDateString: string = null;
|
||||
var localDateString: string = null;
|
||||
|
||||
if (date) {
|
||||
localDateString =
|
||||
@@ -152,8 +152,8 @@ function toLocalDateString(date: Date): string {
|
||||
|
||||
export function localFromUtcDateString(utcDateString: string): string {
|
||||
// TODO validate utcDateString
|
||||
const utcDate: Date = parseDate(utcDateString, true);
|
||||
let localDateString: string = null;
|
||||
var utcDate: Date = parseDate(utcDateString, true),
|
||||
localDateString: string = null;
|
||||
|
||||
if (utcDate) {
|
||||
localDateString = toLocalDateString(utcDate);
|
||||
@@ -164,8 +164,8 @@ export function localFromUtcDateString(utcDateString: string): string {
|
||||
|
||||
export function tryChangeTimestampTimeZone(koTimestamp: ko.Observable<string>, toUTC: boolean): void {
|
||||
if (koTimestamp) {
|
||||
const currentDateString: string = koTimestamp();
|
||||
let newDateString: string;
|
||||
var currentDateString: string = koTimestamp(),
|
||||
newDateString: string;
|
||||
|
||||
if (currentDateString) {
|
||||
if (toUTC) {
|
||||
@@ -189,16 +189,16 @@ export function tryChangeTimestampTimeZone(koTimestamp: ko.Observable<string>, t
|
||||
* Input validation helpers
|
||||
*/
|
||||
|
||||
export const noTooltip = "",
|
||||
export var noTooltip = "",
|
||||
invalidStartTimeTooltip = "Please provide a valid start time.", // localize
|
||||
invalidExpiryTimeRequiredTooltip = "Required field. Please provide a valid expiry time.", // localize
|
||||
invalidExpiryTimeGreaterThanStartTimeTooltip = "The expiry time must be greater than the start time."; // localize
|
||||
|
||||
export function isDateString(dateString: string): boolean {
|
||||
let success = false;
|
||||
var success: boolean = false;
|
||||
|
||||
if (dateString) {
|
||||
const date = Date.parse(dateString);
|
||||
var date: number = Date.parse(dateString);
|
||||
|
||||
success = $.isNumeric(date);
|
||||
}
|
||||
@@ -308,10 +308,10 @@ function _getLocalIsoDateStringFromParts(
|
||||
}
|
||||
|
||||
function _addDaysHours(time: Date, days: number, hours: number): Date {
|
||||
const msPerHour = 1000 * 60 * 60;
|
||||
const daysMs = days * msPerHour * 24;
|
||||
const hoursMs = hours * msPerHour;
|
||||
const newTimeMs = time.getTime() + daysMs + hoursMs;
|
||||
var msPerHour = 1000 * 60 * 60;
|
||||
var daysMs = days * msPerHour * 24;
|
||||
var hoursMs = hours * msPerHour;
|
||||
var newTimeMs = time.getTime() + daysMs + hoursMs;
|
||||
return new Date(newTimeMs);
|
||||
}
|
||||
|
||||
@@ -321,7 +321,7 @@ function _daysHoursBeforeNow(days: number, hours: number): Date {
|
||||
|
||||
export function _queryLastDaysHours(days: number, hours: number): string {
|
||||
/* tslint:disable: no-unused-variable */
|
||||
let daysHoursAgo = _getLocalIsoDateTimeString(_daysHoursBeforeNow(days, hours));
|
||||
var daysHoursAgo = _getLocalIsoDateTimeString(_daysHoursBeforeNow(days, hours));
|
||||
daysHoursAgo = DateTimeUtilities.getUTCDateTime(daysHoursAgo);
|
||||
|
||||
return daysHoursAgo;
|
||||
@@ -329,21 +329,21 @@ export function _queryLastDaysHours(days: number, hours: number): string {
|
||||
}
|
||||
|
||||
export function _queryCurrentMonthLocal(): string {
|
||||
const now = new Date();
|
||||
let start = _getLocalIsoDateStringFromParts(now.getFullYear(), now.getMonth(), 1);
|
||||
var now = new Date();
|
||||
var start = _getLocalIsoDateStringFromParts(now.getFullYear(), now.getMonth(), 1);
|
||||
start = DateTimeUtilities.getUTCDateTime(start);
|
||||
return start;
|
||||
}
|
||||
|
||||
export function _queryCurrentYearLocal(): string {
|
||||
const now = new Date();
|
||||
let start = _getLocalIsoDateStringFromParts(now.getFullYear(), 0, 1); // Month is 0..11, date is 1..31
|
||||
var now = new Date();
|
||||
var start = _getLocalIsoDateStringFromParts(now.getFullYear(), 0, 1); // Month is 0..11, date is 1..31
|
||||
start = DateTimeUtilities.getUTCDateTime(start);
|
||||
return start;
|
||||
}
|
||||
|
||||
function _addTime(time: Date, lastNumber: number, timeUnit: string): Date {
|
||||
let timeMS: number;
|
||||
var timeMS: number;
|
||||
switch (TimeUnit[Number(timeUnit)]) {
|
||||
case TimeUnit.Days.toString():
|
||||
timeMS = lastNumber * 1000 * 60 * 60 * 24;
|
||||
@@ -360,7 +360,7 @@ function _addTime(time: Date, lastNumber: number, timeUnit: string): Date {
|
||||
default:
|
||||
//throw new Errors.ArgumentOutOfRangeError(timeUnit);
|
||||
}
|
||||
const newTimeMS = time.getTime() + timeMS;
|
||||
var newTimeMS = time.getTime() + timeMS;
|
||||
return new Date(newTimeMS);
|
||||
}
|
||||
|
||||
@@ -370,7 +370,7 @@ function _timeBeforeNow(lastNumber: number, timeUnit: string): Date {
|
||||
|
||||
export function _queryLastTime(lastNumber: number, timeUnit: string): string {
|
||||
/* tslint:disable: no-unused-variable */
|
||||
let daysHoursAgo = _getLocalIsoDateTimeString(_timeBeforeNow(lastNumber, timeUnit));
|
||||
var daysHoursAgo = _getLocalIsoDateTimeString(_timeBeforeNow(lastNumber, timeUnit));
|
||||
daysHoursAgo = DateTimeUtilities.getUTCDateTime(daysHoursAgo);
|
||||
return daysHoursAgo;
|
||||
/* tslint:enable: no-unused-variable */
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import * as ViewModels from "../../Contracts/ViewModels";
|
||||
import * as Constants from "./Constants";
|
||||
import * as Entities from "./Entities";
|
||||
@@ -16,12 +17,12 @@ enum DataTypes {
|
||||
Int64 = 18,
|
||||
}
|
||||
|
||||
var tablesIndexers = {
|
||||
const tablesIndexers = {
|
||||
Value: "$v",
|
||||
Type: "$t",
|
||||
};
|
||||
|
||||
export var keyProperties = {
|
||||
export const keyProperties = {
|
||||
PartitionKey: "$pk",
|
||||
Id: "id",
|
||||
Id2: "$id", // This should always be the same value as Id
|
||||
@@ -33,14 +34,17 @@ export var keyProperties = {
|
||||
};
|
||||
|
||||
export function convertDocumentsToEntities(documents: any[]): Entities.ITableEntityForTablesAPI[] {
|
||||
let results: Entities.ITableEntityForTablesAPI[] = [];
|
||||
const results: Entities.ITableEntityForTablesAPI[] = [];
|
||||
documents &&
|
||||
documents.forEach((document) => {
|
||||
if (!document.hasOwnProperty(keyProperties.PartitionKey) || !document.hasOwnProperty(keyProperties.Id)) {
|
||||
if (
|
||||
!Object.prototype.hasOwnProperty.call(document, keyProperties.PartitionKey) ||
|
||||
Object.prototype.hasOwnProperty.call(document, keyProperties.Id)
|
||||
) {
|
||||
//Document does not match the current required format for Tables, so we ignore it
|
||||
return; // The rest of the key properties should be guaranteed as DocumentDB properties
|
||||
}
|
||||
let entity: Entities.ITableEntityForTablesAPI = <Entities.ITableEntityForTablesAPI>{
|
||||
const entity: Entities.ITableEntityForTablesAPI = <Entities.ITableEntityForTablesAPI>{
|
||||
PartitionKey: {
|
||||
_: document[keyProperties.PartitionKey],
|
||||
$: Constants.TableType.String,
|
||||
@@ -71,8 +75,8 @@ export function convertDocumentsToEntities(documents: any[]): Entities.ITableEnt
|
||||
$: Constants.TableType.String,
|
||||
},
|
||||
};
|
||||
for (var property in document) {
|
||||
if (document.hasOwnProperty(property)) {
|
||||
for (const property in document) {
|
||||
if (Object.prototype.hasOwnProperty.call(document, property)) {
|
||||
if (
|
||||
property !== keyProperties.PartitionKey &&
|
||||
property !== keyProperties.Id &&
|
||||
@@ -83,7 +87,10 @@ export function convertDocumentsToEntities(documents: any[]): Entities.ITableEnt
|
||||
property !== keyProperties.attachments &&
|
||||
property !== keyProperties.Id2
|
||||
) {
|
||||
if (!document[property].hasOwnProperty("$v") || !document[property].hasOwnProperty("$t")) {
|
||||
if (
|
||||
!Object.prototype.hasOwnProperty.call(document[property], "$v") ||
|
||||
!Object.prototype.hasOwnProperty.call(document[property], "$t")
|
||||
) {
|
||||
return; //Document property does not match the current required format for Tables, so we ignore it
|
||||
}
|
||||
if (DataTypes[document[property][tablesIndexers.Type]] === DataTypes[DataTypes.DateTime]) {
|
||||
@@ -111,10 +118,10 @@ export function convertEntitiesToDocuments(
|
||||
entities: Entities.ITableEntityForTablesAPI[],
|
||||
collection: ViewModels.Collection
|
||||
): any[] {
|
||||
let results: any[] = [];
|
||||
const results: any[] = [];
|
||||
entities &&
|
||||
entities.forEach((entity) => {
|
||||
let document: any = {
|
||||
const document: any = {
|
||||
$id: entity.RowKey._,
|
||||
id: entity.RowKey._,
|
||||
ts: DateTimeUtilities.convertJSDateToUnix(entity.Timestamp._), // Convert back to unix time
|
||||
@@ -129,7 +136,7 @@ export function convertEntitiesToDocuments(
|
||||
document[collection.partitionKeyProperty] = entity.PartitionKey._;
|
||||
document["partitionKeyValue"] = entity.PartitionKey._;
|
||||
}
|
||||
for (var property in entity) {
|
||||
for (const property in entity) {
|
||||
if (
|
||||
property !== Constants.EntityKeyNames.PartitionKey &&
|
||||
property !== Constants.EntityKeyNames.RowKey &&
|
||||
@@ -160,7 +167,7 @@ export function convertEntitiesToDocuments(
|
||||
}
|
||||
|
||||
export function convertEntityToNewDocument(entity: Entities.ITableEntityForTablesAPI): any {
|
||||
let document: any = {
|
||||
const document: any = {
|
||||
$pk: entity.PartitionKey._,
|
||||
$id: entity.RowKey._,
|
||||
id: entity.RowKey._,
|
||||
|
||||
@@ -92,7 +92,7 @@ export default class DocumentsTab extends TabsBase {
|
||||
|
||||
this.partitionKeyPropertyHeader =
|
||||
(this.collection && this.collection.partitionKeyPropertyHeader) || this._getPartitionKeyPropertyHeader();
|
||||
this.partitionKeyProperty = !!this.partitionKeyPropertyHeader
|
||||
this.partitionKeyProperty = this.partitionKeyPropertyHeader
|
||||
? this.partitionKeyPropertyHeader.replace(/[/]+/g, ".").substr(1).replace(/[']+/g, "")
|
||||
: null;
|
||||
|
||||
@@ -446,8 +446,8 @@ export default class DocumentsTab extends TabsBase {
|
||||
this.partitionKey as PartitionKeyDefinition
|
||||
);
|
||||
const partitionKeyValue = partitionKeyValueArray && partitionKeyValueArray[0];
|
||||
let id = new DocumentId(this, savedDocument, partitionKeyValue);
|
||||
let ids = this.documentIds();
|
||||
const id = new DocumentId(this, savedDocument, partitionKeyValue);
|
||||
const ids = this.documentIds();
|
||||
ids.push(id);
|
||||
|
||||
this.selectedDocumentId(id);
|
||||
@@ -682,10 +682,10 @@ export default class DocumentsTab extends TabsBase {
|
||||
}
|
||||
|
||||
public createIterator(): QueryIterator<ItemDefinition & Resource> {
|
||||
let filters = this.lastFilterContents();
|
||||
const filters = this.lastFilterContents();
|
||||
const filter: string = this.filterContent().trim();
|
||||
const query: string = this.buildQuery(filter);
|
||||
let options: any = {};
|
||||
const options: any = {};
|
||||
options.enableCrossPartitionQuery = HeadersUtility.shouldEnableCrossPartitionKey();
|
||||
|
||||
if (this._resourceTokenPartitionKey) {
|
||||
@@ -778,7 +778,7 @@ export default class DocumentsTab extends TabsBase {
|
||||
|
||||
protected _onEditorContentChange(newContent: string) {
|
||||
try {
|
||||
let parsed: any = JSON.parse(newContent);
|
||||
const parsed: any = JSON.parse(newContent);
|
||||
this.onValidDocumentEdit();
|
||||
} catch (e) {
|
||||
this.onInvalidDocumentEdit();
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||
import { extractPartitionKey, PartitionKeyDefinition } from "@azure/cosmos";
|
||||
import * as ko from "knockout";
|
||||
import Q from "q";
|
||||
@@ -44,7 +46,7 @@ export default class MongoDocumentsTab extends DocumentsTab {
|
||||
super.buildCommandBarOptions();
|
||||
}
|
||||
|
||||
public onSaveNewDocumentClick = (): Promise<any> => {
|
||||
public onSaveNewDocumentClick = (): Promise<void> => {
|
||||
const documentContent = JSON.parse(this.selectedDocumentContent());
|
||||
this.displayedError("");
|
||||
const startKey: number = TelemetryProcessor.traceStart(Action.CreateDocument, {
|
||||
@@ -59,9 +61,8 @@ export default class MongoDocumentsTab extends DocumentsTab {
|
||||
) {
|
||||
const message = `The document is lacking the shard property: ${this.partitionKeyProperty}`;
|
||||
this.displayedError(message);
|
||||
let that = this;
|
||||
setTimeout(() => {
|
||||
that.displayedError("");
|
||||
this.displayedError("");
|
||||
}, Constants.ClientDefaults.errorNotificationTimeoutMs);
|
||||
this.isExecutionError(true);
|
||||
TelemetryProcessor.traceFailure(
|
||||
@@ -82,19 +83,19 @@ export default class MongoDocumentsTab extends DocumentsTab {
|
||||
return createDocument(this.collection.databaseId, this.collection, this.partitionKeyProperty, documentContent)
|
||||
.then(
|
||||
(savedDocument: any) => {
|
||||
let partitionKeyArray = extractPartitionKey(
|
||||
const partitionKeyArray = extractPartitionKey(
|
||||
savedDocument,
|
||||
this._getPartitionKeyDefinition() as PartitionKeyDefinition
|
||||
);
|
||||
|
||||
let partitionKeyValue = partitionKeyArray && partitionKeyArray[0];
|
||||
const partitionKeyValue = partitionKeyArray && partitionKeyArray[0];
|
||||
|
||||
let id = new ObjectId(this, savedDocument, partitionKeyValue);
|
||||
let ids = this.documentIds();
|
||||
const id = new ObjectId(this, savedDocument, partitionKeyValue);
|
||||
const ids = this.documentIds();
|
||||
ids.push(id);
|
||||
delete savedDocument._self;
|
||||
|
||||
let value: string = this.renderObjectForEditor(savedDocument || {}, null, 4);
|
||||
const value: string = this.renderObjectForEditor(savedDocument || {}, null, 4);
|
||||
this.selectedDocumentContent.setBaseline(value);
|
||||
|
||||
this.selectedDocumentId(id);
|
||||
@@ -128,7 +129,7 @@ export default class MongoDocumentsTab extends DocumentsTab {
|
||||
.finally(() => this.isExecuting(false));
|
||||
};
|
||||
|
||||
public onSaveExisitingDocumentClick = (): Promise<any> => {
|
||||
public onSaveExisitingDocumentClick = (): Promise<void> => {
|
||||
const selectedDocumentId = this.selectedDocumentId();
|
||||
const documentContent = this.selectedDocumentContent();
|
||||
this.isExecutionError(false);
|
||||
@@ -141,7 +142,7 @@ export default class MongoDocumentsTab extends DocumentsTab {
|
||||
return updateDocument(this.collection.databaseId, this.collection, selectedDocumentId, documentContent)
|
||||
.then(
|
||||
(updatedDocument: any) => {
|
||||
let value: string = this.renderObjectForEditor(updatedDocument || {}, null, 4);
|
||||
const value: string = this.renderObjectForEditor(updatedDocument || {}, null, 4);
|
||||
this.selectedDocumentContent.setBaseline(value);
|
||||
|
||||
this.documentIds().forEach((documentId: DocumentId) => {
|
||||
@@ -151,7 +152,7 @@ export default class MongoDocumentsTab extends DocumentsTab {
|
||||
this._getPartitionKeyDefinition() as PartitionKeyDefinition
|
||||
);
|
||||
|
||||
let partitionKeyValue = partitionKeyArray && partitionKeyArray[0];
|
||||
const partitionKeyValue = partitionKeyArray && partitionKeyArray[0];
|
||||
|
||||
const id = new ObjectId(this, updatedDocument, partitionKeyValue);
|
||||
documentId.id(id.id());
|
||||
@@ -196,7 +197,7 @@ export default class MongoDocumentsTab extends DocumentsTab {
|
||||
this.initDocumentEditor(documentId, content);
|
||||
}
|
||||
|
||||
public loadNextPage(): Q.Promise<any> {
|
||||
public loadNextPage(): Q.Promise<void> {
|
||||
this.isExecuting(true);
|
||||
this.isExecutionError(false);
|
||||
const filter: string = this.filterContent().trim();
|
||||
@@ -228,7 +229,7 @@ export default class MongoDocumentsTab extends DocumentsTab {
|
||||
this.selectedDocumentId(null);
|
||||
this.editorState(ViewModels.DocumentExplorerState.noDocumentSelected);
|
||||
}
|
||||
if (this.onLoadStartKey != null && this.onLoadStartKey != undefined) {
|
||||
if (this.onLoadStartKey !== null && this.onLoadStartKey !== undefined) {
|
||||
TelemetryProcessor.traceSuccess(
|
||||
Action.Tab,
|
||||
{
|
||||
@@ -243,8 +244,8 @@ export default class MongoDocumentsTab extends DocumentsTab {
|
||||
this.onLoadStartKey = null;
|
||||
}
|
||||
},
|
||||
(error: any) => {
|
||||
if (this.onLoadStartKey != null && this.onLoadStartKey != undefined) {
|
||||
(error: Error) => {
|
||||
if (this.onLoadStartKey !== null && this.onLoadStartKey !== undefined) {
|
||||
TelemetryProcessor.traceFailure(
|
||||
Action.Tab,
|
||||
{
|
||||
@@ -265,13 +266,13 @@ export default class MongoDocumentsTab extends DocumentsTab {
|
||||
.finally(() => this.isExecuting(false));
|
||||
}
|
||||
|
||||
protected _onEditorContentChange(newContent: string) {
|
||||
protected _onEditorContentChange(newContent: string): void {
|
||||
try {
|
||||
if (
|
||||
this.editorState() === ViewModels.DocumentExplorerState.newDocumentValid ||
|
||||
this.editorState() === ViewModels.DocumentExplorerState.newDocumentInvalid
|
||||
) {
|
||||
let parsed: any = JSON.parse(newContent);
|
||||
const parsed: any = JSON.parse(newContent);
|
||||
}
|
||||
|
||||
// Mongo uses BSON format for _id, trying to parse it as JSON blocks normal flow in an edit
|
||||
|
||||
Reference in New Issue
Block a user