Skip to content

Commit

Permalink
Merge pull request #170 from hellboy1975/release/0.1.2
Browse files Browse the repository at this point in the history
Release/0.1.2
  • Loading branch information
hellboy1975 authored Feb 14, 2024
2 parents 76565e7 + 2ecb030 commit 49e8b93
Show file tree
Hide file tree
Showing 56 changed files with 2,124 additions and 666 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ yarn-error.log
/public/build
/public/build/manifest.json
/public/vendor
/public/images
public/js/app.js.LICENSE.txt
/machines/fly-redis

Expand Down
27 changes: 26 additions & 1 deletion app/Filament/Resources/AttemptResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
use App\Models\Attempt;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Infolists;
use Filament\Infolists\Infolist;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Filters\TernaryFilter;
use Filament\Tables\Table;

class AttemptResource extends Resource
Expand All @@ -20,6 +23,26 @@ class AttemptResource extends Resource

protected static ?int $navigationSort = 9;

public static function infolist(Infolist $infolist): Infolist
{
return $infolist
->schema([
Infolists\Components\Section::make('Cave details')
->columns([
'default' => 1,
'xl' => 2,
])
->schema([
Infolists\Components\TextEntry::make('squeeze.name'),
Infolists\Components\IconEntry::make('success')
->boolean(),
Infolists\Components\TextEntry::make('user.name'),
Infolists\Components\TextEntry::make('date')->date(),
]),

]);
}

public static function form(Form $form): Form
{
return $form
Expand Down Expand Up @@ -67,10 +90,11 @@ public static function table(Table $table): Table
->sortable(),
])
->filters([
//
TernaryFilter::make('success'),
])
->actions([
Tables\Actions\EditAction::make()->iconButton(),
Tables\Actions\ViewAction::make()->iconButton(),
])
->bulkActions([
Tables\Actions\DeleteBulkAction::make(),
Expand All @@ -90,6 +114,7 @@ public static function getPages(): array
'index' => Pages\ListAttempts::route('/'),
'create' => Pages\CreateAttempt::route('/create'),
'edit' => Pages\EditAttempt::route('/{record}/edit'),
'view' => Pages\ViewAttempt::route('/{record}'),
];
}
}
11 changes: 11 additions & 0 deletions app/Filament/Resources/AttemptResource/Pages/ViewAttempt.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace App\Filament\Resources\AttemptResource\Pages;

use App\Filament\Resources\AttemptResource;
use Filament\Resources\Pages\ViewRecord;

class ViewAttempt extends ViewRecord
{
protected static string $resource = AttemptResource::class;
}
11 changes: 9 additions & 2 deletions app/Filament/Resources/CaveResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
use App\Filament\Resources\CaveResource\RelationManagers\SqueezesRelationManager;
use App\Filament\Resources\CaveResource\RelationManagers\VisitsRelationManager;
use App\Models\Cave;
use App\Models\User;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Infolists;
use Filament\Infolists\Components\Actions\Action as ActionsAction;
use Filament\Infolists\Infolist;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Actions\Action;
use Filament\Tables\Filters\SelectFilter;
use Filament\Tables\Table;

// use Filament\Forms\Components\Section;

class CaveResource extends Resource
{
protected static ?string $model = Cave::class;
Expand All @@ -41,6 +41,7 @@ public static function infolist(Infolist $infolist): Infolist
return $infolist
->schema([
Infolists\Components\Section::make('Cave details')
->description(fn (Cave $record): string => "Added by {$record->creator->name}")
->columns([
'default' => 1,
'xl' => 2,
Expand All @@ -49,8 +50,14 @@ public static function infolist(Infolist $infolist): Infolist
Infolists\Components\TextEntry::make('name'),
Infolists\Components\TextEntry::make('code'),
Infolists\Components\TextEntry::make('region.name'),
Infolists\Components\TextEntry::make('region.name'),
Infolists\Components\ImageEntry::make('main_picture')
->columnSpanFull(),
])->headerActions([
ActionsAction::make('Favourite')
->action(function (Cave $cave) {
User::toggleFavourite($cave);
})->icon(fn (Cave $record): string => User::hasFavourite($record) ? 'heroicon-m-heart' : 'heroicon-o-heart'),
]),

]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ class UsersRelationManager extends RelationManager
{
protected static string $relationship = 'users';

protected static ?string $recordTitleAttribute = 'email';
protected static ?string $recordTitleAttribute = 'name';

public function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('display_name')
Forms\Components\TextInput::make('name')
->required()
->maxLength(255),
Forms\Components\TextInput::make('email')
Forms\Components\TextInput::make('location')
->required()
->maxLength(255),
]);
Expand All @@ -31,24 +31,27 @@ public function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('display_name'),
Tables\Columns\TextColumn::make('email'),
Tables\Columns\TextColumn::make('name'),
Tables\Columns\TextColumn::make('location'),
])
->filters([
//
])
->headerActions([
// Tables\Actions\CreateAction::make(),
Tables\Actions\AttachAction::make(),
Tables\Actions\AttachAction::make()
->label('Add Member')
->recordSelectSearchColumns(['name', 'location'])
->modalSubmitActionLabel('Add')
->modalHeading('Add Club Member'),
])
->actions([
// Tables\Actions\EditAction::make(),
Tables\Actions\DetachAction::make()->iconButton(),
// Tables\Actions\DeleteAction::make(),
Tables\Actions\DetachAction::make()
->iconButton()
->modalHeading('Remove user')
->modalDescription("Are you sure you'd like to remove this user?"),
])
->bulkActions([
Tables\Actions\DetachBulkAction::make(),
// Tables\Actions\DeleteBulkAction::make(),
]);
}
}
198 changes: 198 additions & 0 deletions app/Filament/Resources/PostResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
<?php

