language files combined, settings fixed, "new" badge integrated

This commit is contained in:
2025-08-01 23:34:41 +02:00
parent b2968f203d
commit 80873877c1
44 changed files with 1319 additions and 358 deletions

View File

@@ -5,6 +5,8 @@ namespace App\Filament\Resources\AiModelResource\Pages;
use App\Filament\Resources\AiModelResource;
use Filament\Actions;
use Filament\Resources\Pages\ListRecords;
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\Eloquent\Builder;
class ListAiModels extends ListRecords
{
@@ -16,4 +18,35 @@ class ListAiModels extends ListRecords
Actions\CreateAction::make(),
];
}
protected function shouldPersistTableFiltersInSession(): bool
{
return true;
}
protected function shouldPersistTableSortInSession(): bool
{
return true;
}
protected function shouldPersistTableSearchInSession(): bool
{
return true;
}
protected function paginateTableQuery(Builder $query): Paginator
{
$paginator = parent::paginateTableQuery($query);
return $paginator;
}
public function updatedTablePage($page)
{
$this->dispatch('table-pagination-updated', ['tableId' => $this->id, 'page' => $page]);
}
protected function getTableQueryStringIdentifier(): ?string
{
return 'ai-models-table';
}
}

View File

@@ -5,6 +5,8 @@ namespace App\Filament\Resources\ApiProviderResource\Pages;
use App\Filament\Resources\ApiProviderResource;
use Filament\Actions;
use Filament\Resources\Pages\ListRecords;
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\Eloquent\Builder;
class ListApiProviders extends ListRecords
{
@@ -16,4 +18,35 @@ class ListApiProviders extends ListRecords
Actions\CreateAction::make(),
];
}
protected function shouldPersistTableFiltersInSession(): bool
{
return true;
}
protected function shouldPersistTableSortInSession(): bool
{
return true;
}
protected function shouldPersistTableSearchInSession(): bool
{
return true;
}
protected function paginateTableQuery(Builder $query): Paginator
{
$paginator = parent::paginateTableQuery($query);
return $paginator;
}
public function updatedTablePage($page)
{
$this->dispatch('table-pagination-updated', ['tableId' => $this->id, 'page' => $page]);
}
protected function getTableQueryStringIdentifier(): ?string
{
return 'api-providers-table';
}
}

View File

@@ -31,6 +31,9 @@ class ImageResource extends Resource
->required()
->image()
->directory('uploads'),
Forms\Components\Toggle::make('is_public')
->label(__('Publicly Visible'))
->default(false),
]);
}

View File

@@ -5,6 +5,8 @@ namespace App\Filament\Resources\ImageResource\Pages;
use App\Filament\Resources\ImageResource;
use Filament\Actions;
use Filament\Resources\Pages\ListRecords;
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\Eloquent\Builder;
class ListImages extends ListRecords
{
@@ -16,4 +18,35 @@ class ListImages extends ListRecords
Actions\CreateAction::make(),
];
}
protected function shouldPersistTableFiltersInSession(): bool
{
return true;
}
protected function shouldPersistTableSortInSession(): bool
{
return true;
}
protected function shouldPersistTableSearchInSession(): bool
{
return true;
}
protected function paginateTableQuery(Builder $query): Paginator
{
$paginator = parent::paginateTableQuery($query);
return $paginator;
}
public function updatedTablePage($page)
{
$this->dispatch('table-pagination-updated', ['tableId' => $this->id, 'page' => $page]);
}
protected function getTableQueryStringIdentifier(): ?string
{
return 'images-table';
}
}

View File

