mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-07-28 17:02:04 +03:00
Limited tag value autosuggestions based on tag name
As requested on #121
This commit is contained in:
@ -67,7 +67,8 @@ class TagController extends Controller
|
||||
public function getValueSuggestions(Request $request)
|
||||
{
|
||||
$searchTerm = $request->get('search');
|
||||
$suggestions = $this->tagRepo->getValueSuggestions($searchTerm);
|
||||
$tagName = $request->has('name') ? $request->get('name') : false;
|
||||
$suggestions = $this->tagRepo->getValueSuggestions($searchTerm, $tagName);
|
||||
return response()->json($suggestions);
|
||||
}
|
||||
|
||||
|
@ -72,15 +72,20 @@ class TagRepo
|
||||
/**
|
||||
* Get tag value suggestions from scanning existing tag values.
|
||||
* @param $searchTerm
|
||||
* @param $tagName
|
||||
* @return array
|
||||
*/
|
||||
public function getValueSuggestions($searchTerm)
|
||||
public function getValueSuggestions($searchTerm, $tagName = false)
|
||||
{
|
||||
if ($searchTerm === '') return [];
|
||||
$query = $this->tag->where('value', 'LIKE', $searchTerm . '%')->groupBy('value')->orderBy('value', 'desc');
|
||||
if ($tagName !== false) {
|
||||
$query = $query->where('name', '=', $tagName);
|
||||
}
|
||||
$query = $this->permissionService->filterRestrictedEntityRelations($query, 'tags', 'entity_id', 'entity_type');
|
||||
return $query->get(['value'])->pluck('value');
|
||||
}
|
||||
|
||||
/**
|
||||
* Save an array of tags to an entity
|
||||
* @param Entity $entity
|
||||
|
Reference in New Issue
Block a user