Skip to content

Commit

Permalink
Fix dependency bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
adrolli committed Feb 11, 2025
1 parent cf87d62 commit d86be25
Show file tree
Hide file tree
Showing 2 changed files with 227 additions and 37 deletions.
227 changes: 227 additions & 0 deletions packages/builder/src/Blocks/Singles/Publish.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
<?php

declare(strict_types=1);

namespace Moox\Builder\Blocks\Singles;

use Moox\Builder\Blocks\AbstractBlock;

class Publish extends AbstractBlock
{
protected array $containsBlocks = [
'Moox\Builder\Blocks\Singles\Simple',
'Moox\Builder\Blocks\Singles\SoftDelete',
];

protected array $incompatibleBlocks = [
'Moox\Builder\Blocks\Singles\Light',
];

public function __construct(
string $name = 'publish',
string $label = 'Publish',
string $description = 'Publication status management',
) {
parent::__construct($name, $label, $description);

$this->useStatements = [
'model' => [
'use Illuminate\Database\Eloquent\Builder;',
],
'resource' => [
'forms' => ['use Filament\Forms\Components\DateTimePicker;'],
'columns' => ['use Filament\Tables\Columns\TextColumn;'],
'filters' => ['use Filament\Tables\Filters\Filter;'],
'actions' => ['use Filament\Actions\Action;'],
],
'pages' => [
'list' => [
// This is missing in the generated list page, why?
'use Illuminate\Database\Eloquent\Builder;',
// while this is generated
'use Moox\Core\Traits\Publish\SinglePublishInListPage;',
],
],
];

$this->traits['model'] = [
'Moox\Core\Traits\Publish\SinglePublishInModel',
'Moox\Core\Traits\Base\BaseInModel',
];
$this->traits['resource'] = [
'Moox\Core\Traits\Publish\SinglePublishInResource',
'Moox\Core\Traits\Base\BaseInResource',
];
$this->traits['pages']['list'] = [
'Moox\Core\Traits\Publish\SinglePublishInListPage',
'Moox\Core\Traits\Base\BaseInListPage',
];
$this->traits['pages']['view'] = [
'Moox\Core\Traits\Publish\SinglePublishInViewPage',
'Moox\Core\Traits\Base\BaseInViewPage',
];
$this->traits['pages']['edit'] = [
'Moox\Core\Traits\Publish\SinglePublishInEditPage',
'Moox\Core\Traits\Base\BaseInEditPage',
];
$this->traits['pages']['create'] = [
'Moox\Core\Traits\Publish\SinglePublishInCreatePage',
'Moox\Core\Traits\Base\BaseInCreatePage',
];

$this->methods['model'] = [
'scopes' => [
'public function scopePublished(Builder $query): Builder {
return $query->whereNotNull("published_at");
}',
'public function scopeScheduled(Builder $query): Builder {
return $query->whereNotNull("publish_at")
->whereNull("published_at");
}',
'public function scopeDraft(Builder $query): Builder {
return $query->whereNull("published_at")
->whereNull("publish_at");
}',
],
];

$this->methods['pages']['list'] = [
'protected function applyStatusFilter(Builder $query, string $status): Builder {
return match ($status) {
"published" => $query->published(),
"scheduled" => $query->scheduled(),
"draft" => $query->draft(),
default => $query,
};
}',
];

$this->metaFields['resource'] = [
'static::getFormActions()',
'static::getPublishAtFormField()',
];

$this->tableColumns['resource'] = [
"TextColumn::make('publish_at')
->label(__('core::core.publish_at'))
->dateTime()
->sortable()
->toggleable()",
"TextColumn::make('published_at')
->label(__('core::core.published_at'))
->dateTime()
->sortable()
->toggleable()",
];

$this->filters = [];
/* TODO: Fix this
$this->filters['resource'] = [
"Filter::make('published')
->label(__('core::core.published'))
->query(fn (Builder \$query): Builder => \$query->published())",
"Filter::make('scheduled')
->label(__('core::core.scheduled'))
->query(fn (Builder \$query): Builder => \$query->scheduled())",
"Filter::make('draft')
->label(__('core::core.draft'))
->query(fn (Builder \$query): Builder => \$query->draft())",
];
*/

$this->actions['pages']['edit']['header'] = [
"Action::make('publish')
->label(__('core::core.publish'))
->color('success')
->action(function (\$livewire) {
\$data = \$livewire->form->getState();
\$data['published_at'] = now();
\$livewire->form->fill(\$data);
\$livewire->save();
})
->visible(fn (\$record) => ! \$record->published_at)",
];

$this->migrations['fields'] = [
'$table->timestamp("published_at")->nullable()',
'$table->timestamp("publish_at")->nullable()',
'$table->softDeletes()',
];

$this->factories['model']['states'] = [
'published' => [
'published_at' => 'now()',
'publish_at' => 'now()',
],
'scheduled' => [
'publish_at' => 'fake()->dateTimeBetween("tomorrow", "+30 days")',
'published_at' => 'null',
],
'draft' => [
'publish_at' => 'null',
'published_at' => 'null',
],
];
}

public function getTabs(): array
{
return [
'all' => [
'label' => 'trans//core::core.all',
'icon' => 'gmdi-filter-list',
'query' => [
[
'field' => 'deleted_at',
'operator' => '=',
'value' => null,
],
],
],
'published' => [
'label' => 'trans//core::core.published',
'icon' => 'gmdi-check-circle',
'query' => [
[
'field' => 'publish_at',
'operator' => '<=',
'value' => 'now()',
],
],
],
'scheduled' => [
'label' => 'trans//core::core.scheduled',
'icon' => 'gmdi-schedule',
'query' => [
[
'field' => 'publish_at',
'operator' => '>',
'value' => 'now()',
],
],
],
'draft' => [
'label' => 'trans//core::core.draft',
'icon' => 'gmdi-text-snippet',
'query' => [
[
'field' => 'published_at',
'operator' => '=',
'value' => null,
],
],
],
'deleted' => [
'label' => 'trans//core::core.deleted',
'icon' => 'gmdi-delete',
'query' => [
[
'field' => 'deleted_at',
'operator' => '!=',
'value' => null,
],
],
],
];
}
}
37 changes: 0 additions & 37 deletions packages/user/src/Commands/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Moox\User\Commands;

use BezhanSalleh\FilamentShield\FilamentShieldServiceProvider;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Schema;
Expand Down Expand Up @@ -104,42 +103,6 @@ public function runMigrations(): void
}
}

public function customizeFilament(): void
{
info('Customizing Filament Shield translations...');

$translationPath = resource_path('lang/vendor/filament-shield');

if (! File::exists($translationPath)) {
$this->call('vendor:publish', [
'--provider' => FilamentShieldServiceProvider::class,
'--tag' => 'translations',
]);

info('Filament Shield translations published.');

return;
}

$locales = File::directories($translationPath);

foreach ($locales as $localePath) {
$files = File::files($localePath);
foreach ($files as $file) {
$translations = include $file->getPathname();
if (isset($translations['nav']['group'])) {
$translations['nav']['group'] = 'Moox User';
$outputPath = $file->getPathname();
$content = "<?php\n\nreturn ".print_r($translations, true).";\n";
File::put($outputPath, $content);
$this->info(sprintf('Updated %s in %s', $file->getFilename(), $localePath));
}
}
}

info('Filament Shield translations customization complete.');
}

public function registerPlugins(string $providerPath): void
{
if (File::exists($providerPath)) {
Expand Down

0 comments on commit d86be25

Please sign in to comment.