namespace App\Filament\Resources;

use App\Filament\Resources\PostResource\Pages;
use App\Models\Post;
use Camya\Filament\Forms\Components\TitleWithSlugInput;
use Filament\Forms\Components\DateTimePicker;
use Filament\Forms\Components\FileUpload;
use Filament\Forms\Components\Group;
use Filament\Forms\Components\MarkdownEditor;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Form;
use Filament\Forms\Get;
use Filament\Infolists\Components\Section as ComponentsSection;
use Filament\Infolists\Components\TextEntry;
use Filament\Infolists\Infolist;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Filters\SelectFilter;
use Filament\Tables\Table;

class PostResource extends Resource
{
protected static ?string $model = Post::class;

protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';

protected static ?string $navigationGroup = 'Manage';

protected static ?int $navigationSort = 10;

public static function infolist(Infolist $infolist): Infolist
{
return $infolist
->schema([
ComponentsSection::make()->schema([
TextEntry::make('title'),
TextEntry::make('status')
->badge()
->color(fn (string $state): string => match ($state) {
'draft' => 'gray',
'reviewing' => 'warning',
'published' => 'success',
'rejected' => 'danger',
}),
TextEntry::make('post_type')
->badge()
->color(fn (string $state): string => match ($state) {
'news' => 'warning',
'page' => 'success',
'journal' => 'danger',
}),
TextEntry::make('description'),
])->columns(3),
ComponentsSection::make()->schema([
TextEntry::make('content')
->hiddenLabel()
->markdown(),
]),
]);
}

public static function form(Form $form): Form
{
return $form
->schema([
Group::make()
->schema([
Section::make('Content')
->schema([
TitleWithSlugInput::make(
fieldTitle: 'title', // The name of the field in your model that stores the title.
fieldSlug: 'slug', // The name of the field in your model that will store the slug.
),
TextInput::make('description')
->required(),
MarkdownEditor::make('content')
->required(),
FileUpload::make('featured_image')
->columnSpanFull()
->directory('postImages')
->disk('public')
->image()
->imageEditor()
->imageEditorAspectRatios([
'16:9',
'4:3',
'1:1',
]),
]),
])
->columnSpan(['lg' => 2]),
Group::make()
->schema([
Section::make('Info')->schema([
Select::make('post_type')
->default('news')
->options([
'news' => 'News',
'page' => 'Page',
'journal' => 'Journal',
])
->live(),
Select::make('status')
->options([
'draft' => 'Draft',
'reviewing' => 'Reviewing',
'published' => 'Published',
'rejected' => 'Rejected',
])
->default('draft'),
Select::make('user_id')
->relationship('author', 'name')
->label('Author')
->default(auth()->user()->id),
Select::make('parent_id')
->relationship('parent', 'title')
->label('Parent Page')
->visible(fn (Get $get): bool => ! $get('post_type') == 'page'),
DateTimePicker::make('published_at')
->default(now()),
])
->columnSpan(['lg' => 1]),
]),
])->columns(3);
}

public static function table(Table $table): Table
{
return $table
->columns([
TextColumn::make('title'),
TextColumn::make('post_type')
->badge()
->color(fn (string $state): string => match ($state) {
'news' => 'warning',
'page' => 'success',
'journal' => 'danger',
}),
TextColumn::make('status')
->badge()
->color(fn (string $state): string => match ($state) {
'draft' => 'gray',
'reviewing' => 'warning',
'published' => 'success',
'rejected' => 'danger',
}),
TextColumn::make('author.name'),
TextColumn::make('published_at')
->date(),
])
->filters([
SelectFilter::make('status')
->options([
'draft' => 'Draft',
'reviewing' => 'Reviewing',
'published' => 'Published',
'rejected' => 'Rejected',
]),
SelectFilter::make('post_type')
->options([
'news' => 'News',
'page' => 'Page',
'journal' => 'Journal',
]),
])
->actions([
Tables\Actions\ViewAction::make()->iconButton(),
Tables\Actions\EditAction::make()->iconButton(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
]);
}

public static function getRelations(): array
{
return [
//
];
}

public static function getPages(): array
{
return [
'index' => Pages\ListPosts::route('/'),
'create' => Pages\CreatePost::route('/create'),
'view' => Pages\ViewPost::route('/{record}'),
'edit' => Pages\EditPost::route('/{record}/edit'),
];
}
}
11 changes: 11 additions & 0 deletions app/Filament/Resources/PostResource/Pages/CreatePost.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace App\Filament\Resources\PostResource\Pages;

use App\Filament\Resources\PostResource;
use Filament\Resources\Pages\CreateRecord;

class CreatePost extends CreateRecord
{
protected static string $resource = PostResource::class;
}
Loading

0 comments on commit 49e8b93

Please sign in to comment.