Skip to content

Commit

Permalink
feat: component work (#83)
Browse files Browse the repository at this point in the history
* feat: add counter optional url field

* wip

* enable budget upper label

* fix: buget level add item

* wip

* feat: add decision number / date

* feat: add decision authors

* wip

* feat: localize datepicker
  • Loading branch information
andreiio authored Oct 26, 2022
1 parent 7258387 commit 4719103
Show file tree
Hide file tree
Showing 32 changed files with 767 additions and 37 deletions.
120 changes: 120 additions & 0 deletions app/Http/Controllers/Admin/DecisionAuthorController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<?php

declare(strict_types=1);

namespace App\Http\Controllers\Admin;

use App\Http\Requests\Admin\DecisionAuthorRequest;
use App\Http\Resources\Collections\DecisionAuthorCollection;
use App\Http\Resources\DecisionAuthorResource;
use App\Models\DecisionAuthor;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Http\RedirectResponse;
use Inertia\Inertia;
use Inertia\Response;

class DecisionAuthorController extends AdminController
{
public function index(): Response
{
return Inertia::render('Decisions/Authors/Index', [
'collection' => new DecisionAuthorCollection(
DecisionAuthor::query()
->withCount([
'decisions' => function (Builder $query) {
$query->withDrafted();
},
])
->sort()
->filter()
->paginate()
),
'subnav' => $this->subnav(),
]);
}

public function create(): Response
{
return Inertia::render('Decisions/Authors/Edit', [
//
])->model(DecisionAuthor::class);
}

public function store(DecisionAuthorRequest $request): RedirectResponse
{
$attributes = $request->validated();

$decisionAuthor = DecisionAuthor::create($attributes);

return redirect()->route('admin.decision_authors.edit', $decisionAuthor)
->with('success', __('decision_author.event.created'));
}

public function edit(DecisionAuthor $decisionAuthor): Response
{
return Inertia::render('Decisions/Authors/Edit', [
'resource' => DecisionAuthorResource::make($decisionAuthor),
'subnav' => $this->subnav(),
])->model(DecisionAuthor::class);
}

public function update(DecisionAuthorRequest $request, DecisionAuthor $decisionAuthor): RedirectResponse
{
$attributes = $request->validated();

$decisionAuthor->update($attributes);

return redirect()->route('admin.decision_authors.edit', $decisionAuthor)
->with('success', __('decision_author.event.updated'));
}

public function duplicate(DecisionAuthor $decisionAuthor): RedirectResponse
{
$duplicate = $decisionAuthor->duplicate();

return redirect()->route('admin.decision_authors.edit', $duplicate)
->with('success', __('decision_author.event.duplicated'));
}

public function destroy(DecisionAuthor $decisionAuthor): RedirectResponse
{
$decisionAuthor->delete();

return redirect()->route('admin.decision_authors.index')
->with('success', __('decision_author.event.deleted'));
}

public function restore(DecisionAuthor $decisionAuthor): RedirectResponse
{
$decisionAuthor->restore();

return redirect()->route('admin.decision_authors.edit', $decisionAuthor)
->with('success', __('decision_author.event.restored'));
}

public function forceDelete(DecisionAuthor $decisionAuthor): RedirectResponse
{
$decisionAuthor->forceDelete();

return redirect()->route('admin.decision_authors.index')
->with('success', __('decision_author.event.deleted'));
}

protected function subnav(): array
{
return [
[
'label' => 'decision.subnav.decisions',
'route' => 'admin.decisions.index',
],
[
'label' => 'decision.subnav.categories',
'route' => 'admin.decision_categories.index',
],
[
'label' => 'decision.subnav.authors',
'route' => 'admin.decision_authors.index',
],
];
}
}
4 changes: 4 additions & 0 deletions app/Http/Controllers/Admin/DecisionCategoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ protected function subnav(): array
'label' => 'decision.subnav.categories',
'route' => 'admin.decision_categories.index',
],
[
'label' => 'decision.subnav.authors',
'route' => 'admin.decision_authors.index',
],
];
}
}
9 changes: 9 additions & 0 deletions app/Http/Controllers/Admin/DecisionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\Http\Resources\Collections\DecisionCollection;
use App\Http\Resources\DecisionResource;
use App\Models\Decision;
use App\Models\DecisionAuthor;
use App\Models\DecisionCategory;
use Illuminate\Http\RedirectResponse;
use Inertia\Inertia;
Expand All @@ -33,6 +34,7 @@ public function create(): Response
{
return Inertia::render('Decisions/Edit', [
'categories' => DecisionCategory::all(['id', 'title']),
'authors' => DecisionAuthor::all(['id', 'title']),
'subnav' => $this->subnav(),
])->model(Decision::class);
}
Expand All @@ -44,6 +46,7 @@ public function store(DecisionRequest $request): RedirectResponse
$decision = Decision::create($attributes);

