Skip to content

Commit

Permalink
Merge pull request #88 from lara-zeus/media-library
Browse files Browse the repository at this point in the history
Media library
  • Loading branch information
atmonshi authored May 20, 2023
2 parents e5c70d0 + 6ae9de5 commit f677be1
Show file tree
Hide file tree
Showing 21 changed files with 714 additions and 150 deletions.
314 changes: 185 additions & 129 deletions composer.lock

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions config/zeus-sky.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
*/
'page_uri_prefix' => 'page',

/**
* set the prefix for library URL.
*/
'library_uri_prefix' => 'library',

/**
* customize the models
*/
Expand All @@ -30,6 +35,7 @@
'post' => \LaraZeus\Sky\Models\Post::class,
'postStatus' => \LaraZeus\Sky\Models\PostStatus::class,
'tag' => \LaraZeus\Sky\Models\Tag::class,
'library' => \LaraZeus\Sky\Models\Library::class,
],

/**
Expand All @@ -40,6 +46,7 @@
LaraZeus\Sky\Filament\Resources\PageResource::class,
LaraZeus\Sky\Filament\Resources\TagResource::class,
LaraZeus\Sky\Filament\Resources\FaqResource::class,
LaraZeus\Sky\Filament\Resources\LibraryResource::class,
],

/**
Expand Down Expand Up @@ -98,4 +105,14 @@
* ex: https://placehold.co/600x400
*/
'default_featured_image' => null,

/**
* these types help you to render the items in the FE
* set it to null to hide it from the form
*/
'library_types' => [
'FILE' => 'File',
'IMAGE' => 'Image',
'VIDEO' => 'Video',
],
];
29 changes: 29 additions & 0 deletions database/factories/LibraryFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Database\Factories;

use Illuminate\Database\Eloquent\Factories\Factory;

class LibraryFactory extends Factory
{
public function getModel(): string
{
return config('zeus-sky.models.library');
}

/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'slug' => $this->faker->slug(2),
'title' => $this->faker->word,
'description' => $this->faker->sentence,
'type' => $this->faker->randomElements(config('zeus-sky.library_types')),
'file_path' => 'https://picsum.photos/200/300',
];
}
}
18 changes: 0 additions & 18 deletions database/migrations/2022_07_04_104832_add_indices_to_posts.php

This file was deleted.

36 changes: 36 additions & 0 deletions database/migrations/create_library_table.php.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

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

return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('libraries', function (Blueprint $table) {
$table->id();
$table->string('slug');
$table->text('title');
$table->text('description')->nullable();
$table->string('type')->nullable();
$table->string('file_path')->nullable();
$table->timestamps();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('libraries');
}
};
14 changes: 13 additions & 1 deletion database/seeders/SkySeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,21 @@ public function run()
->count(8)
->create();

