Fixed issues reported by SonarQube.

This commit is contained in:
Nikhil Mohite 2021-01-18 13:02:19 +05:30 committed by Akshay Joshi
parent 5afa4f1995
commit d4a3e4d92c
9 changed files with 56 additions and 51 deletions

View File

@ -444,7 +444,7 @@ def register_browser_preferences(self):
)
self.dynamic_tab_title = self.preference.register(
'tab settings', 'dynamic_tabs',
'tab_settings', 'dynamic_tabs',
gettext("Dynamic tab size"), 'boolean', False,
category_label=PREF_LABEL_TABS_SETTINGS,
help_str=gettext(
@ -453,7 +453,7 @@ def register_browser_preferences(self):
)
self.qt_tab_title = self.preference.register(
'tab settings', 'qt_tab_title_placeholder',
'tab_settings', 'qt_tab_title_placeholder',
gettext("Query tool tab title"),
'text', '%DATABASE%/%USERNAME%@%SERVER%',
category_label=PREF_LABEL_DISPLAY,
@ -466,7 +466,7 @@ def register_browser_preferences(self):
)
self.ve_edt_tab_title = self.preference.register(
'tab settings', 'vw_edt_tab_title_placeholder',
'tab_settings', 'vw_edt_tab_title_placeholder',
gettext("View/Edit data tab title"),
'text', '%SCHEMA%.%TABLE%/%DATABASE%/%USERNAME%@%SERVER%',
category_label=PREF_LABEL_DISPLAY,
@ -479,7 +479,7 @@ def register_browser_preferences(self):
)
self.debugger_tab_title = self.preference.register(
'tab settings', 'debugger_tab_title_placeholder',
'tab_settings', 'debugger_tab_title_placeholder',
gettext("Debugger tab title"),
'text', '%FUNCTION%(%ARGS%)',
category_label=PREF_LABEL_DISPLAY,
@ -492,7 +492,7 @@ def register_browser_preferences(self):
)
self.open_in_new_tab = self.preference.register(
'tab settings', 'new_browser_tab_open',
'tab_settings', 'new_browser_tab_open',
gettext("Open in new browser tab"), 'select2', None,
category_label=PREF_LABEL_OPTIONS,
options=[{'label': gettext('Query Tool'), 'value': 'qt'},

View File

@ -949,18 +949,18 @@ define([
};
renameItem(file_data);
let path = $('.currentpath').val();
let current_path = $('.currentpath').val();
if(isFolder == true) {
// if its folder rename, remove the temporary added class
$(this).closest('.tbl_folder').removeClass('tbl_folder_rename');
if(path.includes('\\')) {
path = $('.currentpath').val().split('\\').slice(0, -2).join('\\')+'\\';
if(current_path.includes('\\')) {
current_path = $('.currentpath').val().split('\\').slice(0, -2).join('\\')+'\\';
}
else {
path = $('.currentpath').val().split('/').slice(0, -2).join('/')+'/';
current_path = $('.currentpath').val().split('/').slice(0, -2).join('/')+'/';
}
}
getFolderInfo(path);
getFolderInfo(current_path);
}
}
} else {
@ -1005,18 +1005,18 @@ define([
};
renameItem(file_data);
let path = $('.currentpath').val();
let current_path = $('.currentpath').val();
if(isFolder == true) {
// if its folder rename, remove the temporary added class
$(this).closest('.tbl_folder').removeClass('tbl_folder_rename');
if(path.includes('\\')) {
path = $('.currentpath').val().split('\\').slice(0, -2).join('\\')+'\\';
if(current_path.includes('\\')) {
current_path = $('.currentpath').val().split('\\').slice(0, -2).join('\\')+'\\';
}
else {
path = $('.currentpath').val().split('/').slice(0, -2).join('/')+'/';
current_path = $('.currentpath').val().split('/').slice(0, -2).join('/')+'/';
}
}
getFolderInfo(path);
getFolderInfo(current_path);
}
}
} else {

View File

@ -204,9 +204,9 @@ def save(pid):
if data['name'] in ['vw_edt_tab_title_placeholder',
'qt_tab_title_placeholder',
'debugger_tab_title_placeholder']:
if data['value'].isspace():
data['value'] = ''
'debugger_tab_title_placeholder'] \
and data['value'].isspace():
data['value'] = ''
res, msg = Preferences.save(
data['mid'], data['category_id'], data['id'], data['value'])

View File

@ -453,9 +453,9 @@ define([
if(value) {
// Remove the leading and trailing white spaces.
value = value.trim();
let browser_preferences = pgBrowser.get_preferences_for_module('browser');
var label = treeInfo.function ? treeInfo.function.label : treeInfo.trigger_function ? treeInfo.trigger_function.label : treeInfo.trigger ? treeInfo.trigger.label : treeInfo.procedure.label;
debuggerUtils.setDebuggerTitle(panel, browser_preferences, label, treeInfo.schema.label, treeInfo.database.label, value, pgBrowser);
let preferences = pgBrowser.get_preferences_for_module('browser');
var name = treeInfo.function ? treeInfo.function.label : treeInfo.trigger_function ? treeInfo.trigger_function.label : treeInfo.trigger ? treeInfo.trigger.label : treeInfo.procedure.label;
debuggerUtils.setDebuggerTitle(panel, preferences, name, treeInfo.schema.label, treeInfo.database.label, value, pgBrowser);
}
},
// We will execute this function when user clicks on the Cancel
@ -597,9 +597,9 @@ define([
if(value) {
// Remove the leading and trailing white spaces.
value = value.trim();
let browser_preferences = pgBrowser.get_preferences_for_module('browser');
var label = treeInfo.function ? treeInfo.function.label : treeInfo.trigger_function ? treeInfo.trigger_function.label : treeInfo.trigger ? treeInfo.trigger.label : treeInfo.procedure.label;
debuggerUtils.setDebuggerTitle(panel, browser_preferences, label, treeInfo.schema.label, treeInfo.database.label, value, pgBrowser);
let preferences = pgBrowser.get_preferences_for_module('browser');
var name = treeInfo.function ? treeInfo.function.label : treeInfo.trigger_function ? treeInfo.trigger_function.label : treeInfo.trigger ? treeInfo.trigger.label : treeInfo.procedure.label;
debuggerUtils.setDebuggerTitle(panel, preferences, name, treeInfo.schema.label, treeInfo.database.label, value, pgBrowser);
}
},
// We will execute this function when user clicks on the Cancel

View File

@ -801,8 +801,8 @@ define([
if(value) {
// Remove the leading and trailing white spaces.
value = value.trim();
var label = treeInfo.function ? treeInfo.function.label : treeInfo.trigger_function ? treeInfo.trigger_function.label : treeInfo.trigger ? treeInfo.trigger.label : treeInfo.procedure.label;
debuggerUtils.setDebuggerTitle(panel, self.preferences, label, treeInfo.schema.label, treeInfo.database.label, value, pgBrowser);
var name = treeInfo.function ? treeInfo.function.label : treeInfo.trigger_function ? treeInfo.trigger_function.label : treeInfo.trigger ? treeInfo.trigger.label : treeInfo.procedure.label;
debuggerUtils.setDebuggerTitle(panel, self.preferences, name, treeInfo.schema.label, treeInfo.database.label, value, pgBrowser);
}
},
// We will execute this function when user clicks on the Cancel

View File

@ -76,7 +76,7 @@ function setDebuggerTitle(panel, preferences, function_name, schema_name, databa
function get_function_name(function_name) {
var function_data = function_name.split('(');
function_data.splice(-1, 1);
var index = 0;
var index = null;
var func_name = '';
for(index=0; index < function_data.length; index++) {
func_name = func_name.concat(function_data[index]);

View File

@ -2175,7 +2175,6 @@ define('tools.querytool', [
} else{
loadingDiv = $('#fetching_data');
loadingDiv.removeClass('d-none');
msgDiv = loadingDiv.find('.sql-editor-busy-text');
}
self.set_selected_option(connection_details);
$.ajax({

View File

@ -757,7 +757,6 @@ WHERE db.datname = current_database()""")
if cur and cur.query is not None else None
except Exception:
current_app.logger.warning('Error encoding query')
pass
dsn = self.conn.get_dsn_parameters()
current_app.logger.log(

View File

@ -111,22 +111,10 @@ class _Preference(object):
# The data stored in the configuration will be in string format, we
# need to convert them in proper format.
if self._type in ('boolean', 'switch', 'node'):
return res.value == 'True'
if self._type == 'options':
for opt in self.options:
if 'value' in opt and opt['value'] == res.value:
return res.value
if self.select2 and self.select2['tags']:
return res.value
return self.default
if self._type == 'select2':
if res.value:
res.value = res.value.replace('[', '')
res.value = res.value.replace(']', '')
res.value = res.value.replace('\'', '')
return [val.strip() for val in res.value.split(',')]
return None
is_format_data, data = self._get_format_data(res)
if is_format_data:
return data
if self._type == 'text' and res.value == '' and not self.allow_blanks:
return self.default
@ -144,6 +132,31 @@ class _Preference(object):
return self.default
return res.value
def _get_format_data(self, res):
"""
Configuration data get stored in string format, convert it in to
required format.
:param res: type value.
"""
if self._type in ('boolean', 'switch', 'node'):
return True, res.value == 'True'
if self._type == 'options':
for opt in self.options:
if 'value' in opt and opt['value'] == res.value:
return True, res.value
if self.select2 and self.select2['tags']:
return True, res.value
return True, self.default
if self._type == 'select2':
if res.value:
res.value = res.value.replace('[', '')
res.value = res.value.replace(']', '')
res.value = res.value.replace('\'', '')
return True, [val.strip() for val in res.value.split(',')]
return True, None
return False, None
def set(self, value):
"""
set
@ -477,12 +490,6 @@ class Preferences(object):
boolean, integer, numeric, date, datetime,
options, multiline, switch, node
:param default: Default value for the preference/option
:param min_val: Minimum value for integer, and numeric type
:param max_val: Maximum value for integer, and numeric type
:param options: Allowed list of options for 'option' type
:param help_str: Help string show for that preference/option.
:param module_label: Label for the module
:param category_label: Label for the category
"""
min_val = kwargs.get('min_val', None)
max_val = kwargs.get('max_val', None)