]> BookStack Code Mirror - bookstack/commitdiff
Sorting: Added content misses from last commit, started settings
authorDan Brown <redacted>
Thu, 30 Jan 2025 17:49:19 +0000 (17:49 +0000)
committerDan Brown <redacted>
Thu, 30 Jan 2025 17:49:19 +0000 (17:49 +0000)
app/Sorting/SortSet.php [new file with mode: 0644]
database/migrations/2025_01_29_180933_create_sort_sets_table.php [new file with mode: 0644]
lang/en/settings.php
resources/views/settings/categories/sorting.blade.php [new file with mode: 0644]
resources/views/settings/layout.blade.php

diff --git a/app/Sorting/SortSet.php b/app/Sorting/SortSet.php
new file mode 100644 (file)
index 0000000..42e1e09
--- /dev/null
@@ -0,0 +1,35 @@
+<?php
+
+namespace BookStack\Sorting;
+
+use Carbon\Carbon;
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * @property int $id
+ * @property string $name
+ * @property string $sequence
+ * @property Carbon $created_at
+ * @property Carbon $updated_at
+ */
+class SortSet extends Model
+{
+    /**
+     * @return SortSetOption[]
+     */
+    public function getOptions(): array
+    {
+        $strOptions = explode(',', $this->sequence);
+        $options = array_map(fn ($val) => SortSetOption::tryFrom($val), $strOptions);
+        return array_filter($options);
+    }
+
+    /**
+     * @param SortSetOption[] $options
+     */
+    public function setOptions(array $options): void
+    {
+        $values = array_map(fn (SortSetOption $opt) => $opt->value, $options);
+        $this->sequence = implode(',', $values);
+    }
+}
diff --git a/database/migrations/2025_01_29_180933_create_sort_sets_table.php b/database/migrations/2025_01_29_180933_create_sort_sets_table.php
new file mode 100644 (file)
index 0000000..bf9780c
--- /dev/null
@@ -0,0 +1,29 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+    /**
+     * Run the migrations.
+     */
+    public function up(): void
+    {
+        Schema::create('sort_sets', function (Blueprint $table) {
+            $table->increments('id');
+            $table->string('name');
+            $table->text('sequence');
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     */
+    public function down(): void
+    {
+        Schema::dropIfExists('sort_sets');
+    }
+};
index c0b6b692a57b9b5eaf7ce17d51a0baf0ae6380ab..b20152bfe0b3219507061c2a75fd458eaac6407e 100644 (file)
@@ -74,6 +74,13 @@ return [
     'reg_confirm_restrict_domain_desc' => 'Enter a comma separated list of email domains you would like to restrict registration to. Users will be sent an email to confirm their address before being allowed to interact with the application. <br> Note that users will be able to change their email addresses after successful registration.',
     'reg_confirm_restrict_domain_placeholder' => 'No restriction set',
 
+    // Sorting Settings
+    'sorting' => 'Sorting',
+    'sorting_book_default' => 'Default Book Sort',
+    'sorting_book_default_desc' => 'Select the default sort set to apply to new books. This won\'t affect existing books, and can be overridden per-book.',
+    'sorting_sets' => 'Sort Sets',
+    'sorting_sets_desc' => 'These are predefined sorting operations which can be applied to content in the system.',
+
     // Maintenance settings
     'maint' => 'Maintenance',
     'maint_image_cleanup' => 'Cleanup Images',
diff --git a/resources/views/settings/categories/sorting.blade.php b/resources/views/settings/categories/sorting.blade.php
new file mode 100644 (file)
index 0000000..153ea0e
--- /dev/null
@@ -0,0 +1,49 @@
+@extends('settings.layout')
+
+@section('card')
+    <h1 id="sorting" class="list-heading">{{ trans('settings.sorting') }}</h1>
+    <form action="{{ url("/settings/sorting") }}" method="POST">
+        {{ csrf_field() }}
+        <input type="hidden" name="section" value="sorting">
+
+        <div class="setting-list">
+            <div class="grid half gap-xl items-center">
+                <div>
+                    <label for="setting-sorting-book-default"
+                           class="setting-list-label">{{ trans('settings.sorting_book_default') }}</label>
+                    <p class="small">{{ trans('settings.sorting_book_default_desc') }}</p>
+                </div>
+                <div>
+                    <select id="setting-sorting-book-default" name="setting-sorting-book-default"
+                            @if($errors->has('setting-sorting-book-default')) class="neg" @endif>
+                        <option value="0" @if(intval(setting('sorting-book-default', '0')) === 0) selected @endif>
+                            -- {{ trans('common.none') }} --
+                        </option>
+{{--                        TODO--}}
+{{--                        @foreach(\BookStack\Users\Models\Role::all() as $role)--}}
+{{--                            <option value="{{$role->id}}"--}}
+{{--                                    data-system-role-name="{{ $role->system_name ?? '' }}"--}}
+{{--                                    @if(intval(setting('registration-role', '0')) === $role->id) selected @endif--}}
+{{--                            >--}}
+{{--                                {{ $role->display_name }}--}}
+{{--                            </option>--}}
+{{--                        @endforeach--}}
+                    </select>
+                </div>
+            </div>
+
+        </div>
+
+        <div class="form-group text-right">
+            <button type="submit" class="button">{{ trans('settings.settings_save') }}</button>
+        </div>
+    </form>
+@endsection
+
+@section('after-card')
+    <div class="card content-wrap auto-height">
+        <h2 class="list-heading">{{ trans('settings.sorting_sets') }}</h2>
+        <p class="text-muted">{{ trans('settings.sorting_sets_desc') }}</p>
+{{--        TODO--}}
+    </div>
+@endsection
\ No newline at end of file
index a59b58d535c431a0bac129a811b6b1683bb4ece4..930d407a508a57992a2a3aeb88d5fde6552f50d2 100644 (file)
@@ -13,6 +13,7 @@
                     <a href="{{ url('/settings/features') }}" class="{{ $category === 'features' ? 'active' : '' }}">@icon('star') {{ trans('settings.app_features_security') }}</a>
                     <a href="{{ url('/settings/customization') }}" class="{{ $category === 'customization' ? 'active' : '' }}">@icon('palette') {{ trans('settings.app_customization') }}</a>
                     <a href="{{ url('/settings/registration') }}" class="{{ $category === 'registration' ? 'active' : '' }}">@icon('security') {{ trans('settings.reg_settings') }}</a>
+                    <a href="{{ url('/settings/sorting') }}" class="{{ $category === 'sorting' ? 'active' : '' }}">@icon('sort') {{ trans('settings.sorting') }}</a>
                 </nav>
 
                 <h5 class="mt-xl">{{ trans('settings.system_version') }}</h5>
@@ -29,6 +30,7 @@
                 <div class="card content-wrap auto-height">
                     @yield('card')
                 </div>
+                @yield('after-card')
             </div>
 
         </div>