Skip to content

Commit

Permalink
feat: various updates (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
duckietm authored Dec 25, 2024
1 parent 55079d0 commit c7d668e
Show file tree
Hide file tree
Showing 29 changed files with 343 additions and 124 deletions.
8 changes: 8 additions & 0 deletions app/Filament/Resources/Atom/ArticleResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use App\Filament\Resources\Atom\ArticleResource\Pages;
use App\Filament\Resources\Atom\ArticleResource\RelationManagers;

class ArticleResource extends Resource
{
Expand Down Expand Up @@ -183,6 +184,13 @@ public static function getEloquentQuery(): Builder
SoftDeletingScope::class,
]);
}

public static function getRelations(): array
{
return [
RelationManagers\TagsRelationManager::class,
];
}

public static function getPages(): array
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace App\Filament\Resources\Atom\ArticleResource\RelationManagers;

use Filament\Forms;
use Filament\Tables;
use Filament\Forms\Form;
use Filament\Tables\Table;
use App\Filament\Resources\Atom\TagResource;
use App\Filament\Traits\TranslatableResource;
use Filament\Resources\RelationManagers\RelationManager;

class TagsRelationManager extends RelationManager
{
use TranslatableResource;

protected static string $relationship = 'tags';

protected static ?string $recordTitleAttribute = 'name';

public static string $translateIdentifier = 'tags';

public function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('name')
->required()
->maxLength(255),
]);
}

public function table(Table $table): Table
{
return $table
->columns(TagResource::getTable())
->modifyQueryUsing(fn ($query) => $query->latest())
->filters([
//
])
->headerActions([
Tables\Actions\CreateAction::make()
->form(TagResource::getForm()),

Tables\Actions\AttachAction::make()->preloadRecordSelect()
])
->actions([
Tables\Actions\ViewAction::make(),
Tables\Actions\DetachAction::make(),
])
->bulkActions([
Tables\Actions\DetachBulkAction::make(),
]);
}
}
84 changes: 84 additions & 0 deletions app/Filament/Resources/Atom/FotoResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php

namespace App\Filament\Resources\Atom;

use Filament\Tables;
use Filament\Forms\Components\Toggle;
use Filament\Forms\Form;
use Filament\Tables\Table;
use App\Filament\Resources\Atom\FotoResource\Pages;
use Filament\Resources\Resource;
use Filament\Tables\Columns\ImageColumn;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Columns\ToggleColumn;
use App\Models\Camera;

class FotoResource extends Resource
{
protected static ?string $model = Camera::class;

protected static ?string $navigationIcon = 'heroicon-o-photo';

protected static ?string $navigationGroup = 'Website';

protected static ?string $navigationLabel = 'Web Camera';

public static function form(Form $form): Form
{
return $form
->schema([
Toggle::make('visible')
->label(__('Visible'))
->default(true),
]);
}

public static function table(Table $table): Table
{
return $table
->defaultSort('id', 'desc')
->columns([
TextColumn::make('id')
->label(__('filament::resources.columns.id'))
->sortable(),
TextColumn::make('user_id')
->label(__('filament::resources.columns.user_id')),
TextColumn::make('room_id')
->label(__('filament::resources.columns.room_id')),
TextColumn::make('timestamp')
->label(__('filament::resources.columns.created_at'))
->dateTime(),
ImageColumn::make('url')
->label(__('filament::resources.columns.image'))
->extraAttributes(['style' => 'image-rendering: pixelated'])
->size(125),
ToggleColumn::make('visible')
->label(__('Visible'))
])
->actions([
Tables\Actions\DeleteAction::make(),
])
->bulkActions([
Tables\Actions\DeleteBulkAction::make(),
]);
}

public static function getRelations(): array
{
return [
];
}

public static function getPages(): array
{
return [
'index' => Pages\ListFotos::route('/'),
'edit' => Pages\EditFoto::route('/{record}/edit'),
];
}

public static function canCreate(): bool
{
return false;
}
}
19 changes: 19 additions & 0 deletions app/Filament/Resources/Atom/FotoResource/Pages/EditFoto.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Filament\Resources\Atom\FotoResource\Pages;

use App\Filament\Resources\Atom\FotoResource;
use Filament\Actions;
use Filament\Resources\Pages\EditRecord;

class EditFoto extends EditRecord
{
protected static string $resource = FotoResource::class;

protected function getHeaderActions(): array
{
return [
Actions\DeleteAction::make(),
];
}
}
19 changes: 19 additions & 0 deletions app/Filament/Resources/Atom/FotoResource/Pages/ListFotos.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Filament\Resources\Atom\FotoResource\Pages;

use App\Filament\Resources\Atom\FotoResource;
use Filament\Actions;
use Filament\Resources\Pages\ListRecords;

class ListFotos extends ListRecords
{
protected static string $resource = FotoResource::class;

protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make(),
];
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

namespace App\Filament\Resources;
namespace App\Filament\Resources\Hotel;

