Skip to content

Commit

Permalink
Merge branch 'main' into minimal-theme
Browse files Browse the repository at this point in the history
  • Loading branch information
zepfietje committed Feb 23, 2024
2 parents 63bdc4a + d5eabc6 commit 1cc5e6f
Show file tree
Hide file tree
Showing 135 changed files with 2,685 additions and 956 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/pint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ jobs:
- name: Checkout code
uses: actions/checkout@v2
with:
ref: ${{ github.head_ref }}
ref: ${{ github.head_ref }}
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
- name: Install dependencies
run: composer install --no-interaction
- name: Run Pint
Expand Down
100 changes: 100 additions & 0 deletions app/Console/Commands/GetRandomImages.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?php

namespace App\Console\Commands;

use Database\Seeders\LocalImages;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;

class GetRandomImages extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'app:get-random-images';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Get random images stored locally, so that the seed process can be fast.';

/**
* Execute the console command.
*/
public function handle()
{
// Use an empty string to get random images
// We could fine-tune with search terms, examples: 'nature', 'people', 'city', 'abstract', 'food', 'sports', 'technics', 'transport', 'animals'
// This needs some deeper research to get the best results

$schemas = [
['amount' => 40, 'size' => LocalImages::SIZE_200x200, 'terms' => ['']],
['amount' => 40, 'size' => LocalImages::SIZE_1280x720, 'terms' => ['']],
];

foreach ($schemas as $schema) {
$this->getRandomImages($schema);
}

foreach ($schemas as $schema) {
$this->removeDuplicates($schema);
}
}

protected function getRandomImages($schema)
{
['amount' => $amount, 'size' => $size, 'terms' => $terms] = $schema;

$this->comment("Getting $amount random images of size $size, of topic: " . implode(', ', $terms));

File::deleteDirectory(database_path('seeders/local_images/' . $size));

$progressBar = $this->output->createProgressBar($amount);
$progressBar->start();

foreach (range(1, $amount) as $i) {
$url = "https://source.unsplash.com/{$size}/?img=1," . implode(',', $terms);
$image = file_get_contents($url);

File::ensureDirectoryExists(database_path('seeders/local_images/' . $size));
$filename = Str::uuid() . '.jpg';

File::put(
database_path(
path: "seeders/local_images/{$size}/{$filename}"
),
contents: $image
);

$progressBar->advance();
}

$progressBar->finish();

$this->newLine();
$this->info('Done!');
}

protected function removeDuplicates($schema)
{
['size' => $size] = $schema;

$allFiles = fn () => collect(File::files(database_path('seeders/local_images/' . $size)));

$uniqueImageSet = $allFiles()
->mapWithKeys(fn ($file) => [md5_file($file->getPathname()) => $file->getPathname()])
->values();

$allFiles()
->map(fn ($file) => $file->getPathname())
->diff($uniqueImageSet)
->each(fn ($file) => File::delete($file));

$this->info('Kept ' . $uniqueImageSet->count() . " unique files from size $size");
}
}
16 changes: 14 additions & 2 deletions app/Enums/OrderStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
namespace App\Enums;

use Filament\Support\Contracts\HasColor;
use Filament\Support\Contracts\HasIcon;
use Filament\Support\Contracts\HasLabel;

enum OrderStatus: string implements HasColor, HasLabel
enum OrderStatus: string implements HasColor, HasIcon, HasLabel
{
case New = 'new';

Expand All @@ -31,10 +32,21 @@ public function getLabel(): string
public function getColor(): string | array | null
{
return match ($this) {
self::New => 'gray',
self::New => 'info',
self::Processing => 'warning',
self::Shipped, self::Delivered => 'success',
self::Cancelled => 'danger',
};
}

public function getIcon(): ?string
{
return match ($this) {
self::New => 'heroicon-m-sparkles',
self::Processing => 'heroicon-m-arrow-path',
self::Shipped => 'heroicon-m-truck',
self::Delivered => 'heroicon-m-check-badge',
self::Cancelled => 'heroicon-m-x-circle',
};
}
}
16 changes: 16 additions & 0 deletions app/Filament/Clusters/Products.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace App\Filament\Clusters;

