Skip to content

Commit

Permalink
wip on articles && badges
Browse files Browse the repository at this point in the history
  • Loading branch information
gheorghelupu17 committed Jul 4, 2023
1 parent 8fab257 commit 9d35c8b
Show file tree
Hide file tree
Showing 27 changed files with 458 additions and 857 deletions.
58 changes: 54 additions & 4 deletions app/Filament/Resources/ArticleResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,30 @@

use App\Filament\Resources\ArticleResource\Pages;
use App\Models\Article;
use Filament\Forms\Components\RichEditor;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\SpatieMediaLibraryFileUpload;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Toggle;
use Filament\Resources\Form;
use Filament\Resources\Resource;
use Filament\Resources\Table;
use Filament\Tables;
use Filament\Tables\Filters\Layout;
use Filament\Tables\Filters\SelectFilter;

class ArticleResource extends Resource
{
protected static ?string $model = Article::class;

protected static ?string $navigationGroup = 'Administrează';

protected static ?string $navigationLabel = 'Articole';

protected static ?string $label = 'Articol';

protected static ?string $pluralLabel = 'Articole';

protected static ?int $navigationSort = 7;

protected static ?string $navigationIcon = 'heroicon-o-collection';
Expand All @@ -25,22 +38,59 @@ public static function form(Form $form): Form
{
return $form
->schema([
//
]);
TextInput::make('title')
->required()
->label(__('article.title'))
->required()
->maxLength(255),
Select::make('category_id')
->relationship('category', 'name')
->required()
->label(__('article.category')),
RichEditor::make('content')
->required()
->label(__('article.content'))->columnSpanFull(),
TextInput::make('author')
->required()
->label(__('article.author'))
->required()
->maxLength(255),
Toggle::make('is_active')
->label(__('article.is_active'))
->required(),
SpatieMediaLibraryFileUpload::make('cover')
->collection('cover')
->label(__('article.cover_image'))
->required()
->acceptedFileTypes(['image/*'])
->columnSpanFull(),
SpatieMediaLibraryFileUpload::make('gallery')->collection('gallery')
->multiple()
->label(__('article.gallery'))
->enableReordering()->columnSpanFull(),

]);
}

