|
|
|
@@ -1,8 +1,3 @@
|
|
|
|
/**
|
|
|
|
|
|
|
|
* [Todo] disable any type of file.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
|
|
|
|
|
|
import * as _ from "underscore";
|
|
|
|
import * as _ from "underscore";
|
|
|
|
import Q from "q";
|
|
|
|
import Q from "q";
|
|
|
|
import * as Entities from "./Entities";
|
|
|
|
import * as Entities from "./Entities";
|
|
|
|
@@ -13,11 +8,11 @@ import * as Constants from "./Constants";
|
|
|
|
* Generates a pseudo-random GUID.
|
|
|
|
* Generates a pseudo-random GUID.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
export function guid() {
|
|
|
|
export function guid() {
|
|
|
|
const s4 = () => {
|
|
|
|
function s4() {
|
|
|
|
return Math.floor((1 + Math.random()) * 0x10000)
|
|
|
|
return Math.floor((1 + Math.random()) * 0x10000)
|
|
|
|
.toString(16)
|
|
|
|
.toString(16)
|
|
|
|
.substring(1);
|
|
|
|
.substring(1);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return s4() + s4() + "-" + s4() + "-" + s4() + "-" + s4() + "-" + s4() + s4() + s4();
|
|
|
|
return s4() + s4() + "-" + s4() + "-" + s4() + "-" + s4() + "-" + s4() + s4() + s4();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -44,7 +39,7 @@ export function ensureBetweenBounds(value: number, minimum: number, maximum: num
|
|
|
|
* If supplied, the original error will be added as "details".
|
|
|
|
* If supplied, the original error will be added as "details".
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
export function getErrorMessage(error: any, simpleMessage?: string): string {
|
|
|
|
export function getErrorMessage(error: any, simpleMessage?: string): string {
|
|
|
|
let detailsMessage: string;
|
|
|
|
var detailsMessage: string;
|
|
|
|
if (typeof error === "string" || error instanceof String) {
|
|
|
|
if (typeof error === "string" || error instanceof String) {
|
|
|
|
detailsMessage = error.toString();
|
|
|
|
detailsMessage = error.toString();
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
@@ -64,7 +59,7 @@ export function getErrorMessage(error: any, simpleMessage?: string): string {
|
|
|
|
* Get the environment's new line characters
|
|
|
|
* Get the environment's new line characters
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
export function getEnvironmentNewLine(): string {
|
|
|
|
export function getEnvironmentNewLine(): string {
|
|
|
|
const platform = navigator.platform.toUpperCase();
|
|
|
|
var platform = navigator.platform.toUpperCase();
|
|
|
|
|
|
|
|
|
|
|
|
if (platform.indexOf("WIN") >= 0) {
|
|
|
|
if (platform.indexOf("WIN") >= 0) {
|
|
|
|
return "\r\n";
|
|
|
|
return "\r\n";
|
|
|
|
@@ -78,7 +73,7 @@ export function getEnvironmentNewLine(): string {
|
|
|
|
* Tests whether two arrays have same elements in the same sequence.
|
|
|
|
* Tests whether two arrays have same elements in the same sequence.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
export function isEqual<T>(a: T[], b: T[]): boolean {
|
|
|
|
export function isEqual<T>(a: T[], b: T[]): boolean {
|
|
|
|
let isEqual = false;
|
|
|
|
var isEqual: boolean = false;
|
|
|
|
if (!!a && !!b && a.length === b.length) {
|
|
|
|
if (!!a && !!b && a.length === b.length) {
|
|
|
|
isEqual = _.every(a, (value: T, index: number) => value === b[index]);
|
|
|
|
isEqual = _.every(a, (value: T, index: number) => value === b[index]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -90,13 +85,12 @@ export function isEqual<T>(a: T[], b: T[]): boolean {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
export function jQuerySelectorEscape(value: string): string {
|
|
|
|
export function jQuerySelectorEscape(value: string): string {
|
|
|
|
value = value || "";
|
|
|
|
value = value || "";
|
|
|
|
// removed Unnecessary escape character: \/.eslintno-useless-escape
|
|
|
|
return value.replace(/[!"#$%&'()*+,.\/:;<=>?@\[\\\]^`{|}~]/g, "\\$&");
|
|
|
|
return value.replace(/[!"#$%&'()*+,./:;<=>?@[\\\]^`{|}~]/g, "\\$&");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function copyTableQuery(query: Entities.ITableQuery): Entities.ITableQuery {
|
|
|
|
export function copyTableQuery(query: Entities.ITableQuery): Entities.ITableQuery {
|
|
|
|
if (!query) {
|
|
|
|
if (!query) {
|
|
|
|
return undefined;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
@@ -110,7 +104,7 @@ export function copyTableQuery(query: Entities.ITableQuery): Entities.ITableQuer
|
|
|
|
* Html encode
|
|
|
|
* Html encode
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
export function htmlEncode(value: string): string {
|
|
|
|
export function htmlEncode(value: string): string {
|
|
|
|
const _divElem: JQuery = $("<div/>");
|
|
|
|
var _divElem: JQuery = $("<div/>");
|
|
|
|
return _divElem.text(value).html();
|
|
|
|
return _divElem.text(value).html();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -123,22 +117,22 @@ export function onKey(
|
|
|
|
event: any,
|
|
|
|
event: any,
|
|
|
|
eventKeyCode: number,
|
|
|
|
eventKeyCode: number,
|
|
|
|
action: ($sourceElement: JQuery) => void,
|
|
|
|
action: ($sourceElement: JQuery) => void,
|
|
|
|
metaKey?: boolean,
|
|
|
|
metaKey: boolean = null,
|
|
|
|
shiftKey?: boolean,
|
|
|
|
shiftKey: boolean = null,
|
|
|
|
altKey?: boolean
|
|
|
|
altKey: boolean = null
|
|
|
|
): boolean {
|
|
|
|
): boolean {
|
|
|
|
const source: unknown = event.target || event.srcElement,
|
|
|
|
var source: any = event.target || event.srcElement,
|
|
|
|
keyCode: number = event.keyCode,
|
|
|
|
keyCode: number = event.keyCode,
|
|
|
|
$sourceElement = $(source);
|
|
|
|
$sourceElement = $(source),
|
|
|
|
let handled = false;
|
|
|
|
handled: boolean = false;
|
|
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
if (
|
|
|
|
$sourceElement.length &&
|
|
|
|
$sourceElement.length &&
|
|
|
|
keyCode === eventKeyCode &&
|
|
|
|
keyCode === eventKeyCode &&
|
|
|
|
$.isFunction(action) &&
|
|
|
|
$.isFunction(action) &&
|
|
|
|
(metaKey === undefined || metaKey === event.metaKey) &&
|
|
|
|
(metaKey === null || metaKey === event.metaKey) &&
|
|
|
|
(shiftKey === undefined || shiftKey === event.shiftKey) &&
|
|
|
|
(shiftKey === null || shiftKey === event.shiftKey) &&
|
|
|
|
(altKey === undefined || altKey === event.altKey)
|
|
|
|
(altKey === null || altKey === event.altKey)
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
action($sourceElement);
|
|
|
|
action($sourceElement);
|
|
|
|
handled = true;
|
|
|
|
handled = true;
|
|
|
|
@@ -153,9 +147,9 @@ export function onKey(
|
|
|
|
export function onEnter(
|
|
|
|
export function onEnter(
|
|
|
|
event: any,
|
|
|
|
event: any,
|
|
|
|
action: ($sourceElement: JQuery) => void,
|
|
|
|
action: ($sourceElement: JQuery) => void,
|
|
|
|
metaKey?: boolean,
|
|
|
|
metaKey: boolean = null,
|
|
|
|
shiftKey?: boolean,
|
|
|
|
shiftKey: boolean = null,
|
|
|
|
altKey?: boolean
|
|
|
|
altKey: boolean = null
|
|
|
|
): boolean {
|
|
|
|
): boolean {
|
|
|
|
return onKey(event, Constants.keyCodes.Enter, action, metaKey, shiftKey, altKey);
|
|
|
|
return onKey(event, Constants.keyCodes.Enter, action, metaKey, shiftKey, altKey);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -166,9 +160,9 @@ export function onEnter(
|
|
|
|
export function onTab(
|
|
|
|
export function onTab(
|
|
|
|
event: any,
|
|
|
|
event: any,
|
|
|
|
action: ($sourceElement: JQuery) => void,
|
|
|
|
action: ($sourceElement: JQuery) => void,
|
|
|
|
metaKey?: boolean,
|
|
|
|
metaKey: boolean = null,
|
|
|
|
shiftKey?: boolean,
|
|
|
|
shiftKey: boolean = null,
|
|
|
|
altKey?: boolean
|
|
|
|
altKey: boolean = null
|
|
|
|
): boolean {
|
|
|
|
): boolean {
|
|
|
|
return onKey(event, Constants.keyCodes.Tab, action, metaKey, shiftKey, altKey);
|
|
|
|
return onKey(event, Constants.keyCodes.Tab, action, metaKey, shiftKey, altKey);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -179,9 +173,9 @@ export function onTab(
|
|
|
|
export function onEsc(
|
|
|
|
export function onEsc(
|
|
|
|
event: any,
|
|
|
|
event: any,
|
|
|
|
action: ($sourceElement: JQuery) => void,
|
|
|
|
action: ($sourceElement: JQuery) => void,
|
|
|
|
metaKey?: boolean,
|
|
|
|
metaKey: boolean = null,
|
|
|
|
shiftKey?: boolean,
|
|
|
|
shiftKey: boolean = null,
|
|
|
|
altKey?: boolean
|
|
|
|
altKey: boolean = null
|
|
|
|
): boolean {
|
|
|
|
): boolean {
|
|
|
|
return onKey(event, Constants.keyCodes.Esc, action, metaKey, shiftKey, altKey);
|
|
|
|
return onKey(event, Constants.keyCodes.Esc, action, metaKey, shiftKey, altKey);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -206,21 +200,21 @@ export function isEnvironmentAltPressed(event: JQueryEventObject): boolean {
|
|
|
|
* Returns whether the current platform is MacOS.
|
|
|
|
* Returns whether the current platform is MacOS.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
export function isMac(): boolean {
|
|
|
|
export function isMac(): boolean {
|
|
|
|
const platform = navigator.platform.toUpperCase();
|
|
|
|
var platform = navigator.platform.toUpperCase();
|
|
|
|
return platform.indexOf("MAC") >= 0;
|
|
|
|
return platform.indexOf("MAC") >= 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// MAX_SAFE_INTEGER and MIN_SAFE_INTEGER will be provided by ECMAScript 6's Number
|
|
|
|
// MAX_SAFE_INTEGER and MIN_SAFE_INTEGER will be provided by ECMAScript 6's Number
|
|
|
|
export const MAX_SAFE_INTEGER = Math.pow(2, 53) - 1;
|
|
|
|
export var MAX_SAFE_INTEGER = Math.pow(2, 53) - 1;
|
|
|
|
export const MIN_SAFE_INTEGER = -MAX_SAFE_INTEGER;
|
|
|
|
export var MIN_SAFE_INTEGER = -MAX_SAFE_INTEGER;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Tests whether a value a safe integer.
|
|
|
|
* Tests whether a value a safe integer.
|
|
|
|
* A safe integer is an integer that can be exactly represented as an IEEE-754 double precision number (all integers from (2^53 - 1) to -(2^53 - 1))
|
|
|
|
* A safe integer is an integer that can be exactly represented as an IEEE-754 double precision number (all integers from (2^53 - 1) to -(2^53 - 1))
|
|
|
|
* Note: Function and constants will be provided by ECMAScript 6's Number.
|
|
|
|
* Note: Function and constants will be provided by ECMAScript 6's Number.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
export function isSafeInteger(value: number | string): boolean {
|
|
|
|
export function isSafeInteger(value: any): boolean {
|
|
|
|
const n: number = typeof value !== "number" ? Number(value) : value;
|
|
|
|
var n: number = typeof value !== "number" ? Number(value) : value;
|
|
|
|
|
|
|
|
|
|
|
|
return Math.round(n) === n && MIN_SAFE_INTEGER <= n && n <= MAX_SAFE_INTEGER;
|
|
|
|
return Math.round(n) === n && MIN_SAFE_INTEGER <= n && n <= MAX_SAFE_INTEGER;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -246,7 +240,7 @@ export function getInputTypeFromDisplayedName(displayedName: string): string {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function padLongWithZeros(value: string): string {
|
|
|
|
export function padLongWithZeros(value: string): string {
|
|
|
|
const s = "0000000000000000000" + value;
|
|
|
|
var s = "0000000000000000000" + value;
|
|
|
|
return s.substr(s.length - 20);
|
|
|
|
return s.substr(s.length - 20);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -255,13 +249,13 @@ export function padLongWithZeros(value: string): string {
|
|
|
|
* Notice: Not every header will have a data type since some headers don't even exist in entities.
|
|
|
|
* Notice: Not every header will have a data type since some headers don't even exist in entities.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
export function getDataTypesFromEntities(headers: string[], entities: Entities.ITableEntity[]): any {
|
|
|
|
export function getDataTypesFromEntities(headers: string[], entities: Entities.ITableEntity[]): any {
|
|
|
|
let currentHeaders: string[] = _.clone(headers);
|
|
|
|
var currentHeaders: string[] = _.clone(headers);
|
|
|
|
const dataTypes: any = {};
|
|
|
|
var dataTypes: any = {};
|
|
|
|
entities = entities || [];
|
|
|
|
entities = entities || [];
|
|
|
|
entities.forEach((entity: Entities.ITableEntity) => {
|
|
|
|
entities.forEach((entity: Entities.ITableEntity, index: number) => {
|
|
|
|
if (currentHeaders.length) {
|
|
|
|
if (currentHeaders.length) {
|
|
|
|
const keys: string[] = _.keys(entity);
|
|
|
|
var keys: string[] = _.keys(entity);
|
|
|
|
const headersToProcess: string[] = _.intersection(currentHeaders, keys);
|
|
|
|
var headersToProcess: string[] = _.intersection(currentHeaders, keys);
|
|
|
|
headersToProcess &&
|
|
|
|
headersToProcess &&
|
|
|
|
headersToProcess.forEach((propertyName: string) => {
|
|
|
|
headersToProcess.forEach((propertyName: string) => {
|
|
|
|
dataTypes[propertyName] = entity[propertyName].$ || Constants.TableType.String;
|
|
|
|
dataTypes[propertyName] = entity[propertyName].$ || Constants.TableType.String;
|
|
|
|
@@ -276,9 +270,9 @@ export function getDataTypesFromEntities(headers: string[], entities: Entities.I
|
|
|
|
* Set a data type for each header. The data type is inferred from Cassandra Schema.
|
|
|
|
* Set a data type for each header. The data type is inferred from Cassandra Schema.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
export function getDataTypesFromCassandraSchema(schema: CassandraTableKey[]): any {
|
|
|
|
export function getDataTypesFromCassandraSchema(schema: CassandraTableKey[]): any {
|
|
|
|
const dataTypes: any = {};
|
|
|
|
var dataTypes: any = {};
|
|
|
|
schema &&
|
|
|
|
schema &&
|
|
|
|
schema.forEach((schemaItem: CassandraTableKey) => {
|
|
|
|
schema.forEach((schemaItem: CassandraTableKey, index: number) => {
|
|
|
|
dataTypes[schemaItem.property] = schemaItem.type;
|
|
|
|
dataTypes[schemaItem.property] = schemaItem.type;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return dataTypes;
|
|
|
|
return dataTypes;
|
|
|
|
|