From 80d2889217d78ad2c6ae682980757c2bf12d4c94 Mon Sep 17 00:00:00 2001 From: Dan Brown Date: Mon, 31 Oct 2022 11:40:28 +0000 Subject: [PATCH] Updated tags list to new responsive format --- app/Actions/TagRepo.php | 11 +++++- app/Http/Controllers/TagController.php | 17 +++++--- .../Controllers/UserPreferencesController.php | 2 +- resources/lang/en/entities.php | 1 + resources/sass/_blocks.scss | 27 +------------ resources/sass/_layout.scss | 5 +++ resources/sass/_opacity.scss | 28 +++++++++++++ resources/sass/styles.scss | 1 + resources/views/tags/index.blade.php | 39 ++++++++++--------- .../views/tags/parts/table-row.blade.php | 37 ------------------ .../views/tags/parts/tags-list-item.blade.php | 31 +++++++++++++++ 11 files changed, 109 insertions(+), 90 deletions(-) create mode 100644 resources/sass/_opacity.scss delete mode 100644 resources/views/tags/parts/table-row.blade.php create mode 100644 resources/views/tags/parts/tags-list-item.blade.php diff --git a/app/Actions/TagRepo.php b/app/Actions/TagRepo.php index 2618ed2e9..cece30de0 100644 --- a/app/Actions/TagRepo.php +++ b/app/Actions/TagRepo.php @@ -4,6 +4,7 @@ namespace BookStack\Actions; use BookStack\Auth\Permissions\PermissionApplicator; use BookStack\Entities\Models\Entity; +use BookStack\Util\SimpleListOptions; use Illuminate\Database\Eloquent\Builder; use Illuminate\Support\Collection; use Illuminate\Support\Facades\DB; @@ -20,8 +21,14 @@ class TagRepo /** * Start a query against all tags in the system. */ - public function queryWithTotals(string $searchTerm, string $nameFilter): Builder + public function queryWithTotals(SimpleListOptions $listOptions, string $nameFilter): Builder { + $searchTerm = $listOptions->getSearch(); + $sort = $listOptions->getSort(); + if ($sort === 'name' && $nameFilter) { + $sort = 'value'; + } + $query = Tag::query() ->select([ 'name', @@ -32,7 +39,7 @@ class TagRepo DB::raw('SUM(IF(entity_type = \'book\', 1, 0)) as book_count'), DB::raw('SUM(IF(entity_type = \'bookshelf\', 1, 0)) as shelf_count'), ]) - ->orderBy($nameFilter ? 'value' : 'name'); + ->orderBy($sort, $listOptions->getOrder()); if ($nameFilter) { $query->where('name', '=', $nameFilter); diff --git a/app/Http/Controllers/TagController.php b/app/Http/Controllers/TagController.php index 056cc9902..a221437dd 100644 --- a/app/Http/Controllers/TagController.php +++ b/app/Http/Controllers/TagController.php @@ -3,6 +3,7 @@ namespace BookStack\Http\Controllers; use BookStack\Actions\TagRepo; +use BookStack\Util\SimpleListOptions; use Illuminate\Http\Request; class TagController extends Controller @@ -19,22 +20,26 @@ class TagController extends Controller */ public function index(Request $request) { - $search = $request->get('search', ''); + $listOptions = SimpleListOptions::fromRequest($request, 'tags')->withSortOptions([ + 'name' => trans('common.sort_name'), + 'usages' => trans('entities.tags_usages'), + ]); + $nameFilter = $request->get('name', ''); $tags = $this->tagRepo - ->queryWithTotals($search, $nameFilter) + ->queryWithTotals($listOptions, $nameFilter) ->paginate(50) ->appends(array_filter([ - 'search' => $search, + ...$listOptions->getPaginationAppends(), 'name' => $nameFilter, ])); $this->setPageTitle(trans('entities.tags')); return view('tags.index', [ - 'tags' => $tags, - 'search' => $search, - 'nameFilter' => $nameFilter, + 'tags' => $tags, + 'nameFilter' => $nameFilter, + 'listOptions' => $listOptions, ]); } diff --git a/app/Http/Controllers/UserPreferencesController.php b/app/Http/Controllers/UserPreferencesController.php index 8e9160810..ca77dcd0b 100644 --- a/app/Http/Controllers/UserPreferencesController.php +++ b/app/Http/Controllers/UserPreferencesController.php @@ -62,7 +62,7 @@ class UserPreferencesController extends Controller */ public function changeSort(Request $request, string $id, string $type) { - $validSortTypes = ['books', 'bookshelves', 'shelf_books', 'users', 'roles', 'webhooks']; + $validSortTypes = ['books', 'bookshelves', 'shelf_books', 'users', 'roles', 'webhooks', 'tags']; if (!in_array($type, $validSortTypes)) { return redirect()->back(500); } diff --git a/resources/lang/en/entities.php b/resources/lang/en/entities.php index bf6201900..b3dfb0bf7 100644 --- a/resources/lang/en/entities.php +++ b/resources/lang/en/entities.php @@ -275,6 +275,7 @@ return [ 'shelf_tags' => 'Shelf Tags', 'tag' => 'Tag', 'tags' => 'Tags', + 'tags_index_desc' => 'Tags can be applied to content within the system to apply a flexible form of categorization. Tags can have both a key and value, with the value being optional. Once applied, content can then be queried using the tag name and value.', 'tag_name' => 'Tag Name', 'tag_value' => 'Tag Value (Optional)', 'tags_explain' => "Add some tags to better categorise your content. \n You can assign a value to a tag for more in-depth organisation.", diff --git a/resources/sass/_blocks.scss b/resources/sass/_blocks.scss index 0398224ca..6058add82 100644 --- a/resources/sass/_blocks.scss +++ b/resources/sass/_blocks.scss @@ -286,35 +286,10 @@ margin-bottom: 0; } -td .tag-item { +.item-list-row .tag-item { margin-bottom: 0; } -/** - * Pill boxes - */ - -.pill { - display: inline-block; - border: 1px solid currentColor; - padding: .2em .8em; - font-size: 0.8em; - border-radius: 1rem; - position: relative; - overflow: hidden; - line-height: 1.4; - &:before { - content: ''; - background-color: currentColor; - position: absolute; - top: 0; - left: 0; - width: 100%; - height: 100%; - opacity: 0.1; - } -} - /** * API Docs */ diff --git a/resources/sass/_layout.scss b/resources/sass/_layout.scss index 51389dc69..105b6a16f 100644 --- a/resources/sass/_layout.scss +++ b/resources/sass/_layout.scss @@ -160,6 +160,11 @@ body.flexbox { flex-basis: auto; flex-grow: 0; } + &.fill-area { + flex-grow: 1; + flex-shrink: 0; + min-width: fit-content; + } } .flex-2 { diff --git a/resources/sass/_opacity.scss b/resources/sass/_opacity.scss new file mode 100644 index 000000000..235aed48e --- /dev/null +++ b/resources/sass/_opacity.scss @@ -0,0 +1,28 @@ + +.opacity-10 { + opacity: 0.1; +} +.opacity-20 { + opacity: 0.2; +} +.opacity-30 { + opacity: 0.3; +} +.opacity-40 { + opacity: 0.4; +} +.opacity-50 { + opacity: 0.5; +} +.opacity-60 { + opacity: 0.6; +} +.opacity-70 { + opacity: 0.7; +} +.opacity-80 { + opacity: 0.8; +} +.opacity-90 { + opacity: 0.9; +} \ No newline at end of file diff --git a/resources/sass/styles.scss b/resources/sass/styles.scss index 44d0055b5..5e31dbdfb 100644 --- a/resources/sass/styles.scss +++ b/resources/sass/styles.scss @@ -4,6 +4,7 @@ @import "variables"; @import "mixins"; @import "spacing"; +@import "opacity"; @import "html"; @import "text"; @import "colors"; diff --git a/resources/views/tags/index.blade.php b/resources/views/tags/index.blade.php index c88449ce7..b6b3325e0 100644 --- a/resources/views/tags/index.blade.php +++ b/resources/views/tags/index.blade.php @@ -5,25 +5,28 @@
-
-

{{ trans('entities.tags') }}

+

{{ trans('entities.tags') }}

-
-
-
- @include('form.request-query-inputs', ['params' => ['name']]) - -
-
+

{{ trans('entities.tags_index_desc') }}

+ +
+
+
+ @include('form.request-query-inputs', ['params' => ['name']]) + +
+
+
+ @include('common.sort', $listOptions->getSortControlData())
@if($nameFilter) -
- {{ trans('common.filter_active') }} +
+ {{ trans('common.filter_active') }} @include('entities.tag', ['tag' => new \BookStack\Actions\Tag(['name' => $nameFilter])])
@include('form.request-query-inputs', ['params' => ['search']]) @@ -33,13 +36,13 @@ @endif @if(count($tags) > 0) - +
@foreach($tags as $tag) - @include('tags.parts.table-row', ['tag' => $tag, 'nameFilter' => $nameFilter]) + @include('tags.parts.tags-list-item', ['tag' => $tag, 'nameFilter' => $nameFilter]) @endforeach -
+
-
+
{{ $tags->links() }}
@else diff --git a/resources/views/tags/parts/table-row.blade.php b/resources/views/tags/parts/table-row.blade.php deleted file mode 100644 index aa04959a9..000000000 --- a/resources/views/tags/parts/table-row.blade.php +++ /dev/null @@ -1,37 +0,0 @@ - - - @include('entities.tag', ['tag' => $tag]) - - - @icon('leaderboard'){{ $tag->usages }} - - - @icon('page'){{ $tag->page_count }} - - - @icon('chapter'){{ $tag->chapter_count }} - - - @icon('book'){{ $tag->book_count }} - - - @icon('bookshelf'){{ $tag->shelf_count }} - - - @if($tag->values ?? false) - {{ trans('entities.tags_x_unique_values', ['count' => $tag->values]) }} - @elseif(empty($nameFilter)) - {{ trans('entities.tags_all_values') }} - @endif - - \ No newline at end of file diff --git a/resources/views/tags/parts/tags-list-item.blade.php b/resources/views/tags/parts/tags-list-item.blade.php new file mode 100644 index 000000000..3962db760 --- /dev/null +++ b/resources/views/tags/parts/tags-list-item.blade.php @@ -0,0 +1,31 @@ + \ No newline at end of file