foreach (config('zeus-sky.models.post')::all() as $post) { // loop through all posts
foreach (config('zeus-sky.models.post')::all() as $post) {
$random_tags = config('zeus-sky.models.tag')::all()->random(1)->first()->name;
$post->syncTagsWithType([$random_tags], 'category');
}

config('zeus-sky.models.tag')::create(['name' => ['en' => 'support docs', 'ar' => 'الدعم الفني'], 'type' => 'library']);
config('zeus-sky.models.tag')::create(['name' => ['en' => 'how to', 'ar' => 'كيف'], 'type' => 'library']);

config('zeus-sky.models.library')::factory()
->count(8)
->create();

foreach (config('zeus-sky.models.library')::all() as $library) {
$random_tags = config('zeus-sky.models.tag')::getWithType('library')->random(1)->first()->name;
$library->syncTagsWithType([$random_tags], 'library');
}
}
}
6 changes: 6 additions & 0 deletions docs/addons.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ to set the url of the FAQ from the `zeus-sky.php` config file:
'faq_uri_prefix' => 'faq',
```

## Library Addons
to set the url of the Library from the `zeus-sky.php` config file:
```php
'library_uri_prefix' => 'Library',
```

to disable any resource, remove it from the config:
```php
'enabled_resources' => [ ... ],
Expand Down
22 changes: 22 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ return [
*/
'page_uri_prefix' => 'page',

/**
* customize the models
*/
'models' => [
'faq' => \LaraZeus\Sky\Models\Faq::class,
'post' => \LaraZeus\Sky\Models\Post::class,
'postStatus' => \LaraZeus\Sky\Models\PostStatus::class,
'tag' => \LaraZeus\Sky\Models\Tag::class,
'library' => \LaraZeus\Sky\Models\Library::class,
],

/**
* enable or disable individual Resources.
*/
Expand All @@ -46,6 +57,7 @@ return [
LaraZeus\Sky\Filament\Resources\PageResource::class,
LaraZeus\Sky\Filament\Resources\TagResource::class,
LaraZeus\Sky\Filament\Resources\FaqResource::class,
LaraZeus\Sky\Filament\Resources\LibraryResource::class,
],

/**
Expand Down Expand Up @@ -88,5 +100,15 @@ return [
* default featured image, set to null to disable it.
*/
'default_featured_image' => null,

/**
* these types help you to render the items in the FE
* set it to null to hide it from the form
*/
'library_types' => [
'FILE' => 'File',
'IMAGE' => 'Image',
'VIDEO' => 'Video',
],
];
```
50 changes: 50 additions & 0 deletions resources/views/themes/zeus/addons/library-item.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<div x-data class="space-y-4 my-6 mx-4 ">

<x-slot name="header">
<h2>{{ $item->title }}</h2>
</x-slot>

<x-slot name="breadcrumps">
<li class="flex items-center">
<a href="{{ route('library') }}">{{ __('library') }}</a>
<x-iconpark-rightsmall-o class="fill-current w-4 h-4 mx-3" />
</li>

<li class="flex items-center">
Viewing {{ $item->title }}
</li>
</x-slot>

<x-filament::card>
<h1>{{ $item->title }}</h1>

<p>
{{ $item->description }}
</p>

<p class="text-base font-light text-gray-500">
<span>{{ __('created at') }}</span>:
<span>{{ $item->created_at->format('Y.m/d') }}-{{ $item->created_at->format('h:i a') }}</span>
</p>

@if($item->type === 'IMAGE')
<img class="mx-auto" src="{{ $item->file_path }}">
@endif

@if($item->type === 'FILE')
<div class="text-center">
<x-filament::button tag="a" target="_blank" href="{{ $item->file_path }}" class="mx-auto">
{{ __('Show File') }}
</x-filament::button>
</div>
@endif

@if($item->type === 'VIDEO')
<video width="100%" class="w-full" controls>
<source src="{{ $item->file_path }}">
Your browser does not support HTML video.
</video>
@endif

</x-filament::card>
</div>
40 changes: 40 additions & 0 deletions resources/views/themes/zeus/addons/library.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<div class="mx-4">

<x-slot name="header">
<h1>{{ __('Libraries') }}</h1>
</x-slot>

<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-2">
@foreach($categories as $category)
<x-zeus::box>
<h2>{{ $category->name }}</h2>
<div class="space-y-2">
@foreach($category->library as $library)
<div>
<a href="{{ route('library.item', ['slug' => $library->slug]) }}" class="flex flex-col py-2 px-1.5 hover:bg-gray-100 dark:hover:bg-gray-600 rounded-md transition ease-in-out duration-500 block cursor-pointer">
<div x-data class="flex items-center justify-between text-primary-600 dark:text-primary-400 hover:dark:text-primary-300">
<h3>{{ $library->title ?? '' }}</h3>
@if($library->type === 'IMAGE')
<x-heroicon-o-photograph x-tooltip.raw="{{ __('Image') }}" class="w-4 h-4 text-gray-400 dark:text-gray-500" />
@endif

@if($library->type === 'FILE')
<x-heroicon-o-document x-tooltip.raw="{{ __('File') }}" class="w-4 h-4 text-gray-400 dark:text-gray-500" />
@endif

@if($library->type === 'VIDEO')
<x-heroicon-o-film x-tooltip.raw="{{ __('Video') }}" class="w-4 h-4 text-gray-400 dark:text-gray-500" />
@endif
</div>
<cite class="text-sm text-secondary-600 dark:text-secondary-500 hover:dark:text-secondary-300">
{{ $library->description }}
</cite>
</a>
</div>
@endforeach
</div>
</x-zeus::box>
@endforeach
</div>

</div>
11 changes: 11 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use Illuminate\Support\Facades\Route;
use LaraZeus\Sky\Http\Livewire\Faq;
use LaraZeus\Sky\Http\Livewire\Library;
use LaraZeus\Sky\Http\Livewire\Page;
use LaraZeus\Sky\Http\Livewire\Post;
use LaraZeus\Sky\Http\Livewire\Posts;
Expand All @@ -27,3 +28,13 @@
->get(config('zeus-sky.faq_uri_prefix'), Faq::class)
->name('faq');
}

if (in_array('LaraZeus\Sky\Filament\Resources\LibraryResource', config('zeus-sky.enabled_resources'))) {
Route::middleware(config('zeus-sky.middleware'))
->get(config('zeus-sky.library_uri_prefix'), Library::class)
->name('library');

Route::middleware(config('zeus-sky.middleware'))
->get(config('zeus-sky.library_uri_prefix') . '/{slug}', \LaraZeus\Sky\Http\Livewire\LibraryItem::class)
->name('library.item');
}
Loading

0 comments on commit f677be1

Please sign in to comment.