public static function table(Table $table): Table
{
return $table
->columns([
//
Tables\Columns\TextColumn::make('title')->searchable()->label(__('article.title'))->searchable(),
Tables\Columns\TextColumn::make('category.name')->searchable()->label(__('article.category'))->sortable(),
Tables\Columns\TextColumn::make('created_at')->label(__('article.created_at'))->sortable(),

])
->filters([
//
SelectFilter::make('category')
->multiple()
->relationship('category', 'name')
->label(__('article.filter.category')),
])
->actions([
Tables\Actions\EditAction::make(),
])
->filtersLayout(Layout::AboveContent)
->bulkActions([
Tables\Actions\DeleteBulkAction::make(),
]);
Expand Down
14 changes: 12 additions & 2 deletions app/Filament/Resources/BadgeResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

use App\Filament\Resources\BadgeResource\Pages;
use App\Models\Badge;
use Filament\Forms\Components\SpatieMediaLibraryFileUpload;
use Filament\Forms\Components\TextInput;
use Filament\Resources\Form;
use Filament\Resources\Resource;
use Filament\Resources\Table;
Expand All @@ -25,15 +27,23 @@ public static function form(Form $form): Form
{
return $form
->schema([
//
TextInput::make('name')->required()->label(__('badge.name'))->maxLength(255),
SpatieMediaLibraryFileUpload::make('cover')
->collection('cover')
->label(__('badge.cover_image'))
->required()
->acceptedFileTypes(['image/*'])
->columnSpanFull(),
]);
}

public static function table(Table $table): Table
{
return $table
->columns([
//
Tables\Columns\TextColumn::make('name')
->searchable()
->sortable(),
])
->filters([
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static function form(Form $form): Form
Forms\Components\TextInput::make('name')
->required()
->maxLength(255),
Forms\Components\DatePicker::make('start_date')->after(now())->required(),
Forms\Components\DatePicker::make('start_date')->after('today')->required(),
Forms\Components\DatePicker::make('end_date')->after('start_date')->required(),
Forms\Components\Toggle::make('is_current')
->nullable(),
Expand Down
189 changes: 16 additions & 173 deletions app/Http/Controllers/ArticleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace App\Http\Controllers;

use App\Models\Article;
use App\Models\ArticleCategory;
use Illuminate\Http\Request;
use Inertia\Inertia;

Expand All @@ -14,192 +15,34 @@ public function index(Request $request)
{
// $query = Article::query();

$categories = ['SOCIAL', 'EDUCATIE', 'MEDIU', 'LOREM', 'LOREM IPSUM'];
$categories = ArticleCategory::whereHas('articles', function ($query) {
$query->where('is_active', true);
})->get();

$query = [
'current_page' => 1,
'data' => [
[
'id' => 1,
'title' => 'Importanța educației remediale în România în timpul pandemiei',
'content' => '<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Architecto accusantium praesentium eius, ut atque fuga culpa, similique sequi cum eos quis dolorum.</p>',
'author' => 'Ion Popescu',
'ong' => 'Asociatia Pentru Tine',
'image' => '/images/project_img.png',
'category' => 'SOCIAL',
'created_at' => '15.02.2022',
],
[
'id' => 2,
'title' => 'Importanța educației remediale în România în timpul pandemiei',
'content' => '<a href="google.com">Lorem ipsum dolor sit amet consectetur adipisicing elit. Architecto accusantium praesentium eius, ut atque fuga culpa, similique sequi cum eos quis dolorum.</a>',
'author' => 'Ion Popescu',
'ong' => 'Asociatia Pentru Tine',
'image' => '/images/project_img.png',
'category' => 'SOCIAL',
'created_at' => '15.02.2022',
],
[
'id' => 3,
'title' => 'Importanța educației remediale în România în timpul pandemiei',
'content' => '<div><ul><li>unu</li><li>doi</li></ul><img src=""></div>',
'author' => 'Ion Popescu',
'ong' => 'Asociatia Pentru Tine',
'image' => '/images/project_img.png',
'category' => 'SOCIAL',
'created_at' => '15.02.2022',
],
],
'first_page_url' => 'http://bursabinelui.test/articole?page=1',
'from' => 1,
'last_page' => 2,
'last_page_url'=> 'http://bursabinelui.test/articole?page=2',
'links' => [
[
'url' => 'http://bursabinelui.test/articole?page=1',
'label' => '1',
'active' => true,
],
[
'url'=> 'http://bursabinelui.test/articole?page=2',
'label'=> '2',
'active'=> false,
],
],
'next_page_url'=> 'http://bursabinelui.test/articole?page=1',
'path'=> 'http://bursabinelui.test/articole',
'per_page' =>15,
'prev_page_url' => null,
'to' => 15,
'total' => 20,

];
$articles = Article::active()->with('category');
if ($request->get('category')) {
$category = $categories->search(function (ArticleCategory $item) use ($request) {
return $item['slug'] == $request->get('category');
});
$articles = $articles->where('article_category_id', $category);
}
$articles = $articles->paginate(10);

return Inertia::render('Public/Articles/Articles', [
'categories' => $categories,
'query' => $query,
'query' => $articles,
]);
}

public function article(Article $article)
{
$article = [
'id' => 1,
'title' => 'Importanța educației remediale în România în timpul pandemiei',
'content' => '<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Architecto accusantium praesentium eius, ut atque fuga culpa, similique sequi cum eos quis dolorum.</p>',
'author' => 'Ion Popescu',
'ong' => 'Asociatia Pentru Tine',
'image' => '/images/project_img.png',
'category' => 'SOCIAL',
'created_at' => '15.02.2022',
];

$gallery = [
[
'src' => 'https://youtu.be/f-t2nWVauSE',
'type' => 'video',
],
[
'src' => '/images/project_img.png',
'type' => 'image',
],
[
'src' => '/images/project_img.png',
'type' => 'image',
],
[
'src' => '/images/project_img.png',
'type' => 'image',
],
[
'src' => 'https://youtu.be/f-t2nWVauSE',
'type' => 'video',
],
[
'src' => '/images/project_img.png',
'type' => 'image',
],
[
'src' => '/images/project_img.png',
'type' => 'image',
],
[
'src' => 'https://youtu.be/f-t2nWVauSE',
'type' => 'video',
],
[
'src' => '/images/project_img.png',
'type' => 'image',
],
[
'src' => '/images/project_img.png',
'type' => 'image',
],
[
'src' => 'https://youtu.be/f-t2nWVauSE',
'type' => 'video',
],
[
'src' => '/images/project_img.png',
'type' => 'image',
],
[
'src' => '/images/project_img.png',
'type' => 'image',
],
[
'src' => 'https://youtu.be/f-t2nWVauSE',
'type' => 'video',
],
[
'src' => '/images/project_img.png',
'type' => 'image',
],
[
'src' => '/images/project_img.png',
'type' => 'image',
],
[
'src' => '/images/project_img.png',
'type' => 'video',
],
[
'src' => '/images/project_img.png',
'type' => 'image',
],
[
'src' => '/images/project_img.png',
'type' => 'image',
],
[
'src' => '/images/project_img.png',
'type' => 'video',
],
[
'src' => '/images/project_img.png',
'type' => 'image',
],
[
'src' => '/images/project_img.png',
'type' => 'image',
],
[
'src' => '/images/project_img.png',
'type' => 'video',
],
[
'src' => '/images/project_img.png',
'type' => 'image',
],
[
'src' => '/images/project_img.png',
'type' => 'image',
],
];
$article->load('category');
$gallery = $article->getMedia('gallery');

return Inertia::render('Public/Articles/Article', [
'article' => $article,
'gallery' => $gallery,
'related' => $article->relatedArticles()->get()
]);
}
}
Loading

0 comments on commit 9d35c8b

Please sign in to comment.