Skip to content

Commit d86be25

Browse files
committed
Fix dependency bugs
1 parent cf87d62 commit d86be25

File tree

2 files changed

+227
-37
lines changed

2 files changed

+227
-37
lines changed
Lines changed: 227 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,227 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Moox\Builder\Blocks\Singles;
6+
7+
use Moox\Builder\Blocks\AbstractBlock;
8+
9+
class Publish extends AbstractBlock
10+
{
11+
protected array $containsBlocks = [
12+
'Moox\Builder\Blocks\Singles\Simple',
13+
'Moox\Builder\Blocks\Singles\SoftDelete',
14+
];
15+
16+
protected array $incompatibleBlocks = [
17+
'Moox\Builder\Blocks\Singles\Light',
18+
];
19+
20+
public function __construct(
21+
string $name = 'publish',
22+
string $label = 'Publish',
23+
string $description = 'Publication status management',
24+
) {
25+
parent::__construct($name, $label, $description);
26+
27+
$this->useStatements = [
28+
'model' => [
29+
'use Illuminate\Database\Eloquent\Builder;',
30+
],
31+
'resource' => [
32+
'forms' => ['use Filament\Forms\Components\DateTimePicker;'],
33+
'columns' => ['use Filament\Tables\Columns\TextColumn;'],
34+
'filters' => ['use Filament\Tables\Filters\Filter;'],
35+
'actions' => ['use Filament\Actions\Action;'],
36+
],
37+
'pages' => [
38+
'list' => [
39+
// This is missing in the generated list page, why?
40+
'use Illuminate\Database\Eloquent\Builder;',
41+
// while this is generated
42+
'use Moox\Core\Traits\Publish\SinglePublishInListPage;',
43+
],
44+
],
45+
];
46+
47+
$this->traits['model'] = [
48+
'Moox\Core\Traits\Publish\SinglePublishInModel',
49+
'Moox\Core\Traits\Base\BaseInModel',
50+
];
51+
$this->traits['resource'] = [
52+
'Moox\Core\Traits\Publish\SinglePublishInResource',
53+
'Moox\Core\Traits\Base\BaseInResource',
54+
];
55+
$this->traits['pages']['list'] = [
56+
'Moox\Core\Traits\Publish\SinglePublishInListPage',
57+
'Moox\Core\Traits\Base\BaseInListPage',
58+
];
59+
$this->traits['pages']['view'] = [
60+
'Moox\Core\Traits\Publish\SinglePublishInViewPage',
61+
'Moox\Core\Traits\Base\BaseInViewPage',
62+
];
63+
$this->traits['pages']['edit'] = [
64+
'Moox\Core\Traits\Publish\SinglePublishInEditPage',
65+
'Moox\Core\Traits\Base\BaseInEditPage',
66+
];
67+
$this->traits['pages']['create'] = [
68+
'Moox\Core\Traits\Publish\SinglePublishInCreatePage',
69+
'Moox\Core\Traits\Base\BaseInCreatePage',
70+
];
71+
72+
$this->methods['model'] = [
73+
'scopes' => [
74+
'public function scopePublished(Builder $query): Builder {
75+
return $query->whereNotNull("published_at");
76+
}',
77+
'public function scopeScheduled(Builder $query): Builder {
78+
return $query->whereNotNull("publish_at")
79+
->whereNull("published_at");
80+
}',
81+
'public function scopeDraft(Builder $query): Builder {
82+
return $query->whereNull("published_at")
83+
->whereNull("publish_at");
84+
}',
85+
],
86+
];
87+
88+
$this->methods['pages']['list'] = [
89+
'protected function applyStatusFilter(Builder $query, string $status): Builder {
90+
return match ($status) {
91+
"published" => $query->published(),
92+
"scheduled" => $query->scheduled(),
93+
"draft" => $query->draft(),
94+
default => $query,
95+
};
96+
}',
97+
];
98+
99+
$this->metaFields['resource'] = [
100+
'static::getFormActions()',
101+
'static::getPublishAtFormField()',
102+
];
103+
104+
$this->tableColumns['resource'] = [
105+
"TextColumn::make('publish_at')
106+
->label(__('core::core.publish_at'))
107+
->dateTime()
108+
->sortable()
109+
->toggleable()",
110+
"TextColumn::make('published_at')
111+
->label(__('core::core.published_at'))
112+
->dateTime()
113+
->sortable()
114+
->toggleable()",
115+
];
116+
117+
$this->filters = [];
118+
/* TODO: Fix this
119+
$this->filters['resource'] = [
120+
"Filter::make('published')
121+
->label(__('core::core.published'))
122+
->query(fn (Builder \$query): Builder => \$query->published())",
123+
"Filter::make('scheduled')
124+
->label(__('core::core.scheduled'))
125+
->query(fn (Builder \$query): Builder => \$query->scheduled())",
126+
"Filter::make('draft')
127+
->label(__('core::core.draft'))
128+
->query(fn (Builder \$query): Builder => \$query->draft())",
129+
];
130+
*/
131+
132+
$this->actions['pages']['edit']['header'] = [
133+
"Action::make('publish')
134+
->label(__('core::core.publish'))
135+
->color('success')
136+
->action(function (\$livewire) {
137+
\$data = \$livewire->form->getState();
138+
\$data['published_at'] = now();
139+
\$livewire->form->fill(\$data);
140+
\$livewire->save();
141+
})
142+
->visible(fn (\$record) => ! \$record->published_at)",
143+
];
144+
145+
$this->migrations['fields'] = [
146+
'$table->timestamp("published_at")->nullable()',
147+
'$table->timestamp("publish_at")->nullable()',
148+
'$table->softDeletes()',
149+
];
150+
151+
$this->factories['model']['states'] = [
152+
'published' => [
153+
'published_at' => 'now()',
154+
'publish_at' => 'now()',
155+
],
156+
'scheduled' => [
157+
'publish_at' => 'fake()->dateTimeBetween("tomorrow", "+30 days")',
158+
'published_at' => 'null',
159+
],
160+
'draft' => [
161+
'publish_at' => 'null',
162+
'published_at' => 'null',
163+
],
164+
];
165+
}
166+
167+
public function getTabs(): array
168+
{
169+
return [
170+
'all' => [
171+
'label' => 'trans//core::core.all',
172+
'icon' => 'gmdi-filter-list',
173+
'query' => [
174+
[
175+
'field' => 'deleted_at',
176+
'operator' => '=',
177+
'value' => null,
178+
],
179+
],
180+
],
181+
'published' => [
182+
'label' => 'trans//core::core.published',
183+
'icon' => 'gmdi-check-circle',
184+
'query' => [
185+
[
186+
'field' => 'publish_at',
187+
'operator' => '<=',
188+
'value' => 'now()',
189+
],
190+
],
191+
],
192+
'scheduled' => [
193+
'label' => 'trans//core::core.scheduled',
194+
'icon' => 'gmdi-schedule',
195+
'query' => [
196+
[
197+
'field' => 'publish_at',
198+
'operator' => '>',
199+
'value' => 'now()',
200+
],
201+
],
202+
],
203+
'draft' => [
204+
'label' => 'trans//core::core.draft',
205+
'icon' => 'gmdi-text-snippet',
206+
'query' => [
207+
[
208+
'field' => 'published_at',
209+
'operator' => '=',
210+
'value' => null,
211+
],
212+
],
213+
],
214+
'deleted' => [
215+
'label' => 'trans//core::core.deleted',
216+
'icon' => 'gmdi-delete',
217+
'query' => [
218+
[
219+
'field' => 'deleted_at',
220+
'operator' => '!=',
221+
'value' => null,
222+
],
223+
],
224+
],
225+
];
226+
}
227+
}

