Updated the helpdesk module
This commit is contained in:
@@ -37,15 +37,15 @@ final class SettingsManager extends Component
|
||||
/** @var array<string, mixed> */
|
||||
public array $projectForm = ['id' => null, 'company_id' => null, 'team_id' => null, 'title' => '', 'slug' => '', 'color' => 'blue', 'description' => '', 'archived_at' => null];
|
||||
|
||||
/** @var array<string, mixed> */
|
||||
public array $boardForm = ['id' => null, 'name' => '', 'slug' => '', 'description' => '', 'is_default' => false, 'sort_order' => 0, 'status_ids' => []];
|
||||
|
||||
/** @var array<string, mixed> */
|
||||
public array $repositoryForm = ['id' => null, 'company_id' => null, 'project_id' => null, 'name' => '', 'provider' => 'git', 'remote_url' => '', 'default_branch' => 'main', 'webhook_secret' => ''];
|
||||
|
||||
/** @var array<string, mixed> */
|
||||
public array $workflowForm = ['id' => null, 'name' => '', 'event' => 'ticket.created', 'subject' => '', 'html_body' => '', 'text_body' => '', 'to_role' => 'requester', 'cc' => '', 'bcc' => '', 'is_active' => true];
|
||||
|
||||
/** @var array<string, mixed> */
|
||||
public array $boardForm = ['id' => null, 'name' => '', 'slug' => '', 'description' => '', 'is_default' => false, 'sort_order' => 0, 'status_ids' => []];
|
||||
|
||||
public function saveStatus(): void
|
||||
{
|
||||
$data = $this->validate([
|
||||
@@ -211,6 +211,69 @@ final class SettingsManager extends Component
|
||||
$this->projectForm = ['id' => null, 'company_id' => null, 'team_id' => null, 'title' => '', 'slug' => '', 'color' => 'blue', 'description' => '', 'archived_at' => null];
|
||||
}
|
||||
|
||||
|
||||
public function saveBoard(): void
|
||||
{
|
||||
$data = $this->validate([
|
||||
'boardForm.name' => ['required', 'string', 'max:160'],
|
||||
'boardForm.slug' => ['nullable', 'string', 'max:180'],
|
||||
'boardForm.description' => ['nullable', 'string'],
|
||||
'boardForm.is_default' => ['boolean'],
|
||||
'boardForm.sort_order' => ['required', 'integer', 'min:0'],
|
||||
'boardForm.status_ids' => ['array'],
|
||||
'boardForm.status_ids.*' => ['integer', 'exists:helpdesk_statuses,id'],
|
||||
])['boardForm'];
|
||||
|
||||
$statusIds = collect($data['status_ids'] ?? [])->map(static fn ($id): int => (int) $id)->filter()->values();
|
||||
unset($data['status_ids']);
|
||||
|
||||
$data['slug'] = $this->slug($data['slug'] ?: $data['name']);
|
||||
|
||||
if ((bool) ($data['is_default'] ?? false)) {
|
||||
KanbanBoard::query()->whereKeyNot($this->boardForm['id'])->update(['is_default' => false]);
|
||||
}
|
||||
|
||||
$board = KanbanBoard::query()->updateOrCreate(['id' => $this->boardForm['id']], $data);
|
||||
|
||||
$sync = [];
|
||||
foreach ($statusIds as $index => $statusId) {
|
||||
$sync[$statusId] = ['sort_order' => ($index + 1) * 10];
|
||||
}
|
||||
|
||||
$board->statuses()->sync($sync);
|
||||
$this->resetBoardForm();
|
||||
$this->section = 'boards';
|
||||
session()->flash('success', 'Kanban board saved.');
|
||||
}
|
||||
|
||||
public function editBoard(int $id): void
|
||||
{
|
||||
$board = KanbanBoard::query()->with('statuses')->findOrFail($id);
|
||||
|
||||
$this->boardForm = [
|
||||
'id' => $board->id,
|
||||
'name' => $board->name,
|
||||
'slug' => $board->slug,
|
||||
'description' => $board->description,
|
||||
'is_default' => $board->is_default,
|
||||
'sort_order' => $board->sort_order,
|
||||
'status_ids' => $board->statuses->pluck('id')->map(static fn ($id): int => (int) $id)->all(),
|
||||
];
|
||||
|
||||
$this->section = 'boards';
|
||||
}
|
||||
|
||||
public function deleteBoard(int $id): void
|
||||
{
|
||||
KanbanBoard::query()->findOrFail($id)->delete();
|
||||
session()->flash('success', 'Kanban board deleted.');
|
||||
}
|
||||
|
||||
public function resetBoardForm(): void
|
||||
{
|
||||
$this->boardForm = ['id' => null, 'name' => '', 'slug' => '', 'description' => '', 'is_default' => false, 'sort_order' => 0, 'status_ids' => []];
|
||||
}
|
||||
|
||||
public function saveRepository(): void
|
||||
{
|
||||
$data = $this->validate([
|
||||
@@ -245,65 +308,6 @@ final class SettingsManager extends Component
|
||||
$this->repositoryForm = ['id' => null, 'company_id' => null, 'project_id' => null, 'name' => '', 'provider' => 'git', 'remote_url' => '', 'default_branch' => 'main', 'webhook_secret' => ''];
|
||||
}
|
||||
|
||||
|
||||
public function saveBoard(): void
|
||||
{
|
||||
$data = $this->validate([
|
||||
'boardForm.name' => ['required', 'string', 'max:160'],
|
||||
'boardForm.slug' => ['nullable', 'string', 'max:180'],
|
||||
'boardForm.description' => ['nullable', 'string'],
|
||||
'boardForm.is_default' => ['boolean'],
|
||||
'boardForm.sort_order' => ['required', 'integer', 'min:0'],
|
||||
'boardForm.status_ids' => ['required', 'array', 'min:1'],
|
||||
'boardForm.status_ids.*' => ['integer', 'exists:helpdesk_statuses,id'],
|
||||
])['boardForm'];
|
||||
|
||||
$statusIds = collect($data['status_ids'])
|
||||
->map(static fn (mixed $id): int => (int) $id)
|
||||
->filter()
|
||||
->unique()
|
||||
->values();
|
||||
|
||||
unset($data['status_ids']);
|
||||
$data['slug'] = $this->slug($data['slug'] ?: $data['name']);
|
||||
|
||||
if ((bool) $data['is_default']) {
|
||||
KanbanBoard::query()->where('is_default', true)->update(['is_default' => false]);
|
||||
}
|
||||
|
||||
$board = KanbanBoard::query()->updateOrCreate(['id' => $this->boardForm['id']], $data);
|
||||
|
||||
$sync = [];
|
||||
foreach ($statusIds as $index => $statusId) {
|
||||
$sync[$statusId] = ['sort_order' => ($index + 1) * 10];
|
||||
}
|
||||
|
||||
$board->statuses()->sync($sync);
|
||||
$this->resetBoardForm();
|
||||
$this->section = 'boards';
|
||||
session()->flash('success', 'Kanban board saved.');
|
||||
}
|
||||
|
||||
public function editBoard(int $id): void
|
||||
{
|
||||
$board = KanbanBoard::query()->with('statuses')->findOrFail($id);
|
||||
|
||||
$this->boardForm = $board->only(['id', 'name', 'slug', 'description', 'is_default', 'sort_order']);
|
||||
$this->boardForm['status_ids'] = $board->statuses->pluck('id')->map(static fn (mixed $id): int => (int) $id)->all();
|
||||
$this->section = 'boards';
|
||||
}
|
||||
|
||||
public function deleteBoard(int $id): void
|
||||
{
|
||||
KanbanBoard::query()->findOrFail($id)->delete();
|
||||
session()->flash('success', 'Kanban board deleted.');
|
||||
}
|
||||
|
||||
public function resetBoardForm(): void
|
||||
{
|
||||
$this->boardForm = ['id' => null, 'name' => '', 'slug' => '', 'description' => '', 'is_default' => false, 'sort_order' => 0, 'status_ids' => []];
|
||||
}
|
||||
|
||||
public function saveWorkflowTemplate(): void
|
||||
{
|
||||
$data = $this->validate([
|
||||
@@ -349,8 +353,8 @@ final class SettingsManager extends Component
|
||||
'categories' => Category::query()->withCount('tickets')->orderBy('name')->get(),
|
||||
'teams' => Team::query()->withCount(['projects', 'tickets'])->orderBy('name')->get(),
|
||||
'projects' => Project::query()->with(['team'])->withCount('tickets')->orderBy('title')->get(),
|
||||
'boards' => KanbanBoard::query()->with('statuses')->orderBy('sort_order')->orderBy('name')->get(),
|
||||
'repositories' => GitRepository::query()->with(['project'])->withCount('commits')->orderBy('name')->get(),
|
||||
'boards' => KanbanBoard::query()->with('statuses')->withCount('statuses')->orderBy('sort_order')->orderBy('name')->get(),
|
||||
'workflowTemplates' => WorkflowTemplate::query()->orderBy('event')->orderBy('name')->get(),
|
||||
])->layout('layouts.app');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user