51 lines
1.1 KiB
PHP
51 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire;
|
|
|
|
use Livewire\Component;
|
|
use App\Models\Project;
|
|
use App\Models\Folder;
|
|
use App\Models\Document;
|
|
|
|
class ProjectShow extends Component
|
|
{
|
|
|
|
public Project $project;
|
|
public $selectedFolderId = null;
|
|
public $expandedFolders = [];
|
|
|
|
public function mount(Project $project)
|
|
{
|
|
$this->project = $project->load('rootFolders');
|
|
}
|
|
|
|
public function selectFolder($folderId)
|
|
{
|
|
$this->selectedFolderId = $folderId;
|
|
}
|
|
|
|
public function toggleFolder($folderId)
|
|
{
|
|
if (in_array($folderId, $this->expandedFolders)) {
|
|
$this->expandedFolders = array_diff($this->expandedFolders, [$folderId]);
|
|
} else {
|
|
$this->expandedFolders[] = $folderId;
|
|
}
|
|
}
|
|
|
|
public function getDocumentsProperty()
|
|
{
|
|
return Document::where('folder_id', $this->selectedFolderId)
|
|
->where('project_id', $this->project->id)
|
|
->with('versions')
|
|
->get();
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.project-show', [
|
|
'rootFolders' => $this->project->rootFolders
|
|
]);
|
|
}
|
|
}
|