Skip to content

Commit d56bac8

Browse files
SlimDeluxethapacodes4uthapacodes4u
authored
feat: implement banners (CM-10)
* feat: add banner migrations and models * style: fix code style * feat: implement banners (CM-13) * ci: fix workflows for pull requests * ci: remove release-please workflow * feat: implementing complete banner management system with HiDPI support and image modal viewer * refactor: migrate banner management from relation manager to dedicated resource with HiDPI support * refactor: improve banner management and enhanced modal and adding few more test cases * refactor: fixing failing test & image lightbox * feat: implemented all the changes requested in PR * feat: moving lightbox to SliderColumn * feat: importing correct image classes --------- Co-authored-by: Omer Šabić <omer@datalinx.si> Co-authored-by: thapacodes4u <ankitcodes4u@gmail.com> * style: fix code style --------- Co-authored-by: SlimDeluxe <131700+SlimDeluxe@users.noreply.github.com> Co-authored-by: Thapa Godar Ank. <76224530+thapacodes4u@users.noreply.github.com> Co-authored-by: thapacodes4u <ankitcodes4u@gmail.com>
1 parent a959f8f commit d56bac8

34 files changed

+2515
-5
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"eclipsephp/common": "dev-main",
4848
"filament/filament": "^3.3",
4949
"filament/spatie-laravel-translatable-plugin": "^3.3",
50+
"spatie/image": "^3.8",
5051
"solution-forest/filament-tree": "^2.1",
5152
"spatie/laravel-package-tools": "^1.19"
5253
},
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
namespace Eclipse\Cms\Factories;
4+
5+
use Eclipse\Cms\Models\Banner;
6+
use Illuminate\Database\Eloquent\Factories\Factory;
7+
8+
class BannerFactory extends Factory
9+
{
10+
protected $model = Banner::class;
11+
12+
public function definition(): array
13+
{
14+
$names = [
15+
'en' => ['Summer Sale', 'Winter Sale', 'Special Offer', 'New Arrivals', 'Featured Deal'],
16+
'sl' => ['Poletna Razprodaja', 'Zimska Razprodaja', 'Posebna Ponudba', 'Nove Stvari', 'Izpostavljena Ponudba'],
17+
];
18+
19+
$nameIndex = $this->faker->numberBetween(0, count($names['en']) - 1);
20+
21+
return [
22+
'name' => [
23+
'en' => $names['en'][$nameIndex],
24+
'sl' => $names['sl'][$nameIndex],
25+
],
26+
'link' => 'https://example.com/'.$this->faker->slug(2),
27+
'is_active' => $this->faker->boolean(80),
28+
'new_tab' => $this->faker->boolean(30),
29+
'sort' => $this->faker->numberBetween(1, 10),
30+
];
31+
}
32+
33+
public function active(): static
34+
{
35+
return $this->state(fn (array $attributes): array => [
36+
'is_active' => true,
37+
]);
38+
}
39+
40+
public function inactive(): static
41+
{
42+
return $this->state(fn (array $attributes): array => [
43+
'is_active' => false,
44+
]);
45+
}
46+
47+
public function newTab(): static
48+
{
49+
return $this->state(fn (array $attributes): array => [
50+
'new_tab' => true,
51+
]);
52+
}
53+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
3+
namespace Eclipse\Cms\Factories;
4+
5+
use Eclipse\Cms\Models\Banner\Image;
6+
use Illuminate\Database\Eloquent\Factories\Factory;
7+
8+
class BannerImageFactory extends Factory
9+
{
10+
protected $model = Image::class;
11+
12+
public function definition(): array
13+
{
14+
$sampleImages = [
15+
'banners/summer-sale-desktop.jpg',
16+
'banners/winter-collection-mobile.jpg',
17+
'banners/spring-deals-tablet.jpg',
18+
'banners/black-friday-hero.jpg',
19+
'banners/new-arrivals-sidebar.jpg',
20+
'banners/limited-offer-footer.jpg',
21+
'banners/featured-product-square.jpg',
22+
'banners/special-promo-wide.jpg',
23+
'banners/holiday-sale-banner.jpg',
24+
'banners/end-season-deals.jpg',
25+
];
26+
27+
return [
28+
'file' => $this->faker->randomElement($sampleImages),
29+
'image_width' => $this->faker->randomElement([400, 800, 1200, 1920]),
30+
'image_height' => $this->faker->randomElement([200, 400, 600, 800]),
31+
'is_hidpi' => $this->faker->boolean(30),
32+
];
33+
}
34+
35+
public function desktop(): static
36+
{
37+
return $this->state(fn (array $attributes): array => [
38+
'file' => 'banners/desktop-'.$this->faker->slug().'.jpg',
39+
'image_width' => 1920,
40+
'image_height' => 600,
41+
'is_hidpi' => false,
42+
]);
43+
}
44+
45+
public function mobile(): static
46+
{
47+
return $this->state(fn (array $attributes): array => [
48+
'file' => 'banners/mobile-'.$this->faker->slug().'.jpg',
49+
'image_width' => 800,
50+
'image_height' => 400,
51+
'is_hidpi' => true,
52+
]);
53+
}
54+
55+
public function tablet(): static
56+
{
57+
return $this->state(fn (array $attributes): array => [
58+
'file' => 'banners/tablet-'.$this->faker->slug().'.jpg',
59+
'image_width' => 1024,
60+
'image_height' => 500,
61+
'is_hidpi' => false,
62+
]);
63+
}
64+
65+
public function square(): static
66+
{
67+
return $this->state(fn (array $attributes): array => [
68+
'file' => 'banners/square-'.$this->faker->slug().'.jpg',
69+
'image_width' => 400,
70+
'image_height' => 400,
71+
'is_hidpi' => false,
72+
]);
73+
}
74+
75+
public function hidpi(): static
76+
{
77+
return $this->state(fn (array $attributes): array => [
78+
'is_hidpi' => true,
79+
'image_width' => $attributes['image_width'] * 2,
80+
'image_height' => $attributes['image_height'] * 2,
81+
]);
82+
}
83+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
namespace Eclipse\Cms\Factories;
4+
5+
use Eclipse\Cms\Models\Banner\ImageType;
6+
use Illuminate\Database\Eloquent\Factories\Factory;
7+
8+
class BannerImageTypeFactory extends Factory
9+
{
10+
protected $model = ImageType::class;
11+
12+
public function definition(): array
13+
{
14+
return [
15+
'name' => [
16+
'en' => 'Desktop',
17+
'sl' => 'Namizje',
18+
],
19+
'code' => 'desktop',
20+
'image_width' => 1200,
21+
'image_height' => 400,
22+
'is_hidpi' => false,
23+
];
24+
}
25+
26+
public function desktop(): static
27+
{
28+
return $this->state(fn (array $attributes) => [
29+
'name' => [
30+
'en' => 'Desktop',
31+
'sl' => 'Namizje',
32+
],
33+
'code' => 'desktop',
34+
'image_width' => 1200,
35+
'image_height' => 400,
36+
'is_hidpi' => false,
37+
]);
38+
}
39+
40+
public function mobile(): static
41+
{
42+
return $this->state(fn (array $attributes) => [
43+
'name' => [
44+
'en' => 'Mobile',
45+
'sl' => 'Mobilni',
46+
],
47+
'code' => 'mobile',
48+
'image_width' => 800,
49+
'image_height' => 400,
50+
'is_hidpi' => true,
51+
]);
52+
}
53+
54+
public function hidpi(): static
55+
{
56+
return $this->state(fn (array $attributes) => [
57+
'is_hidpi' => true,
58+
]);
59+
}
60+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace Eclipse\Cms\Factories;
4+
5+
use Eclipse\Cms\Models\Banner\Position;
6+
use Illuminate\Database\Eloquent\Factories\Factory;
7+
8+
class BannerPositionFactory extends Factory
9+
{
10+
protected $model = Position::class;
11+
12+
public function definition(): array
13+
{
14+
return [
15+
'name' => [
16+
'en' => 'Website Banners',
17+
'sl' => 'Spletni Bannerji',
18+
],
19+
'code' => 'website',
20+
];
21+
}
22+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
public function up(): void
10+
{
11+
Schema::create('cms_banner_positions', function (Blueprint $table) {
12+
$table->id();
13+
14+
if (config('eclipse-cms.tenancy.enabled')) {
15+
$tenantClass = config('eclipse-cms.tenancy.model');
16+
/** @var \Illuminate\Database\Eloquent\Model $tenant */
17+
$tenant = new $tenantClass;
18+
$table->foreignId(config('eclipse-cms.tenancy.foreign_key'))
19+
->constrained($tenant->getTable(), $tenant->getKeyName())
20+
->cascadeOnUpdate()
21+
->cascadeOnDelete();
22+
}
23+
24+
$table->string('name');
25+
$table->string('code', 20)->nullable();
26+
$table->timestamps();
27+
$table->softDeletes();
28+
});
29+
}
30+
31+
public function down(): void
32+
{
33+
Schema::dropIfExists('cms_banner_positions');
34+
}
35+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
public function up(): void
10+
{
11+
Schema::create('cms_banner_image_types', function (Blueprint $table) {
12+
$table->id();
13+
$table->foreignId('position_id');
14+
$table->string('name');
15+
$table->string('code')->nullable();
16+
$table->smallInteger('image_width')->nullable();
17+
$table->smallInteger('image_height')->nullable();
18+
$table->boolean('is_hidpi');
19+
});
20+
}
21+
22+
public function down(): void
23+
{
24+
Schema::dropIfExists('cms_banner_image_types');
25+
}
26+
};
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
public function up(): void
10+
{
11+
Schema::create('cms_banners', function (Blueprint $table) {
12+
$table->id();
13+
$table->foreignId('position_id')
14+
->constrained('cms_banner_positions', 'id')
15+
->cascadeOnUpdate()
16+
->cascadeOnDelete();
17+
$table->string('name');
18+
$table->string('link')->nullable();
19+
$table->boolean('is_active')->default(false);
20+
$table->boolean('new_tab')->default(false);
21+
$table->unsignedTinyInteger('sort')->default(0);
22+
$table->timestamps();
23+
$table->softDeletes();
24+
});
25+
}
26+
27+
public function down(): void
28+
{
29+
Schema::dropIfExists('cms_banners');
30+
}
31+
};
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
public function up(): void
10+
{
11+
Schema::create('cms_banner_images', function (Blueprint $table) {
12+
$table->id();
13+
$table->foreignId('banner_id')
14+
->constrained('cms_banners', 'id')
15+
->cascadeOnUpdate()
16+
->cascadeOnDelete();
17+
$table->foreignId('type_id')
18+
->constrained('cms_banner_image_types', 'id')
19+
->cascadeOnUpdate()
20+
->cascadeOnDelete();
21+
$table->string('file');
22+
$table->boolean('is_hidpi');
23+
$table->smallInteger('image_width');
24+
$table->smallInteger('image_height');
25+
});
26+
}
27+
28+
public function down(): void
29+
{
30+
Schema::dropIfExists('cms_banner_images');
31+
}
32+
};
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
public function up(): void
10+
{
11+
Schema::table('cms_banner_images', function (Blueprint $table) {
12+
$table->json('file')->change();
13+
});
14+
}
15+
16+
public function down(): void
17+
{
18+
Schema::table('cms_banner_images', function (Blueprint $table) {
19+
$table->string('file')->change();
20+
});
21+
}
22+
};

0 commit comments

Comments
 (0)