use Filament\Clusters\Cluster;

class Products extends Cluster
{
protected static ?string $navigationIcon = 'heroicon-o-squares-2x2';

protected static ?string $navigationGroup = 'Shop';

protected static ?int $navigationSort = 0;

protected static ?string $slug = 'shop/products';
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<?php

namespace App\Filament\Resources\Shop;
namespace App\Filament\Clusters\Products\Resources;

use App\Filament\Resources\Shop\BrandResource\Pages;
use App\Filament\Resources\Shop\BrandResource\RelationManagers;
use App\Filament\Clusters\Products;
use App\Models\Shop\Brand;
use Filament\Forms;
use Filament\Forms\Form;
Expand All @@ -17,17 +16,15 @@ class BrandResource extends Resource
{
protected static ?string $model = Brand::class;

protected static ?string $slug = 'shop/brands';
protected static ?string $cluster = Products::class;

protected static ?string $recordTitleAttribute = 'name';

protected static ?string $navigationGroup = 'Shop';

protected static ?string $navigationIcon = 'heroicon-m-bookmark-square';

protected static ?string $navigationParentItem = 'Products';

protected static ?int $navigationSort = 4;
protected static ?int $navigationSort = 2;

public static function form(Form $form): Form
{
Expand Down Expand Up @@ -121,17 +118,17 @@ public static function table(Table $table): Table
public static function getRelations(): array
{
return [
RelationManagers\ProductsRelationManager::class,
RelationManagers\AddressesRelationManager::class,
\App\Filament\Clusters\Products\Resources\BrandResource\RelationManagers\ProductsRelationManager::class,
\App\Filament\Clusters\Products\Resources\BrandResource\RelationManagers\AddressesRelationManager::class,
];
}

public static function getPages(): array
{
return [
'index' => Pages\ListBrands::route('/'),
'create' => Pages\CreateBrand::route('/create'),
'edit' => Pages\EditBrand::route('/{record}/edit'),
'index' => \App\Filament\Clusters\Products\Resources\BrandResource\Pages\ListBrands::route('/'),
'create' => \App\Filament\Clusters\Products\Resources\BrandResource\Pages\CreateBrand::route('/create'),
'edit' => \App\Filament\Clusters\Products\Resources\BrandResource\Pages\EditBrand::route('/{record}/edit'),
];
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace App\Filament\Resources\Shop\BrandResource\Pages;
namespace App\Filament\Clusters\Products\Resources\BrandResource\Pages;

use App\Filament\Resources\Shop\BrandResource;
use App\Filament\Clusters\Products\Resources\BrandResource;
use Filament\Resources\Pages\CreateRecord;

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

namespace App\Filament\Resources\Shop\BrandResource\Pages;
namespace App\Filament\Clusters\Products\Resources\BrandResource\Pages;

use App\Filament\Resources\Shop\BrandResource;
use App\Filament\Clusters\Products\Resources\BrandResource;
use Filament\Actions;
use Filament\Resources\Pages\EditRecord;

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

namespace App\Filament\Resources\Shop\BrandResource\Pages;
namespace App\Filament\Clusters\Products\Resources\BrandResource\Pages;

use App\Filament\Resources\Shop\BrandResource;
use App\Filament\Clusters\Products\Resources\BrandResource;
use App\Filament\Exports\Shop\BrandExporter;
use Filament\Actions;
use Filament\Resources\Pages\ListRecords;

Expand All @@ -13,6 +14,8 @@ class ListBrands extends ListRecords
protected function getActions(): array
{
return [
Actions\ExportAction::make()
->exporter(BrandExporter::class),
Actions\CreateAction::make(),
];
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace App\Filament\Resources\Shop\BrandResource\RelationManagers;
namespace App\Filament\Clusters\Products\Resources\BrandResource\RelationManagers;

use Filament\Forms;
use Filament\Forms\Form;
Expand Down Expand Up @@ -30,7 +30,7 @@ public function form(Form $form): Form
Forms\Components\Select::make('country')
->searchable()
->getSearchResultsUsing(fn (string $query) => Country::where('name', 'like', "%{$query}%")->pluck('name', 'id'))
->getOptionLabelUsing(fn ($value): ?string => Country::find($value)?->getAttribute('name')),
->getOptionLabelUsing(fn ($value): ?string => Country::firstWhere('id', $value)?->getAttribute('name')),
]);
}

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

namespace App\Filament\Resources\Shop\CategoryResource\RelationManagers;
namespace App\Filament\Clusters\Products\Resources\BrandResource\RelationManagers;

use App\Filament\Resources\Shop\ProductResource;
use App\Filament\Clusters\Products\Resources\ProductResource;
use Filament\Forms\Form;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Tables;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<?php

namespace App\Filament\Resources\Shop;
namespace App\Filament\Clusters\Products\Resources;

use App\Filament\Resources\Shop\CategoryResource\Pages;
use App\Filament\Resources\Shop\CategoryResource\RelationManagers;
use App\Filament\Clusters\Products;
use App\Models\Shop\Category;
use Filament\Forms;
use Filament\Forms\Form;
Expand All @@ -18,17 +17,15 @@ class CategoryResource extends Resource
{
protected static ?string $model = Category::class;

protected static ?string $slug = 'shop/categories';
protected static ?string $cluster = Products::class;

protected static ?string $recordTitleAttribute = 'name';

protected static ?string $navigationGroup = 'Shop';

protected static ?string $navigationIcon = 'heroicon-m-tag';

protected static ?string $navigationParentItem = 'Products';

protected static ?int $navigationSort = 3;
protected static ?int $navigationSort = 1;

public static function form(Form $form): Form
{
Expand Down Expand Up @@ -122,16 +119,16 @@ public static function table(Table $table): Table
public static function getRelations(): array
{
return [
RelationManagers\ProductsRelationManager::class,
\App\Filament\Clusters\Products\Resources\CategoryResource\RelationManagers\ProductsRelationManager::class,
];
}

public static function getPages(): array
{
return [
'index' => Pages\ListCategories::route('/'),
'create' => Pages\CreateCategory::route('/create'),
'edit' => Pages\EditCategory::route('/{record}/edit'),
'index' => \App\Filament\Clusters\Products\Resources\CategoryResource\Pages\ListCategories::route('/'),
'create' => \App\Filament\Clusters\Products\Resources\CategoryResource\Pages\CreateCategory::route('/create'),
'edit' => \App\Filament\Clusters\Products\Resources\CategoryResource\Pages\EditCategory::route('/{record}/edit'),
];
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace App\Filament\Resources\Shop\CategoryResource\Pages;
namespace App\Filament\Clusters\Products\Resources\CategoryResource\Pages;

use App\Filament\Resources\Shop\CategoryResource;
use App\Filament\Clusters\Products\Resources\CategoryResource;
use Filament\Resources\Pages\CreateRecord;

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

namespace App\Filament\Resources\Shop\CategoryResource\Pages;
namespace App\Filament\Clusters\Products\Resources\CategoryResource\Pages;

use App\Filament\Resources\Shop\CategoryResource;
use App\Filament\Clusters\Products\Resources\CategoryResource;
use Filament\Actions;
use Filament\Resources\Pages\EditRecord;

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

namespace App\Filament\Resources\Shop\CategoryResource\Pages;
namespace App\Filament\Clusters\Products\Resources\CategoryResource\Pages;

use App\Filament\Clusters\Products\Resources\CategoryResource;
use App\Filament\Imports\Shop\CategoryImporter;
use App\Filament\Resources\Shop\CategoryResource;
use Filament\Actions;
use Filament\Resources\Pages\ListRecords;

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

namespace App\Filament\Resources\Shop\BrandResource\RelationManagers;
namespace App\Filament\Clusters\Products\Resources\CategoryResource\RelationManagers;

use App\Filament\Resources\Shop\ProductResource;
use App\Filament\Clusters\Products\Resources\ProductResource;
use Filament\Forms\Form;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Tables;
Expand Down
Loading

0 comments on commit 1cc5e6f

Please sign in to comment.