feature: reverts select2 changes

This commit is contained in:
ievgenii vdovenko 2025-12-08 11:44:35 +01:00
parent cf5ea2eac5
commit 56fc497067
7 changed files with 4449 additions and 7146 deletions

View file

@ -27,10 +27,6 @@
{
"src": "<%= dirs.js.node_modules %>/filepond/dist/filepond.css",
"dest": "<%= dirs.css.dest %>/filepond.css"
},
{
"src": "<%= dirs.js.src %>/select2/select2.css",
"dest": "<%= dirs.css.dest %>/select2.css"
}
]
}

View file

@ -2249,8 +2249,7 @@ def dropdownmenu(name, selected, options, enable_filter=False, **attrs):
$('#%s').select2({
containerCssClass: 'drop-menu %s',
dropdownCssClass: 'drop-menu-dropdown',
dropdownAutoWidth: true,
width: 'auto'%s
dropdownAutoWidth: true'%s
});
});
</script>

File diff suppressed because it is too large Load diff

File diff suppressed because one or more lines are too long

View file

@ -63,7 +63,6 @@ c.template_context['attachment_store'] = {
## CSS definitions
<%def name="css()">
<link rel="stylesheet" type="text/css" href="${h.asset('css/select2.css', ver=c.rhodecode_version_hash)}" media="screen"/>
<link rel="stylesheet" type="text/css" href="${h.asset('css/filepond.css', ver=c.rhodecode_version_hash)}" media="screen"/>
<link rel="stylesheet" type="text/css" href="${h.asset('css/style.css', ver='321')}" media="screen"/>
## EXTRA FOR CSS

View file

@ -1279,7 +1279,7 @@ def get_comments_for(diff_type, comments, filename, line_version, line_number):
};
var animateText = function (fPath, anchorId) {
fPath = jQuery.fn.select2.defaults.defaults.escapeMarkup(fPath);
fPath = Select2.util.escapeMarkup(fPath);
$('.fpath-placeholder-text').html(contextPrefix + '<a href="#a_' + anchorId + '">' + fPath + '</a>')
};

View file

