Update to laravel 12, other changes.

This commit is contained in:
Simon Pocrnjič 2025-03-25 21:38:24 +01:00
parent 0f8cfd3f16
commit 86a021143a
22 changed files with 2820 additions and 1504 deletions

View File

@ -4,6 +4,8 @@
use App\Models\ClientCase;
use App\Models\Contract;
use Exception;
use Illuminate\Database\QueryException;
use Illuminate\Http\Request;
use Inertia\Inertia;
@ -121,26 +123,32 @@ public function updateContract(ClientCase $clientCase, String $uuid, Request $re
}
public function storeActivity(ClientCase $clientCase, Request $request) {
$attributes = $request->validate([
'due_date' => 'nullable|date',
'amount' => 'nullable|decimal:0,4',
'note' => 'string',
'action_id' => 'exists:\App\Models\Action,id',
'decision_id' => 'exists:\App\Models\Decision,id'
]);
//Create activity
$activity = $clientCase->activities()->create($attributes);
foreach ($activity->decision->events as $e) {
$class = '\\App\\Events\\' . $e->name;
event(new $class($clientCase));
}
try {
$attributes = $request->validate([
'due_date' => 'nullable|date',
'amount' => 'nullable|decimal:0,4',
'note' => 'nullable|string',
'action_id' => 'exists:\App\Models\Action,id',
'decision_id' => 'exists:\App\Models\Decision,id'
]);
return to_route('clientCase.show', $clientCase);
//Create activity
$row = $clientCase->activities()->create($attributes);
/*foreach ($activity->decision->events as $e) {
$class = '\\App\\Events\\' . $e->name;
event(new $class($clientCase));
}*/
logger()->info('Activity successfully inserted', $attributes);
return to_route('clientCase.show', $clientCase)->with('success', 'Successful created!');
} catch (QueryException $e) {
logger()->error('Database error occurred:', ['error' => $e->getMessage()]);
return back()->with('error', 'Failed to insert activity. ' . $e->getMessage());
} catch (Exception $e) {
logger()->error('An unexpected error occurred:', ['error' => $e->getMessage()]);
// Return a generic error response
return back()->with('error', 'An unexpected error occurred. Please try again later.');
}
}

View File

@ -0,0 +1,64 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class DecisionController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*/
public function show(string $id)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit(string $id)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, string $id)
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}
}

View File

@ -21,4 +21,31 @@ public function index(Request $request){
]
);
}
public function updateAction(int $id, Request $request) {
$row = \App\Models\Action::findOrFail($id);
$attributes = $request->validate([
'name' => 'required|string|max:50',
'color_tag' => 'nullable|string|max:25',
'decisions' => 'nullable|array',
'decisions.*.id' => 'required_with:decisions.*|integer|exists:decisions,id',
'decisions.*.name' => 'required_with:decisions.*|string|max:50'
]);
$decisionIds = collect($attributes['decisions'] ?? [])->pluck('id')->toArray();
\DB::transaction(function() use ($attributes, $decisionIds, $row) {
$row->update([
'name' => $attributes['name'],
'color_tag' => $attributes['color_tag']
]);
$row->decisions()->sync($decisionIds);
});
logger()->info('Model updated successfully', ['model_id' => $row->id]);
return to_route('settings')->with('success', 'Update successful!');
}
}

View File

