More code cleanup for SonarQube.

This commit is contained in:
Akshay Joshi 2020-06-18 16:20:34 +01:00 committed by Dave Page
parent 6d3f13076f
commit bc24e3643f
13 changed files with 73 additions and 87 deletions

View File

@ -71,7 +71,7 @@ module.exports = Alertify.dialog('fileSelectionDlg', function() {
if (transId.readyState == 4) {
t_res = JSON.parse(transId.responseText);
}
self.trans_id = t_res.data.fileTransId;
self.trans_id = _.isUndefined(t_res) ? 0 : t_res.data.fileTransId;
setTimeout(function() {
$(self.$container.find('.file_manager')).on('enter-key', function() {

View File

@ -1186,7 +1186,7 @@ define([
if (transId.readyState == 4) {
t_res = JSON.parse(transId.responseText);
}
t_id = t_res.data.fileTransId;
t_id = _.isUndefined(t_res) ? 0 : t_res.data.fileTransId;
var root_url = url_for('file_manager.index'),
file_manager_config_json = root_url + t_id + '/file_manager_config.json',
fileConnector = root_url + 'filemanager/' + t_id + '/',
@ -1201,6 +1201,9 @@ define([
homedir=config.options.homedir;
}
if (_.isUndefined(config))
return;
// set main url to filemanager and its capabilites
var fileRoot = config.options.fileRoot,
capabilities = config.options.capabilities;
@ -1288,20 +1291,20 @@ define([
}
// handle show hidden files functionality
this.handleClick = function(cb) {
var data = {
var tmp_data = {
'is_checked': false,
};
if (cb.checked) {
$('div.allowed_file_types select').trigger('change');
data['is_checked'] = true;
tmp_data['is_checked'] = true;
} else {
// User wants to hide it again
$('div.allowed_file_types select').trigger('change');
data['is_checked'] = false;
tmp_data['is_checked'] = false;
}
// Save it in preference
save_show_hidden_file_option(data['is_checked'], pgAdmin.FileUtils.transId);
save_show_hidden_file_option(tmp_data['is_checked'], pgAdmin.FileUtils.transId);
return;
};
}
@ -1616,10 +1619,10 @@ define([
setTimeout(function() {}, 10000);
},
success: function(file, response) {
var data = response.data.result,
var resp_data = response.data.result,
$this = $(file.previewTemplate);
if (data.Code == 1) {
if (resp_data.Code == 1) {
setTimeout(function() {
$this.find('.dz-upload').addClass('success');
}, 1000);
@ -1628,7 +1631,7 @@ define([
} else {
$this.find('.dz-upload').addClass('error');
$this.find('.dz-upload').css('width', '0%').html('0%');
Alertify.error(data.Error);
Alertify.error(resp_data.Error);
}
getFolderInfo(path);
},
@ -1670,7 +1673,7 @@ define([
} else {
$('.storage_dialog #uploader .input-path').val(path);
}
} else if (!(config.options.platform_type === 'win32') &&
} else if ((config.options.platform_type !== 'win32') &&
(path == '' || !path.startsWith('/'))) {
path = '/' + path;
$('.storage_dialog #uploader .input-path').val(path);

View File

@ -51,7 +51,7 @@ define(['jquery',
'title="' + gettext('Select/Deselect All') + '">' +
'<br>' +
columnDefinitions[0].name +
'<img class="select-all-icon" src="' + url_for('static', {'filename': 'img/select-all-icon.png'}) + '"></img>';
'<img class="select-all-icon" src="' + url_for('static', {'filename': 'img/select-all-icon.png'}) + '"></img>' +
'</span>';
return columnDefinitions;
};

View File

@ -235,6 +235,7 @@ export class QueryHistoryEntries {
newItem.onClick(this.setSelectedListItem.bind(this));
newItem.render(this.is_pgadmin_queries_shown);
if (!_.isUndefined($groupEl))
$groupEl.find('.query-entries').prepend(newItem.$el);
this.setSelectedListItem(newItem.$el);
}

View File

@ -211,7 +211,7 @@ _.extend(pgBrowser.browserTreeState, {
node = data && pgBrowser.Nodes[data._type],
treeHierarchy = node && node.getTreeNodeHierarchy(item);
if (treeHierarchy === null || !pgBrowser.tree.hasParent(item) || !(self.parent in treeHierarchy))
if (treeHierarchy === null || !pgBrowser.tree.hasParent(item) || !(treeHierarchy.hasOwnProperty(self.parent)))
return;
let topParent = treeHierarchy && treeHierarchy[self.parent]['_id'],
@ -231,7 +231,7 @@ _.extend(pgBrowser.browserTreeState, {
let tmpTreeData = self.current_state[topParent]['paths'],
databaseId = undefined;
if ('database' in treeHierarchy)
if (treeHierarchy.hasOwnProperty('database'))
databaseId = treeHierarchy['database']['id'];
if (!_.isUndefined(tmpTreeData) && !_.isUndefined(tmpTreeData.length)) {
@ -269,7 +269,7 @@ _.extend(pgBrowser.browserTreeState, {
treeHierarchy = node && node.getTreeNodeHierarchy(item);
if (treeHierarchy === null || !pgBrowser.tree.hasParent(item) || !(self.parent in treeHierarchy))
if (treeHierarchy === null || !pgBrowser.tree.hasParent(item) || !(treeHierarchy.hasOwnProperty(self.parent)))
return;
// If the server node is open then only we should populate the tree
@ -290,7 +290,7 @@ _.extend(pgBrowser.browserTreeState, {
let tmpTreeDataPaths = [...tmpTreeData['paths']],
databaseId = undefined;
if ('database' in treeHierarchy)
if (treeHierarchy.hasOwnProperty('database'))
databaseId = treeHierarchy['database']['id'];
_.each(tmpTreeDataPaths, function(tData) {
@ -325,7 +325,7 @@ _.extend(pgBrowser.browserTreeState, {
node = data && pgBrowser.Nodes[data._type],
treeHierarchy = node.getTreeNodeHierarchy(item);
if ('database' in treeHierarchy) {
if (treeHierarchy.hasOwnProperty('database')) {
let databaseItem = treeHierarchy['database']['id'],
topParent = treeHierarchy && treeHierarchy[this.parent]['_id'];
@ -358,7 +358,7 @@ _.extend(pgBrowser.browserTreeState, {
selectedItem = selectedItem ? selectedItem.id : undefined;
if ('database' in treeHierarchy) {
if (treeHierarchy.hasOwnProperty('database')) {
databaseItem = treeHierarchy['database']['id'];
}
@ -379,7 +379,7 @@ _.extend(pgBrowser.browserTreeState, {
tmpTreeData = treeData[treeHierarchy[this.parent]['_id']];
if ('database' in treeHierarchy) {
if (treeHierarchy.hasOwnProperty('database')) {
let databaseItem = treeHierarchy['database']['id'];
if (tmpTreeData && 'selected' in tmpTreeData && databaseItem in tmpTreeData['selected']) {

View File

@ -324,6 +324,8 @@ export class Tree {
if (parent === this.rootNode) {
node.parentNode = null;
}
if (parent !== null && parent !== undefined)
parent.children.push(node);
return node;
}

View File

@ -200,7 +200,7 @@ define([
var t = pgBrowser.tree,
i = t.selected(),
d = i && i.length == 1 ? t.itemData(i) : undefined;
return d.version >= 110000;
return _.isUndefined(d) ? false : d.version >= 110000;
}
return true;
},
@ -392,9 +392,9 @@ define([
var t = pgBrowser.tree,
i = t.selected(),
d = i && i.length == 1 ? t.itemData(i) : undefined,
s = pgBrowser.Nodes[d._type].getTreeNodeHierarchy(i)['server'];
s = _.isUndefined(d) ? undefined : pgBrowser.Nodes[d._type].getTreeNodeHierarchy(i)['server'];
return s.version >= 110000;
return _.isUndefined(s) ? false : s.version >= 110000;
},
}],
}, {
@ -467,9 +467,9 @@ define([
var t = pgBrowser.tree,
i = t.selected(),
d = i && i.length == 1 ? t.itemData(i) : undefined,
s = pgBrowser.Nodes[d._type].getTreeNodeHierarchy(i)['server'];
s = _.isUndefined(d) ? undefined : pgBrowser.Nodes[d._type].getTreeNodeHierarchy(i)['server'];
return s.version >= 110000;
return _.isUndefined(s) ? false : s.version >= 110000;
},
}],
}, {
@ -519,9 +519,9 @@ define([
var t = pgBrowser.tree,
i = t.selected(),
d = i && i.length == 1 ? t.itemData(i) : undefined,
s = pgBrowser.Nodes[d._type].getTreeNodeHierarchy(i)['server'];
s = _.isUndefined(d) ? undefined : pgBrowser.Nodes[d._type].getTreeNodeHierarchy(i)['server'];
if (s.version >= 120000)
if (!_.isUndefined(s) && s.version >= 120000)
return true;
if (m.get('use_column_inserts') || m.get('use_insert_commands')) {

View File

@ -46,7 +46,7 @@ export function showDataGrid(
const gridUrl = generateUrl(transId, connectionData, node.getData(), parentData);
const queryToolTitle = generateDatagridTitle(pgBrowser, aciTreeIdentifier);
if(filter) {
initFilterDialog(alertify, pgBrowser, preferences);
initFilterDialog(alertify, pgBrowser);
const validateUrl = generateFilterValidateUrl(node.getData(), parentData);

View File

@ -463,12 +463,13 @@ define([
i = item || t.selected(),
d = i && i.length == 1 ? t.itemData(i) : undefined,
node = d && pgBrowser.Nodes[d._type],
self = this,
is_edb_proc = d._type == 'edbproc';
self = this;
if (!d)
return;
var is_edb_proc = d._type == 'edbproc';
var treeInfo = node.getTreeNodeHierarchy.apply(node, [i]),
_url = this.generate_url('init', treeInfo, node);

View File

@ -442,6 +442,8 @@ define([
d = this.d = i && i.length == 1 ? t.itemData(i) : undefined,
info = this.info = pgBrowser.Node.getTreeNodeHierarchy(i);
if(_.isUndefined(d))
return;
/**
Generate a URL using:
gid, did, sid(server id), node_id(node id),

View File

@ -272,9 +272,9 @@ define('tools.restore', [
var t = pgBrowser.tree,
i = t.selected(),
d = i && i.length == 1 ? t.itemData(i) : undefined,
s = pgBrowser.Nodes[d._type].getTreeNodeHierarchy(i)['server'];
s = _.isUndefined(d) ? undefined : pgBrowser.Nodes[d._type].getTreeNodeHierarchy(i)['server'];
return s.version >= 110000;
return _.isUndefined(s) ? false : s.version >= 110000;
},
}],
}, {

View File

@ -375,8 +375,8 @@ describe('queryToolActions', () => {
beforeEach(() => {
setUpSpies('', 'a string\nddd\nsss');
sqlEditorController.gridView.query_tool_obj.getCursor = (isFrom) => {
return isFrom ? 3 : 3;
sqlEditorController.gridView.query_tool_obj.getCursor = () => {
return 3;
};
});
@ -422,8 +422,8 @@ describe('queryToolActions', () => {
beforeEach(() => {
setUpSpies('', 'a string\nddd\nsss');
sqlEditorController.gridView.query_tool_obj.getCursor = (isFrom) => {
return isFrom ? 3 : 3;
sqlEditorController.gridView.query_tool_obj.getCursor = () => {
return 3;
};
});
@ -469,8 +469,8 @@ describe('queryToolActions', () => {
beforeEach(() => {
setUpSpies('', 'a string\nddd\nsss');
sqlEditorController.gridView.query_tool_obj.getCursor = (isFrom) => {
return isFrom ? 3 : 3;
sqlEditorController.gridView.query_tool_obj.getCursor = () => {
return 3;
};
});
@ -514,8 +514,8 @@ describe('queryToolActions', () => {
beforeEach(() => {
setUpSpies('', 'a string\nddd\nsss');
sqlEditorController.gridView.query_tool_obj.getCursor = (isFrom) => {
return isFrom ? 3 : 3;
sqlEditorController.gridView.query_tool_obj.getCursor = () => {
return 3;
};
});

View File

@ -896,9 +896,9 @@ acorn@^6.0.7, acorn@^6.4.1:
integrity sha512-ZVA9k326Nwrj3Cj9jlh3wGFutC2ZornPNARZwsNYqQYgN0EsV2d53w5RN/co65Ohn4sUAUtb1rSUAOD6XN9idA==
acorn@^7.0.0, acorn@^7.1.1:
version "7.2.0"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-7.2.0.tgz#17ea7e40d7c8640ff54a694c889c26f31704effe"
integrity sha512-apwXVmYVpQ34m/i71vrApRrRKCWQnZZF1+npOD0WV5xZFfwWOmKGQ2RWlfdy9vWITsenisM8M0Qeq8agcFHNiQ==
version "7.3.1"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-7.3.1.tgz#85010754db53c3fbaf3b9ea3e083aa5c5d147ffd"
integrity sha512-tLc0wSnatxAQHVHUapaHdz72pi9KUyHjq5KyHjGg9Y8Ifdc79pTh2XvI6I1/chZbnM7QtNKzh66ooDogPZSleA==
after@0.8.2:
version "0.8.2"
@ -2435,16 +2435,11 @@ component-bind@1.0.0:
resolved "https://registry.yarnpkg.com/component-bind/-/component-bind-1.0.0.tgz#00c608ab7dcd93897c0009651b1d3a8e1e73bbd1"
integrity sha1-AMYIq33Nk4l8AAllGx06jh5zu9E=
component-emitter@1.2.1:
component-emitter@1.2.1, component-emitter@^1.2.1:
version "1.2.1"
resolved "https://registry.yarnpkg.com/component-emitter/-/component-emitter-1.2.1.tgz#137918d6d78283f7df7a6b7c5a63e140e69425e6"
integrity sha1-E3kY1teCg/ffemt8WmPhQOaUJeY=
component-emitter@^1.2.1:
version "1.3.0"
resolved "https://registry.yarnpkg.com/component-emitter/-/component-emitter-1.3.0.tgz#16e4070fba8ae29b679f2215853ee181ab2eabc0"
integrity sha512-Rd3se6QB+sO1TwqZjscQrurpEPIfO0/yYnSin6Q/rD3mOutHvUrCAhJub3r90uNb+SESBuE0QYoB90YdfatsRg==
component-inherit@0.0.3:
version "0.0.3"
resolved "https://registry.yarnpkg.com/component-inherit/-/component-inherit-0.0.3.tgz#645fc4adf58b72b649d5cae65135619db26ff143"
@ -3197,9 +3192,9 @@ ejs@~3.0.2:
integrity sha512-IncmUpn1yN84hy2shb0POJ80FWrfGNY0cxO9f4v+/sG7qcBvAtVWUA1IdzY/8EYUmOVhoKJVdJjNd3AZcnxOjA==
electron-to-chromium@^1.3.413:
version "1.3.466"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.466.tgz#89f716db3afc4bb482ea2aaaa16c4808f89f762a"
integrity sha512-eieqkoM2hCkZZRhETKyCouMziDV3l4XEKHRLuzcHG+HV+P7PeODU/z9HAmBgMQkzvHg2DoyQhfIDmmeguLZT/Q==
version "1.3.477"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.477.tgz#7e6b931d0c1a2572101a6e9a835128c50fd49323"
integrity sha512-81p6DZ/XmHDD7O0ITJMa7ESo9bSCfE+v3Fny3MIYR0y77xmhoriu2ShNOLXcPS4eowF6dkxw6d2QqxTkS3DjBg==
elliptic@^6.0.0, elliptic@^6.5.2:
version "6.5.2"
@ -3291,9 +3286,9 @@ enhanced-resolve@4.1.0:
tapable "^1.0.0"
enhanced-resolve@^4.1.0:
version "4.1.1"
resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-4.1.1.tgz#2937e2b8066cd0fe7ce0990a98f0d71a35189f66"
integrity sha512-98p2zE+rL7/g/DzMHMTF4zZlCgeVdJ7yr6xzEpJRYwFYrGi9ANdn5DnJURg6RpBkyk60XYDnWIv51VfIhfNGuA==
version "4.2.0"
resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-4.2.0.tgz#5d43bda4a0fd447cb0ebbe71bef8deff8805ad0d"
integrity sha512-S7eiFb/erugyd1rLb6mQ3Vuq+EXHv5cpCkNqqIkYkBgN2QdFnyCZzFBleqwGEx4lgNGYij81BWnCrFNK7vxvjQ==
dependencies:
graceful-fs "^4.1.2"
memory-fs "^0.5.0"
@ -3324,21 +3319,21 @@ error-ex@^1.2.0, error-ex@^1.3.1:
is-arrayish "^0.2.1"
es-abstract@^1.17.0-next.1, es-abstract@^1.17.2, es-abstract@^1.17.5:
version "1.17.5"
resolved "https://registry.yarnpkg.com/es-abstract/-/es-abstract-1.17.5.tgz#d8c9d1d66c8981fb9200e2251d799eee92774ae9"
integrity sha512-BR9auzDbySxOcfog0tLECW8l28eRGpDpU3Dm3Hp4q/N+VtLTmyj4EUN088XZWQDW/hzj6sYRDXeOFsaAODKvpg==
version "1.17.6"
resolved "https://registry.yarnpkg.com/es-abstract/-/es-abstract-1.17.6.tgz#9142071707857b2cacc7b89ecb670316c3e2d52a"
integrity sha512-Fr89bON3WFyUi5EvAeI48QTWX0AyekGgLA8H+c+7fbfCkJwRWRMLd8CQedNEyJuoYYhmtEqY92pgte1FAhBlhw==
dependencies:
es-to-primitive "^1.2.1"
function-bind "^1.1.1"
has "^1.0.3"
has-symbols "^1.0.1"
is-callable "^1.1.5"
is-regex "^1.0.5"
is-callable "^1.2.0"
is-regex "^1.1.0"
object-inspect "^1.7.0"
object-keys "^1.1.1"
object.assign "^4.1.0"
string.prototype.trimleft "^2.1.1"
string.prototype.trimright "^2.1.1"
string.prototype.trimend "^1.0.1"
string.prototype.trimstart "^1.0.1"
es-to-primitive@^1.2.1:
version "1.2.1"
@ -4813,7 +4808,7 @@ is-buffer@^2.0.2, is-buffer@^2.0.3:
resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-2.0.4.tgz#3e572f23c8411a5cfd9557c849e3665e0b290623"
integrity sha512-Kq1rokWXOPXWuaMAqZiJW4XxsmD9zGx9q4aePabbn3qCRGedtH7Cm+zV8WETitMfu1wdh+Rvd6w5egwSngUX2A==
is-callable@^1.1.4, is-callable@^1.1.5:
is-callable@^1.1.4, is-callable@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/is-callable/-/is-callable-1.2.0.tgz#83336560b54a38e35e3a2df7afd0454d691468bb"
integrity sha512-pyVD9AaGLxtg6srb2Ng6ynWJqkHU9bEM087AKck0w8QwDarTfNcpIYoU8x8Hv2Icm8u6kFJM18Dag8lyqGkviw==
@ -4981,7 +4976,7 @@ is-png@^1.0.0:
resolved "https://registry.yarnpkg.com/is-png/-/is-png-1.1.0.tgz#d574b12bf275c0350455570b0e5b57ab062077ce"
integrity sha1-1XSxK/J1wDUEVVcLDltXqwYgd84=
is-regex@^1.0.5:
is-regex@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/is-regex/-/is-regex-1.1.0.tgz#ece38e389e490df0dc21caea2bd596f987f767ff"
integrity sha512-iI97M8KTWID2la5uYXlkbSDQIg4F6o1sYboZKKTDpnDQMLtUL86zxhgDet3Q2SriaYsyGqZ6Mn2SjbRKeLHdqw==
@ -8126,7 +8121,7 @@ string.prototype.codepointat@^0.2.0:
resolved "https://registry.yarnpkg.com/string.prototype.codepointat/-/string.prototype.codepointat-0.2.1.tgz#004ad44c8afc727527b108cd462b4d971cd469bc"
integrity sha512-2cBVCj6I4IOvEnjgO/hWqXjqBGsY+zwPmHl12Srk9IXSZ56Jwwmy+66XO5Iut/oQVR7t5ihYdLB0GMa4alEUcg==
string.prototype.trimend@^1.0.0:
string.prototype.trimend@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/string.prototype.trimend/-/string.prototype.trimend-1.0.1.tgz#85812a6b847ac002270f5808146064c995fb6913"
integrity sha512-LRPxFUaTtpqYsTeNKaFOw3R4bxIzWOnbQ837QfBylo8jIxtcbK/A/sMV7Q+OAV/vWo+7s25pOE10KYSjaSO06g==
@ -8134,25 +8129,7 @@ string.prototype.trimend@^1.0.0:
define-properties "^1.1.3"
es-abstract "^1.17.5"
string.prototype.trimleft@^2.1.1:
version "2.1.2"
resolved "https://registry.yarnpkg.com/string.prototype.trimleft/-/string.prototype.trimleft-2.1.2.tgz#4408aa2e5d6ddd0c9a80739b087fbc067c03b3cc"
integrity sha512-gCA0tza1JBvqr3bfAIFJGqfdRTyPae82+KTnm3coDXkZN9wnuW3HjGgN386D7hfv5CHQYCI022/rJPVlqXyHSw==
dependencies:
define-properties "^1.1.3"
es-abstract "^1.17.5"
string.prototype.trimstart "^1.0.0"
string.prototype.trimright@^2.1.1:
version "2.1.2"
resolved "https://registry.yarnpkg.com/string.prototype.trimright/-/string.prototype.trimright-2.1.2.tgz#c76f1cef30f21bbad8afeb8db1511496cfb0f2a3"
integrity sha512-ZNRQ7sY3KroTaYjRS6EbNiiHrOkjihL9aQE/8gfQ4DtAC/aEBRHFJa44OmoWxGGqXuJlfKkZW4WcXErGr+9ZFg==
dependencies:
define-properties "^1.1.3"
es-abstract "^1.17.5"
string.prototype.trimend "^1.0.0"
string.prototype.trimstart@^1.0.0:
string.prototype.trimstart@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/string.prototype.trimstart/-/string.prototype.trimstart-1.0.1.tgz#14af6d9f34b053f7cfc89b72f8f2ee14b9039a54"
integrity sha512-XxZn+QpvrBI1FOcg6dIpxUPgWCPuNXvMD72aaRaUQv1eD4e/Qy8i/hFTe0BUmD60p/QA6bh1avmuPTfNjqVWRw==
@ -8451,9 +8428,9 @@ terser-webpack-plugin@^2.2.2:
webpack-sources "^1.4.3"
terser@^4.1.2, terser@^4.6.12:
version "4.7.0"
resolved "https://registry.yarnpkg.com/terser/-/terser-4.7.0.tgz#15852cf1a08e3256a80428e865a2fa893ffba006"
integrity sha512-Lfb0RiZcjRDXCC3OSHJpEkxJ9Qeqs6mp2v4jf2MHfy8vGERmVDuvjXdd/EnP5Deme5F2yBRBymKmKHCBg2echw==
version "4.8.0"
resolved "https://registry.yarnpkg.com/terser/-/terser-4.8.0.tgz#63056343d7c70bb29f3af665865a46fe03a0df17"
integrity sha512-EAPipTNeWsb/3wLPeup1tVPaXfIaU68xMnVdPafIL1TV05OhASArYyIfFvnvJCNrR2NIOvDVNNTFRa+Re2MWyw==
dependencies:
commander "^2.20.0"
source-map "~0.6.1"