@ -44,31 +44,13 @@
</div>
</div>
<style>
.select2-container--default .select2-selection--single {
border-radius: 0 !important;
}
.select2-container--default .select2-selection--single {
margin: 0 5px; /* left/right margin */
height: 32px;
line-height: 32px;
border-radius: 0 !important;
}
.select2-container--default .select2-selection--single .select2-selection__arrow {
height: 32px;
right: 6px;
}
</style>
<script type="text/javascript">
var initFileJS = function () {
var state = getFileState();
// select code link event
$("#hlcode").on('mouseup', getSelectionLink);
$("#hlcode").mouseup(getSelectionLink);
// file history select2 used for history of file, and switch to
var initialCommitData = {
@ -225,193 +207,144 @@
};
var initTreeJS = function () {
var state = getFileState();
getFilesMetadata();
var state = getFileState();
getFilesMetadata();
// fuzzy file filter
fileBrowserListeners(state.node_list_url, state.url_base);
// fuzzy file filter
fileBrowserListeners(state.node_list_url, state.url_base);
// switch to widget
var initialCommitData = {
at_ref: atRef,
id: null,
text: '${c.commit.raw_id}',
type: 'sha',
raw_id: '${c.commit.raw_id}',
idx: ${c.commit.idx},
files_url: null
};
// check if we have ref info.
var selectedRef = fileTreeRefs[atRef];
if (selectedRef !== undefined) {
$.extend(initialCommitData, selectedRef);
}
var loadUrl = pyroutes.url('repo_refs_data', {repo_name: templateContext.repo_name});
var cacheKey = '__ALL_FILE_REFS__';
var cachedDataSource = {};
/**
* Build filtered data (similar to old feedRefsData) based on term and cached data.
*/
var buildFilteredRefsData = function (term, cachedData) {
var data = {results: []};
term = term || '';
// filter results
$.each(cachedData.results, function () {
var section = this.text;
var children = [];
$.each(this.children, function () {
if (!term.length || this.text.toUpperCase().indexOf(term.toUpperCase()) >= 0) {
children.push(this);
}
});
data.results.push({
text: section,
children: children
});
});
// push the typed-in commit idx (numeric commit)
if (term && !isNaN(term)) {
var files_url = pyroutes.url('repo_files', {
repo_name: templateContext.repo_name,
commit_id: term,
f_path: state.f_path
});
data.results.push({
text: _gettext('go to numeric commit'),
children: [{
at_ref: null,
id: null,
text: 'r{0}'.format(term),
type: 'sha',
raw_id: term,
idx: term,
files_url: files_url
}]
});
}
return data;
};
/**
* Ensure refs data is loaded and filtered, then call callback(data).
* Replaces old loadRefsData + feedRefsData + query().
*/
var ensureRefsData = function (term, callback) {
var cachedData = cachedDataSource[cacheKey];
if (cachedData) {
var filtered = buildFilteredRefsData(term, cachedData);
callback(filtered);
} else {
$.ajax({
url: loadUrl,
data: {},
dataType: 'json',
type: 'GET',
success: function (data) {
cachedDataSource[cacheKey] = data;
var filtered = buildFilteredRefsData(term, data);
callback(filtered);
}
});
}
};
var select2RefFileSwitcher = function (targetElement, loadUrl, initialData) {
var formatResult = function (result) {
return formatSelect2SelectionRefs(result);
// switch to widget
var initialCommitData = {
at_ref: atRef,
id: null,
text: '${c.commit.raw_id}',
type: 'sha',
raw_id: '${c.commit.raw_id}',
idx: ${c.commit.idx},
files_url: null,
};
var formatSelection = function (data) {
var commit_ref = data || {};
var tmpl = '';
if (commit_ref.type === 'sha') {
tmpl = (commit_ref.raw_id || commit_ref.text || "").substr(0, 8);
} else if (commit_ref.type === 'branch') {
tmpl = tmpl.concat('<i class="icon-branch"></i> ');
tmpl = tmpl.concat(escapeHtml(commit_ref.text || ''));
} else if (commit_ref.type === 'tag') {
tmpl = tmpl.concat('<i class="icon-tag"></i> ');
tmpl = tmpl.concat(escapeHtml(commit_ref.text || ''));
} else if (commit_ref.type === 'book') {
tmpl = tmpl.concat('<i class="icon-bookmark"></i> ');
tmpl = tmpl.concat(escapeHtml(commit_ref.text || ''));
} else {
// fallback
tmpl = escapeHtml(commit_ref.text || '');
}
var idx = commit_ref.idx || 0;
if (idx !== 0) {
tmpl = tmpl.concat('<span class="select-index-number">r{0}</span>'.format(idx));
}
return tmpl;
};
var $element = $(targetElement);
// --- initSelection replacement: pre-populate selected option ---
if (initialData) {
// Ensure there is an id; Select2 v4 needs an id field
if (!initialData.id) {
initialData.id = initialData.raw_id || initialData.text;
}
var option = new Option(initialData.text, initialData.id, true, true);
// Attach full data object so templateSelection has access to type/raw_id/idx
$(option).data('data', initialData);
$element.append(option).trigger('change');
// check if we have ref info.
var selectedRef = fileTreeRefs[atRef];
if (selectedRef !== undefined) {
$.extend(initialCommitData, selectedRef)
}
$element.select2({
dropdownAutoWidth: true,
width: "100%",
containerCssClass: "drop-menu",
dropdownCssClass: "drop-menu-dropdown",
var loadUrl = pyroutes.url('repo_refs_data', {'repo_name': templateContext.repo_name});
var cacheKey = '__ALL_FILE_REFS__';
var cachedDataSource = {};
// --- Select2 v4 ajax API instead of "query" ---
ajax: {
transport: function (params, success, failure) {
var term = (params.data && params.data.term) ? params.data.term : '';
ensureRefsData(term, function (data) {
success(data); // data already in {results: [...] } format
});
var loadRefsData = function (query) {
$.ajax({
url: loadUrl,
data: {},
dataType: 'json',
type: 'GET',
success: function (data) {
cachedDataSource[cacheKey] = data;
query.callback({results: data.results});
}
});
};
var feedRefsData = function (query, cachedData) {
var data = {results: []};
//filter results
$.each(cachedData.results, function () {
var section = this.text;
var children = [];
$.each(this.children, function () {
if (query.term.length === 0 || this.text.toUpperCase().indexOf(query.term.toUpperCase()) >= 0) {
children.push(this)
}
});
data.results.push({
'text': section,
'children': children
})
});
//push the typed in commit idx
if (!isNaN(query.term)) {
var files_url = pyroutes.url('repo_files',
{'repo_name': templateContext.repo_name,
'commit_id': query.term, 'f_path': state.f_path});
data.results.push({
'text': _gettext('go to numeric commit'),
'children': [{
at_ref: null,
id: null,
text: 'r{0}'.format(query.term),
type: 'sha',
raw_id: query.term,
idx: query.term,
files_url: files_url,
}]
});
}
query.callback(data);
};
var select2RefFileSwitcher = function (targetElement, loadUrl, initialData) {
var formatResult = function (result, container, query) {
return formatSelect2SelectionRefs(result);
};
var formatSelection = function (data, container) {
var commit_ref = data;
var tmpl = '';
if (commit_ref.type === 'sha') {
tmpl = (commit_ref.raw_id || "").substr(0,8);
} else if (commit_ref.type === 'branch') {
tmpl = tmpl.concat('<i class="icon-branch"></i> ');
tmpl = tmpl.concat(escapeHtml(commit_ref.text));
} else if (commit_ref.type === 'tag') {
tmpl = tmpl.concat('<i class="icon-tag"></i> ');
tmpl = tmpl.concat(escapeHtml(commit_ref.text));
} else if (commit_ref.type === 'book') {
tmpl = tmpl.concat('<i class="icon-bookmark"></i> ');
tmpl = tmpl.concat(escapeHtml(commit_ref.text));
}
var idx = commit_ref.idx || 0;
if (idx !== 0) {
tmpl = tmpl.concat('<span class="select-index-number">r{0}</span>'.format(idx));
}
return tmpl
};
$(targetElement).select2({
dropdownAutoWidth: true,
width: "resolve",
containerCssClass: "drop-menu",
dropdownCssClass: "drop-menu-dropdown",
query: function(query) {
var cachedData = cachedDataSource[cacheKey];
if (cachedData) {
feedRefsData(query, cachedData)
} else {
loadRefsData(query)
}
},
processResults: function (data /*, params */) {
// data is already in the expected {results: [...]} format
return data;
}
},
initSelection: function(element, callback) {
callback(initialData);
},
formatResult: formatResult,
formatSelection: formatSelection
});
// --- v4 template callbacks (replacing formatResult/formatSelection) ---
templateResult: formatResult,
templateSelection: formatSelection,
};
// allow HTML from our templates
escapeMarkup: function (markup) { return markup; }
select2RefFileSwitcher('#refs_filter', loadUrl, initialCommitData);
// switcher for file tree
$('#refs_filter').on('change', function(e) {
var data = $('#refs_filter').select2('data');
window.location = data.files_url
});
};
select2RefFileSwitcher('#refs_filter', loadUrl, initialCommitData);
// switcher for file tree
// In v4, prefer the "select2:select" event and e.params.data
$('#refs_filter').on('select2:select', function (e) {
var data = e.params && e.params.data;
if (data && data.files_url) {
window.location = data.files_url;
}
});
};
$(document).ready(function() {