Skip to content

Commit

Permalink
Merge pull request #276 from ploi/package-updates
Browse files Browse the repository at this point in the history
Package updates & small tweaks
  • Loading branch information
Cannonb4ll authored Aug 20, 2024
2 parents badff22 + d46d7c0 commit 5c99c38
Show file tree
Hide file tree
Showing 6 changed files with 1,791 additions and 1,013 deletions.
74 changes: 34 additions & 40 deletions app/Filament/Resources/CommentResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use App\Models\Comment;
use Filament\Forms\Form;
use Filament\Support\Enums\Alignment;
use Filament\Tables\Actions\DeleteAction;
use Filament\Tables\Table;
use Filament\Resources\Resource;
use Filament\Forms\Components\Select;
Expand Down Expand Up @@ -44,44 +46,39 @@ public static function getPluralModelLabel(): string
public static function form(Form $form): Form
{
return $form
->schema(
[
->schema([
Section::make()
->columns()
->schema(
[
Select::make('user_id')
->label(trans('resources.comment.user'))
->columnSpan(1)
->relationship('user', 'name')
->searchable(),

Select::make('item_id')
->label(trans('resources.comment.item'))
->columnSpan(1)
->relationship('item', 'title')
->searchable(),

Toggle::make('private')
->label(trans('resources.comment.private'))
->helperText(trans('resources.comment.private-helper-text'))
->label('Private')
->default(false),

MarkdownEditor::make('content')
->label(trans('resources.comment.content'))
->columnSpan(2),
]
)
]
);
->schema([
Select::make('user_id')
->label(trans('resources.comment.user'))
->columnSpan(1)
->relationship('user', 'name')
->searchable(),

Select::make('item_id')
->label(trans('resources.comment.item'))
->columnSpan(1)
->relationship('item', 'title')
->searchable(),

Toggle::make('private')
->label(trans('resources.comment.private'))
->helperText(trans('resources.comment.private-helper-text'))
->label('Private')
->default(false),

MarkdownEditor::make('content')
->label(trans('resources.comment.content'))
->columnSpan(2),
])
]);
}

public static function table(Table $table): Table
{
return $table
->columns(
[
->columns([
TextColumn::make('content')
->label(trans('resources.comment.content'))
->wrap()
Expand All @@ -98,13 +95,10 @@ public static function table(Table $table): Table
->label(trans('resources.created-at'))
->dateTime()
->sortable(),
]
)
->filters(
[
//
]
)
])
->actions([
DeleteAction::make()->modalAlignment(Alignment::Left)
])
->defaultSort('created_at', 'desc');
}

Expand All @@ -118,9 +112,9 @@ public static function getRelations(): array
public static function getPages(): array
{
return [
'index' => Pages\ListComments::route('/'),
'index' => Pages\ListComments::route('/'),
'create' => Pages\CreateComment::route('/create'),
'edit' => Pages\EditComment::route('/{record}/edit'),
'edit' => Pages\EditComment::route('/{record}/edit'),
];
}
}
25 changes: 11 additions & 14 deletions app/Filament/Resources/ItemResource/Pages/EditItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function getHeaderActions(): array
Action::make('view_public')
->label(trans('resources.item.view-public'))
->color('gray')
->url(fn () => route('items.show', $this->record))
->url(fn() => route('items.show', $this->record))
->openUrlInNewTab(),

