1
0
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:
Dan Brown
2016-06-04 14:54:31 +01:00
parent 6c1e06bf86
commit 246d1621f5
4 changed files with 34 additions and 14 deletions

View File

@ -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);
}

View File

@ -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