packages/user/src/Commands/InstallCommand.php

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Moox\User\Commands;
44

5-
use BezhanSalleh\FilamentShield\FilamentShieldServiceProvider;
65
use Illuminate\Console\Command;
76
use Illuminate\Support\Facades\File;
87
use Illuminate\Support\Facades\Schema;
@@ -104,42 +103,6 @@ public function runMigrations(): void
104103
}
105104
}
106105

107-
public function customizeFilament(): void
108-
{
109-
info('Customizing Filament Shield translations...');
110-
111-
$translationPath = resource_path('lang/vendor/filament-shield');
112-
113-
if (! File::exists($translationPath)) {
114-
$this->call('vendor:publish', [
115-
'--provider' => FilamentShieldServiceProvider::class,
116-
'--tag' => 'translations',
117-
]);
118-
119-
info('Filament Shield translations published.');
120-
121-
return;
122-
}
123-
124-
$locales = File::directories($translationPath);
125-
126-
foreach ($locales as $localePath) {
127-
$files = File::files($localePath);
128-
foreach ($files as $file) {
129-
$translations = include $file->getPathname();
130-
if (isset($translations['nav']['group'])) {
131-
$translations['nav']['group'] = 'Moox User';
132-
$outputPath = $file->getPathname();
133-
$content = "<?php\n\nreturn ".print_r($translations, true).";\n";
134-
File::put($outputPath, $content);
135-
$this->info(sprintf('Updated %s in %s', $file->getFilename(), $localePath));
136-
}
137-
}
138-
}
139-
140-
info('Filament Shield translations customization complete.');
141-
}
142-
143106
public function registerPlugins(string $providerPath): void
144107
{
145108
if (File::exists($providerPath)) {

0 commit comments

Comments
 (0)