Action::make('flush_og_images')
Expand All @@ -43,16 +43,16 @@ function () {
->requiresConfirmation()
->modalHeading(trans('settings.og.delete-single'))
->modalAlignment(Alignment::Left)
->modalDescription(trans('settings.og.confirm-single')) ,
->modalDescription(trans('settings.og.confirm-single')),

Action::make('merge item')
->label(trans('resources.item.merge'))
->color('warning')
->action(
function (array $data): void {
/**
* @var Item $selectedItem
*/
* @var Item $selectedItem
*/
$selectedItem = Item::query()->find($data['item_id']);

if (!$selectedItem->hasVoted($this->record->user)) {
Expand All @@ -61,15 +61,15 @@ function (array $data): void {

$selectedItem->comments()->create(
[
'user_id' => auth()->id(),
'content' => sprintf(trans('resources.item.merged-content'), $this->record->title, $this->record->user->name, $this->record->content),
'private' => $data['private'],
'user_id' => auth()->id(),
'content' => sprintf(trans('resources.item.merged-content'), $this->record->title, $this->record->user->name, $this->record->content),
'private' => $data['private'],
]
);

$this->record->comments()->update(
[
'item_id' => $selectedItem->id,
'item_id' => $selectedItem->id,
]
);

Expand All @@ -85,9 +85,7 @@ function (array $data): void {
$this->redirect(ItemResource::getUrl());
}
)
->form(
[

->form([
Select::make('item_id')
->label(trans('resources.item.label'))
->options(Item::query()->whereNot('id', $this->record->id)->pluck('title', 'id'))
Expand All @@ -97,11 +95,10 @@ function (array $data): void {
Toggle::make('private')
->label(trans('resources.item.private-comment'))
->default(true),
]
)
])
->modalDescription(trans('resources.item.merge-helper-text'))
->modalSubmitActionLabel(trans('resources.item.merge-submit')),
DeleteAction::make(),
DeleteAction::make()->modalAlignment(Alignment::Left),
];
}

Expand Down
36 changes: 12 additions & 24 deletions app/Filament/Resources/VoteResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
namespace App\Filament\Resources;

use App\Models\Vote;
use Filament\Forms\Form;
use Filament\Tables\Table;
use Filament\Resources\Resource;
use Filament\Support\Enums\Alignment;
use Filament\Tables\Columns\IconColumn;
use Filament\Tables\Columns\TextColumn;
use Illuminate\Database\Eloquent\Model;
use Filament\Tables\Actions\DeleteAction;
use App\Filament\Resources\VoteResource\Pages;

class VoteResource extends Resource
Expand Down Expand Up @@ -39,26 +40,16 @@ public static function getPluralModelLabel(): string
return trans('resources.vote.label-plural');
}

public static function form(Form $form): Form
{
return $form
->schema(
[
//
]
);
}

public static function table(Table $table): Table
{
return $table
->columns(
[
->columns([
TextColumn::make('user.name')
->label(trans('resources.user.label')),
->label(trans('resources.user.label')),

TextColumn::make('model.title')
->label(trans('resources.vote.item')),
->label(trans('resources.vote.item'))
->searchable(),

IconColumn::make('subscribed')
->label(trans('resources.vote.subscribed'))
Expand All @@ -68,13 +59,10 @@ public static function table(Table $table): Table
->label(trans('resources.created-at'))
->dateTime()
->sortable(),
]
)
->filters(
[
//
]
)
])
->actions([
DeleteAction::make()->modalAlignment(Alignment::Left)
])
->defaultSort('created_at', 'desc');
}

Expand All @@ -88,9 +76,9 @@ public static function getRelations(): array
public static function getPages(): array
{
return [
'index' => Pages\ListVotes::route('/'),
'index' => Pages\ListVotes::route('/'),
'create' => Pages\CreateVote::route('/create'),
'edit' => Pages\EditVote::route('/{record}/edit'),
'edit' => Pages\EditVote::route('/{record}/edit'),
];
}

Expand Down
6 changes: 3 additions & 3 deletions app/Livewire/Header.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use App\Models\User;
use App\Enums\UserRole;
use App\Models\Project;
use Filament\Forms\Components\Placeholder;
use Livewire\Component;
use Filament\Actions\Action;
use App\Rules\ProfanityCheck;
Expand All @@ -20,6 +19,7 @@
use Filament\Forms\Components\TextInput;
use Filament\Notifications\Notification;
use Filament\Actions\Contracts\HasActions;
use Filament\Forms\Components\Placeholder;
use Filament\Forms\Components\MarkdownEditor;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Actions\Concerns\InteractsWithActions;
Expand Down Expand Up @@ -111,8 +111,8 @@ public function submitItemAction(): Action
if (app(GeneralSettings::class)->select_board_when_creating_item) {
$inputs[] = Select::make('board_id')
->label(trans('table.board'))
->visible(fn($get) => $get('project_id'))
->options(fn($get) => Project::find($get('project_id'))->boards()->where('can_users_create', true)->pluck('title', 'id'))
->visible(fn ($get) => $get('project_id'))
->options(fn ($get) => Project::find($get('project_id'))->boards()->where('can_users_create', true)->pluck('title', 'id'))
->required(app(GeneralSettings::class)->board_required_when_creating_item);
}

Expand Down
Loading

0 comments on commit 5c99c38

Please sign in to comment.