Rename the "Resize by data?" to "Columns sized by" and disabled the 'Maximum column width'

button if 'Columns sized by' is set to 'Column data'. Fixes #6622
This commit is contained in:
Akshay Joshi 2021-07-27 15:17:06 +05:30
parent 3f67f512ec
commit 508f97b08e
8 changed files with 90 additions and 30 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 160 KiB

After

Width:  |  Height:  |  Size: 147 KiB

View File

@ -377,14 +377,13 @@ Use the fields on the *Options* panel to manage editor preferences.
Use the fields on the *Results grid* panel to specify your formatting Use the fields on the *Results grid* panel to specify your formatting
preferences for copied data. preferences for copied data.
* Specify the maximum width of the column when 'Resize by data?' is set to True. * When the *Columns sized by* is set to *Column data*, then data columns will
If it is set to 0 then columns will auto-size to the maximum width of the data
in the column. If 'Resize by data?' is set to False then this setting won't
take any effect.
* When the *Resize by data?* switch is set to *True*, then data columns will
auto-size to the maximum width of the data in the column as loaded in the auto-size to the maximum width of the data in the column as loaded in the
first batch. If False, the column will be sized to the widest of the data first batch. If set to *Column name*, the column will be sized to the widest
type or column name. of the data type or column name.
* Specify the maximum width of the column in pixel when 'Columns sized by' is
set to *Column data*. If 'Columns sized by' is set to *Column name* then this
setting won't have any effect.
* Use the *Result copy field separator* drop-down listbox to select the field * Use the *Result copy field separator* drop-down listbox to select the field
separator for copied data. separator for copied data.
* Use the *Result copy quote character* drop-down listbox to select the quote * Use the *Result copy quote character* drop-down listbox to select the quote

View File

@ -13,6 +13,7 @@ New features
Housekeeping Housekeeping
************ ************
| `Issue #6622 <https://redmine.postgresql.org/issues/6622>`_ - Rename the "Resize by data?" to "Columns sized by" and disabled the 'Maximum column width' button if 'Columns sized by' is set to 'Column data'.
Bug fixes Bug fixes
********* *********

View File

