This commit is contained in:
Kamil Niemczycki 2023-07-28 12:18:13 +02:00
parent f5977c1b5d
commit d943e81da4
Signed by: kamilniemczycki
GPG Key ID: 04D4E2012F969213
14 changed files with 209 additions and 69 deletions

View File

@ -16,6 +16,7 @@ class AdminPanelController extends Controller
private ProjectRepository $projectRepository
) {
$this->categoryRepository->auth = true;
$this->projectRepository->auth = true;
}
public function __invoke(Request $request): InertiaResponse

View File

@ -29,12 +29,19 @@ class CategoryController
public function store(CategoryRequest $request)
{
$validate = $request->validated();
if ($category = $this->categoryRepository->create($validate)) {
return redirect()->route('admin.category.update', ['category' => $category])->with('message', 'Utworzono kategorię!');
}
// $validate = $request->validated();
// if ($category = $this->categoryRepository->create($validate)) {
// return redirect()
// ->route('admin.category.update', compact('category'))
// ->with('message', 'Utworzono kategorię!');
// }
return back()->withError(['message_error', 'Wystąpił błąd podczas tworzenia!']);
// return back()->withError(['message_error', 'Wystąpił błąd podczas tworzenia!']);
$category = $this->categoryRepository->create($request->validated());
return redirect()
->route('admin.category.update', compact('category'))
->with('message', 'Utworzono kategorię!');
}
public function create(): View

View File

