Skip to content

Commit

Permalink
finish container resolution for admini
Browse files Browse the repository at this point in the history
  • Loading branch information
repl6669 committed Sep 5, 2024
1 parent 5456e89 commit 8f97c5e
Show file tree
Hide file tree
Showing 49 changed files with 171 additions and 154 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
use Lunar\Admin\Support\Resources\BaseResource;
use Lunar\Admin\Support\Tables\Columns\TranslatedTextColumn;
use Lunar\Facades\AttributeManifest;
use Lunar\Models\Contracts\AttributeGroup;
use Lunar\Models\Contracts\AttributeGroup as AttributeGroupContract;
use Lunar\Models\Language;

class AttributeGroupResource extends BaseResource
{
protected static ?string $permission = 'settings:manage-attributes';

protected static ?string $model = AttributeGroup::class;
protected static ?string $model = AttributeGroupContract::class;

protected static ?int $navigationSort = 1;

Expand Down Expand Up @@ -90,7 +90,7 @@ protected static function getNameFormComponent(): Component
if ($operation !== 'create') {
return;
}
$set('handle', Str::slug($state[Language::getDefault()->code]));
$set('handle', Str::slug($state[Language::modelClass()::getDefault()->code]));
})
->live(onBlur: true)
->autofocus();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function getDefaultForm(Form $form): Form
if ($operation !== 'create') {
return;
}
$set('handle', Str::slug($state[Language::getDefault()->code]));
$set('handle', Str::slug($state[Language::modelClass()::getDefault()->code]));
}),
TranslatedText::make('description')
->label(
Expand All @@ -51,7 +51,7 @@ public function getDefaultForm(Form $form): Form
->helperText(
__('lunarpanel::attribute.form.description.helper')
)
->afterStateHydrated(fn ($state, $component) => $state ?: $component->state([Language::getDefault()->code => null]))
->afterStateHydrated(fn ($state, $component) => $state ?: $component->state([Language::modelClass()::getDefault()->code => null]))
->maxLength(255),
Forms\Components\TextInput::make('handle')
->label(
Expand Down
4 changes: 2 additions & 2 deletions packages/admin/src/Filament/Resources/BrandResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
use Lunar\Admin\Filament\Resources\BrandResource\Pages;
use Lunar\Admin\Support\Forms\Components\Attributes;
use Lunar\Admin\Support\Resources\BaseResource;
use Lunar\Models\Contracts\Brand;
use Lunar\Models\Contracts\Brand as BrandContract;

class BrandResource extends BaseResource
{
protected static ?string $permission = 'catalog:manage-products';

protected static ?string $model = Brand::class;
protected static ?string $model = BrandContract::class;

protected static ?int $navigationSort = 3;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Lunar\Admin\Support\Pages\BaseManageRelatedRecords;
use Lunar\Admin\Support\Tables\Columns\TranslatedTextColumn;
use Lunar\Models\Collection;
use Lunar\Models\Contracts\Collection as CollectionContract;

class ManageBrandCollections extends BaseManageRelatedRecords
{
Expand Down Expand Up @@ -52,9 +53,9 @@ function (Forms\Components\Select $select) {
__('lunarpanel::brand.pages.collections.table.header_actions.attach.record_select.placeholder')
)
->getSearchResultsUsing(static function (Forms\Components\Select $component, string $search): array {
return Collection::search($search)
return Collection::modelClass()::search($search)
->get()
->mapWithKeys(fn (Collection $record): array => [$record->getKey() => $record->breadcrumb->push($record->translateAttribute('name'))->join(' > ')])
->mapWithKeys(fn (CollectionContract $record): array => [$record->getKey() => $record->breadcrumb->push($record->translateAttribute('name'))->join(' > ')])
->all();
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Lunar\Admin\Filament\Resources\BrandResource;
use Lunar\Admin\Filament\Resources\ProductResource;
use Lunar\Admin\Support\Pages\BaseManageRelatedRecords;
use Lunar\Models\Contracts\Product as ProductContract;
use Lunar\Models\Product;

class ManageBrandProducts extends BaseManageRelatedRecords
Expand Down Expand Up @@ -71,14 +72,14 @@ public function table(Table $table): Table
->required()
->searchable()
->getSearchResultsUsing(static function (Forms\Components\Select $component, string $search): array {
return Product::search($search)
return Product::modelClass()::search($search)
->get()
->mapWithKeys(fn (Product $record): array => [$record->getKey() => $record->translateAttribute('name')])
->mapWithKeys(fn (ProductContract $record): array => [$record->getKey() => $record->translateAttribute('name')])
->all();
}),
])
->action(function (array $arguments, array $data) {
Product::where('id', '=', $data['recordId'])
Product::modelClass()::where('id', '=', $data['recordId'])
->update([
'brand_id' => $this->getRecord()->id,
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

use Lunar\Admin\Filament\Resources\BrandResource;
use Lunar\Admin\Support\Resources\Pages\ManageUrlsRelatedRecords;
use Lunar\Models\Brand;
use Lunar\Models\Contracts\Brand as BrandContract;

class ManageBrandUrls extends ManageUrlsRelatedRecords
{
protected static string $resource = BrandResource::class;

protected static string $model = Brand::class;
protected static string $model = BrandContract::class;
}
4 changes: 2 additions & 2 deletions packages/admin/src/Filament/Resources/ChannelResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
use Illuminate\Support\Str;
use Lunar\Admin\Filament\Resources\ChannelResource\Pages;
use Lunar\Admin\Support\Resources\BaseResource;
use Lunar\Models\Contracts\Channel;
use Lunar\Models\Contracts\Channel as ChannelContract;

class ChannelResource extends BaseResource
{
protected static ?string $permission = 'settings:core';

protected static ?string $model = Channel::class;
protected static ?string $model = ChannelContract::class;

protected static ?int $navigationSort = 1;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
use Illuminate\Support\Str;
use Lunar\Admin\Filament\Resources\CollectionGroupResource\Pages;
use Lunar\Admin\Support\Resources\BaseResource;
use Lunar\Models\Contracts\CollectionGroup;
use Lunar\Models\Contracts\CollectionGroup as CollectionGroupContract;

class CollectionGroupResource extends BaseResource
{
protected static ?string $permission = 'catalog:manage-products';

protected static ?string $model = CollectionGroup::class;
protected static ?string $model = CollectionGroupContract::class;

protected static ?int $navigationSort = 3;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ public function sort($movedId, $siblingId, $direction = 'after')
{
// Look to use `afterNode`
DB::transaction(function () use ($movedId, $siblingId, $direction) {
$moved = Collection::find($movedId);
$sibling = Collection::find($siblingId);
$moved = Collection::modelClass()::find($movedId);
$sibling = Collection::modelClass()::find($siblingId);
$parent = $moved->parent;

if ($direction == 'after') {
Expand Down Expand Up @@ -121,7 +121,7 @@ public function toggleChildren($nodeId, $keepOpen = false)

if (! count($nodes) || $keepOpen) {
$childNodes = static::mapCollections(
Collection::whereParentId($nodeId)->withCount('children')->defaultOrder()->get()
Collection::modelClass()::whereParentId($nodeId)->withCount('children')->defaultOrder()->get()
);
}

Expand Down Expand Up @@ -161,11 +161,11 @@ public function makeRootAction()
return Action::make('makeRoot')->requiresConfirmation()->icon(
fn () => FilamentIcon::resolve('actions::make-collection-root-action')
)->action(function (array $arguments) {
$collection = Collection::find($arguments['id']);
$collection = Collection::modelClass()::find($arguments['id']);
$collection->makeRoot()->save();
$this->loadRootNodes();
})->hidden(function (array $arguments) {
return Collection::find($arguments['id'])->isRoot();
return Collection::modelClass()::find($arguments['id'])->isRoot();
});
}

Expand All @@ -191,12 +191,12 @@ public function moveAction()
->label(
__('lunarpanel::components.collection-tree-view.actions.move.form.target_id.label')
)
->model(Collection::class)
->model(Collection::modelClass())
->searchable()
->getSearchResultsUsing(static function (Forms\Components\Select $component, string $search): array {
return get_search_builder(Collection::class, $search)
return get_search_builder(Collection::modelClass(), $search)
->get()
->mapWithKeys(fn (Collection $record): array => [$record->getKey() => $record->breadcrumb->push($record->translateAttribute('name'))->join(' > ')])
->mapWithKeys(fn (CollectionContract $record): array => [$record->getKey() => $record->breadcrumb->push($record->translateAttribute('name'))->join(' > ')])
->all();
}),
])->after(
Expand All @@ -216,7 +216,7 @@ public function getTreeActions()

public function getTreeNodesProperty()
{
return Collection::query()
return Collection::modelClass()::query()
->when($this->record?->id,
fn ($query, $groupId) => $query->whereCollectionGroupId($groupId)
)->when($this->parentId,
Expand Down
6 changes: 3 additions & 3 deletions packages/admin/src/Filament/Resources/CollectionResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
use Lunar\Admin\Filament\Resources\CollectionResource\Pages;
use Lunar\Admin\Support\Forms\Components\Attributes;
use Lunar\Admin\Support\Resources\BaseResource;
use Lunar\Models\Contracts\Collection;
use Lunar\Models\Contracts\Collection as CollectionContract;

class CollectionResource extends BaseResource
{
protected static ?string $permission = 'catalog:manage-collections';

protected static ?string $model = Collection::class;
protected static ?string $model = CollectionContract::class;

protected static int $globalSearchResultsLimit = 5;

Expand All @@ -38,7 +38,7 @@ public static function getNavigationItems(): array
return [];
}

public static function getCollectionBreadcrumbs(Collection $collection): array
public static function getCollectionBreadcrumbs(CollectionContract $collection): array
{
$crumbs = [
CollectionGroupResource::getUrl('index') => CollectionGroupResource::getPluralLabel(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Lunar\Admin\Support\Pages\BaseEditRecord;
use Lunar\Facades\DB;
use Lunar\Models\Collection;
use Lunar\Models\Contracts\Collection as CollectionContract;

class EditCollection extends BaseEditRecord
{
Expand Down Expand Up @@ -51,27 +52,27 @@ protected function getDefaultHeaderActions(): array
return [
DeleteAction::make('delete')->form([
Forms\Components\Select::make('target_collection')
->model(Collection::class)
->model(Collection::modelClass())
->searchable()
->getSearchResultsUsing(static function (Forms\Components\Select $component, string $search) use ($record): array {
return get_search_builder(Collection::class, $search)
return get_search_builder(Collection::modelClass(), $search)
->get()
->reject(
fn ($result) => $result->isDescendantOf($record)
)
->mapWithKeys(fn (Collection $record): array => [$record->getKey() => $record->translateAttribute('name')])
->mapWithKeys(fn (CollectionContract $record): array => [$record->getKey() => $record->translateAttribute('name')])
->all();
})->helperText(
'Choose which collection the children of this collection should be transferred to.'
)->hidden(
fn () => ! $record->children()->count()
),
])->before(function (Collection $collection, array $data) {
])->before(function (CollectionContract $collection, array $data) {

$targetId = $data['target_collection'] ?? null;

if ($targetId) {
$parent = Collection::find($targetId);
$parent = Collection::modelClass()::find($targetId);

DB::beginTransaction();
foreach ($collection->children as $child) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Lunar\Admin\Filament\Resources\CollectionResource;
use Lunar\Admin\Filament\Resources\ProductResource;
use Lunar\Admin\Support\Pages\BaseManageRelatedRecords;
use Lunar\Models\Contracts\Product as ProductContract;
use Lunar\Models\Product;

class ManageCollectionProducts extends BaseManageRelatedRecords
Expand Down Expand Up @@ -91,13 +92,13 @@ public function table(Table $table): Table

return get_search_builder($relationModel, $search)
->get()
->mapWithKeys(fn (Product $record): array => [$record->getKey() => $record->translateAttribute('name')])
->mapWithKeys(fn (ProductContract $record): array => [$record->getKey() => $record->translateAttribute('name')])
->all();
}),
])->action(function (array $arguments, array $data, Form $form, Table $table) {
$relationship = Relation::noConstraints(fn () => $table->getRelationship());

$product = Product::find($data['recordId']);
$product = Product::modelClass()::find($data['recordId']);

$relationship->attach($product, [
'position' => $relationship->count() + 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

use Lunar\Admin\Filament\Resources\CollectionResource;
use Lunar\Admin\Support\Resources\Pages\ManageUrlsRelatedRecords;
use Lunar\Models\Collection;
use Lunar\Models\Contracts\Collection as CollectionContract;

class ManageCollectionUrls extends ManageUrlsRelatedRecords
{
protected static string $resource = CollectionResource::class;

protected static string $model = Collection::class;
protected static string $model = CollectionContract::class;

public function getBreadcrumbs(): array
{
Expand Down
4 changes: 2 additions & 2 deletions packages/admin/src/Filament/Resources/CurrencyResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
use Illuminate\Database\Eloquent\Model;
use Lunar\Admin\Filament\Resources\CurrencyResource\Pages;
use Lunar\Admin\Support\Resources\BaseResource;
use Lunar\Models\Contracts\Currency;
use Lunar\Models\Contracts\Currency as CurrencyContract;

class CurrencyResource extends BaseResource
{
protected static ?string $permission = 'settings:core';

protected static ?string $model = Currency::class;
protected static ?string $model = CurrencyContract::class;

protected static ?int $navigationSort = 1;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
use Lunar\Admin\Filament\Resources\CustomerGroupResource\Pages;
use Lunar\Admin\Support\Forms\Components\Attributes;
use Lunar\Admin\Support\Resources\BaseResource;
use Lunar\Models\Contracts\CustomerGroup;
use Lunar\Models\Contracts\CustomerGroup as CustomerGroupContract;

class CustomerGroupResource extends BaseResource
{
protected static ?string $permission = 'settings:core';

protected static ?string $model = CustomerGroup::class;
protected static ?string $model = CustomerGroupContract::class;

protected static ?int $navigationSort = 1;

Expand Down
4 changes: 2 additions & 2 deletions packages/admin/src/Filament/Resources/CustomerResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
use Lunar\Admin\Filament\Resources\CustomerResource\RelationManagers\UserRelationManager;
use Lunar\Admin\Filament\Resources\CustomerResource\Widgets\CustomerStatsOverviewWidget;
use Lunar\Admin\Support\Resources\BaseResource;
use Lunar\Models\Contracts\Customer;
use Lunar\Models\Contracts\Customer as CustomerContract;

class CustomerResource extends BaseResource
{
protected static ?string $permission = 'sales:manage-customers';

protected static ?string $model = Customer::class;
protected static ?string $model = CustomerContract::class;

protected static ?int $navigationSort = 2;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Illuminate\Database\Eloquent\Model;
use Lunar\Admin\Events\CustomerAddressEdited;
use Lunar\Admin\Support\RelationManagers\BaseRelationManager;
use Lunar\Models\Address;
use Lunar\Models\Contracts\Address as AddressContract;
use Lunar\Models\State;

class AddressRelationManager extends BaseRelationManager
Expand Down Expand Up @@ -71,7 +71,7 @@ public function getDefaultTable(Table $table): Table
->after(
fn (Model $record) => CustomerAddressEdited::dispatch($record)
)
->fillForm(fn (Address $record): array => [
->fillForm(fn (AddressContract $record): array => [
'title' => $record->title,
'first_name' => $record->first_name,
'last_name' => $record->last_name,
Expand Down Expand Up @@ -124,7 +124,7 @@ public function getDefaultTable(Table $table): Table
Forms\Components\TextInput::make('state')->label(
__('lunarpanel::address.form.state.label')
)->datalist(function ($record) {
return State::whereCountryId($record->country_id)
return State::modelClass()::whereCountryId($record->country_id)
->where('name', 'LIKE', "%{$record->state}%")
->get()->map(
fn ($state) => $state->name
Expand Down
Loading

0 comments on commit 8f97c5e

Please sign in to comment.