@ -83,7 +83,8 @@ define('pgadmin.preferences', [
}); });
preferences.on('change', function(m) { preferences.on('change', function(m) {
var id = m.get('id'); var id = m.get('id'),
dependents = m.get('dependents');
if (!(id in changed)) { if (!(id in changed)) {
// Keep track of the original value // Keep track of the original value
changed[id] = m._previousAttributes.value; changed[id] = m._previousAttributes.value;
@ -91,8 +92,46 @@ define('pgadmin.preferences', [
// Remove unchanged models. // Remove unchanged models.
delete changed[id]; delete changed[id];
} }
// Check dependents exist or not. If exists then call dependentsFound function.
if (!_.isNull(dependents) && Array.isArray(dependents) && dependents.length > 0) {
dependentsFound(m.get('name'), m.get('value'), dependents);
}
}); });
/*
* Function: dependentsFound
*
* This method will be used to iterate through all the controls and
* dependents. If found then perform the appropriate action.
*/
var dependentsFound = function(pref_name, pref_val, dependents) {
// Iterate through all the controls and check the dependents
_.each(controls, function(c) {
let ctrl_name = c.model.get('name');
_.each(dependents, function(deps) {
if (ctrl_name === deps) {
// Create methods to take appropriate actions and call here.
enableDisableMaxWidth(pref_name, pref_val, c);
}
});
});
};
/*
* Function: enableDisableMaxWidth
*
* This method will be used to enable and disable Maximum Width control
*/
var enableDisableMaxWidth = function(pref_name, pref_val, control) {
if (pref_name === 'column_data_auto_resize' && pref_val === 'by_name') {
control.$el.find('input').prop('disabled', true);
control.$el.find('input').val(0);
} else if (pref_name === 'column_data_auto_resize' && pref_val === 'by_data') {
control.$el.find('input').prop('disabled', false);
}
};
/* /*
* Function: renderPreferencePanel * Function: renderPreferencePanel
* *
@ -144,6 +183,16 @@ define('pgadmin.preferences', [
controls.push(cntr); controls.push(cntr);
}); });
/* Iterate through all preferences and check if dependents found.
* If found then call the dependentsFound method
*/
_.each(prefs, function(p) {
let m = preferences.get(p.id);
let dependents = m.get('dependents');
if (!_.isNull(dependents) && Array.isArray(dependents) && dependents.length > 0) {
dependentsFound(m.get('name'), m.get('value'), dependents);
}
});
}; };
/* /*
@ -383,6 +432,7 @@ define('pgadmin.preferences', [
'category_id': d.id, 'category_id': d.id,
'mid': d.mid, 'mid': d.mid,
'name': p.name, 'name': p.name,
'dependents': p.dependents,
}); });
/* /*
* We don't know until now, how to render the control for * We don't know until now, how to render the control for

View File

@ -39,13 +39,13 @@
} }
} }
function resizeAllColumns(maxWidth) { function resizeAllColumns(maxWidth, max_width_changed=false) {
var elHeaders = $container.find('.slick-header-column'); var elHeaders = $container.find('.slick-header-column');
var allColumns = grid.getColumns(); var allColumns = grid.getColumns();
elHeaders.each(function(index, el) { elHeaders.each(function(index, el) {
var columnDef = $(el).data('column'); var columnDef = $(el).data('column');
// Check if width is set then no need to resize that column. // Check if width is set then no need to resize that column.
if (typeof(columnDef.width) !== 'undefined' && !isNaN(columnDef.width)) { if (typeof(columnDef.width) !== 'undefined' && !isNaN(columnDef.width) && !max_width_changed) {
return; return;
} }

View File

@ -892,6 +892,13 @@ define('tools.querytool', [
column_size[table_name] = {}; column_size[table_name] = {};
} }
// Keep track of column_data_max_width
self.max_width_changed = false;
if (_.isUndefined(self.old_column_data_max_width) || self.old_column_data_max_width != self.preferences.column_data_max_width) {
self.old_column_data_max_width = self.preferences.column_data_max_width;
self.max_width_changed = true;
}
_.each(columns, function(c) { _.each(columns, function(c) {
c.display_name = _.escape(c.display_name); c.display_name = _.escape(c.display_name);
@ -931,12 +938,12 @@ define('tools.querytool', [
} }
if (_.isUndefined(column_size[table_name][options.nonative_field])) { if (_.isUndefined(column_size[table_name][options.nonative_field])) {
/* If column_data_auto_resize is true then for the first time set /* If column_data_auto_resize is 'by_data' then for the first time set
* the addWidth parameter to iconWidth and if it is false then * the addWidth parameter to iconWidth and if it is 'by_name' then
* calculate width based on longer string among data type or * calculate width based on longer string among data type or
* column name. * column name.
*/ */
if (self.preferences.column_data_auto_resize) { if (self.preferences.column_data_auto_resize === 'by_data') {
options['addWidth'] = iconWidth; options['addWidth'] = iconWidth;
options['width'] = NaN; options['width'] = NaN;
} else { } else {
@ -1187,9 +1194,9 @@ define('tools.querytool', [
dataView.onRowsChanged.subscribe(function(e, args) { dataView.onRowsChanged.subscribe(function(e, args) {
grid.invalidateRows(args.rows); grid.invalidateRows(args.rows);
grid.render(); grid.render();
// Resize all columns if column_data_auto_resize is true. // Resize all columns if column_data_auto_resize is 'by_data'.
if (self.preferences.column_data_auto_resize) { if (self.preferences.column_data_auto_resize === 'by_data') {
grid.resizeAllColumns && grid.resizeAllColumns(self.preferences.column_data_max_width); grid.resizeAllColumns && grid.resizeAllColumns(self.preferences.column_data_max_width, self.max_width_changed);
} }
}); });
@ -1430,7 +1437,7 @@ define('tools.querytool', [
} }
dataView.setItems(collection, self.client_primary_key); dataView.setItems(collection, self.client_primary_key);
/* Resize the columns once if data empty */ /* Resize the columns once if data empty */
if (collection.length === 0 && self.preferences.column_data_auto_resize) { if (collection.length === 0 && self.preferences.column_data_auto_resize === 'by_data') {
self.grid.resizeAllColumns && self.grid.resizeAllColumns(); self.grid.resizeAllColumns && self.grid.resizeAllColumns();
} }
}, },

View File

@ -270,27 +270,27 @@ def register_query_tool_preferences(self):
self.column_data_auto_resize = self.preference.register( self.column_data_auto_resize = self.preference.register(
'Results_grid', 'column_data_auto_resize', 'Results_grid', 'column_data_auto_resize',
gettext("Resize by data?"), 'boolean', True, gettext("Columns sized by"), 'radioModern', 'by_data',
options=[{'label': gettext('Column data'), 'value': 'by_data'},
{'label': gettext('Column name'), 'value': 'by_name'}],
category_label=PREF_LABEL_RESULTS_GRID, category_label=PREF_LABEL_RESULTS_GRID,
help_str=gettext( help_str=gettext(
'If set to True then data columns will auto-size to the maximum ' 'If set to \'Column data\' columns will auto-size to the maximum '
'width of the data in the column as loaded in the first batch. If ' 'width of the data in the column as loaded in the first batch. If '
'False, the column will be sized to the widest of the data type ' 'set to \'Column name\', the column will be sized to the widest '
'or column name.' 'of the data type or column name.'
) ),
dependents=['column_data_max_width']
) )
self.column_data_max_width = self.preference.register( self.column_data_max_width = self.preference.register(
'Results_grid', 'column_data_max_width', 'Results_grid', 'column_data_max_width',
gettext("Maximum column width"), 'integer', 0, gettext("Maximum column width (in Pixel)"), 'integer', 0,
category_label=PREF_LABEL_RESULTS_GRID, category_label=PREF_LABEL_RESULTS_GRID,
help_str=gettext( help_str=gettext(
'Specify the maximum width of the column when \'Resize by data?\' ' 'Specify the maximum width of the column when '
'is set to True. If it is set to 0 then columns will auto-size to ' '\'Columns sized by \' is set to \'Column data\'.'
'the maximum width of the data in the column. If ' ),
'\'Resize by data?\' is set to False then this setting won\'t '
'take any effect.'
)
) )
self.sql_font_size = self.preference.register( self.sql_font_size = self.preference.register(

View File

@ -73,6 +73,7 @@ class _Preference(object):
self.fields = kwargs.get('fields', None) self.fields = kwargs.get('fields', None)
self.allow_blanks = kwargs.get('allow_blanks', None) self.allow_blanks = kwargs.get('allow_blanks', None)
self.disabled = kwargs.get('disabled', False) self.disabled = kwargs.get('disabled', False)
self.dependents = kwargs.get('dependents', None)
# Look into the configuration table to find out the id of the specific # Look into the configuration table to find out the id of the specific
# preference. # preference.
@ -254,6 +255,7 @@ class _Preference(object):
'value': self.get(), 'value': self.get(),
'fields': self.fields, 'fields': self.fields,
'disabled': self.disabled, 'disabled': self.disabled,
'dependents': self.dependents
} }
return res return res
@ -427,6 +429,7 @@ class Preferences(object):
fields = kwargs.get('fields', None) fields = kwargs.get('fields', None)
allow_blanks = kwargs.get('allow_blanks', None) allow_blanks = kwargs.get('allow_blanks', None)
disabled = kwargs.get('disabled', False) disabled = kwargs.get('disabled', False)
dependents = kwargs.get('dependents', None)
cat = self.__category(category, category_label) cat = self.__category(category, category_label)
if name in cat['preferences']: if name in cat['preferences']:
@ -444,7 +447,7 @@ class Preferences(object):
cat['id'], name, label, _type, default, help_str=help_str, cat['id'], name, label, _type, default, help_str=help_str,
min_val=min_val, max_val=max_val, options=options, min_val=min_val, max_val=max_val, options=options,
select2=select2, fields=fields, allow_blanks=allow_blanks, select2=select2, fields=fields, allow_blanks=allow_blanks,
disabled=disabled disabled=disabled, dependents=dependents
) )
return res return res