first commit
This commit is contained in:
50
app/Livewire/ProjectShow.php
Normal file
50
app/Livewire/ProjectShow.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?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
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user