@@ -12,18 +12,31 @@ use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Fieldset;
class SettingResource extends Resource
{
protected static ?string $model = Setting::class;
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
protected static ?string $navigationIcon = 'heroicon-o-cog';
public static function form(Form $form): Form
{
return $form
->schema([
//
Forms\Components\TextInput::make('key')
->label(__('Key'))
->required()
->maxLength(255)
->hiddenOn('edit'),
Forms\Components\Fieldset::make()
->label(fn (?Setting $record) => $record ? $record->key : __('New Setting'))
->schema([
TextInput::make('value')
->label(__('Value'))
->disableLabel()
])
]);
}
@@ -31,7 +44,8 @@ class SettingResource extends Resource
{
return $table
->columns([
//
Tables\Columns\TextColumn::make('key')->label(__('Key'))->searchable()->sortable(),
Tables\Columns\TextColumn::make('value')->label(__('Value'))->searchable()->sortable(),
])
->filters([
//
@@ -39,6 +53,7 @@ class SettingResource extends Resource
->actions([
Tables\Actions\EditAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),

View File

@@ -1,64 +0,0 @@
<?php
namespace App\Filament\Resources\SettingResource\Pages;
use App\Filament\Resources\SettingResource;
use App\Models\Setting;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Filament\Forms\Form;
use Filament\Notifications\Notification;
use Filament\Pages\Page;
use Illuminate\Database\Eloquent\Model;
class Settings extends Page implements HasForms
{
use InteractsWithForms;
protected static string $resource = SettingResource::class;
protected static ?string $navigationIcon = 'heroicon-o-cog';
protected static ?string $navigationGroup = 'Settings';
protected static ?string $navigationLabel = 'Global Settings';
protected static ?string $slug = 'global-settings';
protected static string $view = 'filament.resources.setting-resource.pages.settings';
public ?array $data = [];
public function mount(): void
{
$this->form->fill(
collect(Setting::all())
->mapWithKeys(fn (Setting $setting) => [$setting->key => $setting->value])
->all()
);
}
public function form(Form $form): Form
{
return $form
->schema([
TextInput::make('gallery_heading')
->label(__('settings.gallery_heading')),
])
->statePath('data')
->model(Setting::class);
}
public function submit(): void
{
foreach ($this->form->getState() as $key => $value) {
Setting::updateOrCreate(['key' => $key], ['value' => $value]);
}
Notification::make()
->title(__('settings.saved_successfully'))
->success()
->send();
}
}

View File

@@ -110,9 +110,7 @@ class StyleResource extends Resource
])
->emptyStateActions([
Tables\Actions\CreateAction::make(),
])
->persistFiltersInSession()
->persistSortInSession();
]);
}
public static function getRelations(): array

View File

@@ -5,6 +5,8 @@ namespace App\Filament\Resources\StyleResource\Pages;
use App\Filament\Resources\StyleResource;
use Filament\Actions;
use Filament\Resources\Pages\ListRecords;
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\Eloquent\Builder;
class ListStyles extends ListRecords
{
@@ -16,4 +18,35 @@ class ListStyles extends ListRecords
Actions\CreateAction::make(),
];
}
protected function shouldPersistTableFiltersInSession(): bool
{
return true;
}
protected function shouldPersistTableSortInSession(): bool
{
return true;
}
protected function shouldPersistTableSearchInSession(): bool
{
return true;
}
protected function paginateTableQuery(Builder $query): Paginator
{
$paginator = parent::paginateTableQuery($query);
return $paginator;
}
public function updatedTablePage($page)
{
$this->dispatch('table-pagination-updated', ['tableId' => $this->id, 'page' => $page]);
}
protected function getTableQueryStringIdentifier(): ?string
{
return 'styles-table';
}
}

View File

@@ -27,24 +27,50 @@ class UserResource extends Resource
{
return $form
->schema([
TextInput::make('name')
->label(__('filament.resource.user.form.name'))
->required()
->maxLength(255),
TextInput::make('email')
->label(__('filament.resource.user.form.email'))
->email()
->required()
->maxLength(255),
TextInput::make('password')
->label(__('filament.resource.user.form.password'))
->password()
->required()
->maxLength(255),
Select::make('role_id')
->relationship('role', 'name')
->label(__('filament.resource.user.form.role'))
->required(),
Forms\Components\Section::make('User Details')
->schema([
TextInput::make('name')
->label(__('filament.resource.user.form.name'))
->required()
->maxLength(255),
TextInput::make('email')
->label(__('filament.resource.user.form.email'))
->email()
->required()
->maxLength(255),
TextInput::make('password')
->label(__('filament.resource.user.form.password'))
->password()
->dehydrateStateUsing(fn (string $state): string => bcrypt($state))
->dehydrated(fn (?string $state): bool => filled($state))
->required(fn (string $operation): bool => $operation === 'create')
->maxLength(255),
Select::make('role_id')
->relationship('role', 'name')
->label(__('filament.resource.user.form.role'))
->required(),
])->columns(2),
Forms\Components\Section::make('Preferences')
->schema([
Forms\Components\Toggle::make('email_notifications_enabled')
->label(__('Email Notifications'))
->default(true),
Select::make('theme_preference')
->label(__('Theme'))
->options([
'light' => 'Light',
'dark' => 'Dark',
])
->default('light'),
Select::make('locale')
->label(__('Language'))
->options([
'en' => 'English',
'de' => 'Deutsch',
])
->default('en'),
])->columns(2),
]);
}