@ -14,6 +14,8 @@ class Action extends Model
use HasFactory;
use Searchable;
protected $fillable = ['name', 'color_tag'];
public function decisions(): BelongsToMany
{
return $this->belongsToMany(\App\Models\Decision::class);

View File

@ -7,16 +7,15 @@
"require": {
"php": "^8.2",
"arielmejiadev/larapex-charts": "^2.1",
"diglactic/laravel-breadcrumbs": "^9.0",
"diglactic/laravel-breadcrumbs": "^10.0",
"http-interop/http-factory-guzzle": "^1.2",
"inertiajs/inertia-laravel": "^1.0",
"laravel/framework": "^11.9",
"inertiajs/inertia-laravel": "^2.0",
"laravel/framework": "12.0",
"laravel/jetstream": "^5.2",
"laravel/sanctum": "^4.0",
"laravel/scout": "^10.11",
"laravel/tinker": "^2.9",
"meilisearch/meilisearch-php": "^1.11",
"robertboes/inertia-breadcrumbs": "^0.6.0",
"tightenco/ziggy": "^2.0"
},
"require-dev": {
@ -24,8 +23,9 @@
"laravel/pint": "^1.13",
"laravel/sail": "^1.26",
"mockery/mockery": "^1.6",
"nunomaduro/collision": "^8.1",
"phpunit/phpunit": "^11.0.1"
"nunomaduro/collision": "8.7",
"pestphp/pest": "^3.7",
"phpunit/phpunit": "^11.3"
},
"autoload": {
"psr-4": {

2434
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,26 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('activities', function (Blueprint $table) {
$table->date('due_date')->nullable()->default(null)->change();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
//
}
};

1415
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -6,7 +6,7 @@
"build": "vite build"
},
"devDependencies": {
"@inertiajs/vue3": "^1.0.14",
"@inertiajs/vue3": "2.0",
"@mdi/js": "^7.4.47",
"@tailwindcss/forms": "^0.5.7",
"@tailwindcss/typography": "^0.5.10",
@ -28,7 +28,7 @@
"@headlessui/vue": "^1.7.23",
"@heroicons/vue": "^2.1.5",
"@vuepic/vue-datepicker": "^9.0.3",
"apexcharts": "^3.54.1",
"apexcharts": "^4.0.0",
"flowbite": "^2.5.2",
"flowbite-vue": "^0.1.6",
"lodash": "^4.17.21",

View File

@ -58,7 +58,7 @@ const update = () => {
props.options.editor_data.form.route.params,
formUpdate[props.options.editor_data.form.key]
)
formUpdate.put(putRoute, {
onSuccess: () => {
closeEditor();

View File

@ -0,0 +1,30 @@
<script setup>
import { ref, watch } from 'vue';
defineProps({
type: {
type: String,
default: 'submit',
},
bgcolor: {
type: String,
default: 'bg-blue-500'
},
});
const isHover = ref(false);
watch(
() => isHover.value,
(isHover) => {
console.log(isHover)
}
)
</script>
<template>
<button :type="type" class="inline-flex items-center px-4 py-2 bg-blue-500 border border-transparent rounded-md font-semibold text-xs text-white uppercase tracking-widest hover:bg-blue-700 focus:bg-blue-700 active:bg-blue-900 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2 disabled:opacity-50 transition ease-in-out duration-150" :class="[bgcolor, color]">
<slot />
</button>
</template>

View File

@ -1,10 +1,12 @@
<script setup>
import ActionMessage from '@/Components/ActionMessage.vue';
import BasicButton from '@/Components/buttons/BasicButton.vue';
import Drawer from '@/Components/Drawer.vue';
import InputLabel from '@/Components/InputLabel.vue';
import PrimaryButton from '@/Components/PrimaryButton.vue';
import SectionTitle from '@/Components/SectionTitle.vue';
import TextInput from '@/Components/TextInput.vue';
import { PlusIcon } from '@/Utilities/Icons';
import { useForm } from '@inertiajs/vue3';
import { FwbTextarea } from 'flowbite-vue';
import { ref, watch } from 'vue';
@ -45,6 +47,17 @@ watch(
}
);
watch(
() => form.due_date,
(due_date) => {
if (due_date) {
let date = new Date(form.due_date).toISOString().split('T')[0];
console.table({old: due_date, new: date});
}
}
);
const store = () => {
console.table({
due_date: form.due_date,
@ -55,13 +68,19 @@ const store = () => {
});
form.post(route('clientCase.activity.store', props.client_case), {
onBefore: () => {
if(form.due_date !== null || form.due_date !== '') {
form.due_date = new Date(form.due_date).toISOString();
if(form.due_date) {
form.due_date = new Date(form.due_date).toISOString().split('T')[0];
}
},
},
onSuccess: () => {
close();
form.reset();
},
onError: (errors) => {
console.log('Validation or server error:', errors);
},
onFinish: () => {
console.log('Request finished processing.')
}
});
}
@ -75,32 +94,6 @@ const store = () => {
<template #title>Dodaj aktivnost</template>
<template #content>
<form @submit.prevent="store">
<SectionTitle class="mt-4 border-b mb-4">
<template #title>
Aktivnost
</template>
</SectionTitle>
<div class="col-span-6 sm:col-span-4">
<InputLabel for="activityDueDate" value="Datum zapadlosti"/>
<vue-date-picker
id="activityDueDate"
:enable-time-picker="false"
format="dd.MM.yyyy"
class="mt-1 block w-full"
v-model="form.due_date"
/>
</div>
<div class="col-span-6 sm:col-span-4">
<InputLabel for="activityAmount" value="Znesek"/>
<TextInput
id="activityAmount"
ref="activityAmountinput"
v-model="form.amount"
type="number"
class="mt-1 block w-full"
autocomplete="0.00"
/>
</div>
<div class="col-span-6 sm:col-span-4">
<InputLabel for="activityAction" value="Akcija"/>
<select
@ -134,14 +127,37 @@ const store = () => {
class="block w-full border-gray-300 focus:border-indigo-500 focus:ring-indigo-500 rounded-md shadow-sm"
/>
</div>
<div class="col-span-6 sm:col-span-4">
<InputLabel for="activityDueDate" value="Datum zapadlosti"/>
<vue-date-picker
id="activityDueDate"
:enable-time-picker="false"
format="dd.MM.yyyy"
class="mt-1 block w-full"
v-model="form.due_date"
/>
</div>
<div class="col-span-6 sm:col-span-4">
<InputLabel for="activityAmount" value="Znesek"/>
<TextInput
id="activityAmount"
ref="activityAmountinput"
v-model="form.amount"
type="number"
class="mt-1 block w-full"
autocomplete="0.00"
/>
</div>
<div class="flex justify-end mt-4">
<ActionMessage :on="form.recentlySuccessful" class="me-3">
Saved.
Shranjuje.
</ActionMessage>
<PrimaryButton :class="{ 'opacity-25': form.processing }" :disabled="form.processing">
Save
</PrimaryButton>
<BasicButton
:class="{ 'opacity-25': form.processing }"
:disabled="form.processing"
>
Shrani
</BasicButton>
</div>
</form>
</template>

View File

@ -23,7 +23,7 @@ const createBody = (data) => {
data.forEach((p) => {
const createdDate = new Date(p.created_at).toLocaleDateString('de');
const dueDate = (p.due_date === null) ? new Date().toLocaleDateString('de') : null;
const dueDate = (p.due_date) ? new Date().toLocaleDateString('de') : null;
const cols = [
C_TD.make(createdDate, 'body' ),

View File

@ -9,6 +9,7 @@ import ContractTable from "./Partials/ContractTable.vue";
import ActivityDrawer from "./Partials/ActivityDrawer.vue";
import ActivityTable from "./Partials/ActivityTable.vue";
import { AngleDownIcon, AngleUpIcon } from "@/Utilities/Icons";
import Pagination from "@/Components/Pagination.vue";
const props = defineProps({
client: Object,
@ -134,13 +135,15 @@ const hideClietnDetails = () => {
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
<div class="bg-white overflow-hidden shadow-xl sm:rounded-lg border-l-4">
<div class="mx-auto max-w-4x1">
<div class="flex justify-between p-3">
<div class="flex justify-between p-4">
<SectionTitle>
<template #title> Aktivnosti </template>
<template #title>Aktivnosti</template>
</SectionTitle>
<FwbButton @click="openDrawerAddActivity">Nova</FwbButton>
</div>
<ActivityTable :client_case="client_case" :activities="activities" />
<Pagination :links="activities.links" :from="activities.from" :to="activities.to" :total="activities.total" />
</div>
</div>
</div>

View File

@ -1,25 +1,26 @@
<script setup>
import { FwbTable, FwbTableBody, FwbTableHead, FwbTableHeadCell, FwbTableCell, FwbTableRow } from 'flowbite-vue';
import { EditIcon, TrashBinIcon } from '@/Utilities/Icons';
import { FwbTable, FwbTableBody, FwbTableHead, FwbTableHeadCell, FwbTableCell, FwbTableRow, FwbDropdown } from 'flowbite-vue';
import { DottedMenu, EditIcon, TrashBinIcon } from '@/Utilities/Icons';
import Drawer from '@/Components/Drawer.vue';
import { onMounted, ref } from 'vue';
import { useForm } from '@inertiajs/vue3';
import InputLabel from '@/Components/InputLabel.vue';
import TextInput from '@/Components/TextInput.vue';
import Multiselect from 'vue-multiselect';
import PrimaryButton from '@/Components/PrimaryButton.vue';
import ActionMessage from '@/Components/ActionMessage.vue';
const props = defineProps({
actions: Array,
decisions: Array
});
const menuDropdown = ref();
const drawerEdit = ref(false);
const selectOptions = ref([]);
const selectValue = ref([]);
const form = useForm({
id: 0,
name: '',
@ -32,39 +33,43 @@ const openEditDrawer = (item) => {
form.name = item.name;
form.color_tag = item.color_tag;
drawerEdit.value = true;
console.log(item.decisions);
item.decisions.forEach((d) => {
selectValue.value.push({
form.decisions.push({
name: d.name,
code: d.name.substring(0,2).toLowerCase() + d.id
id: d.id
});
})
}
const closeEditDrawer = () => {
form.reset();
drawerEdit.value = false;
form.reset();
}
const onColorPickerChange = () => {
console.log(form.color_tag);
}
onMounted(() => {
props.decisions.forEach((d) => {
selectOptions.value.push({
name: d.name,
code: d.name.substring(0,2).toLowerCase() + d.id
id: d.id
});
});
console.log(selectOptions.value);
});
});
const update = () => {
form.put(route('settings.actions.update', { id: form.id }), {
onSuccess: () => {
closeEditDrawer();
},
});
};
</script>
<template>
<fwb-table>
@ -84,7 +89,7 @@ onMounted(() => {
<fwb-table-cell>{{ act.color_tag }}</fwb-table-cell>
<fwb-table-cell>{{ act.decisions.length }}</fwb-table-cell>
<fwb-table-cell>
<button @click="openEditDrawer(act)"><EditIcon /></button>
<button class="px-2" @click="openEditDrawer(act)"><EditIcon size="md" css="text-gray-500" /></button>
</fwb-table-cell>
</fwb-table-row>
</fwb-table-body>
@ -98,7 +103,7 @@ onMounted(() => {
<span>Spremeni akcijo</span>
</template>
<template #content>
<form @submit.prevent="">
<form @submit.prevent="update">
<div class="col-span-6 sm:col-span-4">
<InputLabel for="name" value="Ime"/>
<TextInput
@ -131,15 +136,25 @@ onMounted(() => {
<multiselect
id="decisions"
ref="decisionsSelect"
v-model="selectValue"
v-model="form.decisions"
:options="selectOptions"
:multiple="true"
track-by="code"
track-by="id"
:taggable="true"
placeholder="Dodaj odločitev"
label="name"
/>
</div>
<div class="flex justify-end mt-4">
<ActionMessage :on="form.recentlySuccessful" class="me-3">
Shranjuje.
</ActionMessage>
<PrimaryButton :class="{ 'opacity-25': form.processing }" :disabled="form.processing">
Shrani
</PrimaryButton>
</div>
</form>
</template>
</Drawer>

View File

@ -53,7 +53,7 @@ const AlignCenterIcon = {
const EditIcon = {
__proto__: Icon,
template: `<svg class="dark:text-white" :class="[defineSize(size),css]" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24">
template: `<svg :class="[defineSize(size),css]" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24">
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m14.304 4.844 2.852 2.852M7 7H4a1 1 0 0 0-1 1v10a1 1 0 0 0 1 1h11a1 1 0 0 0 1-1v-4.5m2.409-9.91a2.017 2.017 0 0 1 0 2.853l-6.844 6.844L8 14l.713-3.565 6.844-6.844a2.015 2.015 0 0 1 2.852 0Z"/>
</svg>`
}
@ -121,6 +121,14 @@ const PlusIcon = {
`
}
const DottedMenu = {
__proto__: Icon,
template: `<svg :class="[defineSize(size),css]" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 4 15">
<path d="M3.5 1.5a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0Zm0 6.041a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0Zm0 5.959a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0Z" />
</svg>
`
}
export {
AddressBookIcon,
AlignCenterIcon,
@ -132,5 +140,6 @@ export {
AngleUpIcon,
UserEditIcon,
CirclePlusIcon,
PlusIcon
PlusIcon,
DottedMenu
};

View File

@ -1,8 +1,21 @@
<?php
use Illuminate\Foundation\Inspiring;
/*use Illuminate\Foundation\Inspiring;
use Illuminate\Support\Facades\Artisan;
Artisan::command('inspire', function () {
$this->comment(Inspiring::quote());
})->purpose('Display an inspiring quote')->hourly();
})->purpose('Display an inspiring quote')->hourly();*/
Artisan::command('question', function () {
$name = $this->ask('What is your name?');
$language = $this->choice('Which language do you prefer?', [
'PHP',
'Ruby',
'Python',
]);
$this->line('Your name is '.$name.' and you prefer '.$language.'.');
});

View File

@ -110,9 +110,10 @@
Route::delete('client-cases/{client_case:uuid}/contract/{uuid}', [ClientCaseContoller::class, 'deleteContract'])->name('clientCase.contract.delete');
//client-case / activity
Route::post('client-cases/{client_case:uuid}/activity', [ClientCaseContoller::class, 'storeActivity'])->name('clientCase.activity.store');
//settings
Route::get('settings', [SettingController::class, 'index'])->name('settings');
Route::put('settings/actions/{id}', [SettingController::class, 'updateAction'])->name('settings.actions.update');
//Route::put()
//types
Route::get('types/address', function(Request $request){

View File

@ -0,0 +1,22 @@
<?php
namespace Tests\Feature;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;
use App\Models\User;
class InsertDatabaseTest extends TestCase
{
use RefreshDatabase;
/**
* A basic feature test example.
*/
public function test_example(): void
{
$this->actingAs($user = User::factory()->create());
$this->assertTrue(false);
}
}

View File

@ -6,5 +6,8 @@
abstract class TestCase extends BaseTestCase
{
//
public function testBasicTest(): void
{
$this->assertTrue(true);
}
}

View File

@ -0,0 +1,23 @@
<?php
namespace Tests\Unit;
use Illuminate\Foundation\Testing\WithConsoleEvents;
use Tests\TestCase;
class ConsoleEventTest extends TestCase
{
use WithConsoleEvents;
/**
* A basic unit test example.
*/
public function test_example(): void
{
$this->artisan('question')
->expectsQuestion('What is your name?', 'Taylor Otwell')
->expectsQuestion('Which language do you prefer?', 'PHP')
->expectsOutput('Your name is Taylor Otwell and you prefer PHP.')
->doesntExpectOutput('Your name is Taylor Otwell and you prefer Ruby.')
->assertExitCode(0);
}
}

View File

@ -9,8 +9,37 @@ class ExampleTest extends TestCase
/**
* A basic test example.
*/
public function test_that_true_is_true(): void
public function test_that_true_is_true(): string
{
$this->assertTrue(true);
$this->assertTrue(false);
return 'first';
}
public function testPushAndPop(): void
{
$stack = [];
$this->assertSame(0, count($stack));
array_push($stack, 'foo');
$this->assertSame('foo', $stack[count($stack)-1]);
$this->assertSame(1, count($stack));
$this->assertSame('foo', array_pop($stack));
$this->assertSame(0, count($stack));
}
public function testDeprecationCanBeExpected(): void
{
$this->expectDeprecation();
// Optionally test that the message is equal to a string
$this->expectDeprecationMessage('foo');
// Or optionally test that the message matches a regular expression
$this->expectDeprecationMessageMatches('/foo/');
\trigger_error('foo', \E_USER_DEPRECATED);
}
}