@ -18,15 +18,14 @@ class ProjectController
$this->projectRepository->auth = true;
}
public function edit(Project $project): View
public function edit(Project $project): InertiaResponse
{
return view('dashboard.projects.edit', compact('project'));
return inertia('Projects/Edit', compact('project'));
}
public function update(ProjectRequest $request, Project $project): RedirectResponse
{
$validated = $request->validated();
if ($this->projectRepository->update($project, $validated)) {
if ($this->projectRepository->update($project, $request->validated())) {
return back()->with('message', 'Zaktualizowano projekt!');
}

View File

@ -1,34 +1,34 @@
<?php
declare(strict_types=1);
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class CategoryRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
public function rules(): array
{
return [
'name' => 'required|string|min:3|max:25',
'slug' => 'required|string|min:3|max:25',
'priority' => 'required|numeric|min:0|max:10',
'default' => 'nullable|in:yes,1,true,on',
'visible' => 'nullable|in:yes,1,true,on'
'default' => 'nullable|boolean',
'visible' => 'required|boolean',
];
}
protected function prepareForValidation(): void
{
$this->merge([
'default' => $this->toBoolean($this->default),
'visible' => $this->toBoolean($this->visible),
]);
}
private function toBoolean($booleable): bool
{
return filter_var($booleable, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
}
}

View File

@ -1,27 +1,14 @@
<?php
declare(strict_types=1);
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class ProjectRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
public function rules(): array
{
return [
'title' => 'required|string|min:3|max:255',
@ -37,7 +24,19 @@ class ProjectRequest extends FormRequest
'project_url' => 'nullable|string',
'project_version' => 'nullable|string',
'description' => 'nullable|string',
'visible' => 'nullable|in:yes,1,true,on'
'visible' => 'required|boolean'
];
}
protected function prepareForValidation(): void
{
$this->merge([
'visible' => $this->toBoolean($this->visible),
]);
}
private function toBoolean($booleable): bool
{
return filter_var($booleable, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
}
}

View File

@ -8,7 +8,6 @@ use App\Http\Resources\ProjectCollection;
use App\Http\Resources\ProjectResource;
use App\Models\Project;
use App\Repository\Interfaces\ProjectRepository as ProjectRepositoryInterface;
use Illuminate\Database\Query\Builder;
use Illuminate\Support\Collection;
class ProjectRepository implements ProjectRepositoryInterface
@ -104,11 +103,7 @@ class ProjectRepository implements ProjectRepositoryInterface
else
$toSave['update_date'] = null;
if (
isset($data['visible']) &&
in_array($data['visible'], ['yes', 'on', 1, true])
) $toSave['visible'] = true;
else $toSave['visible'] = false;
$toSave['visible'] = $data['visible'];
return $toSave;
}

2
package-lock.json generated
View File

@ -1,5 +1,5 @@
{
"name": "kamilcraft-api2",
"name": "application",
"lockfileVersion": 3,
"requires": true,
"packages": {

View File

@ -14,8 +14,12 @@ const form = useForm({
project_url: null,
project_version: null,
description: null,
visible: false,
visible: Boolean(false),
});
function createProject() {
form.post('/dashboard/project');
}
</script>
<template>
@ -25,7 +29,7 @@ const form = useForm({
<h1 class="text-3xl font-roboto font-light">Nowy projekt</h1>
</header>
<div>
<form class="flex flex-col gap-4" @submit.prevent>
<form class="flex flex-col gap-4" @submit.prevent="createProject">
<Input
id="title"
label="Tytuł"

View File

@ -0,0 +1,133 @@
<script setup>
import { useForm } from '@inertiajs/inertia-vue3';
import Input from '../../Share/Components/Input.vue';
const props = defineProps({
project: {
type: Object,
required: true,
},
});
const form = useForm({
title: props.project.title,
author: props.project.author,
categories: props.project.categories,
release_date: props.project.release_date,
update_date: props.project.update_date,
image_small: props.project.image_small,
image_medium: props.project.image_medium,
image_large: props.project.image_large,
project_url: props.project.project_url,
project_version: props.project.project_version,
description: props.project.description,
visible: Boolean(props.project.visible),
});
function updateProject() {
form.put(`/dashboard/project/${props.project.id}`);
}
</script>
<template>
<InertiaHead title="Nowy projekt" />
<div class="p-4">
<header class="pb-4">
<h1 class="text-3xl font-roboto font-light">Edytuj {{ project.title }}</h1>
</header>
<div>
<form class="flex flex-col gap-4" @submit.prevent="updateProject">
<Input
id="title"
label="Tytuł"
placeholder="Nazwa projektu"
v-model="form.title"
:error="form.errors.title"
/>
<Input
id="author"
label="Autor"
placeholder="Imię i nazwisko"
v-model="form.author"
:error="form.errors.author"
/>
<Input
id="categories"
label="Kategorie"
placeholder="Kategorie projektu"
v-model="form.categories"
:error="form.errors.categories"
/>
<Input
id="release_date"
label="Data pierwszego wydania"
type="date"
v-model="form.release_date"
:error="form.errors.release_date"
/>
<Input
id="update_date"
label="Data aktualizacji"
type="date"
v-model="form.update_date"
:error="form.errors.update_date"
/>
<Input
id="image_small"
label="Zdjęcie projekty - małe"
v-model="form.image_small"
:error="form.errors.image_small"
/>
<Input
id="image_medium"
label="Zdjęcie projekty - średnie"
v-model="form.image_medium"
:error="form.errors.image_medium"
/>
<Input
id="image_large"
label="Zdjęcie projekty - duże"
v-model="form.image_large"
:error="form.errors.image_large"
/>
<Input
id="project_url"
label="Adres projektu"
placeholder="Adres www strony projektu"
v-model="form.project_url"
:error="form.errors.project_url"
/>
<Input
id="project_url"
label="Adres projektu"
placeholder="Adres www strony projektu"
v-model="form.project_url"
:error="form.errors.project_url"
/>
<Input
id="project_version"
label="Wersja projektu"
placeholder="v1.0.0"
v-model="form.project_version"
:error="form.errors.project_version"
/>
<Input
id="description"
label="Opis"
type="textarea"
placeholder="Ładny opis"
v-model="form.description"
:error="form.errors.description"
textareaHeight="200px"
/>
<Input
id="visible"
label="Widoczny"
type="checkbox"
v-model="form.visible"
/>
<button class="px-0.5 py-1 rounded-lg bg-[#436da7] border-4 border-[#436da7] text-white text-lg hover:bg-transparent hover:text-[#436da7]">Aktualizuj projekt</button>
</form>
</div>
</div>
</template>

View File

@ -1,15 +1,18 @@
<script setup>
defineProps({
modelValue: String,
modelValue: [String, Boolean, Number],
id: String,
type: {
type: String,
default: 'text',
},
label: String,
placeholder: String,
placeholder: {
type: String,
default: null,
},
error: {
type: Object,
type: String,
default: null,
},
textareaHeight: {
@ -22,7 +25,8 @@ defineEmits(['update:modelValue']);
<template>
<div :class="['flex w-full', (type === 'checkbox' ? 'flex-row gap-2 items-center bg-gray-200 px-2 py-2 rounded-md' : 'flex-col gap-1')]">
<label :for="id"
<label v-if="id"
:for="id"
class="text-gray-500">{{ label }}</label>
<textarea v-if="type === 'textarea'"
:id="id"

View File

@ -2,7 +2,7 @@
</script>
<style lang="css">
<style lang="css" scoped>
.header {
background: linear-gradient(237.74deg,#1199a5,#436da7 83%);
}

View File

@ -2,7 +2,7 @@
</script>
<style lang="css">
<style lang="css" scoped>
.header {
@apply min-h-[220px];
background: linear-gradient(237.74deg,#1199a5,#436da7 83%);

View File

@ -18,11 +18,15 @@ defineProps({
v-for="(project, key) in projects"
:key="key"
>
<InertiaLink href="/dashboard">
<div class="px-3 py-2 bg-white hover:bg-zinc-300 cursor-pointer">
{{ project.title }}
<div class="flex items-center justify-between px-3 py-2 bg-white hover:bg-zinc-300 cursor-pointer">
<InertiaLink :href="`/dashboard/project/${project.id}`">{{ project.title }}</InertiaLink>
<div>
<InertiaLink
as="button"
class="px-2 py-1 bg-green-200"
:href="`/dashboard/project/${project.id}`">Edit</InertiaLink>
</div>
</div>
</InertiaLink>
</li>
</ul>
<div v-else>

6
webpack.mix.js vendored
View File

@ -1,6 +0,0 @@
const mix = require('laravel-mix');
mix.js('resources/js/app.js', 'public/js');
mix.sass('resources/sass/app.scss', 'public/css');
mix.sass('resources/sass/dashboard.scss', 'public/css');