View File

@@ -5,6 +5,8 @@ namespace App\Filament\Resources\UserResource\Pages;
use App\Filament\Resources\UserResource;
use Filament\Actions;
use Filament\Resources\Pages\ListRecords;
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\Eloquent\Builder;
class ListUsers extends ListRecords
{
@@ -16,4 +18,35 @@ class ListUsers extends ListRecords
Actions\CreateAction::make(),
];
}
protected function shouldPersistTableFiltersInSession(): bool
{
return true;
}
protected function shouldPersistTableSortInSession(): bool
{
return true;
}
protected function shouldPersistTableSearchInSession(): bool
{
return true;
}
protected function paginateTableQuery(Builder $query): Paginator
{
$paginator = parent::paginateTableQuery($query);
return $paginator;
}
public function updatedTablePage($page)
{
$this->dispatch('table-pagination-updated', ['tableId' => $this->id, 'page' => $page]);
}
protected function getTableQueryStringIdentifier(): ?string
{
return 'users-table';
}
}

View File

@@ -9,10 +9,12 @@ use App\Models\ApiProvider;
use App\Models\Style;
use App\Models\Image;
use Illuminate\Support\Facades\File;
use Carbon\Carbon;
use App\Models\Setting;
class ImageController extends Controller
{
public function index()
public function index(Request $request)
{
$publicUploadsPath = public_path('storage/uploads');
@@ -34,15 +36,28 @@ class ImageController extends Controller
// Add images from disk that are not in the database
$imagesToAdd = array_diff($diskImagePaths, $dbImagePaths);
foreach ($imagesToAdd as $path) {
Image::create(['path' => $path]);
Image::create(['path' => $path, 'is_public' => true]);
}
// Remove images from database that are not on disk
$imagesToRemove = array_diff($dbImagePaths, $diskImagePaths);
Image::whereIn('path', $imagesToRemove)->delete();
// Fetch all images from the database after synchronization
$images = Image::orderBy('updated_at', 'desc')->get();
// Fetch images from the database after synchronization
$query = Image::orderBy('updated_at', 'desc');
// If user is not authenticated, filter by is_public
if (!auth()->check()) {
$query->where('is_public', true);
}
$newImageTimespanMinutes = Setting::where('key', 'new_image_timespan_minutes')->first()->value ?? 60; // Default to 60 minutes
$images = $query->get()->map(function ($image) use ($newImageTimespanMinutes) {
$image->is_new = Carbon::parse($image->created_at)->diffInMinutes(Carbon::now()) <= $newImageTimespanMinutes;
return $image;
});
$formattedImages = [];
foreach ($images as $image) {
$formattedImages[] = [
@@ -50,6 +65,8 @@ class ImageController extends Controller
'path' => asset('storage/' . $image->path),
'name' => basename($image->path),
'is_temp' => (bool) $image->is_temp,
'is_public' => (bool) $image->is_public,
'is_new' => (bool) $image->is_new,
];
}
return response()->json($formattedImages);
@@ -75,6 +92,7 @@ class ImageController extends Controller
$image = Image::create([
'path' => $relativePath,
'is_public' => true,
]);
return response()->json([
@@ -96,15 +114,29 @@ class ImageController extends Controller
$request->validate([
'image_id' => 'required|exists:images,id',
'style_id' => 'required|exists:styles,id',
'style_id' => 'nullable|exists:styles,id',
]);
$image = Image::find($request->image_id);
$style = Style::with(['aiModel' => function ($query) {
$query->where('enabled', true)->with(['apiProviders' => function ($query) {
$query->where('enabled', true);
}]);
}])->find($request->style_id);
$style = null;
if ($request->style_id) {
$style = Style::with(['aiModel' => function ($query) {
$query->where('enabled', true)->with(['apiProviders' => function ($query) {
$query->where('enabled', true);
}]);
}])->find($request->style_id);
} else {
// Attempt to get default style from settings
$defaultStyleSetting = \App\Models\Setting::where('key', 'default_style_id')->first();
if ($defaultStyleSetting && $defaultStyleSetting->value) {
$style = Style::with(['aiModel' => function ($query) {
$query->where('enabled', true)->with(['apiProviders' => function ($query) {
$query->where('enabled', true);
}]);
}])->find($defaultStyleSetting->value);
}
}
if (!$style || !$style->aiModel || $style->aiModel->apiProviders->isEmpty()) {
return response()->json(['error' => __('api.style_or_provider_not_found')], 404);

View File

@@ -4,20 +4,33 @@ namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Setting;
use App\Models\Image;
use Inertia\Inertia;
use Illuminate\Support\Facades\Lang;
use Carbon\Carbon;
class HomeController extends Controller
{
public function index()
{
$locale = app()->getLocale();
$translations = Lang::get('messages', [], $locale);
$translations = array_merge(
Lang::get('api', [], $locale),
Lang::get('settings', [], $locale)
);
$galleryHeading = Setting::where('key', 'gallery_heading')->first()->value ?? 'Style Gallery';
$newImageTimespanMinutes = Setting::where('key', 'new_image_timespan_minutes')->first()->value ?? 60; // Default to 60 minutes
$images = Image::all()->map(function ($image) use ($newImageTimespanMinutes) {
$image->is_new = Carbon::parse($image->created_at)->diffInMinutes(Carbon::now()) <= $newImageTimespanMinutes;
$image->path = 'storage/' . $image->path;
return $image;
});
return Inertia::render('Home', [
'translations' => $translations,
'galleryHeading' => $galleryHeading,
'images' => $images,
]);
}
}

View File

@@ -35,14 +35,21 @@ class HandleInertiaRequests extends Middleware
'user' => $request->user(),
],
'locale' => app()->getLocale(),
'lang' => function () {
'translations' => function () use ($request) {
$currentLocale = app()->getLocale(); // Store current locale
$requestedLocale = $request->input('locale', $currentLocale);
app()->setLocale($requestedLocale); // Set locale based on request or current
$lang = [
'filament' => trans('filament'),
'api' => trans('api'),
'settings' => trans('settings'),
'messages' => trans('messages'),
// Add other translation files as needed
];
dd($lang); // <-- ADDED FOR DEBUGGING
app()->setLocale($currentLocale); // Revert to original locale
return $lang;
},
];

View File

@@ -15,12 +15,16 @@ class SetLocale
*/
public function handle(Request $request, Closure $next): Response
{
$locale = substr($request->server('HTTP_ACCEPT_LANGUAGE'), 0, 2);
if (in_array($locale, ['de'])) {
app()->setLocale($locale);
if (auth()->check() && auth()->user()->locale) {
app()->setLocale(auth()->user()->locale);
} else {
app()->setLocale('en');
$locale = substr($request->server('HTTP_ACCEPT_LANGUAGE'), 0, 2);
if (in_array($locale, ['de'])) {
app()->setLocale($locale);
} else {
app()->setLocale('en');
}
}
return $next($request);

View File

@@ -16,5 +16,6 @@ class Image extends Model
'original_image_id',
'style_id',
'is_temp',
'is_public',
];
}

View File

@@ -22,6 +22,9 @@ class User extends Authenticatable
'email',
'password',
'role_id',
'email_notifications_enabled',
'theme_preference',
'locale',
];
public function role()

View File

@@ -2,6 +2,7 @@
namespace App\Providers;
use Filament\Support\Facades\FilamentAsset;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
@@ -19,6 +20,10 @@ class AppServiceProvider extends ServiceProvider
*/
public function boot(): void
{
FilamentAsset::register([
\Filament\Support\Assets\Js::make('custom-navigation-state', __DIR__ . '/../../resources/js/custom/navigation-state.js'),
]);
$locale = substr(request()->server('HTTP_ACCEPT_LANGUAGE'), 0, 2);
if (in_array($locale, ['de'])) {

View File

@@ -19,12 +19,13 @@ use Illuminate\Session\Middleware\StartSession;
use Illuminate\View\Middleware\ShareErrorsFromSession;
use App\Filament\Resources\StyleResource;
use App\Filament\Resources\SettingResource\Pages\Settings;
use Illuminate\Support\Facades\Auth;
class AdminPanelProvider extends PanelProvider
{
public function panel(Panel $panel): Panel
{
return $panel
$panel = $panel
->default()
->id('admin')
->path('admin')
@@ -37,7 +38,7 @@ class AdminPanelProvider extends PanelProvider
->pages([
Pages\Dashboard::class,
\App\Filament\Pages\InstallPluginPage::class,
Settings::class,
])
->discoverWidgets(in: app_path('Filament/Widgets'), for: 'App\\Filament\\Widgets')
->widgets([
@@ -60,6 +61,19 @@ class AdminPanelProvider extends PanelProvider
])
->plugins([
]);
])
->profile();
if (Auth::check()) {
$user = Auth::user();
if ($user->theme_preference === 'dark') {
$panel->darkMode();
} else {
$panel->lightMode();
}
}
return $panel;
}
}