Aded documentation module

This commit is contained in:
Mark Gregory
2026-06-12 15:32:09 +01:00
parent a2c68bc4dc
commit 1c9ed1a537
18 changed files with 418 additions and 85 deletions
+5 -1
View File
@@ -62,7 +62,11 @@ final class KanbanBoard extends Component
->get();
$board = $boards->firstWhere('id', $this->board_id) ?? $boards->first();
$statuses = $board?->statuses ?? Status::query()->orderBy('sort_order')->orderBy('name')->get();
$statuses = $board?->statuses ?? collect();
if ($statuses->isEmpty()) {
$statuses = Status::query()->orderBy('sort_order')->orderBy('name')->get();
}
return view('helpdesk::livewire.kanban-board', [
'boards' => $boards,
@@ -11,6 +11,7 @@ use Illuminate\Support\Str;
use Livewire\Component;
use Modules\Helpdesk\Models\Category;
use Modules\Helpdesk\Models\GitRepository;
use Modules\Helpdesk\Models\KanbanBoard;
use Modules\Helpdesk\Models\Priority;
use Modules\Helpdesk\Models\Project;
use Modules\Helpdesk\Models\Status;
@@ -42,6 +43,9 @@ final class SettingsManager extends Component
/** @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([
@@ -241,6 +245,65 @@ 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([
@@ -287,6 +350,7 @@ final class SettingsManager extends Component
'teams' => Team::query()->withCount(['projects', 'tickets'])->orderBy('name')->get(),
'projects' => Project::query()->with(['team'])->withCount('tickets')->orderBy('title')->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');
}
+17 -23
View File
@@ -73,6 +73,7 @@ final class TicketShow extends Component
$this->reset(['commentBody', 'internal', 'attachments']);
$this->ticket = $this->freshTicket($this->ticket);
$this->dispatch('helpdesk-editor-reset', model: 'commentBody');
$this->dispatch('helpdesk-comment-added');
}
@@ -87,8 +88,9 @@ final class TicketShow extends Component
$tickets->comment($this->ticket, Auth::user(), $this->replyBody, $this->internal, [], $this->reply_parent_id);
$this->cancelReply();
$this->reset(['reply_parent_id', 'replyBody']);
$this->ticket = $this->freshTicket($this->ticket);
$this->dispatch('helpdesk-editor-reset', model: 'replyBody');
$this->dispatch('helpdesk-reply-added');
}
@@ -144,39 +146,31 @@ final class TicketShow extends Component
'team',
'attachments.user',
'gitCommits.repository',
'comments.attachments',
'comments.replies.attachments',
'comments.replies.replies.attachments',
]) ?? $ticket;
$comments = $ticket->comments
->merge($ticket->comments->flatMap->replies)
->merge($ticket->comments->flatMap->replies->flatMap->replies);
$comments = \Modules\Helpdesk\Models\Comment::query()
->where('ticket_id', $ticket->id)
->with(['user', 'attachments.user'])
->oldest()
->get();
$users = User::query()
->whereIn('id', $comments->pluck('user_id')->filter()->unique())
->get()
->keyBy('id');
$this->attachCommentUsers($ticket->comments, $users);
$ticket->setRelation('comments', $this->buildCommentTree($comments->groupBy('parent_id')));
return $ticket;
}
/**
* Attach loaded users to comment hierarchy without triggering lazy loading.
* Build an unlimited nested comment tree from a flat eager-loaded collection.
*
* @param Collection<int, mixed> $comments
* @param Collection<int, User> $users
* @param Collection<int|string, Collection<int, mixed>> $grouped
* @return Collection<int, mixed>
*/
private function attachCommentUsers(Collection $comments, Collection $users): void
private function buildCommentTree(Collection $grouped, ?int $parentId = null): Collection
{
foreach ($comments as $comment) {
$comment->setRelation('user', $users->get($comment->user_id));
return $grouped->get($parentId, collect())->map(function ($comment) use ($grouped) {
$comment->setRelation('replies', $this->buildCommentTree($grouped, (int) $comment->id));
if ($comment->relationLoaded('replies')) {
$this->attachCommentUsers($comment->replies, $users);
}
}
return $comment;
})->values();
}
}