mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-08-07 23:03:00 +03:00
Started interface user shortcut form interface
Built controller actions and initual UI. Still needs JS logic for shortcut input handling.
This commit is contained in:
@@ -26,6 +26,8 @@ return [
|
||||
|
||||
// User-level default settings
|
||||
'user' => [
|
||||
'ui-shortcuts' => '{}',
|
||||
'ui-shortcuts-enabled' => false,
|
||||
'dark-mode-enabled' => env('APP_DEFAULT_DARK_MODE', false),
|
||||
'bookshelves_view_type' => env('APP_VIEWS_BOOKSHELVES', 'grid'),
|
||||
'bookshelf_view_type' => env('APP_VIEWS_BOOKSHELF', 'grid'),
|
||||
|
@@ -3,6 +3,7 @@
|
||||
namespace BookStack\Http\Controllers;
|
||||
|
||||
use BookStack\Auth\UserRepo;
|
||||
use BookStack\Settings\UserShortcutMap;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class UserPreferencesController extends Controller
|
||||
@@ -14,6 +15,37 @@ class UserPreferencesController extends Controller
|
||||
$this->userRepo = $userRepo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the user-specific interface shortcuts.
|
||||
*/
|
||||
public function showShortcuts()
|
||||
{
|
||||
$shortcuts = UserShortcutMap::fromUserPreferences();
|
||||
$enabled = setting()->getForCurrentUser('ui-shortcuts-enabled', false);
|
||||
|
||||
return view('users.preferences.shortcuts', [
|
||||
'shortcuts' => $shortcuts,
|
||||
'enabled' => $enabled,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the user-specific interface shortcuts.
|
||||
*/
|
||||
public function updateShortcuts(Request $request)
|
||||
{
|
||||
$enabled = $request->get('enabled') === 'true';
|
||||
$providedShortcuts = $request->get('shortcuts', []);
|
||||
$shortcuts = new UserShortcutMap($providedShortcuts);
|
||||
|
||||
setting()->putUser(user(), 'ui-shortcuts', $shortcuts->toJson());
|
||||
setting()->putUser(user(), 'ui-shortcuts-enabled', $enabled);
|
||||
|
||||
$this->showSuccessNotification('Shortcuts preferences have been updated!');
|
||||
|
||||
return redirect('/preferences/shortcuts');
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the user's preferred book-list display setting.
|
||||
*/
|
||||
|
82
app/Settings/UserShortcutMap.php
Normal file
82
app/Settings/UserShortcutMap.php
Normal file
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace BookStack\Settings;
|
||||
|
||||
class UserShortcutMap
|
||||
{
|
||||
protected const DEFAULTS = [
|
||||
// Header actions
|
||||
"home_view" => "1",
|
||||
"shelves_view" => "2",
|
||||
"books_view" => "3",
|
||||
"settings_view" => "4",
|
||||
"favourites_view" => "5",
|
||||
"profile_view" => "6",
|
||||
"global_search" => "/",
|
||||
"logout" => "0",
|
||||
|
||||
// Common actions
|
||||
"edit" => "e",
|
||||
"new" => "n",
|
||||
"copy" => "c",
|
||||
"delete" => "d",
|
||||
"favourite" => "f",
|
||||
"export" => "x",
|
||||
"sort" => "s",
|
||||
"permissions" => "p",
|
||||
"move" => "m",
|
||||
"revisions" => "r",
|
||||
|
||||
// Navigation
|
||||
"next" => "ArrowRight",
|
||||
"previous" => "ArrowLeft",
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected array $mapping;
|
||||
|
||||
public function __construct(array $map)
|
||||
{
|
||||
$this->mapping = static::DEFAULTS;
|
||||
$this->merge($map);
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge the given map into the current shortcut mapping.
|
||||
*/
|
||||
protected function merge(array $map): void
|
||||
{
|
||||
foreach ($map as $key => $value) {
|
||||
if (is_string($value) && isset($this->mapping[$key])) {
|
||||
$this->mapping[$key] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the shortcut defined for the given ID.
|
||||
*/
|
||||
public function getShortcut(string $id): string
|
||||
{
|
||||
return $this->mapping[$id] ?? '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert this mapping to JSON.
|
||||
*/
|
||||
public function toJson(): string
|
||||
{
|
||||
return json_encode($this->mapping);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance from the current user's preferences.
|
||||
*/
|
||||
public static function fromUserPreferences(): self
|
||||
{
|
||||
$userKeyMap = setting()->getForCurrentUser('ui-shortcuts');
|
||||
return new self(json_decode($userKeyMap, true) ?: []);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user