143 lines
5.1 KiB
PHP
143 lines
5.1 KiB
PHP
<?php
|
|||
|
|
|
||
|
|
use App\Models\User;
|
||
|
|
use Flux\Flux;
|
||
|
|
use Illuminate\Support\Collection;
|
||
|
|
use Livewire\Attributes\Computed;
|
||
|
|
use Livewire\Attributes\Locked;
|
||
|
|
use Livewire\Attributes\Title;
|
||
|
|
use Livewire\Component;
|
||
|
|
|
||
|
|
new #[Title('Notes limits')] class extends Component
|
||
|
|
{
|
||
|
|
public function mount(): void
|
||
|
|
{
|
||
|
|
if (! auth()->user()->isAdmin()) {
|
||
|
|
abort(403);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
#[Locked]
|
||
|
|
public ?int $editingUserId = null;
|
||
|
|
|
||
|
|
public bool $showLimitForm = false;
|
||
|
|
|
||
|
|
public string $notesLimitInput = '';
|
||
|
|
|
||
|
|
#[Computed]
|
||
|
|
public function users(): Collection
|
||
|
|
{
|
||
|
|
return User::query()
|
||
|
|
->orderBy('name')
|
||
|
|
->get();
|
||
|
|
}
|
||
|
|
|
||
|
|
public function startEditLimit(int $userId): void
|
||
|
|
{
|
||
|
|
$user = $this->userById($userId);
|
||
|
|
|
||
|
|
$this->editingUserId = $user->id;
|
||
|
|
$this->notesLimitInput = (string) $user->notesLimit();
|
||
|
|
$this->resetErrorBag('notesLimitInput');
|
||
|
|
$this->showLimitForm = true;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function saveNotesLimit(): void
|
||
|
|
{
|
||
|
|
$user = $this->userById($this->editingUserId);
|
||
|
|
|
||
|
|
$validated = $this->validate([
|
||
|
|
'notesLimitInput' => ['required', 'integer', 'min:1', 'max:1000000'],
|
||
|
|
]);
|
||
|
|
|
||
|
|
$user->update(['notes_limit' => (int) $validated['notesLimitInput']]);
|
||
|
|
|
||
|
|
$this->reset('showLimitForm', 'editingUserId', 'notesLimitInput');
|
||
|
|
|
||
|
|
Flux::toast(variant: 'success', text: __('Notes limit updated.'));
|
||
|
|
}
|
||
|
|
|
||
|
|
private function userById(int $userId): User
|
||
|
|
{
|
||
|
|
return User::query()->findOrFail($userId);
|
||
|
|
}
|
||
|
|
}; ?>
|
||
|
|
|
||
|
|
<div class="flex h-full w-full flex-1 flex-col gap-6">
|
||
|
|
<div>
|
||
|
|
<flux:heading size="xl">{{ __('Notes limits') }}</flux:heading>
|
||
|
|
<flux:text class="mt-1">{{ __('Set how many characters each user may write in todo notes.') }}</flux:text>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<flux:card>
|
||
|
|
<flux:table>
|
||
|
|
<flux:table.columns>
|
||
|
|
<flux:table.column>{{ __('Name') }}</flux:table.column>
|
||
|
|
<flux:table.column>{{ __('Email') }}</flux:table.column>
|
||
|
|
<flux:table.column>{{ __('Role') }}</flux:table.column>
|
||
|
|
<flux:table.column>{{ __('Notes limit') }}</flux:table.column>
|
||
|
|
<flux:table.column align="end" width="5rem">{{ __('Actions') }}</flux:table.column>
|
||
|
|
</flux:table.columns>
|
||
|
|
|
||
|
|
<flux:table.rows>
|
||
|
|
@foreach ($this->users as $user)
|
||
|
|
<flux:table.row :key="$user->id" data-test="user-row-{{ $user->id }}">
|
||
|
|
<flux:table.cell>{{ $user->name }}</flux:table.cell>
|
||
|
|
<flux:table.cell class="text-zinc-500">{{ $user->email }}</flux:table.cell>
|
||
|
|
<flux:table.cell>
|
||
|
|
@if ($user->isAdmin())
|
||
|
|
<flux:badge size="sm" color="blue">{{ __('Admin') }}</flux:badge>
|
||
|
|
@else
|
||
|
|
<flux:badge size="sm" color="zinc">{{ __('Member') }}</flux:badge>
|
||
|
|
@endif
|
||
|
|
</flux:table.cell>
|
||
|
|
<flux:table.cell data-test="notes-limit-{{ $user->id }}">
|
||
|
|
{{ $user->notesLimit() }} {{ __('characters') }}
|
||
|
|
</flux:table.cell>
|
||
|
|
<flux:table.cell class="py-0">
|
||
|
|
<div class="flex justify-end gap-1">
|
||
|
|
<flux:button
|
||
|
|
size="sm"
|
||
|
|
variant="ghost"
|
||
|
|
icon="pencil-square"
|
||
|
|
:title="__('Edit notes limit')"
|
||
|
|
wire:click="startEditLimit({{ $user->id }})"
|
||
|
|
data-test="edit-notes-limit-{{ $user->id }}"
|
||
|
|
/>
|
||
|
|
</div>
|
||
|
|
</flux:table.cell>
|
||
|
|
</flux:table.row>
|
||
|
|
@endforeach
|
||
|
|
</flux:table.rows>
|
||
|
|
</flux:table>
|
||
|
|
</flux:card>
|
||
|
|
|
||
|
|
<flux:modal wire:model.self="showLimitForm" class="md:w-lg">
|
||
|
|
<form wire:submit="saveNotesLimit" class="space-y-6">
|
||
|
|
<div>
|
||
|
|
<flux:heading size="lg">{{ __('Edit notes limit') }}</flux:heading>
|
||
|
|
<flux:text class="mt-2">{{ __('Enter the maximum number of characters allowed in todo notes.') }}</flux:text>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<flux:field>
|
||
|
|
<flux:label>{{ __('Notes limit (characters)') }}</flux:label>
|
||
|
|
<flux:input
|
||
|
|
wire:model="notesLimitInput"
|
||
|
|
type="number"
|
||
|
|
min="1"
|
||
|
|
max="1000000"
|
||
|
|
inputmode="numeric"
|
||
|
|
data-test="notes-limit-input"
|
||
|
|
/>
|
||
|
|
<flux:error name="notesLimitInput" />
|
||
|
|
</flux:field>
|
||
|
|
|
||
|
|
<div class="flex justify-end gap-3">
|
||
|
|
<flux:modal.close>
|
||
|
|
<flux:button variant="ghost">{{ __('Cancel') }}</flux:button>
|
||
|
|
</flux:modal.close>
|
||
|
|
<flux:button type="submit" variant="primary">{{ __('Save') }}</flux:button>
|
||
|
|
</div>
|
||
|
|
</form>
|
||
|
|
</flux:modal>
|
||
|
|
</div>
|