$decision->categories()->sync($attributes['categories']);
$decision->authors()->sync($attributes['authors']);

$decision->saveBlocks($attributes['blocks'])
->saveMedia($attributes['media']);
Expand All @@ -57,6 +60,7 @@ public function edit(Decision $decision): Response
return Inertia::render('Decisions/Edit', [
'resource' => DecisionResource::make($decision),
'categories' => DecisionCategory::all(['id', 'title']),
'authors' => DecisionAuthor::all(['id', 'title']),
'subnav' => $this->subnav(),
])->model(Decision::class);
}
Expand All @@ -68,6 +72,7 @@ public function update(DecisionRequest $request, Decision $decision): RedirectRe
$decision->update($attributes);

$decision->categories()->sync($attributes['categories']);
$decision->authors()->sync($attributes['authors']);

$decision->saveBlocks($attributes['blocks'])
->saveMedia($attributes['media']);
Expand Down Expand Up @@ -119,6 +124,10 @@ protected function subnav(): array
'label' => 'decision.subnav.categories',
'route' => 'admin.decision_categories.index',
],
[
'label' => 'decision.subnav.authors',
'route' => 'admin.decision_authors.index',
],
];
}
}
32 changes: 32 additions & 0 deletions app/Http/Controllers/Front/DecisionAuthorController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace App\Http\Controllers\Front;

use App\Http\Controllers\Controller;
use App\Models\DecisionAuthor;
use Illuminate\Http\RedirectResponse;
use Illuminate\View\View;

class DecisionAuthorController extends Controller
{
public function index(): RedirectResponse
{
return redirect()->route('front.decisions.index');
}

public function show(string $locale, DecisionAuthor $decisionAuthor): View
{
seo()
->title($decisionAuthor->title)
->description($decisionAuthor->description);

return view('front.decisions.category', [
'category' => $decisionAuthor,
'decisions' => $decisionAuthor
->decisions()
->paginate(12),
]);
}
}
1 change: 0 additions & 1 deletion app/Http/Controllers/Front/DecisionCategoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public function show(string $locale, DecisionCategory $decisionCategory): View
'category' => $decisionCategory,
'decisions' => $decisionCategory
->decisions()
->with('categories')
->paginate(12),
]);
}
Expand Down
26 changes: 26 additions & 0 deletions app/Http/Requests/Admin/DecisionAuthorRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace App\Http\Requests\Admin;

use App\Models\DecisionAuthor;
use App\Services\TranslatableFormRequestRules;
use Illuminate\Foundation\Http\FormRequest as BaseRequest;

class DecisionAuthorRequest extends BaseRequest
{
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules(): array
{
return TranslatableFormRequestRules::make(DecisionAuthor::class, [
'title' => ['required', 'string', 'max:200'],
'slug' => ['nullable', 'string', 'max:200'],
'description' => ['nullable', 'string'],
]);
}
}
4 changes: 2 additions & 2 deletions app/Http/Requests/Admin/DecisionCategoryRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace App\Http\Requests\Admin;

use App\Models\Decision;
use App\Models\DecisionCategory;
use App\Services\TranslatableFormRequestRules;
use Illuminate\Foundation\Http\FormRequest as BaseRequest;

Expand All @@ -17,7 +17,7 @@ class DecisionCategoryRequest extends BaseRequest
*/
public function rules(): array
{
return TranslatableFormRequestRules::make(Decision::class, [
return TranslatableFormRequestRules::make(DecisionCategory::class, [
'title' => ['required', 'string', 'max:200'],
'slug' => ['nullable', 'string', 'max:200'],
'description' => ['nullable', 'string'],
Expand Down
4 changes: 4 additions & 0 deletions app/Http/Requests/Admin/DecisionRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@ public function rules(): array
return TranslatableFormRequestRules::make(Decision::class, [
'title' => ['required', 'string', 'max:200'],
'slug' => ['nullable', 'string', 'max:200'],
'number' => ['nullable', 'string', 'max:200'],
'date' => ['nullable', 'date'],
'description' => ['nullable', 'string'],
'published_at' => ['nullable', 'date'],
'categories' => ['array'],
'categories.*' => ['required', 'exists:decision_categories,id'],
'authors' => ['array'],
'authors.*' => ['required', 'exists:decision_authors,id'],
'media' => ['array'],
'media.*.id' => ['required', 'exists:media'],
'blocks' => ['array'],
Expand Down
17 changes: 17 additions & 0 deletions app/Http/Resources/Collections/DecisionAuthorCollection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace App\Http\Resources\Collections;

class DecisionAuthorCollection extends ResourceCollection
{
/**
* The default table columns.
*
* @var array
*/
protected array $columns = [
'title', 'decisions_count',
];
}
2 changes: 1 addition & 1 deletion app/Http/Resources/Collections/DecisionCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ class DecisionCollection extends ResourceCollection
* @var array
*/
protected array $columns = [
'title', 'created_at',
'title', 'number', 'date', 'created_at',
];
}
46 changes: 46 additions & 0 deletions app/Http/Resources/DecisionAuthorResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types=1);

namespace App\Http\Resources;

use Illuminate\Http\Request;

class DecisionAuthorResource extends Resource
{
public array $routeMap = [
'admin.decision_authors.index' => 'index',
'admin.decision_authors.edit' => 'edit',
];

protected function index(Request $request): array
{
return [
'id' => $this->id,
'title' => $this->title,
'slug' => $this->slug,
'decisions_count' => $this->decisions_count,
'trashed' => $this->trashed(),
];
}

protected function edit(Request $request): array
{
return [
'id' => $this->id,
'title' => $this->getTranslations('title'),
'description' => $this->getTranslations('description'),
'slug' => $this->getTranslations('slug'),
];
}

protected function default(Request $request): array
{
$this->withoutPermissions();

return [
'id' => $this->id,
'title' => $this->title,
];
}
}
10 changes: 8 additions & 2 deletions app/Http/Resources/DecisionResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ protected function index(Request $request): array
'id' => $this->id,
'title' => $this->title,
'slug' => $this->slug,
'number' => $this->number,
'date' => $this->date?->toDateString(),
'created_at' => $this->created_at->toDateTimeString(),
'published_at' => $this->published_at?->toDateTimeString(),
'categories' => $this->categories,
'authors' => $this->authors,
'trashed' => $this->trashed(),
'status' => $this->status(),
];
Expand All @@ -37,6 +40,9 @@ protected function edit(Request $request): array
'created_at' => $this->created_at->toDateTimeString(),
'published_at' => $this->published_at?->toDateTimeString(),
'categories' => $this->categories->pluck('id'),
'authors' => $this->authors->pluck('id'),
'number' => $this->number,
'date' => $this->date,
'blocks' => BlockResource::collection($this->blocks),
'media' => MediaResource::collection(
$this->media()->whereIsOriginal()->get()
Expand All @@ -47,8 +53,8 @@ protected function edit(Request $request): array
protected function default(Request $request): array
{
return [
'id' => $this->id,
'title' => $this->title,
'id' => $this->id,
'title' => $this->title,
];
}
}
Loading

0 comments on commit 4719103

Please sign in to comment.