Skip to content

Commit 01c8e38

Browse files
committed
small unfinished feature for sneak peak demo
1 parent 69fd9e4 commit 01c8e38

File tree

4 files changed

+31
-11
lines changed

4 files changed

+31
-11
lines changed

app/Livewire/Project/EditProject.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,21 +141,16 @@ public function removePost(int $index): void
141141
}
142142
}
143143

144-
public function rules(): array
145-
{
146-
return $this->getState()->rules();
147-
}
148-
149144
/**
150145
* Save the project
151146
*/
152-
public function save()
147+
public function saveAs($stateName)
153148
{
154-
$validator = Validator::make($this->getValues(), $this->rules());
149+
$state = ProjectState::make($stateName, $this->getProject() ?? new Project);
150+
$validator = Validator::make($this->getValues(), $state->rules());
155151
$filtered = collect($validator->validate());
156152
$filteredMeta = $filtered->except('posts')->toArray();
157153
$filteredPosts = $filtered->get('posts') ?? [];
158-
159154
try {
160155
DB::beginTransaction();
161156
if ($this->isNew) {

app/States/Project/Draft.php

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

33
namespace App\States\Project;
44

5+
use App\Rules\ExactlyOneZeroMoneyRule;
6+
use App\Rules\FluxEditorRule;
7+
58
class Draft extends ProjectState
69
{
710
public static string $name = 'draft';
@@ -22,8 +25,25 @@ public function color(): string
2225
#[\Override]
2326
public function rules(): array
2427
{
28+
// default but nothing is required but the name
2529
return [
2630
'name' => 'required|string|max:128',
31+
'responsible' => 'sometimes|string|max:128|email',
32+
'org' => 'sometimes|string|max:64',
33+
'protocol' => 'sometimes|nullable|string|url',
34+
// 'recht' => 'required|string|in:...',
35+
// 'recht-additional' => 'sometimes|nullable|string',
36+
'date_start' => 'sometimes|date',
37+
'date_end' => 'sometimes|date|after:date_start',
38+
'beschreibung' => ['sometimes', 'string', new FluxEditorRule],
39+
'posts' => 'sometimes|array|min:1',
40+
'posts.*.id' => 'sometimes|integer',
41+
// 'posts.*.titel_id' => 'sometimes|integer|exists:App\Models\Legacy\LegacyBudgetItem,id',
42+
'posts.*.name' => 'sometimes|string|max:128|min:1',
43+
'posts.*.einnahmen' => 'sometimes|money:EUR',
44+
'posts.*.ausgaben' => 'sometimes|money:EUR',
45+
'posts.*.position' => 'sometimes|integer',
46+
'posts.*.bemerkung' => 'sometimes|string|max:256',
2747
];
2848
}
2949
}

lang/de/errors.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@
1616
'blog-link.title' => 'Blog und News',
1717
'blog-link.subtitle' => 'Lies den StuFis-Blog mit den neusten Updates',
1818
'flux-editor-malicious-html' => 'Fehlerhafte HTML-Tags',
19-
'one-money-has-to-be-zero' => 'Eines der beiden muss 0 sein.',
19+
'one-money-has-to-be-zero' => 'Maximal eines der beiden darf 0 sein.',
2020
];

resources/views/livewire/project/edit-project.blade.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<div class="flex flex-col items-end space-y-4">
2323
<div class="flex items-center space-x-4">
2424
<flux:button :href="url()->previous()" variant="outline" icon="arrow-left">Zurück</flux:button>
25-
<flux:button wire:click="save" variant="primary">
25+
<flux:button wire:click="saveAs('{{ $state_name }}')" variant="primary">
2626
Speichern
2727
</flux:button>
2828
</div>
@@ -349,9 +349,14 @@
349349
<div class="flex flex-col items-end space-y-4">
350350
<div class="flex items-center space-x-4">
351351
<flux:button :href="url()->previous()" variant="outline" icon="arrow-left">Zurück</flux:button>
352-
<flux:button wire:click="save" variant="primary">
352+
<flux:button wire:click="saveAs({{ $state_name }})" variant="primary">
353353
Speichern
354354
</flux:button>
355+
@if($this->getState()->equals(\App\States\Project\Draft::class))
356+
<flux:button wire:click="saveAs('wip')" variant="primary">
357+
Speichern als beantragt
358+
</flux:button>
359+
@endif
355360
</div>
356361
@error('save')
357362
<p class="text-red-600 text-sm">{{ $message }}</p>

0 commit comments

Comments
 (0)