mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-07-30 04:23:11 +03:00
Default templates: Added page picker and working forms
- Adapted existing page picker to be usable elsewhere. - Added endpoint for getting templates for entity picker. - Added search template filter to support above. - Updated book save handling to check/validate submitted template. - Allows non-visible pages to flow through the save process, if not being changed. - Updated page deletes to handle removal of default usage on books. - Tweaked wording and form styles to suit. - Updated migration to explicity reflect default value.
This commit is contained in:
@ -2,6 +2,7 @@
|
||||
|
||||
namespace BookStack\Search;
|
||||
|
||||
use BookStack\Entities\Models\Page;
|
||||
use BookStack\Entities\Queries\Popular;
|
||||
use BookStack\Entities\Tools\SiblingFetcher;
|
||||
use BookStack\Http\Controller;
|
||||
@ -82,6 +83,32 @@ class SearchController extends Controller
|
||||
return view('search.parts.entity-selector-list', ['entities' => $entities, 'permission' => $permission]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Search for a list of templates to choose from.
|
||||
*/
|
||||
public function templatesForSelector(Request $request)
|
||||
{
|
||||
$searchTerm = $request->get('term', false);
|
||||
|
||||
if ($searchTerm !== false) {
|
||||
$searchOptions = SearchOptions::fromString($searchTerm);
|
||||
$searchOptions->setFilter('is_template');
|
||||
$entities = $this->searchRunner->searchEntities($searchOptions, 'page', 1, 20)['results'];
|
||||
} else {
|
||||
$entities = Page::visible()
|
||||
->where('template', '=', true)
|
||||
->where('draft', '=', false)
|
||||
->orderBy('updated_at', 'desc')
|
||||
->take(20)
|
||||
->get(Page::$listAttributes);
|
||||
}
|
||||
|
||||
return view('search.parts.entity-selector-list', [
|
||||
'entities' => $entities,
|
||||
'permission' => 'view'
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Search for a list of entities and return a partial HTML response of matching entities
|
||||
* to be used as a result preview suggestion list for global system searches.
|
||||
|
@ -170,6 +170,14 @@ class SearchOptions
|
||||
return $parsed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value of a specific filter in the search options.
|
||||
*/
|
||||
public function setFilter(string $filterName, string $filterValue = ''): void
|
||||
{
|
||||
$this->filters[$filterName] = $filterValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode this instance to a search string.
|
||||
*/
|
||||
|
@ -58,7 +58,7 @@ class SearchRunner
|
||||
$entityTypesToSearch = $entityTypes;
|
||||
|
||||
if ($entityType !== 'all') {
|
||||
$entityTypesToSearch = $entityType;
|
||||
$entityTypesToSearch = [$entityType];
|
||||
} elseif (isset($searchOpts->filters['type'])) {
|
||||
$entityTypesToSearch = explode('|', $searchOpts->filters['type']);
|
||||
}
|
||||
@ -469,6 +469,13 @@ class SearchRunner
|
||||
});
|
||||
}
|
||||
|
||||
protected function filterIsTemplate(EloquentBuilder $query, Entity $model, $input)
|
||||
{
|
||||
if ($model instanceof Page) {
|
||||
$query->where('template', '=', true);
|
||||
}
|
||||
}
|
||||
|
||||
protected function filterSortBy(EloquentBuilder $query, Entity $model, $input)
|
||||
{
|
||||
$functionName = Str::camel('sort_by_' . $input);
|
||||
|
Reference in New Issue
Block a user