mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-08 04:18:52 +00:00
[ticket/13713] Introduce priorities for groups
PHPBB3-13713
This commit is contained in:
parent
e874ce9898
commit
aee1dfd837
4 changed files with 36 additions and 24 deletions
|
@ -493,7 +493,7 @@ function getCaretPosition(txtarea) {
|
||||||
sorter: function(query, items, searchKey) {
|
sorter: function(query, items, searchKey) {
|
||||||
let i;
|
let i;
|
||||||
let len;
|
let len;
|
||||||
let highestPriority = 0;
|
let highestPriorities = {u: 0, g: 0};
|
||||||
let _unsorted = {u: {}, g: {}};
|
let _unsorted = {u: {}, g: {}};
|
||||||
let _exactMatch = [];
|
let _exactMatch = [];
|
||||||
let _results = [];
|
let _results = [];
|
||||||
|
@ -517,8 +517,7 @@ function getCaretPosition(txtarea) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the item hasn't been added yet - add it
|
// If the item hasn't been added yet - add it
|
||||||
// Group names do not have priorities and are also handled here
|
if (!_unsorted[item.type][item.id]) {
|
||||||
if (!_unsorted[item.type][item.id] || item.type === 'g') {
|
|
||||||
_unsorted[item.type][item.id] = item;
|
_unsorted[item.type][item.id] = item;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -527,26 +526,23 @@ function getCaretPosition(txtarea) {
|
||||||
_unsorted[item.type][item.id].priority += parseFloat(item.priority);
|
_unsorted[item.type][item.id].priority += parseFloat(item.priority);
|
||||||
|
|
||||||
// Calculate the highest priority - we'll give it to group names
|
// Calculate the highest priority - we'll give it to group names
|
||||||
highestPriority = Math.max(highestPriority, _unsorted[item.type][item.id].priority);
|
highestPriorities[item.type] = Math.max(highestPriorities[item.type], _unsorted[item.type][item.id].priority);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Push user names to the result array
|
// All types of names should come at the same level of importance,
|
||||||
if (_unsorted['u']) {
|
// otherwise they will be unlikely to be shown
|
||||||
$.each(_unsorted['u'], function(name, value) {
|
// That's why we normalize priorities and push names to a single results array
|
||||||
|
$.each(['u', 'g'], function(key, type) {
|
||||||
|
if (_unsorted[type]) {
|
||||||
|
$.each(_unsorted[type], function(name, value) {
|
||||||
|
// Normalize priority
|
||||||
|
value.priority /= highestPriorities[type];
|
||||||
|
|
||||||
|
// Add item to all results
|
||||||
_results.push(value);
|
_results.push(value);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Push group names to the result array and give them the highest priority
|
|
||||||
// They will be sorted together with the usernames on top of the list
|
|
||||||
if (_unsorted['g']) {
|
|
||||||
$.each(_unsorted['g'], function(name, value) {
|
|
||||||
// Groups should come at the same level of importance
|
|
||||||
// as users, otherwise they will be unlikely to be shown
|
|
||||||
value.priority = highestPriority;
|
|
||||||
_results.push(value);
|
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
// Sort names by priorities - higher values come first
|
// Sort names by priorities - higher values come first
|
||||||
_results = _results.sort(function(a, b) {
|
_results = _results.sort(function(a, b) {
|
||||||
|
|
|
@ -107,6 +107,15 @@ abstract class base_group implements source_interface
|
||||||
*/
|
*/
|
||||||
abstract protected function query($keyword, $topic_id);
|
abstract protected function query($keyword, $topic_id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function get_priority($row)
|
||||||
|
{
|
||||||
|
// By default every result from the source increases the priority by a fixed value
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
@ -141,6 +150,7 @@ abstract class base_group implements source_interface
|
||||||
'img' => phpbb_get_group_avatar($groups[$group_id]),
|
'img' => phpbb_get_group_avatar($groups[$group_id]),
|
||||||
],
|
],
|
||||||
'rank' => $group_rank['title'],
|
'rank' => $group_rank['title'],
|
||||||
|
'priority' => $this->get_priority($groups[$group_id]),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,13 +60,11 @@ abstract class base_user implements source_interface
|
||||||
abstract protected function query($keyword, $topic_id);
|
abstract protected function query($keyword, $topic_id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the priority of the currently selected name
|
* {@inheritdoc}
|
||||||
*
|
|
||||||
* @param array $row Array of fetched user data
|
|
||||||
* @return int Priority (defaults to 1)
|
|
||||||
*/
|
*/
|
||||||
public function get_priority($row)
|
public function get_priority($row)
|
||||||
{
|
{
|
||||||
|
// By default every result from the source increases the priority by a fixed value
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,4 +24,12 @@ interface source_interface
|
||||||
* @param int $topic_id Current topic ID
|
* @param int $topic_id Current topic ID
|
||||||
*/
|
*/
|
||||||
public function get(array &$names, $keyword, $topic_id);
|
public function get(array &$names, $keyword, $topic_id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the priority of the currently selected name
|
||||||
|
*
|
||||||
|
* @param array $row Array of fetched data for the name type (e.g. user row)
|
||||||
|
* @return int Priority (defaults to 1)
|
||||||
|
*/
|
||||||
|
public function get_priority($row);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue