http://git-wip-us.apache.org/repos/asf/ignite/blob/541e17d0/modules/web-console/src/main/js/controllers/common-module.js
----------------------------------------------------------------------
diff --git a/modules/web-console/src/main/js/controllers/common-module.js
b/modules/web-console/src/main/js/controllers/common-module.js
index 930fbc8..ba6ec62 100644
--- a/modules/web-console/src/main/js/controllers/common-module.js
+++ b/modules/web-console/src/main/js/controllers/common-module.js
@@ -35,22 +35,23 @@ import alertTemplate from '../views/templates/alert.jade!';
consoleModule.run(['$rootScope', '$http', '$state', '$common', 'Auth', 'User',
'gettingStarted',
($root, $http, $state, $common, Auth, User, gettingStarted) => {
- $root.gettingStarted = gettingStarted;
-
- $root.revertIdentity = function () {
- $http
- .get('/api/v1/admin/revert/identity')
- .then(User.read)
- .then(function (user) {
- $root.$broadcast('user', user);
-
- $state.go('settings.admin');
- })
- .catch(function (errMsg) {
- $common.showError($common.errorMessage(errMsg));
- });
- };
-}]);
+ $root.gettingStarted = gettingStarted;
+
+ $root.revertIdentity = function() {
+ $http
+ .get('/api/v1/admin/revert/identity')
+ .then(User.read)
+ .then(function(user) {
+ $root.$broadcast('user', user);
+
+ $state.go('settings.admin');
+ })
+ .catch(function(errMsg) {
+ $common.showError($common.errorMessage(errMsg));
+ });
+ };
+ }
+]);
// Modal popup configuration.
consoleModule.config(['$modalProvider', ($modalProvider) => {
@@ -124,7 +125,7 @@ consoleModule.service('$common', ['$alert', '$popover',
'$anchorScroll', '$locat
$anchorScroll.yOffset = 55;
function isDefined(v) {
- return !(v === undefined || v === null);
+ return !_.isNil(v);
}
function isEmptyString(s) {
@@ -134,7 +135,7 @@ consoleModule.service('$common', ['$alert', '$popover',
'$anchorScroll', '$locat
return true;
}
- var msgModal;
+ let msgModal;
function errorMessage(errMsg) {
if (errMsg) {
@@ -155,7 +156,7 @@ consoleModule.service('$common', ['$alert', '$popover',
'$anchorScroll', '$locat
title: errorMessage(msg),
placement: placement ? placement : 'top-right',
container: container ? container : 'body',
- duration: persistent ? false : 5
+ duration: persistent ? false : 10
});
msgModal.$scope.icon = icon ? icon : 'fa-exclamation-triangle';
@@ -163,16 +164,16 @@ consoleModule.service('$common', ['$alert', '$popover',
'$anchorScroll', '$locat
return false;
}
- var javaBuiltInClasses = [
+ const javaBuiltInClasses = [
'BigDecimal', 'Boolean', 'Byte', 'Date', 'Double', 'Float',
'Integer', 'Long', 'Object', 'Short', 'String', 'Time', 'Timestamp', 'UUID'
];
- var javaBuiltInTypes = [
+ const javaBuiltInTypes = [
'BigDecimal', 'boolean', 'Boolean', 'byte', 'Byte', 'Date',
'double', 'Double', 'float', 'Float',
'int', 'Integer', 'long', 'Long', 'Object', 'short', 'Short',
'String', 'Time', 'Timestamp', 'UUID'
];
- var javaBuiltInFullNameClasses = [
+ const javaBuiltInFullNameClasses = [
'java.math.BigDecimal', 'java.lang.Boolean', 'java.lang.Byte',
'java.sql.Date', 'java.lang.Double',
'java.lang.Float', 'java.lang.Integer', 'java.lang.Long',
'java.lang.Object', 'java.lang.Short',
'java.lang.String', 'java.sql.Time', 'java.sql.Timestamp',
'java.util.UUID'
@@ -189,7 +190,7 @@ consoleModule.service('$common', ['$alert', '$popover',
'$anchorScroll', '$locat
return _.includes(javaBuiltInClasses, clsName) ||
_.includes(javaBuiltInFullNameClasses, clsName);
}
- var SUPPORTED_JDBC_TYPES = [
+ const SUPPORTED_JDBC_TYPES = [
'BIGINT',
'BIT',
'BOOLEAN',
@@ -214,10 +215,10 @@ consoleModule.service('$common', ['$alert', '$popover',
'$anchorScroll', '$locat
'VARCHAR'
];
- var ALL_JDBC_TYPES = [
+ const ALL_JDBC_TYPES = [
{dbName: 'BIT', dbType: -7, javaType: 'Boolean', primitiveType:
'boolean'},
{dbName: 'TINYINT', dbType: -6, javaType: 'Byte', primitiveType:
'byte'},
- {dbName: 'SMALLINT', dbType: 5, javaType: 'Short', primitiveType:
'short'},
+ {dbName: 'SMALLINT', dbType: 5, javaType: 'Short', primitiveType:
'short'},
{dbName: 'INTEGER', dbType: 4, javaType: 'Integer', primitiveType:
'int'},
{dbName: 'BIGINT', dbType: -5, javaType: 'Long', primitiveType:
'long'},
{dbName: 'FLOAT', dbType: 6, javaType: 'Float', primitiveType:
'float'},
@@ -253,7 +254,8 @@ consoleModule.service('$common', ['$alert', '$popover',
'$anchorScroll', '$locat
{dbName: 'SQLXML', dbType: 2009, javaType: 'Object'}
];
- var JAVA_KEYWORDS = [
+ /*eslint-disable */
+ const JAVA_KEYWORDS = [
'abstract', 'assert', 'boolean', 'break',
'byte',
'case', 'catch', 'char', 'class',
'const',
'continue', 'default', 'do', 'double',
'else',
@@ -266,8 +268,99 @@ consoleModule.service('$common', ['$alert', '$popover',
'$anchorScroll', '$locat
'throw', 'throws', 'transient', 'true',
'try',
'void', 'volatile', 'while'
];
+ /*eslint-enable */
+
+ const VALID_JAVA_IDENTIFIER = new RegExp('^[a-zA-Z_$][a-zA-Z\\d_$]*$');
+
+ let popover = null;
+
+ function isElementInViewport(el) {
+ const rect = el.getBoundingClientRect();
+
+ return (
+ rect.top >= 0 &&
+ rect.left >= 0 &&
+ rect.bottom <= (window.innerHeight ||
document.documentElement.clientHeight) &&
+ rect.right <= (window.innerWidth ||
document.documentElement.clientWidth)
+ );
+ }
+
+ const _showPopoverMessage = (id, message, showTime) => {
+ const body = $('body');
+
+ let el = body.find('#' + id);
+
+ if (!el || el.length === 0)
+ el = body.find('[name="' + id + '"]');
+
+ if (el && el.length > 0) {
+ if (!isElementInViewport(el[0])) {
+ $location.hash(el[0].id);
+
+ $anchorScroll();
+ }
- var VALID_JAVA_IDENTIFIER = new RegExp('^[a-zA-Z_$][a-zA-Z\\d_$]*$');
+ const newPopover = $popover(el, {content: message});
+
+ popover = newPopover;
+
+ $timeout(() => newPopover.$promise.then(newPopover.show), 400);
+ $timeout(() => newPopover.hide(), showTime || 5000);
+ }
+ };
+
+ function ensureActivePanel(ui, pnl, focusId) {
+ if (ui) {
+ const collapses = $('div.panel-collapse');
+
+ ui.loadPanel(pnl);
+
+ const idx = _.findIndex(collapses, function(collapse) {
+ return collapse.id === pnl;
+ });
+
+ if (idx >= 0) {
+ const activePanels = ui.activePanels;
+
+ if (!_.includes(ui.topPanels, idx)) {
+ ui.expanded = true;
+
+ const customExpanded = ui[pnl];
+
+ if (customExpanded)
+ ui[customExpanded] = true;
+ }
+
+ if (!activePanels || activePanels.length < 1)
+ ui.activePanels = [idx];
+ else if (!_.includes(activePanels, idx)) {
+ const newActivePanels = angular.copy(activePanels);
+
+ newActivePanels.push(idx);
+
+ ui.activePanels = newActivePanels;
+ }
+ }
+
+ if (isDefined(focusId))
+ $focus(focusId);
+ }
+ }
+
+ function showPopoverMessage(ui, panelId, id, message, showTime) {
+ if (popover)
+ popover.hide();
+
+ if (ui) {
+ ensureActivePanel(ui, panelId);
+
+ $timeout(() => _showPopoverMessage(id, message, showTime),
ui.isPanelLoaded(panelId) ? 200 : 500);
+ }
+ else
+ _showPopoverMessage(id, message, showTime);
+
+ return false;
+ }
function isValidJavaIdentifier(msg, ident, elemId, panels, panelId) {
if (isEmptyString(ident))
@@ -282,7 +375,7 @@ consoleModule.service('$common', ['$alert', '$popover',
'$anchorScroll', '$locat
return true;
}
- var context = null;
+ let context = null;
/**
* Calculate width of specified text in body's font.
@@ -292,11 +385,11 @@ consoleModule.service('$common', ['$alert', '$popover',
'$anchorScroll', '$locat
*/
function measureText(text) {
if (!context) {
- var canvas = document.createElement('canvas');
+ const canvas = document.createElement('canvas');
context = canvas.getContext('2d');
- var style =
window.getComputedStyle(document.getElementsByTagName('body')[0]);
+ const style =
window.getComputedStyle(document.getElementsByTagName('body')[0]);
context.font = style.fontSize + ' ' + style.fontFamily;
}
@@ -312,17 +405,17 @@ consoleModule.service('$common', ['$alert', '$popover',
'$anchorScroll', '$locat
* @returns {*} Array of compacted class names.
*/
function compactByMaxCharts(names, nameLength) {
- for (var nameIx = 0; nameIx < names.length; nameIx ++) {
- var s = names[nameIx];
+ for (let nameIx = 0; nameIx < names.length; nameIx++) {
+ const s = names[nameIx];
if (s.length > nameLength) {
- var totalLength = s.length;
+ let totalLength = s.length;
- var packages = s.split('.');
+ const packages = s.split('.');
- var packageCnt = packages.length - 1;
+ const packageCnt = packages.length - 1;
- for (var i = 0; i < packageCnt && totalLength >
nameLength; i++) {
+ for (let i = 0; i < packageCnt && totalLength >
nameLength; i++) {
if (packages[i].length > 0) {
totalLength -= packages[i].length - 1;
@@ -331,11 +424,11 @@ consoleModule.service('$common', ['$alert', '$popover',
'$anchorScroll', '$locat
}
if (totalLength > nameLength) {
- var className = packages[packageCnt];
+ const className = packages[packageCnt];
- var classNameLen = className.length;
+ const classNameLen = className.length;
- var remains = Math.min(nameLength - totalLength +
classNameLen, classNameLen);
+ let remains = Math.min(nameLength - totalLength +
classNameLen, classNameLen);
if (remains < 3)
remains = Math.min(3, classNameLen);
@@ -343,9 +436,9 @@ consoleModule.service('$common', ['$alert', '$popover',
'$anchorScroll', '$locat
packages[packageCnt] = className.substring(0, remains)
+ '...';
}
- var result = packages[0];
+ let result = packages[0];
- for (i = 1; i < packages.length; i++)
+ for (let i = 1; i < packages.length; i++)
result += '.' + packages[i];
names[nameIx] = result;
@@ -367,27 +460,27 @@ consoleModule.service('$common', ['$alert', '$popover',
'$anchorScroll', '$locat
if (nameWidth <= 0)
return names;
- var fitted = [];
+ const fitted = [];
- var widthByName = [];
+ const widthByName = [];
- var len = names.length;
+ const len = names.length;
- var divideTo = len;
+ let divideTo = len;
- for (var nameIx = 0; nameIx < len; nameIx ++) {
+ for (let nameIx = 0; nameIx < len; nameIx++) {
fitted[nameIx] = false;
widthByName[nameIx] = nameWidth;
}
// Try to distribute space from short class names to long class
names.
- do {
- var remains = 0;
+ let remains = 0;
- for (nameIx = 0; nameIx < len; nameIx++) {
+ do {
+ for (let nameIx = 0; nameIx < len; nameIx++) {
if (!fitted[nameIx]) {
- var curNameWidth = measureText(names[nameIx]);
+ const curNameWidth = measureText(names[nameIx]);
if (widthByName[nameIx] > curNameWidth) {
fitted[nameIx] = true;
@@ -401,29 +494,28 @@ consoleModule.service('$common', ['$alert', '$popover',
'$anchorScroll', '$locat
}
}
- var remainsByName = remains / divideTo;
+ const remainsByName = remains / divideTo;
- for (nameIx = 0; nameIx < len; nameIx++) {
- if (!fitted[nameIx]) {
+ for (let nameIx = 0; nameIx < len; nameIx++) {
+ if (!fitted[nameIx])
widthByName[nameIx] += remainsByName;
- }
}
}
- while(remains > 0);
+ while (remains > 0);
// Compact class names to available for each space.
- for (nameIx = 0; nameIx < len; nameIx ++) {
- var s = names[nameIx];
+ for (let nameIx = 0; nameIx < len; nameIx++) {
+ const s = names[nameIx];
if (s.length > (nameLength / 2 | 0)) {
- var totalWidth = measureText(s);
+ let totalWidth = measureText(s);
if (totalWidth > widthByName[nameIx]) {
- var packages = s.split('.');
+ const packages = s.split('.');
- var packageCnt = packages.length - 1;
+ const packageCnt = packages.length - 1;
- for (var i = 0; i < packageCnt && totalWidth >
widthByName[nameIx]; i++) {
+ for (let i = 0; i < packageCnt && totalWidth >
widthByName[nameIx]; i++) {
if (packages[i].length > 1) {
totalWidth -=
measureText(packages[i].substring(1, packages[i].length));
@@ -431,39 +523,31 @@ consoleModule.service('$common', ['$alert', '$popover',
'$anchorScroll', '$locat
}
}
- var shortPackage = '';
+ let shortPackage = '';
- for (i = 0; i < packageCnt; i++)
+ for (let i = 0; i < packageCnt; i++)
shortPackage += packages[i] + '.';
- var className = packages[packageCnt];
+ const className = packages[packageCnt];
- var classLen = className.length;
+ const classLen = className.length;
- var minLen = Math.min(classLen, 3);
+ let minLen = Math.min(classLen, 3);
totalWidth = measureText(shortPackage + className);
// Compact class name if shorten package path is very
long.
if (totalWidth > widthByName[nameIx]) {
- var maxLen = classLen;
-
- var middleLen = (minLen + (maxLen - minLen) / 2 )
| 0;
-
- var minLenPx = measureText(shortPackage +
className.substr(0, minLen) + '...');
- var maxLenPx = totalWidth;
+ let maxLen = classLen;
+ let middleLen = (minLen + (maxLen - minLen) / 2 )
| 0;
while (middleLen !== minLen && middleLen !==
maxLen) {
- var middleLenPx = measureText(shortPackage +
className.substr(0, middleLen) + '...');
+ const middleLenPx = measureText(shortPackage +
className.substr(0, middleLen) + '...');
- if (middleLenPx > widthByName[nameIx]) {
+ if (middleLenPx > widthByName[nameIx])
maxLen = middleLen;
- maxLenPx = middleLenPx;
- }
- else {
+ else
minLen = middleLen;
- minLenPx = middleLenPx;
- }
middleLen = (minLen + (maxLen - minLen) / 2 )
| 0;
}
@@ -490,29 +574,20 @@ consoleModule.service('$common', ['$alert', '$popover',
'$anchorScroll', '$locat
if (nameWidth <= 0)
return label;
- var totalWidth = measureText(label);
+ const totalWidth = measureText(label);
if (totalWidth > nameWidth) {
- var maxLen = label.length;
-
- var minLen = Math.min(maxLen, 3);
-
- var middleLen = (minLen + (maxLen - minLen) / 2 ) | 0;
-
- var minLenPx = measureText(label.substr(0, minLen) + '...');
- var maxLenPx = totalWidth;
+ let maxLen = label.length;
+ let minLen = Math.min(maxLen, 3);
+ let middleLen = (minLen + (maxLen - minLen) / 2 ) | 0;
while (middleLen !== minLen && middleLen !== maxLen) {
- var middleLenPx = measureText(label.substr(0, middleLen) +
'...');
+ const middleLenPx = measureText(label.substr(0, middleLen)
+ '...');
- if (middleLenPx > nameWidth) {
+ if (middleLenPx > nameWidth)
maxLen = middleLen;
- maxLenPx = middleLenPx;
- }
- else {
+ else
minLen = middleLen;
- minLenPx = middleLenPx;
- }
middleLen = (minLen + (maxLen - minLen) / 2 ) | 0;
}
@@ -531,19 +606,19 @@ consoleModule.service('$common', ['$alert', '$popover',
'$anchorScroll', '$locat
* @returns {*[]} First element is length of class for single value,
second element is length for pair vlaue.
*/
function availableWidth(index, id) {
- var idElem = $('#' + id);
+ const idElem = $('#' + id);
- var width = 0;
+ let width = 0;
- switch (idElem.prop("tagName")) {
+ switch (idElem.prop('tagName')) {
// Detection of available width in presentation table row.
case 'TABLE':
- var cont = $(idElem.find('tr')[index - 1]).find('td')[0];
+ const cont = $(idElem.find('tr')[index - 1]).find('td')[0];
width = cont.clientWidth;
if (width > 0) {
- var children = $(cont).children(':not("a")');
+ const children = $(cont).children(':not("a")');
_.forEach(children, function(child) {
if ('offsetWidth' in child)
@@ -563,104 +638,15 @@ consoleModule.service('$common', ['$alert', '$popover',
'$anchorScroll', '$locat
});
break;
- }
-
- return width | 0;
- }
-
- var popover = null;
-
- function ensureActivePanel(ui, pnl, focusId) {
- if (ui) {
- var collapses = $('div.panel-collapse');
-
- ui.loadPanel(pnl);
-
- var idx = _.findIndex(collapses, function(collapse) {
- return collapse.id === pnl;
- });
-
- if (idx >= 0) {
- var activePanels = ui.activePanels;
-
- if (!_.includes(ui.topPanels, idx)) {
- ui.expanded = true;
-
- var customExpanded = ui[pnl];
-
- if (customExpanded)
- ui[customExpanded] = true;
- }
-
- if (!activePanels || activePanels.length < 1)
- ui.activePanels = [idx];
- else if (!_.includes(activePanels, idx)) {
- var newActivePanels = angular.copy(activePanels);
-
- newActivePanels.push(idx);
-
- ui.activePanels = newActivePanels;
- }
- }
-
- if (isDefined(focusId))
- $focus(focusId);
- }
- }
-
- function isElementInViewport(el) {
- var rect = el.getBoundingClientRect();
-
- return (
- rect.top >= 0 &&
- rect.left >= 0 &&
- rect.bottom <= (window.innerHeight ||
document.documentElement.clientHeight) &&
- rect.right <= (window.innerWidth ||
document.documentElement.clientWidth)
- );
- }
-
- const _showPopoverMessage = (id, message, showTime) => {
- var body = $('body');
-
- var el = body.find('#' + id);
-
- if (!el || el.length === 0)
- el = body.find('[name="' + id + '"]');
-
- if (el && el.length > 0) {
- if (!isElementInViewport(el[0])) {
- $location.hash(el[0].id);
-
- $anchorScroll();
- }
-
- var newPopover = $popover(el, {content: message});
-
- popover = newPopover;
-
- $timeout(function () {
newPopover.$promise.then(newPopover.show); }, 400);
-
- $timeout(function () { newPopover.hide(); }, showTime || 5000);
- }
- };
-
- function showPopoverMessage(ui, panelId, id, message, showTime) {
- if (popover)
- popover.hide();
- if (ui) {
- ensureActivePanel(ui, panelId);
-
- $timeout(() => _showPopoverMessage(id, message, showTime),
ui.isPanelLoaded(panelId) ? 200 : 500);
+ default:
}
- else
- _showPopoverMessage(id, message, showTime);
- return false;
+ return width | 0;
}
function getModel(obj, field) {
- var path = field.path;
+ let path = field.path;
if (!isDefined(path) || !isDefined(obj))
return obj;
@@ -668,11 +654,11 @@ consoleModule.service('$common', ['$alert', '$popover',
'$anchorScroll', '$locat
path = path.replace(/\[(\w+)\]/g, '.$1'); // convert indexes to
properties
path = path.replace(/^\./, ''); // strip a leading dot
- var segs = path.split('.');
- var root = obj;
+ const segs = path.split('.');
+ let root = obj;
while (segs.length > 0) {
- var pathStep = segs.shift();
+ const pathStep = segs.shift();
if (typeof root[pathStep] === 'undefined')
root[pathStep] = {};
@@ -683,52 +669,9 @@ consoleModule.service('$common', ['$alert', '$popover',
'$anchorScroll', '$locat
return root;
}
- function checkGroupDirty(group, curItem, srcItem) {
- function _compareField(field) {
- var curModel = getModel(curItem, field);
- var srcModel = getModel(srcItem, field);
-
- if (field.model) {
- if (field.model === 'kind' && isDefined(curModel.kind)) {
- if (curModel.kind !== srcModel.kind)
- return true;
-
- if
(_compareFields(field.details[curModel.kind].fields))
- return true;
- }
-
- var curValue = curModel[field.model];
- var srcValue = srcModel[field.model];
-
- if ((_.isArray(curValue) || _.isString(curValue)) &&
(curValue.length === 0) && (srcValue === undefined))
- curValue = undefined;
-
- if (_.isBoolean(curValue) && !curValue && srcValue ===
undefined)
- curValue = undefined;
-
- var isCur = isDefined(curValue);
- var isSrc = isDefined(srcValue);
-
- return !!((isCur && !isSrc) || (!isCur && isSrc) || (isCur
&& isSrc && !angular.equals(curValue, srcValue)));
- }
- else if (field.type === 'panel-details' &&
_compareFields(field.details))
- return true;
-
- return false;
- }
-
- function _compareFields(fields) {
- return _.findIndex(fields, _compareField) >= 0;
- }
-
- group.dirty = _compareFields(group.fields);
-
- return group.dirty;
- }
-
function extractDataSource(cache) {
if (cache.cacheStoreFactory && cache.cacheStoreFactory.kind) {
- var storeFactory =
cache.cacheStoreFactory[cache.cacheStoreFactory.kind];
+ const storeFactory =
cache.cacheStoreFactory[cache.cacheStoreFactory.kind];
if (storeFactory.dialect || (storeFactory.connectVia ===
'DataSource'))
return storeFactory;
@@ -737,7 +680,7 @@ consoleModule.service('$common', ['$alert', '$popover',
'$anchorScroll', '$locat
return null;
}
- var cacheStoreJdbcDialects = [
+ const cacheStoreJdbcDialects = [
{value: 'Generic', label: 'Generic JDBC'},
{value: 'Oracle', label: 'Oracle'},
{value: 'DB2', label: 'IBM DB2'},
@@ -748,7 +691,7 @@ consoleModule.service('$common', ['$alert', '$popover',
'$anchorScroll', '$locat
];
function domainForStoreConfigured(domain) {
- var isEmpty = !isDefined(domain) ||
(isEmptyString(domain.databaseSchema) &&
+ const isEmpty = !isDefined(domain) ||
(isEmptyString(domain.databaseSchema) &&
isEmptyString(domain.databaseTable) &&
_.isEmpty(domain.keyFields) &&
_.isEmpty(domain.valueFields));
@@ -756,46 +699,49 @@ consoleModule.service('$common', ['$alert', '$popover',
'$anchorScroll', '$locat
return !isEmpty;
}
- var DS_CHECK_SUCCESS = { checked: true };
+ const DS_CHECK_SUCCESS = { checked: true };
function compareDataSources(firstCache, secondCache) {
- var firstDs = extractDataSource(firstCache);
- var secondDs = extractDataSource(secondCache);
+ const firstDs = extractDataSource(firstCache);
+ const secondDs = extractDataSource(secondCache);
if (firstDs && secondDs) {
- var firstDB = firstDs.dialect;
- var secondDB = secondDs.dialect;
+ const firstDB = firstDs.dialect;
+ const secondDB = secondDs.dialect;
- if (firstDs.dataSourceBean === secondDs.dataSourceBean &&
firstDB !== secondDB) {
- return {
- checked: false,
- firstCache: firstCache,
- firstDB: firstDB,
- secondCache: secondCache,
- secondDB: secondDB
- };
- }
+ if (firstDs.dataSourceBean === secondDs.dataSourceBean &&
firstDB !== secondDB)
+ return {checked: false, firstCache, firstDB, secondCache,
secondDB};
}
return DS_CHECK_SUCCESS;
}
+ function compareSQLSchemaNames(firstCache, secondCache) {
+ const firstName = firstCache.sqlSchema;
+ const secondName = secondCache.sqlSchema;
+
+ if (firstName && secondName && (firstName === secondName))
+ return {checked: false, firstCache, secondCache};
+
+ return DS_CHECK_SUCCESS;
+ }
+
function toJavaName(prefix, name) {
- var javaName = name ? name.replace(/[^A-Za-z_0-9]+/g, '_') :
'dflt';
+ const javaName = name ? name.replace(/[^A-Za-z_0-9]+/g, '_') :
'dflt';
return prefix + javaName.charAt(0).toLocaleUpperCase() +
javaName.slice(1);
}
return {
- getModel: getModel,
- mkOptions: function (options) {
- return _.map(options, function (option) {
+ getModel,
+ mkOptions(options) {
+ return _.map(options, (option) => {
return {value: option, label: isDefined(option) ? option :
'Not set'};
});
},
- isDefined: isDefined,
- hasProperty: function (obj, props) {
- for (var propName in props) {
+ isDefined,
+ hasProperty(obj, props) {
+ for (const propName in props) {
if (props.hasOwnProperty(propName)) {
if (obj[propName])
return true;
@@ -804,14 +750,14 @@ consoleModule.service('$common', ['$alert', '$popover',
'$anchorScroll', '$locat
return false;
},
- isEmptyString: isEmptyString,
- errorMessage: errorMessage,
- hideAlert: function () {
+ isEmptyString,
+ errorMessage,
+ hideAlert() {
if (msgModal)
msgModal.hide();
},
- showError: showError,
- showInfo: function (msg) {
+ showError,
+ showInfo(msg) {
if (msgModal)
msgModal.hide();
@@ -823,25 +769,25 @@ consoleModule.service('$common', ['$alert', '$popover',
'$anchorScroll', '$locat
msgModal.$scope.icon = 'fa-check-circle-o';
},
- SUPPORTED_JDBC_TYPES: SUPPORTED_JDBC_TYPES,
- findJdbcType: function (jdbcType) {
- var res = _.find(ALL_JDBC_TYPES, function (item) {
+ SUPPORTED_JDBC_TYPES,
+ findJdbcType(jdbcType) {
+ const res = _.find(ALL_JDBC_TYPES, function(item) {
return item.dbType === jdbcType;
});
return res ? res : {dbName: 'Unknown', javaType: 'Unknown'};
},
- javaBuiltInClasses: javaBuiltInClasses,
- javaBuiltInTypes: javaBuiltInTypes,
- isJavaBuiltInClass: isJavaBuiltInClass,
- isValidJavaIdentifier: isValidJavaIdentifier,
- isValidJavaClass: function (msg, ident, allowBuiltInClass, elemId,
packageOnly, panels, panelId) {
+ javaBuiltInClasses,
+ javaBuiltInTypes,
+ isJavaBuiltInClass,
+ isValidJavaIdentifier,
+ isValidJavaClass(msg, ident, allowBuiltInClass, elemId,
packageOnly, panels, panelId) {
if (isEmptyString(ident))
return showPopoverMessage(panels, panelId, elemId, msg + '
could not be empty!');
- var parts = ident.split('.');
+ const parts = ident.split('.');
- var len = parts.length;
+ const len = parts.length;
if (!allowBuiltInClass && isJavaBuiltInClass(ident))
return showPopoverMessage(panels, panelId, elemId, msg + '
should not be the Java build-in class!');
@@ -849,8 +795,8 @@ consoleModule.service('$common', ['$alert', '$popover',
'$anchorScroll', '$locat
if (len < 2 && !isJavaBuiltInClass(ident) && !packageOnly)
return showPopoverMessage(panels, panelId, elemId, msg + '
does not have package specified!');
- for (var i = 0; i < parts.length; i++) {
- var part = parts[i];
+ for (let i = 0; i < parts.length; i++) {
+ const part = parts[i];
if (!isValidJavaIdentifier(msg, part, elemId, panels,
panelId))
return false;
@@ -858,14 +804,14 @@ consoleModule.service('$common', ['$alert', '$popover',
'$anchorScroll', '$locat
return true;
},
- domainForQueryConfigured: function (domain) {
- var isEmpty = !isDefined(domain) || (_.isEmpty(domain.fields)
&&
+ domainForQueryConfigured(domain) {
+ const isEmpty = !isDefined(domain) ||
(_.isEmpty(domain.fields) &&
_.isEmpty(domain.aliases) &&
_.isEmpty(domain.indexes));
return !isEmpty;
},
- domainForStoreConfigured: domainForStoreConfigured,
+ domainForStoreConfigured,
/**
* Cut class name by width in pixel or width in symbol count.
*
@@ -876,17 +822,17 @@ consoleModule.service('$common', ['$alert', '$popover',
'$anchorScroll', '$locat
* @param divider String to visualy divide items.
* @returns {*} Array of compacted class names.
*/
- compactJavaName: function (id, index, maxLength, names, divider) {
+ compactJavaName(id, index, maxLength, names, divider) {
divider = ' ' + divider + ' ';
- var prefix = index + ') ';
+ const prefix = index + ') ';
- var nameCnt = names.length;
+ const nameCnt = names.length;
- var nameLength = ((maxLength - 3 * (nameCnt - 1)) / nameCnt) |
0;
+ const nameLength = ((maxLength - 3 * (nameCnt - 1)) / nameCnt)
| 0;
try {
- var nameWidth = (availableWidth(index, id) -
measureText(prefix) - (nameCnt - 1) * measureText(divider)) /
+ const nameWidth = (availableWidth(index, id) -
measureText(prefix) - (nameCnt - 1) * measureText(divider)) /
nameCnt | 0;
// HTML5 calculation of showed message width.
@@ -896,9 +842,9 @@ consoleModule.service('$common', ['$alert', '$popover',
'$anchorScroll', '$locat
names = compactByMaxCharts(names, nameLength);
}
- var result = prefix + names[0];
+ let result = prefix + names[0];
- for (var nameIx = 1; nameIx < names.length; nameIx ++)
+ for (let nameIx = 1; nameIx < names.length; nameIx++)
result += divider + names[nameIx];
return result;
@@ -912,28 +858,28 @@ consoleModule.service('$common', ['$alert', '$popover',
'$anchorScroll', '$locat
* @param label Text to compact.
* @returns Compacted label text.
*/
- compactTableLabel: function (id, index, maxLength, label) {
+ compactTableLabel(id, index, maxLength, label) {
label = index + ') ' + label;
try {
- var nameWidth = availableWidth(index, id) | 0;
+ const nameWidth = availableWidth(index, id) | 0;
// HTML5 calculation of showed message width.
label = compactLabelByPixels(label, nameWidth);
}
catch (err) {
- var nameLength = maxLength - 3 | 0;
+ const nameLength = maxLength - 3 | 0;
label = label.length > maxLength ? label.substr(0,
nameLength) + '...' : label;
}
return label;
},
- widthIsSufficient: function(id, index, text) {
+ widthIsSufficient(id, index, text) {
try {
- var available = availableWidth(index, id);
+ const available = availableWidth(index, id);
- var required = measureText(text);
+ const required = measureText(text);
return !available || available >= Math.floor(required);
}
@@ -941,15 +887,15 @@ consoleModule.service('$common', ['$alert', '$popover',
'$anchorScroll', '$locat
return true;
}
},
- ensureActivePanel: function (panels, id, focusId) {
+ ensureActivePanel(panels, id, focusId) {
ensureActivePanel(panels, id, focusId);
},
- showPopoverMessage: showPopoverMessage,
- hidePopover: function () {
+ showPopoverMessage,
+ hidePopover() {
if (popover)
popover.hide();
},
- confirmUnsavedChanges: function(dirty, selectFunc) {
+ confirmUnsavedChanges(dirty, selectFunc) {
if (dirty) {
if ($window.confirm('You have unsaved changes.\n\nAre you
sure you want to discard them?'))
selectFunc();
@@ -957,16 +903,16 @@ consoleModule.service('$common', ['$alert', '$popover',
'$anchorScroll', '$locat
else
selectFunc();
},
- saveBtnTipText: function (dirty, objectName) {
+ saveBtnTipText(dirty, objectName) {
if (dirty)
return 'Save ' + objectName;
return 'Nothing to save';
},
- download: function (type, name, data) {
- var file = document.createElement('a');
+ download(type, name, data) {
+ const file = document.createElement('a');
- file.setAttribute('href', 'data:' + type +';charset=utf-8,' +
data);
+ file.setAttribute('href', 'data:' + type + ';charset=utf-8,' +
data);
file.setAttribute('download', name);
file.setAttribute('target', '_self');
@@ -978,49 +924,46 @@ consoleModule.service('$common', ['$alert', '$popover',
'$anchorScroll', '$locat
document.body.removeChild(file);
},
- formUI: function () {
+ formUI() {
return {
ready: false,
expanded: false,
loadedPanels: [],
- loadPanel: function(pnl) {
+ loadPanel(pnl) {
if (!_.includes(this.loadedPanels, pnl))
this.loadedPanels.push(pnl);
},
- isPanelLoaded: function(pnl) {
+ isPanelLoaded(pnl) {
return _.includes(this.loadedPanels, pnl);
}
};
},
- getQueryVariable: function(name) {
- var attrs = window.location.search.substring(1).split("&");
-
- var attr = _.find(attrs, function(attr) {
- return attr === name || (attr.indexOf('=') >= 0 &&
attr.substr(0, attr.indexOf('=')) === name);
- });
+ getQueryVariable(name) {
+ const attrs = window.location.search.substring(1).split('&');
+ const attr = _.find(attrs, (a) => a === name ||
(a.indexOf('=') >= 0 && a.substr(0, a.indexOf('=')) === name));
if (!isDefined(attr))
- return undefined;
+ return null;
if (attr === name)
return true;
return attr.substr(attr.indexOf('=') + 1);
},
- cacheStoreJdbcDialects: cacheStoreJdbcDialects,
- cacheStoreJdbcDialectsLabel: function (dialect) {
- var found = _.find(cacheStoreJdbcDialects, function
(dialectVal) {
+ cacheStoreJdbcDialects,
+ cacheStoreJdbcDialectsLabel(dialect) {
+ const found = _.find(cacheStoreJdbcDialects,
function(dialectVal) {
return dialectVal.value === dialect;
});
- return found ? found.label : undefined;
+ return found ? found.label : null;
},
- checkCachesDataSources: function (caches, checkCacheExt) {
- var res = DS_CHECK_SUCCESS;
+ checkCachesDataSources(caches, checkCacheExt) {
+ let res = DS_CHECK_SUCCESS;
- _.find(caches, function (curCache, curIx) {
+ _.find(caches, function(curCache, curIx) {
if (isDefined(checkCacheExt)) {
- if (!isDefined(checkCacheExt._id) || checkCacheExt.id
!= curCache._id) {
+ if (checkCacheExt._id !== curCache._id) {
res = compareDataSources(checkCacheExt, curCache);
return !res.checked;
@@ -1028,27 +971,53 @@ consoleModule.service('$common', ['$alert', '$popover',
'$anchorScroll', '$locat
return false;
}
- else {
- return _.find(caches, function (checkCache, checkIx) {
- if (checkIx < curIx) {
- res = compareDataSources(checkCache, curCache);
- return !res.checked;
- }
+ return _.find(caches, function(checkCache, checkIx) {
+ if (checkIx < curIx) {
+ res = compareDataSources(checkCache, curCache);
- return false;
- });
+ return !res.checked;
+ }
+
+ return false;
+ });
+ });
+
+ return res;
+ },
+ checkCacheSQLSchemas(caches, checkCacheExt) {
+ let res = DS_CHECK_SUCCESS;
+
+ _.find(caches, (curCache, curIx) => {
+ if (isDefined(checkCacheExt)) {
+ if (checkCacheExt._id !== curCache._id) {
+ res = compareSQLSchemaNames(checkCacheExt,
curCache);
+
+ return !res.checked;
+ }
+
+ return false;
}
+
+ return _.find(caches, function(checkCache, checkIx) {
+ if (checkIx < curIx) {
+ res = compareSQLSchemaNames(checkCache, curCache);
+
+ return !res.checked;
+ }
+
+ return false;
+ });
});
return res;
},
- autoCacheStoreConfiguration: function (cache, domains) {
- var cacheStoreFactory = isDefined(cache.cacheStoreFactory) &&
+ autoCacheStoreConfiguration(cache, domains) {
+ const cacheStoreFactory = isDefined(cache.cacheStoreFactory) &&
isDefined(cache.cacheStoreFactory.kind);
if (!cacheStoreFactory && _.findIndex(domains,
domainForStoreConfigured) >= 0) {
- var dflt = !cache.readThrough && !cache.writeThrough;
+ const dflt = !cache.readThrough && !cache.writeThrough;
return {
cacheStoreFactory: {
@@ -1063,17 +1032,17 @@ consoleModule.service('$common', ['$alert', '$popover',
'$anchorScroll', '$locat
};
}
},
- autoClusterSwapSpiConfiguration: function (cluster, caches) {
- var swapConfigured = cluster.swapSpaceSpi &&
cluster.swapSpaceSpi.kind;
+ autoClusterSwapSpiConfiguration(cluster, caches) {
+ const swapConfigured = cluster.swapSpaceSpi &&
cluster.swapSpaceSpi.kind;
- if (!swapConfigured && _.find(caches, function (cache) {
+ if (!swapConfigured && _.find(caches, function(cache) {
return cache.swapEnabled;
}))
return {swapSpaceSpi: {kind: 'FileSwapSpaceSpi'}};
- return undefined;
+ return null;
},
- randomString: (len) => {
+ randomString(len) {
const possible =
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
const possibleLen = possible.length;
@@ -1083,6 +1052,41 @@ consoleModule.service('$common', ['$alert', '$popover',
'$anchorScroll', '$locat
res += possible.charAt(Math.floor(Math.random() *
possibleLen));
return res;
+ },
+ checkFieldValidators(ui) {
+ const form = ui.inputForm;
+ const errors = form.$error;
+ const errKeys = Object.keys(errors);
+
+ if (errKeys && errKeys.length > 0) {
+ const firstErrorKey = errKeys[0];
+
+ const firstError = errors[firstErrorKey][0];
+ const actualError = firstError.$error[firstErrorKey][0];
+
+ const errNameFull = actualError.$name;
+ const errNameShort = errNameFull.endsWith('TextInput') ?
errNameFull.substring(0, errNameFull.length - 9) : errNameFull;
+
+ const extractErrorMessage = function(errName) {
+ try {
+ return
errors[firstErrorKey][0].$errorMessages[errName][firstErrorKey];
+ }
+ catch (ignored) {
+ try {
+ return
form[firstError.$name].$errorMessages[errName][firstErrorKey];
+ }
+ catch (ignited) {
+ return false;
+ }
+ }
+ };
+
+ const msg = extractErrorMessage(errNameFull) ||
extractErrorMessage(errNameShort) || 'Invalid value!';
+
+ return showPopoverMessage(ui, firstError.$name,
errNameFull, msg);
+ }
+
+ return true;
}
};
}]);
@@ -1090,25 +1094,24 @@ consoleModule.service('$common', ['$alert', '$popover',
'$anchorScroll', '$locat
// Confirm change location.
consoleModule.service('$unsavedChangesGuard', ['$rootScope', ($root) => {
return {
- install: function ($scope) {
- $scope.$on("$destroy", function() {
+ install($scope, customDirtyCheck = () => $scope.ui.inputForm.$dirty) {
+ $scope.$on('$destroy', function() {
window.onbeforeunload = null;
});
- var unbind = $root.$on('$stateChangeStart', function(event) {
- if ($scope.ui && $scope.ui.inputForm &&
$scope.ui.inputForm.$dirty) {
- if (!confirm('You have unsaved changes.\n\nAre you sure
you want to discard them?')) {
+ const unbind = $root.$on('$stateChangeStart', function(event) {
+ if ($scope.ui && $scope.ui.inputForm && customDirtyCheck()) {
+ if (!confirm('You have unsaved changes.\n\nAre you sure
you want to discard them?')) // eslint-disable-line no-alert
event.preventDefault();
- } else {
+ else
unbind();
- }
}
});
- window.onbeforeunload = function(){
+ window.onbeforeunload = function() {
return $scope.ui && $scope.ui.inputForm &&
$scope.ui.inputForm.$dirty
? 'You have unsaved changes.\n\nAre you sure you want to
discard them?'
- : undefined;
+ : null;
};
}
};
@@ -1116,9 +1119,9 @@ consoleModule.service('$unsavedChangesGuard',
['$rootScope', ($root) => {
// Service for confirm or skip several steps.
consoleModule.service('$confirmBatch', ['$modal', '$rootScope', '$q', ($modal,
$root, $q) => {
- var scope = $root.$new();
+ const scope = $root.$new();
- scope.confirmModal = $modal({templateUrl: '/templates/batch-confirm.html',
scope: scope, placement: 'center', show: false});
+ scope.confirmModal = $modal({templateUrl: '/templates/batch-confirm.html',
scope, placement: 'center', show: false});
function _done(cancel) {
scope.confirmModal.hide();
@@ -1138,43 +1141,43 @@ consoleModule.service('$confirmBatch', ['$modal',
'$rootScope', '$q', ($modal, $
_done();
}
- scope.cancel = function () {
- _done(true);
+ scope.cancel = function() {
+ _done(true);
};
- scope.skip = function (applyToAll) {
+ scope.skip = function(applyToAll) {
if (applyToAll) {
- for (var i = scope.curIx; i < scope.items.length; i++)
+ for (let i = scope.curIx; i < scope.items.length; i++)
scope.items[i].skip = true;
- _done();
- }
- else
- _nextElement(true);
+ _done();
+ }
+ else
+ _nextElement(true);
};
- scope.overwrite = function (applyToAll) {
+ scope.overwrite = function(applyToAll) {
if (applyToAll)
- _done();
- else
- _nextElement(false);
+ _done();
+ else
+ _nextElement(false);
};
return {
- /**
- * Show confirm all dialog.
- *
- * @param confirmMessageFn Function to generate a confirm message.
- * @param itemsToConfirm Array of element to process by confirm.
- */
- confirm: function (confirmMessageFn, itemsToConfirm) {
+ /**
+ * Show confirm all dialog.
+ *
+ * @param confirmMessageFn Function to generate a confirm message.
+ * @param itemsToConfirm Array of element to process by confirm.
+ */
+ confirm(confirmMessageFn, itemsToConfirm) {
scope.deferred = $q.defer();
scope.contentGenerator = confirmMessageFn;
scope.items = itemsToConfirm;
scope.curIx = 0;
- scope.content = (scope.items && scope.items.length > 0) ?
scope.contentGenerator(scope.items[0]) : undefined;
+ scope.content = (scope.items && scope.items.length > 0) ?
scope.contentGenerator(scope.items[0]) : null;
scope.confirmModal.$promise.then(scope.confirmModal.show);
@@ -1185,28 +1188,17 @@ consoleModule.service('$confirmBatch', ['$modal',
'$rootScope', '$q', ($modal, $
// 'Clone' popup service.
consoleModule.service('$clone', ['$modal', '$rootScope', '$q', ($modal, $root,
$q) => {
- var scope = $root.$new();
+ const scope = $root.$new();
- var deferred;
- var _names = [];
- var _validator;
-
- scope.ok = function (newName) {
- if (!_validator || _validator(newName)) {
- deferred.resolve(_nextAvailableName(newName));
-
- cloneModal.hide();
- }
- };
-
- var cloneModal = $modal({templateUrl: '/templates/clone.html', scope:
scope, placement: 'center', show: false});
+ let _names = [];
+ let deferred;
+ let _validator;
function _nextAvailableName(name) {
- var num = 1;
-
- var tmpName = name;
+ let num = 1;
+ let tmpName = name;
- while(_.includes(_names, tmpName)) {
+ while (_.includes(_names, tmpName)) {
tmpName = name + '_' + num.toString();
num++;
@@ -1215,7 +1207,17 @@ consoleModule.service('$clone', ['$modal', '$rootScope',
'$q', ($modal, $root, $
return tmpName;
}
- cloneModal.confirm = function (oldName, names, validator) {
+ const cloneModal = $modal({templateUrl: '/templates/clone.html', scope,
placement: 'center', show: false});
+
+ scope.ok = function(newName) {
+ if (!_validator || _validator(newName)) {
+ deferred.resolve(_nextAvailableName(newName));
+
+ cloneModal.hide();
+ }
+ };
+
+ cloneModal.confirm = function(oldName, names, validator) {
_names = names;
scope.newName = _nextAvailableName(oldName);
@@ -1233,15 +1235,15 @@ consoleModule.service('$clone', ['$modal',
'$rootScope', '$q', ($modal, $root, $
}]);
// Tables support service.
-consoleModule.service('$table', ['$common', '$focus', function ($common,
$focus) {
+consoleModule.service('$table', ['$common', '$focus', function($common,
$focus) {
function _model(item, field) {
return $common.getModel(item, field);
}
- var table = {name: 'none', editIndex: -1};
+ const table = {name: 'none', editIndex: -1};
function _tableReset() {
- table.field = undefined;
+ delete table.field;
table.name = 'none';
table.editIndex = -1;
@@ -1249,9 +1251,9 @@ consoleModule.service('$table', ['$common', '$focus',
function ($common, $focus)
}
function _tableSaveAndReset() {
- var field = table.field;
+ const field = table.field;
- var save = $common.isDefined(field) && $common.isDefined(field.save);
+ const save = $common.isDefined(field) && $common.isDefined(field.save);
if (!save || !$common.isDefined(field) || field.save(field,
table.editIndex, true)) {
_tableReset();
@@ -1269,7 +1271,7 @@ consoleModule.service('$table', ['$common', '$focus',
function ($common, $focus)
}
function _tableUI(field) {
- var ui = field.ui;
+ const ui = field.ui;
return ui ? ui : field.type;
}
@@ -1285,9 +1287,9 @@ consoleModule.service('$table', ['$common', '$focus',
function ($common, $focus)
function _tableStartEdit(item, tbl, index, save) {
_tableState(tbl, index);
- var val = _model(item, tbl)[tbl.model][index];
+ const val = _.get(_model(item, tbl), tbl.model)[index];
- var ui = _tableUI(tbl);
+ const ui = _tableUI(tbl);
tbl.save = save;
@@ -1317,7 +1319,7 @@ consoleModule.service('$table', ['$common', '$focus',
function ($common, $focus)
function _tableNewItem(tbl) {
_tableState(tbl, -1);
- var ui = _tableUI(tbl);
+ const ui = _tableUI(tbl);
if (ui === 'table-pair') {
tbl.newKey = null;
@@ -1347,53 +1349,55 @@ consoleModule.service('$table', ['$common', '$focus',
function ($common, $focus)
tableReset: _tableReset,
tableSaveAndReset: _tableSaveAndReset,
tableNewItem: _tableNewItem,
- tableNewItemActive: function (tbl) {
+ tableNewItemActive(tbl) {
return table.name === tbl.model && table.editIndex < 0;
},
- tableEditing: function (tbl, index) {
+ tableEditing(tbl, index) {
return table.name === tbl.model && table.editIndex === index;
},
- tableEditedRowIndex: function () {
+ tableEditedRowIndex() {
return table.editIndex;
},
- tableField: function () {
+ tableField() {
return table.field;
},
tableStartEdit: _tableStartEdit,
- tableRemove: function (item, field, index) {
+ tableRemove(item, field, index) {
_tableReset();
- _model(item, field)[field.model].splice(index, 1);
+ _.get(_model(item, field), field.model).splice(index, 1);
},
tablePairValue: _tablePairValue,
- tablePairSave: function (pairValid, item, field, index, stopEdit) {
- var valid = pairValid(item, field, index);
+ tablePairSave(pairValid, item, field, index, stopEdit) {
+ const valid = pairValid(item, field, index);
if (valid) {
- var pairValue = _tablePairValue(field, index);
+ const pairValue = _tablePairValue(field, index);
+
+ let pairModel = {};
- var pairModel = {};
+ const container = _.get(item, field.model);
if (index < 0) {
pairModel[field.keyName] = pairValue.key;
pairModel[field.valueName] = pairValue.value;
- if (item[field.model])
- item[field.model].push(pairModel);
+ if (container)
+ container.push(pairModel);
else
- item[field.model] = [pairModel];
+ _.set(item, field.model, [pairModel]);
if (!stopEdit)
_tableNewItem(field);
}
else {
- pairModel = item[field.model][index];
+ pairModel = container[index];
pairModel[field.keyName] = pairValue.key;
pairModel[field.valueName] = pairValue.value;
if (!stopEdit) {
- if (index < item[field.model].length - 1)
+ if (index < container.length - 1)
_tableStartEdit(item, field, index + 1);
else
_tableNewItem(field);
@@ -1403,33 +1407,33 @@ consoleModule.service('$table', ['$common', '$focus',
function ($common, $focus)
return valid;
},
- tablePairSaveVisible: function (field, index) {
- var pairValue = _tablePairValue(field, index);
+ tablePairSaveVisible(field, index) {
+ const pairValue = _tablePairValue(field, index);
return !$common.isEmptyString(pairValue.key) &&
!$common.isEmptyString(pairValue.value);
},
- tableFocusInvalidField: function (index, id) {
+ tableFocusInvalidField(index, id) {
_tableFocus(id, index);
return false;
},
- tableFieldId: function (index, id) {
+ tableFieldId(index, id) {
return (index < 0 ? 'new' : 'cur') + id + (index >= 0 ? index :
'');
}
};
}]);
-consoleModule.service('ngCopy', ['$window', '$common', function ($window,
$common) {
- var body = angular.element($window.document.body);
+consoleModule.service('ngCopy', ['$window', '$common', function($window,
$common) {
+ const body = angular.element($window.document.body);
- var textArea = angular.element('<textarea/>');
+ const textArea = angular.element('<textarea/>');
textArea.css({
position: 'fixed',
opacity: '0'
});
- return function (toCopy) {
+ return function(toCopy) {
textArea.val(toCopy);
body.append(textArea);
@@ -1440,18 +1444,18 @@ consoleModule.service('ngCopy', ['$window', '$common',
function ($window, $commo
if (document.execCommand('copy'))
$common.showInfo('Value copied to clipboard');
else
- window.prompt("Copy to clipboard: Ctrl+C, Enter", toCopy);
+ window.prompt('Copy to clipboard: Ctrl+C, Enter', toCopy); //
eslint-disable-line no-alert
} catch (err) {
- window.prompt("Copy to clipboard: Ctrl+C, Enter", toCopy);
+ window.prompt('Copy to clipboard: Ctrl+C, Enter', toCopy); //
eslint-disable-line no-alert
}
textArea.remove();
};
-}]).directive('ngClickCopy', ['ngCopy', function (ngCopy) {
+}]).directive('ngClickCopy', ['ngCopy', function(ngCopy) {
return {
restrict: 'A',
- link: function (scope, element, attrs) {
- element.bind('click', function () {
+ link(scope, element, attrs) {
+ element.bind('click', function() {
ngCopy(attrs.ngClickCopy);
});
@@ -1461,36 +1465,16 @@ consoleModule.service('ngCopy', ['$window', '$common',
function ($window, $commo
};
}]);
-consoleModule.filter('tablesSearch', function() {
- return function(array, query) {
- if (!angular.isUndefined(array) && !angular.isUndefined(query) &&
!angular.isUndefined(query.$)) {
- var filtredArray = [];
-
- var matchString = query.$.toLowerCase();
-
- angular.forEach(array, function (row) {
- var label = (row.schema + '.' + row.tbl).toLowerCase();
-
- if (label.indexOf(matchString) >= 0)
- filtredArray.push(row);
- });
-
- return filtredArray;
- } else
- return array;
- };
-});
-
// Filter domain models with key fields configuration.
-consoleModule.filter('domainsValidation', ['$common', function ($common) {
+consoleModule.filter('domainsValidation', ['$common', function($common) {
return function(domains, valid, invalid) {
if (valid && invalid)
return domains;
- var out = [];
+ const out = [];
- _.forEach(domains, function (domain) {
- var _valid = !$common.domainForStoreConfigured(domain) ||
$common.isJavaBuiltInClass(domain.keyType) || !_.isEmpty(domain.keyFields);
+ _.forEach(domains, function(domain) {
+ const _valid = !$common.domainForStoreConfigured(domain) ||
$common.isJavaBuiltInClass(domain.keyType) || !_.isEmpty(domain.keyFields);
if (valid && _valid || invalid && !_valid)
out.push(domain);
@@ -1504,7 +1488,7 @@ consoleModule.filter('domainsValidation', ['$common',
function ($common) {
consoleModule.directive('match', ['$parse', ($parse) => {
return {
require: 'ngModel',
- link: (scope, elem, attrs, ctrl) => {
+ link(scope, elem, attrs, ctrl) {
scope.$watch(() => $parse(attrs.match)(scope) ===
ctrl.$modelValue, (currentValue) => ctrl.$setValidity('mismatch',
currentValue));
}
};
@@ -1512,13 +1496,11 @@ consoleModule.directive('match', ['$parse', ($parse) =>
{
// Directive to bind ENTER key press with some user action.
consoleModule.directive('onEnter', ['$timeout', ($timeout) => {
- return function (scope, elem, attrs) {
- elem.on('keydown keypress', function (event) {
+ return function(scope, elem, attrs) {
+ elem.on('keydown keypress', function(event) {
if (event.which === 13) {
- scope.$apply(function () {
- $timeout(function () {
- scope.$eval(attrs.onEnter)
- });
+ scope.$apply(function() {
+ $timeout(() => scope.$eval(attrs.onEnter));
});
event.preventDefault();
@@ -1526,7 +1508,7 @@ consoleModule.directive('onEnter', ['$timeout',
($timeout) => {
});
// Removes bound events in the element itself when the scope is
destroyed.
- scope.$on('$destroy', function () {
+ scope.$on('$destroy', function() {
elem.off('keydown keypress');
});
};
@@ -1534,10 +1516,10 @@ consoleModule.directive('onEnter', ['$timeout',
($timeout) => {
// Directive to bind ESC key press with some user action.
consoleModule.directive('onEscape', () => {
- return function (scope, elem, attrs) {
- elem.on('keydown keypress', function (event) {
+ return function(scope, elem, attrs) {
+ elem.on('keydown keypress', function(event) {
if (event.which === 27) {
- scope.$apply(function () {
+ scope.$apply(function() {
scope.$eval(attrs.onEscape);
});
@@ -1546,7 +1528,7 @@ consoleModule.directive('onEscape', () => {
});
// Removes bound events in the element itself when the scope is
destroyed
- scope.$on('$destroy', function () {
+ scope.$on('$destroy', function() {
elem.off('keydown keypress');
});
};
@@ -1554,35 +1536,35 @@ consoleModule.directive('onEscape', () => {
// Directive to retain selection. To fix angular-strap typeahead bug with
setting cursor to the end of text.
consoleModule.directive('retainSelection', ['$timeout', ($timeout) => {
- var promise;
+ let promise;
- return function (scope, elem) {
- elem.on('keydown', function (evt) {
- var key = evt.which;
- var ctrlDown = evt.ctrlKey || evt.metaKey;
- var input = this;
- var start = input.selectionStart;
+ return function(scope, elem) {
+ elem.on('keydown', function(evt) {
+ const key = evt.which;
+ const ctrlDown = evt.ctrlKey || evt.metaKey;
+ const input = this;
+ let start = input.selectionStart;
if (promise)
$timeout.cancel(promise);
- promise = $timeout(function () {
- var setCursor = false;
+ promise = $timeout(() => {
+ let setCursor = false;
// Handle Backspace[8].
- if (key == 8 && start > 0) {
+ if (key === 8 && start > 0) {
start -= 1;
setCursor = true;
}
// Handle Del[46].
- else if (key == 46)
+ else if (key === 46)
setCursor = true;
// Handle: Caps Lock[20], Tab[9], Shift[16], Ctrl[17],
Alt[18], Esc[27], Enter[13], Arrows[37..40], Home[36], End[35], Ins[45],
PgUp[33], PgDown[34], F1..F12[111..124], Num Lock[], Scroll Lock[145].
- else if (!(key == 8 || key == 9 || key == 13 || (key > 15 &&
key < 20) || key == 27 ||
- (key > 32 && key < 41) || key == 45 || (key > 111 && key <
124) || key == 144 || key == 145)) {
+ else if (!(key === 8 || key === 9 || key === 13 || (key > 15
&& key < 20) || key === 27 ||
+ (key > 32 && key < 41) || key === 45 || (key > 111 && key
< 124) || key === 144 || key === 145)) {
// Handle: Ctrl + [A[65], C[67], V[86]].
- if (!(ctrlDown && (key = 65 || key == 67 || key == 86))) {
+ if (!(ctrlDown && (key === 65 || key === 67 || key ===
86))) {
start += 1;
setCursor = true;
@@ -1592,12 +1574,12 @@ consoleModule.directive('retainSelection', ['$timeout',
($timeout) => {
if (setCursor)
input.setSelectionRange(start, start);
- promise = undefined;
+ promise = null;
});
});
// Removes bound events in the element itself when the scope is
destroyed
- scope.$on('$destroy', function () {
+ scope.$on('$destroy', function() {
elem.off('keydown');
});
};
@@ -1605,12 +1587,12 @@ consoleModule.directive('retainSelection', ['$timeout',
($timeout) => {
// Factory function to focus element.
consoleModule.factory('$focus', ['$timeout', ($timeout) => {
- return function (id) {
+ return function(id) {
// Timeout makes sure that is invoked after any other event has been
triggered.
// E.g. click events that need to run before the focus or inputs
elements that are
// in a disabled state but are enabled when those events are triggered.
- $timeout(function () {
- var elem = $('#' + id);
+ $timeout(() => {
+ const elem = $('#' + id);
if (elem.length > 0)
elem[0].focus();
@@ -1622,18 +1604,16 @@ consoleModule.factory('$focus', ['$timeout', ($timeout)
=> {
consoleModule.directive('autoFocus', ['$timeout', ($timeout) => {
return {
restrict: 'AC',
- link: function(scope, element) {
- $timeout(function(){
- element[0].focus();
- });
+ link(scope, element) {
+ $timeout(() => element[0].focus());
}
};
}]);
// Directive to focus next element on ENTER key.
consoleModule.directive('enterFocusNext', ['$focus', ($focus) => {
- return function (scope, elem, attrs) {
- elem.on('keydown keypress', function (event) {
+ return function(scope, elem, attrs) {
+ elem.on('keydown keypress', function(event) {
if (event.which === 13) {
event.preventDefault();
@@ -1645,13 +1625,13 @@ consoleModule.directive('enterFocusNext', ['$focus',
($focus) => {
// Directive to mark elements to focus.
consoleModule.directive('onClickFocus', ['$focus', ($focus) => {
- return function (scope, elem, attr) {
- elem.on('click', function () {
+ return function(scope, elem, attr) {
+ elem.on('click', function() {
$focus(attr.onClickFocus);
});
// Removes bound events in the element itself when the scope is
destroyed
- scope.$on('$destroy', function () {
+ scope.$on('$destroy', function() {
elem.off('click');
});
};
@@ -1660,9 +1640,9 @@ consoleModule.directive('onClickFocus', ['$focus',
($focus) => {
consoleModule.controller('resetPassword', [
'$scope', '$modal', '$http', '$common', '$focus', 'Auth', '$state',
($scope, $modal, $http, $common, $focus, Auth, $state) => {
- if ($state.params.token)
+ if ($state.params.token) {
$http.post('/api/v1/password/validate/token', {token:
$state.params.token})
- .success(function (res) {
+ .success((res) => {
$scope.email = res.email;
$scope.token = res.token;
$scope.error = res.error;
@@ -1670,16 +1650,17 @@ consoleModule.controller('resetPassword', [
if ($scope.token && !$scope.error)
$focus('user_password');
});
+ }
// Try to reset user password for provided token.
- $scope.resetPassword = function (reset_info) {
+ $scope.resetPassword = function(reset_info) {
$http.post('/api/v1/password/reset', reset_info)
- .success(function () {
+ .success(function() {
$common.showInfo('Password successfully changed');
$state.go('base.configuration.clusters');
})
- .error(function (data, state) {
+ .error(function(data, state) {
$common.showError(data);
if (state === 503)
@@ -1693,7 +1674,7 @@ consoleModule.controller('resetPassword', [
// TODO IGNITE-1936 Refactor this controller.
consoleModule.controller('auth', ['$scope', '$focus', 'Auth',
'IgniteCountries', ($scope, $focus, Auth, Countries) => {
$scope.auth = Auth.auth;
-
+ $scope.forgotPassword = Auth.forgotPassword;
$scope.action = 'signin';
$scope.countries = Countries.getAll();
@@ -1703,57 +1684,58 @@ consoleModule.controller('auth', ['$scope', '$focus',
'Auth', 'IgniteCountries',
// Navigation bar controller.
consoleModule.controller('notebooks', ['$rootScope', '$scope', '$modal',
'$state', '$http', '$common',
($root, $scope, $modal, $state, $http, $common) => {
- $root.notebooks = [];
+ $root.notebooks = [];
- // Pre-fetch modal dialogs.
- var _notebookNewModal = $modal({scope: $scope, templateUrl:
'/sql/notebook-new.html', show: false});
+ // Pre-fetch modal dialogs.
+ const _notebookNewModal = $modal({scope: $scope, templateUrl:
'/sql/notebook-new.html', show: false});
- $root.rebuildDropdown = function() {
- $scope.notebookDropdown = [
- {text: 'Create new notebook', click: 'inputNotebookName()'},
- {divider: true}
- ];
+ $root.rebuildDropdown = function() {
+ $scope.notebookDropdown = [
+ {text: 'Create new notebook', click: 'inputNotebookName()'},
+ {divider: true}
+ ];
- _.forEach($root.notebooks, function (notebook) {
- $scope.notebookDropdown.push({
- text: notebook.name,
- sref: 'base.sql.notebook({noteId:"' + notebook._id + '"})'
+ _.forEach($root.notebooks, function(notebook) {
+ $scope.notebookDropdown.push({
+ text: notebook.name,
+ sref: 'base.sql.notebook({noteId:"' + notebook._id + '"})'
+ });
});
- });
- };
+ };
- $root.reloadNotebooks = function() {
- // When landing on the page, get clusters and show them.
- $http.post('/api/v1/notebooks/list')
- .success(function (data) {
- $root.notebooks = data;
+ $root.reloadNotebooks = function() {
+ // When landing on the page, get clusters and show them.
+ $http.post('/api/v1/notebooks/list')
+ .success(function(data) {
+ $root.notebooks = data;
- $root.rebuildDropdown();
- })
- .error(function (errMsg) {
- $common.showError(errMsg);
- });
- };
+ $root.rebuildDropdown();
+ })
+ .error(function(errMsg) {
+ $common.showError(errMsg);
+ });
+ };
- $root.inputNotebookName = function() {
- _notebookNewModal.$promise.then(_notebookNewModal.show);
- };
+ $root.inputNotebookName = function() {
+ _notebookNewModal.$promise.then(_notebookNewModal.show);
+ };
- $root.createNewNotebook = function(name) {
- $http.post('/api/v1/notebooks/new', {name: name})
- .success(function (noteId) {
- _notebookNewModal.hide();
+ $root.createNewNotebook = function(name) {
+ $http.post('/api/v1/notebooks/new', {name})
+ .success(function(noteId) {
+ _notebookNewModal.hide();
- $root.reloadNotebooks();
+ $root.reloadNotebooks();
- $state.go('base.sql.notebook', {noteId: noteId});
- })
- .error(function (message) {
- $common.showError(message);
- });
- };
+ $state.go('base.sql.notebook', {noteId});
+ })
+ .error(function(message) {
+ $common.showError(message);
+ });
+ };
- $root.reloadNotebooks();
-}]);
+ $root.reloadNotebooks();
+ }
+]);
export default consoleModule;