use App\Filament\Resources\CatalogPageResource\Pages;
use App\Filament\Resources\CatalogPageResource\RelationManagers\CatalogItemsRelationManager;
use App\Filament\Resources\Hotel\CatalogPageResource\Pages;
use App\Filament\Resources\Hotel\CatalogPageResource\RelationManagers\CatalogItemsRelationManager;
use App\Models\Game\Furniture\CatalogPage;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Form;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace App\Filament\Resources\CatalogPageResource\Pages;
namespace App\Filament\Resources\Hotel\CatalogPageResource\Pages;

use App\Filament\Resources\CatalogPageResource;
use App\Filament\Resources\Hotel\CatalogPageResource;
use Filament\Resources\Pages\CreateRecord;

class CreateCatalogPage extends CreateRecord
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace App\Filament\Resources\CatalogPageResource\Pages;
namespace App\Filament\Resources\Hotel\CatalogPageResource\Pages;

use App\Filament\Resources\CatalogPageResource;
use App\Filament\Resources\Hotel\CatalogPageResource;
use Filament\Actions\DeleteAction;
use Filament\Resources\Pages\EditRecord;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace App\Filament\Resources\CatalogPageResource\Pages;
namespace App\Filament\Resources\Hotel\CatalogPageResource\Pages;

use App\Filament\Resources\CatalogPageResource;
use App\Filament\Resources\Hotel\CatalogPageResource;
use Filament\Actions\CreateAction;
use Filament\Resources\Pages\ListRecords;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace App\Filament\Resources\CatalogPageResource\RelationManagers;
namespace App\Filament\Resources\Hotel\CatalogPageResource\RelationManagers;

use App\Models\Game\Furniture\ItemBase;
use Filament\Forms;
Expand Down
1 change: 1 addition & 0 deletions app/Http/Controllers/Miscellaneous/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public function __invoke(): View
->get(),
'photos' => CameraWeb::latest('id')
->take(4)
->where('visible', true)
->with('user:id,username,look')
->get(),
]);
Expand Down
56 changes: 1 addition & 55 deletions app/Models/Camera.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,61 +24,7 @@ class Camera extends Model
protected $casts = [
'timestamp' => 'datetime',
];

public static function getFriendsWhoHaveStories()
{
$friendsId = \Auth::user()
->friends()
->pluck('user_two_id')
->toArray();

return DB::table('users')
->leftJoin('camera_web', 'users.id', '=', 'camera_web.user_id')
->select('users.id', 'users.username', 'users.avatar_background', 'users.look', 'camera_web.timestamp', 'camera_web.url')
->whereIn('camera_web.user_id', $friendsId)
->where('camera_web.timestamp', '>=', now()->subDay()->timestamp)
->orderBy('camera_web.timestamp', 'desc')
->get()
->map(function ($item) {
$item->timestamp = Carbon::parse($item->timestamp)->diffForHumans();
return $item;
})
->groupBy('username');
}

public static function latestWith(bool $includesRoom = false): Builder
{
$query = Camera::query()->latest('id');

$includes = [
'user:id,look,username',
'likes' => fn ($query) => $query->whereLiked(true)
];

if ($includesRoom) {
array_push($includes, 'room:id,name');
}

return $query->with($includes);
}

public function scopeFilter(Builder $query, $filter): void
{
$user = \Auth::user();

if($filter == 'only_my_friends') {
$friendsId = $user->friends()->pluck('id')->toArray();

$query->whereIn('user_id', $friendsId);
}

if($filter == 'liked_by_me') {
$likedPhotoIds = $user->photoLikes()->pluck('camera_id')->toArray();

$query->whereIn('id', $likedPhotoIds);
}
}


public function scopePeriod(Builder $query, $period): void
{
if($period == 'today') {
Expand Down
7 changes: 4 additions & 3 deletions app/Services/Community/CameraService.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ class CameraService
{
public function fetchPhotos(bool $paginate = false, int $perPage = 8): mixed
{
$photos = CameraWeb::latest('id')->with('user:id,username,look');

return $paginate ? $photos->paginate($perPage) : $photos->get();
$photos = CameraWeb::where('visible', true)
->latest('id')
->with('user:id,username,look');
return $paginate ? $photos->paginate($perPage) : $photos->get();
}
}
28 changes: 28 additions & 0 deletions database/migrations/2024_12_22_201248_create_tagable_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

use App\Models\Articles\Tag;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('taggables', function (Blueprint $table) {
$table->foreignIdFor(Tag::class);
$table->morphs('taggable');
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('taggables');
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AddVisibleToCameraWebTable extends Migration
{
public function up()
{
Schema::table('camera_web', function (Blueprint $table) {
$table->boolean('visible')->default(true);
});
}

public function down()
{
Schema::table('camera_web', function (Blueprint $table) {
$table->dropColumn('visible');
});
}
}
Loading

0 comments on commit c7d668e

Please sign in to comment.