2023-10-04 07:58:39 +00:00
< ? php
2023-12-07 18:06:32 +00:00
namespace App\Livewire\Project\Service ;
2023-10-04 07:58:39 +00:00
use App\Models\LocalPersistentVolume ;
use Livewire\Component ;
class Storage extends Component
{
public $resource ;
2024-06-10 20:43:34 +00:00
2024-08-05 18:00:57 +00:00
public $fileStorage ;
2024-04-15 17:47:17 +00:00
public function getListeners ()
2023-10-04 07:58:39 +00:00
{
2024-08-05 18:00:57 +00:00
$teamId = auth () -> user () -> currentTeam () -> id ;
2024-04-15 17:47:17 +00:00
return [
2024-08-05 18:00:57 +00:00
" echo-private:team. { $teamId } ,FileStorageChanged " => 'refreshStoragesFromEvent' ,
2024-08-05 18:07:08 +00:00
'refreshStorages' ,
2024-04-15 17:47:17 +00:00
'addNewVolume' ,
];
2023-10-04 07:58:39 +00:00
}
2024-06-10 20:43:34 +00:00
2024-08-05 18:00:57 +00:00
public function mount ()
{
$this -> refreshStorages ();
}
public function refreshStoragesFromEvent ()
{
$this -> refreshStorages ();
$this -> dispatch ( 'warning' , 'File storage changed. Usually it means that the file / directory is already defined on the server, so Coolify set it up for you properly on the UI.' );
}
public function refreshStorages ()
{
$this -> fileStorage = $this -> resource -> fileStorages () -> get ();
2024-08-05 18:07:08 +00:00
$this -> dispatch ( '$refresh' );
2024-08-05 18:00:57 +00:00
}
2023-10-04 07:58:39 +00:00
public function addNewVolume ( $data )
{
try {
LocalPersistentVolume :: create ([
'name' => $data [ 'name' ],
'mount_path' => $data [ 'mount_path' ],
'host_path' => $data [ 'host_path' ],
'resource_id' => $this -> resource -> id ,
'resource_type' => $this -> resource -> getMorphClass (),
]);
$this -> resource -> refresh ();
2023-12-07 18:06:32 +00:00
$this -> dispatch ( 'success' , 'Storage added successfully' );
$this -> dispatch ( 'clearAddStorage' );
2024-08-05 18:00:57 +00:00
$this -> dispatch ( 'refreshStorages' );
2023-10-04 07:58:39 +00:00
} catch ( \Throwable $e ) {
return handleError ( $e , $this );
}
}
2024-06-10 20:43:34 +00:00
2024-04-15 17:47:17 +00:00
public function render ()
{
return view ( 'livewire.project.service.storage' );
}
2023-10-04 07:58:39 +00:00
}