first&last
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\System;
|
||||
|
||||
use App\Exports\CsvExport;
|
||||
use App\Models\ActivityLog;
|
||||
use App\Models\User;
|
||||
use Livewire\Attributes\Layout;
|
||||
use Livewire\Component;
|
||||
use Livewire\WithPagination;
|
||||
|
||||
#[Layout('layouts.app')]
|
||||
class ActivityLogPage extends Component
|
||||
{
|
||||
use WithPagination;
|
||||
|
||||
public string $userId = '';
|
||||
|
||||
public string $action = '';
|
||||
|
||||
public string $dateFrom = '';
|
||||
|
||||
public string $dateTo = '';
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
abort_unless(auth()->user()->isAdmin(), 403);
|
||||
}
|
||||
|
||||
public function exportCsv()
|
||||
{
|
||||
$rows = $this->query()->get()->map(fn (ActivityLog $log) => [
|
||||
$log->user?->name,
|
||||
$log->action,
|
||||
class_basename($log->model_type),
|
||||
$log->description,
|
||||
$log->ip_address,
|
||||
$log->created_at?->format('d.m.Y H:i:s'),
|
||||
])->toArray();
|
||||
|
||||
return CsvExport::download('activity-log.csv', ['Пользователь', 'Действие', 'Сущность', 'Описание', 'IP', 'Дата'], $rows);
|
||||
}
|
||||
|
||||
private function query()
|
||||
{
|
||||
return ActivityLog::query()
|
||||
->with('user')
|
||||
->when($this->userId !== '', fn ($q) => $q->where('user_id', $this->userId))
|
||||
->when($this->action !== '', fn ($q) => $q->where('action', 'like', "%{$this->action}%"))
|
||||
->when($this->dateFrom !== '', fn ($q) => $q->whereDate('created_at', '>=', $this->dateFrom))
|
||||
->when($this->dateTo !== '', fn ($q) => $q->whereDate('created_at', '<=', $this->dateTo))
|
||||
->latest('created_at');
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.system.activity-log-page', [
|
||||
'logs' => $this->query()->paginate(20),
|
||||
'users' => User::query()->orderBy('name')->get(),
|
||||
])->title('Журнал действий');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\System;
|
||||
|
||||
use App\Services\SettingsService;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Livewire\Attributes\Layout;
|
||||
use Livewire\Component;
|
||||
|
||||
#[Layout('layouts.app')]
|
||||
class SettingsPage extends Component
|
||||
{
|
||||
public string $companyName = '';
|
||||
|
||||
public string $timezone = 'Asia/Yekaterinburg';
|
||||
|
||||
public int $defaultSlaHours = 24;
|
||||
|
||||
public bool $maintenanceMode = false;
|
||||
|
||||
public bool $notifyAssigned = true;
|
||||
|
||||
public bool $notifyStatusChanged = true;
|
||||
|
||||
public bool $notifyCommentAdded = true;
|
||||
|
||||
public bool $notifyOverdue = true;
|
||||
|
||||
public bool $notifySlaWarning = true;
|
||||
|
||||
/**
|
||||
* @var array<string, string>
|
||||
*/
|
||||
public array $russianTimezones = [
|
||||
'Europe/Kaliningrad' => 'Калининград (UTC+2)',
|
||||
'Europe/Moscow' => 'Москва (UTC+3)',
|
||||
'Europe/Samara' => 'Самара (UTC+4)',
|
||||
'Asia/Yekaterinburg' => 'Екатеринбург (UTC+5)',
|
||||
'Asia/Omsk' => 'Омск (UTC+6)',
|
||||
'Asia/Krasnoyarsk' => 'Красноярск (UTC+7)',
|
||||
'Asia/Irkutsk' => 'Иркутск (UTC+8)',
|
||||
'Asia/Yakutsk' => 'Якутск (UTC+9)',
|
||||
'Asia/Vladivostok' => 'Владивосток (UTC+10)',
|
||||
'Asia/Magadan' => 'Магадан (UTC+11)',
|
||||
'Asia/Sakhalin' => 'Сахалин (UTC+11)',
|
||||
'Asia/Kamchatka' => 'Камчатка (UTC+12)',
|
||||
];
|
||||
|
||||
public function mount(SettingsService $settingsService): void
|
||||
{
|
||||
abort_unless(auth()->user()->isAdmin(), 403);
|
||||
|
||||
$this->companyName = (string) $settingsService->get('company_name', 'Computer Service');
|
||||
$this->timezone = (string) $settingsService->get('timezone', 'Asia/Yekaterinburg');
|
||||
$this->defaultSlaHours = (int) $settingsService->get('default_sla_hours', 24);
|
||||
$this->maintenanceMode = (bool) $settingsService->get('maintenance_mode', false);
|
||||
$notifications = $settingsService->emailNotifications();
|
||||
$this->notifyAssigned = (bool) ($notifications['assigned'] ?? true);
|
||||
$this->notifyStatusChanged = (bool) ($notifications['status_changed'] ?? true);
|
||||
$this->notifyCommentAdded = (bool) ($notifications['comment_added'] ?? true);
|
||||
$this->notifyOverdue = (bool) ($notifications['overdue'] ?? true);
|
||||
$this->notifySlaWarning = (bool) ($notifications['sla_warning'] ?? true);
|
||||
}
|
||||
|
||||
public function save(SettingsService $settingsService): void
|
||||
{
|
||||
$this->validate([
|
||||
'companyName' => ['required', 'string', 'max:255'],
|
||||
'timezone' => ['required', Rule::in(array_keys($this->russianTimezones))],
|
||||
'defaultSlaHours' => ['required', 'integer', 'min:1', 'max:720'],
|
||||
'maintenanceMode' => ['boolean'],
|
||||
'notifyAssigned' => ['boolean'],
|
||||
'notifyStatusChanged' => ['boolean'],
|
||||
'notifyCommentAdded' => ['boolean'],
|
||||
'notifyOverdue' => ['boolean'],
|
||||
'notifySlaWarning' => ['boolean'],
|
||||
]);
|
||||
|
||||
$settingsService->set('company_name', $this->companyName, 'string');
|
||||
$settingsService->set('timezone', $this->timezone, 'string');
|
||||
$settingsService->set('default_sla_hours', $this->defaultSlaHours, 'integer');
|
||||
$settingsService->set('maintenance_mode', $this->maintenanceMode, 'boolean');
|
||||
|
||||
$settingsService->set('email_notifications', [
|
||||
'assigned' => $this->notifyAssigned,
|
||||
'status_changed' => $this->notifyStatusChanged,
|
||||
'comment_added' => $this->notifyCommentAdded,
|
||||
'overdue' => $this->notifyOverdue,
|
||||
'sla_warning' => $this->notifySlaWarning,
|
||||
], 'json');
|
||||
|
||||
session()->flash('success', 'Настройки сохранены.');
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.system.settings-page')->title('Системные настройки');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user