-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
63 changed files
with
3,018 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace App\Enum; | ||
|
||
enum ServerStatusEnum: string | ||
{ | ||
// provisioning, active, deprovisioning, deleted | ||
case PROVISIONING = 'provisioning'; | ||
case ACTIVE = 'active'; | ||
case DEPROVISIONING = 'deprovisioning'; | ||
case DELETED = 'deleted'; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace App\Enum; | ||
|
||
enum StreamStatusEnum: string | ||
{ | ||
case STARTING_SOON = 'starting_soon'; | ||
case PROVISIONING = 'provisioning'; | ||
case ONLINE = 'online'; | ||
case OFFLINE = 'offline'; | ||
case TECHNICAL_ISSUE = 'technical_issue'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace App\Events; | ||
|
||
use App\Models\User; | ||
use Illuminate\Broadcasting\InteractsWithSockets; | ||
use Illuminate\Broadcasting\PrivateChannel; | ||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast; | ||
use Illuminate\Foundation\Events\Dispatchable; | ||
use Illuminate\Queue\SerializesModels; | ||
|
||
class ServerAssignedEvent implements ShouldBroadcast | ||
{ | ||
use Dispatchable, InteractsWithSockets, SerializesModels; | ||
|
||
public function __construct(public readonly User $user) | ||
{ | ||
} | ||
|
||
public function broadcastOn(): array | ||
{ | ||
return [ | ||
new PrivateChannel('User.'.$this->user->id.'.StreamUrl') | ||
]; | ||
} | ||
|
||
public function broadcastWith() | ||
{ | ||
return ['streamUrls' => $this->user->getUserStreamUrls()]; | ||
} | ||
|
||
public function broadcastAs(): string | ||
{ | ||
return 'stream.url.changed'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace App\Events; | ||
|
||
use Illuminate\Broadcasting\Channel; | ||
use Illuminate\Broadcasting\InteractsWithSockets; | ||
use Illuminate\Broadcasting\PresenceChannel; | ||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Foundation\Events\Dispatchable; | ||
use Illuminate\Queue\SerializesModels; | ||
|
||
class StreamListenerChangeEvent implements ShouldBroadcast | ||
{ | ||
use Dispatchable, InteractsWithSockets, SerializesModels; | ||
|
||
public function __construct(public readonly int $listeners) | ||
{ | ||
} | ||
|
||
public function broadcastOn(): array | ||
{ | ||
return [ | ||
new Channel('StreamInfo') | ||
]; | ||
} | ||
|
||
public function broadcastAs(): string | ||
{ | ||
return 'stream.listeners.changed'; | ||
} | ||
|
||
public function broadcastWith() | ||
{ | ||
return ['listeners' => $this->listeners]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace App\Events; | ||
|
||
use App\Enum\StreamStatusEnum; | ||
use Illuminate\Broadcasting\Channel; | ||
use Illuminate\Broadcasting\InteractsWithSockets; | ||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast; | ||
use Illuminate\Foundation\Events\Dispatchable; | ||
use Illuminate\Queue\SerializesModels; | ||
|
||
class StreamStatusEvent implements ShouldBroadcast | ||
{ | ||
use Dispatchable, InteractsWithSockets, SerializesModels; | ||
|
||
public function __construct(public readonly StreamStatusEnum $status) | ||
{ | ||
} | ||
|
||
public function broadcastOn(): array | ||
{ | ||
return [ | ||
new Channel('StreamInfo'), | ||
]; | ||
} | ||
|
||
public function broadcastAs(): string | ||
{ | ||
return 'stream.status.changed'; | ||
} | ||
|
||
public function broadcastWith(): array | ||
{ | ||
return ['status' => $this->status->value]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace App\Events; | ||
|
||
use App\Models\User; | ||
use Illuminate\Foundation\Events\Dispatchable; | ||
|
||
class UserWaitingForProvisioningEvent | ||
{ | ||
use Dispatchable; | ||
|
||
public function __construct(public readonly User $user) | ||
{ | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace App\Filament\Pages; | ||
|
||
use App\Enum\StreamStatusEnum; | ||
use App\Events\StreamStatusEvent; | ||
use App\Filament\Widgets\Capacity; | ||
use App\Filament\Widgets\ServerActive; | ||
use App\Filament\Widgets\ServerUserActive; | ||
use Filament\Pages\Actions\Action; | ||
use Filament\Pages\Actions\ActionGroup; | ||
use Filament\Pages\Page; | ||
use Illuminate\Support\Facades\Event; | ||
|
||
class Stream extends Page | ||
{ | ||
protected static ?string $navigationIcon = 'heroicon-o-cog'; | ||
|
||
protected static ?int $navigationSort = 99; | ||
|
||
protected static ?string $navigationGroup = "Mission Control Center"; | ||
protected static ?string $navigationLabel = "Stream Settings"; | ||
|
||
protected static string $view = 'filament.pages.stream'; | ||
|
||
protected function getActions(): array | ||
{ | ||
return [ | ||
Action::make('set_offline')->action(fn() => event(new StreamStatusEvent(StreamStatusEnum::OFFLINE)))->label('Set Stream Offline')->requiresConfirmation(), | ||
Action::make('set_online')->action(fn() => event(new StreamStatusEvent(StreamStatusEnum::ONLINE)))->label('Set Stream Online')->requiresConfirmation(), | ||
Action::make('set_issue')->action(fn() => event(new StreamStatusEvent(StreamStatusEnum::TECHNICAL_ISSUE)))->label('Set Stream Technical Issue')->requiresConfirmation(), | ||
Action::make('set_pending')->action(fn() => event(new StreamStatusEvent(StreamStatusEnum::STARTING_SOON)))->label('Set Stream Starting Soon')->requiresConfirmation(), | ||
]; | ||
} | ||
|
||
protected function getHeaderWidgets(): array | ||
{ | ||
return [ | ||
ServerUserActive::class, | ||
ServerActive::class, | ||
Capacity::class | ||
]; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
|
||
namespace App\Filament\Resources; | ||
|
||
use App\Filament\Resources\ServerResource\Pages; | ||
use App\Filament\Resources\ServerResource\RelationManagers\UserRelationManager; | ||
use App\Models\Server; | ||
use Filament\Forms\Components\Placeholder; | ||
use Filament\Forms\Components\TextInput; | ||
use Filament\Resources\Form; | ||
use Filament\Resources\Resource; | ||
use Filament\Resources\Table; | ||
use Filament\Tables\Columns\TextColumn; | ||
|
||
class ServerResource extends Resource | ||
{ | ||
protected static ?string $model = Server::class; | ||
|
||
protected static ?string $slug = 'servers'; | ||
|
||
protected static ?string $recordTitleAttribute = 'id'; | ||
|
||
public static function form(Form $form): Form | ||
{ | ||
return $form | ||
->schema([ | ||
TextInput::make('hetzner_id') | ||
->required(), | ||
|
||
TextInput::make('cloudflare_id') | ||
->required(), | ||
|
||
TextInput::make('hostname') | ||
->required(), | ||
|
||
TextInput::make('ip') | ||
->required(), | ||
|
||
TextInput::make('status') | ||
->required(), | ||
|
||
Placeholder::make('created_at') | ||
->label('Created Date') | ||
->content(fn(?Server $record): string => $record?->created_at?->diffForHumans() ?? '-'), | ||
|
||
Placeholder::make('updated_at') | ||
->label('Last Modified Date') | ||
->content(fn(?Server $record): string => $record?->updated_at?->diffForHumans() ?? '-'), | ||
]); | ||
} | ||
|
||
public static function table(Table $table): Table | ||
{ | ||
return $table | ||
->columns([ | ||
TextColumn::make('hetzner_id'), | ||
|
||
TextColumn::make('cloudflare_id'), | ||
|
||
TextColumn::make('hostname'), | ||
|
||
TextColumn::make('ip'), | ||
|
||
TextColumn::make('status'), | ||
]); | ||
} | ||
|
||
public static function getRelations(): array | ||
{ | ||
return [ | ||
UserRelationManager::class, | ||
]; | ||
} | ||
|
||
public static function getPages(): array | ||
{ | ||
return [ | ||
'index' => Pages\ListServers::route('/'), | ||
'create' => Pages\CreateServer::route('/create'), | ||
'edit' => Pages\EditServer::route('/{record}/edit'), | ||
]; | ||
} | ||
|
||
public static function getGloballySearchableAttributes(): array | ||
{ | ||
return []; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
app/Filament/Resources/ServerResource/Pages/CreateServer.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
namespace App\Filament\Resources\ServerResource\Pages; | ||
|
||
use App\Filament\Resources\ServerResource; | ||
use Filament\Resources\Pages\CreateRecord; | ||
|
||
class CreateServer extends CreateRecord | ||
{ | ||
protected static string $resource = ServerResource::class; | ||
} |
19 changes: 19 additions & 0 deletions
19
app/Filament/Resources/ServerResource/Pages/EditServer.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace App\Filament\Resources\ServerResource\Pages; | ||
|
||
use App\Filament\Resources\ServerResource; | ||
use Filament\Pages\Actions\DeleteAction; | ||
use Filament\Resources\Pages\EditRecord; | ||
|
||
class EditServer extends EditRecord | ||
{ | ||
protected static string $resource = ServerResource::class; | ||
|
||
protected function getActions(): array | ||
{ | ||
return [ | ||
DeleteAction::make(), | ||
]; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
app/Filament/Resources/ServerResource/Pages/ListServers.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace App\Filament\Resources\ServerResource\Pages; | ||
|
||
use App\Filament\Resources\ServerResource; | ||
use Filament\Pages\Actions\CreateAction; | ||
use Filament\Resources\Pages\ListRecords; | ||
|
||
class ListServers extends ListRecords | ||
{ | ||
protected static string $resource = ServerResource::class; | ||
|
||
protected function getActions(): array | ||
{ | ||
return [ | ||
CreateAction::make(), | ||
]; | ||
} | ||
} |
Oops, something went wrong.