This commit is contained in:
Simon Pocrnjič 2025-09-26 06:02:59 +02:00
parent a8383d3a69
commit d17e34941b
11 changed files with 552 additions and 30 deletions

View File

@ -13,15 +13,46 @@ public function index(Request $request){
return Inertia::render('Settings/Index', [
'actions' => \App\Models\Action::query()
->with('decisions')
->with(['decisions', 'segment'])
->get(),
'decisions' => \App\Models\Decision::query()
->with('actions')
->get(),
'segments' => \App\Models\Segment::query()
->get()
]
);
}
public function storeAction(Request $request)
{
$attributes = $request->validate([
'name' => 'required|string|max:50',
'color_tag' => 'nullable|string|max:25',
'segment_id' => 'nullable|integer|exists:segments,id',
'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) {
/** @var \App\Models\Action $row */
$row = \App\Models\Action::create([
'name' => $attributes['name'],
'color_tag' => $attributes['color_tag'] ?? null,
'segment_id' => $attributes['segment_id'] ?? null,
]);
if (!empty($decisionIds)) {
$row->decisions()->sync($decisionIds);
}
});
return to_route('settings')->with('success', 'Action created successfully!');
}
public function updateAction(int $id, Request $request) {
$row = \App\Models\Action::findOrFail($id);
@ -29,6 +60,7 @@ public function updateAction(int $id, Request $request) {
$attributes = $request->validate([
'name' => 'required|string|max:50',
'color_tag' => 'nullable|string|max:25',
'segment_id' => 'nullable|integer|exists:segments,id',
'decisions' => 'nullable|array',
'decisions.*.id' => 'required_with:decisions.*|integer|exists:decisions,id',
'decisions.*.name' => 'required_with:decisions.*|string|max:50'
@ -39,7 +71,8 @@ public function updateAction(int $id, Request $request) {
\DB::transaction(function() use ($attributes, $decisionIds, $row) {
$row->update([
'name' => $attributes['name'],
'color_tag' => $attributes['color_tag']
'color_tag' => $attributes['color_tag'],
'segment_id' => $attributes['segment_id'] ?? null,
]);
$row->decisions()->sync($decisionIds);
@ -48,4 +81,56 @@ public function updateAction(int $id, Request $request) {
return to_route('settings')->with('success', 'Update successful!');
}
public function storeDecision(Request $request)
{
$attributes = $request->validate([
'name' => 'required|string|max:50',
'color_tag' => 'nullable|string|max:25',
'actions' => 'nullable|array',
'actions.*.id' => 'required_with:actions.*|integer|exists:actions,id',
'actions.*.name' => 'required_with:actions.*|string|max:50',
]);
$actionIds = collect($attributes['actions'] ?? [])->pluck('id')->toArray();
\DB::transaction(function () use ($attributes, $actionIds) {
/** @var \App\Models\Decision $row */
$row = \App\Models\Decision::create([
'name' => $attributes['name'],
'color_tag' => $attributes['color_tag'] ?? null,
]);
if (!empty($actionIds)) {
$row->actions()->sync($actionIds);
}
});
return to_route('settings')->with('success', 'Decision created successfully!');
}
public function updateDecision(int $id, Request $request)
{
$row = \App\Models\Decision::findOrFail($id);
$attributes = $request->validate([
'name' => 'required|string|max:50',
'color_tag' => 'nullable|string|max:25',
'actions' => 'nullable|array',
'actions.*.id' => 'required_with:actions.*|integer|exists:actions,id',
'actions.*.name' => 'required_with:actions.*|string|max:50',
]);
$actionIds = collect($attributes['actions'] ?? [])->pluck('id')->toArray();
\DB::transaction(function () use ($attributes, $actionIds, $row) {
$row->update([
'name' => $attributes['name'],
'color_tag' => $attributes['color_tag'] ?? null,
]);
$row->actions()->sync($actionIds);
});
return to_route('settings')->with('success', 'Decision updated successfully!');
}
}

View File

@ -14,7 +14,7 @@ class Action extends Model
use HasFactory;
use Searchable;
protected $fillable = ['name', 'color_tag'];
protected $fillable = ['name', 'color_tag', 'segment_id'];
public function decisions(): BelongsToMany
{

View File

@ -18,6 +18,7 @@ class Activity extends Model
'amount',
'note',
'action_id',
'user_id',
'decision_id'
];
@ -25,9 +26,20 @@ class Activity extends Model
'action_id',
'decision_id',
'client_case_id',
'user_id',
'contract_id'
];
protected static function booted(){
static::creating(function (Activity $activity) {
if(!isset($activity->user_id)){
$activity->user_id = auth()->id();
}
});
}
public function action(): BelongsTo
{
return $this->belongsTo(\App\Models\Action::class);

View File

@ -13,6 +13,8 @@ class Decision extends Model
/** @use HasFactory<\Database\Factories\DecisionFactory> */
use HasFactory;
protected $fillable = ['name', 'color_tag'];
public function actions(): BelongsToMany
{
return $this->belongsToMany(\App\Models\Action::class);

View File

@ -0,0 +1,32 @@
<?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->foreignId('user_id')->nullable()->constrained('users')->nullOnDelete();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('activities', function (Blueprint $table) {
// Drop FK then column
if (Schema::hasColumn('activities', 'user_id')) {
$table->dropForeign(['user_id']);
$table->dropColumn('user_id');
}
});
}
};

View File

@ -0,0 +1,57 @@
<?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::create('documents', function (Blueprint $table) {
$table->id();
// Public identifier to reference documents externally
$table->uuid('uuid')->unique();
// Optional human-friendly title and description
$table->string('name');
$table->text('description')->nullable();
// Uploader (nullable, to preserve docs if user is removed)
$table->foreignId('user_id')->nullable()->constrained('users')->nullOnDelete();
// Polymorphic relation to attach a document to any model (e.g., ClientCase, Contract, etc.)
$table->nullableMorphs('documentable'); // creates documentable_type + documentable_id (indexed)
// Storage metadata
$table->string('disk', 50)->default('public');
$table->string('path', 2048); // relative path within the disk
$table->string('file_name'); // stored file name (basename)
$table->string('original_name'); // original client file name
$table->string('extension', 20)->nullable();
$table->string('mime_type', 100)->nullable();
$table->unsignedBigInteger('size')->nullable(); // bytes
$table->string('checksum', 64)->nullable(); // e.g., SHA-256
// Visibility / flags
$table->boolean('is_public')->default(false);
// Index to speed up path lookups per disk
$table->index(['disk', 'path']);
$table->timestamps();
$table->softDeletes();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('documents');
}
};

2
package-lock.json generated
View File

@ -1,5 +1,5 @@
{
"name": "teren-app",
"name": "Teren-app",
"lockfileVersion": 3,
"requires": true,
"packages": {

View File

@ -7,7 +7,8 @@ import DecisionTable from './Partials/DecisionTable.vue';
const props = defineProps({
actions: Array,
decisions: Array
decisions: Array,
segments: Array
});
const activeTab = ref('actions')
@ -21,10 +22,10 @@ const activeTab = ref('actions')
<div class="bg-white overflow-hidden shadow-xl sm:rounded-lg">
<fwb-tabs v-model="activeTab" variant="underline" >
<fwb-tab name="actions" title="Actions">
<ActionTable :actions="actions" :decisions="decisions" />
<ActionTable :actions="actions" :decisions="decisions" :segments="segments" />
</fwb-tab>
<fwb-tab name="decisions" title="Decisions">
<DecisionTable :decisions="decisions" />
<DecisionTable :decisions="decisions" :actions="actions" />
</fwb-tab>
</fwb-tabs>
</div>

View File

@ -12,26 +12,39 @@ import ActionMessage from '@/Components/ActionMessage.vue';
const props = defineProps({
actions: Array,
decisions: Array
decisions: Array,
segments: Array
});
const menuDropdown = ref();
const drawerEdit = ref(false);
const drawerCreate = ref(false);
const selectOptions = ref([]);
const segmentOptions = ref([]);
const form = useForm({
id: 0,
name: '',
color_tag: '',
segment_id: null,
decisions: []
});
const createForm = useForm({
name: '',
color_tag: '',
segment_id: null,
decisions: []
});
const openEditDrawer = (item) => {
form.decisions = [];
form.id = item.id;
form.name = item.name;
form.color_tag = item.color_tag;
form.segment_id = item.segment ? item.segment.id : null;
drawerEdit.value = true;
item.decisions.forEach((d) => {
@ -47,6 +60,16 @@ const closeEditDrawer = () => {
form.reset();
}
const openCreateDrawer = () => {
createForm.reset();
drawerCreate.value = true;
}
const closeCreateDrawer = () => {
drawerCreate.value = false;
createForm.reset();
}
const onColorPickerChange = () => {
console.log(form.color_tag);
}
@ -59,6 +82,12 @@ onMounted(() => {
});
});
props.segments.forEach((s) => {
segmentOptions.value.push({
name: s.name,
id: s.id
})
})
});
@ -70,8 +99,19 @@ const update = () => {
});
};
const store = () => {
createForm.post(route('settings.actions.store'), {
onSuccess: () => {
closeCreateDrawer();
},
});
};
</script>
<template>
<div class="py-4 px-3">
<PrimaryButton @click="openCreateDrawer">+ Dodaj akcijo</PrimaryButton>
</div>
<fwb-table>
<fwb-table-head>
<fwb-table-head-cell>#</fwb-table-head-cell>
@ -131,6 +171,20 @@ const update = () => {
</div>
</div>
<div class="col-span-6 sm:col-span-4">
<InputLabel for="segmentEdit" value="Segment"/>
<multiselect
id="segmentEdit"
v-model="form.segment_id"
:options="segmentOptions.map(s=>s.id)"
:multiple="false"
:searchable="true"
:taggable="false"
placeholder="Izberi segment"
:custom-label="(opt) => (segmentOptions.find(s=>s.id===opt)?.name || '')"
/>
</div>
<div class="col-span-6 sm:col-span-4">
<InputLabel for="decisions" value="Odločitve"/>
<multiselect
@ -158,4 +212,78 @@ const update = () => {
</form>
</template>
</Drawer>
<Drawer
:show="drawerCreate"
@close="closeCreateDrawer"
>
<template #title>
<span>Dodaj akcijo</span>
</template>
<template #content>
<form @submit.prevent="store">
<div class="col-span-6 sm:col-span-4">
<InputLabel for="nameCreate" value="Ime"/>
<TextInput
id="nameCreate"
v-model="createForm.name"
type="text"
class="mt-1 block w-full"
autocomplete="name"
/>
</div>
<div class="col-span-6 sm:col-span-4">
<InputLabel for="colorTagCreate" value="Barva"/>
<div class="mt-1 w-full border flex p-1">
<TextInput
id="colorTagCreate"
v-model="createForm.color_tag"
type="color"
class="mr-2"
autocomplete="color-tag"
/>
<span>{{ createForm.color_tag }}</span>
</div>
</div>
<div class="col-span-6 sm:col-span-4">
<InputLabel for="segmentCreate" value="Segment"/>
<multiselect
id="segmentCreate"
v-model="createForm.segment_id"
:options="segmentOptions.map(s=>s.id)"
:multiple="false"
:searchable="true"
:taggable="false"
placeholder="Izberi segment"
:custom-label="(opt) => (segmentOptions.find(s=>s.id===opt)?.name || '')"
/>
</div>
<div class="col-span-6 sm:col-span-4">
<InputLabel for="decisionsCreate" value="Odločitve"/>
<multiselect
id="decisionsCreate"
v-model="createForm.decisions"
:options="selectOptions"
:multiple="true"
track-by="id"
:taggable="true"
placeholder="Dodaj odločitev"
label="name"
/>
</div>
<div class="flex justify-end mt-4">
<ActionMessage :on="createForm.recentlySuccessful" class="me-3">
Shranjuje.
</ActionMessage>
<PrimaryButton :class="{ 'opacity-25': createForm.processing }" :disabled="createForm.processing">
Dodaj
</PrimaryButton>
</div>
</form>
</template>
</Drawer>
</template>

View File

@ -1,36 +1,238 @@
<script setup>
import BasicTable from '@/Components/BasicTable.vue';
import { LinkOptions as C_LINK, TableColumn as C_TD, TableRow as C_TR} from '@/Shared/AppObjects';
import { FwbTable, FwbTableBody, FwbTableHead, FwbTableHeadCell, FwbTableCell, FwbTableRow } from 'flowbite-vue';
import { EditIcon } 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({
decisions: Array
decisions: Array,
actions: Array
});
const header = [
C_TD.make('#', 'header'),
C_TD.make('Name', 'header'),
C_TD.make('Color tag', 'header'),
C_TD.make('Belongs to actions', 'header')
];
const drawerEdit = ref(false);
const drawerCreate = ref(false);
const createBody = (data) => {
let content = [];
const actionOptions = ref([]);
data.forEach((a) => {
const cols = [
C_TD.make(a.id, 'body'),
C_TD.make(a.name, 'body'),
C_TD.make(a.color_tag, 'body'),
C_TD.make(a.actions.length, 'body')
];
const form = useForm({
id: 0,
name: '',
color_tag: '',
actions: []
});
content.push(C_TR.make(cols));
});
const createForm = useForm({
name: '',
color_tag: '',
actions: []
});
return content;
const openEditDrawer = (item) => {
form.actions = [];
form.id = item.id;
form.name = item.name;
form.color_tag = item.color_tag;
drawerEdit.value = true;
item.actions.forEach((a) => {
form.actions.push({
name: a.name,
id: a.id
});
})
}
const closeEditDrawer = () => {
drawerEdit.value = false;
form.reset();
}
const openCreateDrawer = () => {
createForm.reset();
drawerCreate.value = true;
}
const closeCreateDrawer = () => {
drawerCreate.value = false;
createForm.reset();
}
onMounted(() => {
props.actions.forEach((a) => {
actionOptions.value.push({
name: a.name,
id: a.id
});
});
});
const update = () => {
form.put(route('settings.decisions.update', { id: form.id }), {
onSuccess: () => {
closeEditDrawer();
},
});
};
const store = () => {
createForm.post(route('settings.decisions.store'), {
onSuccess: () => {
closeCreateDrawer();
},
});
};
</script>
<template>
<BasicTable :header="header" :body="createBody(decisions)" />
<div class="py-4 px-3">
<PrimaryButton @click="openCreateDrawer">+ Dodaj odločitev</PrimaryButton>
</div>
<fwb-table>
<fwb-table-head>
<fwb-table-head-cell>#</fwb-table-head-cell>
<fwb-table-head-cell>Name</fwb-table-head-cell>
<fwb-table-head-cell>Color tag</fwb-table-head-cell>
<fwb-table-head-cell>Belongs to actions</fwb-table-head-cell>
<fwb-table-head-cell>
<span class="sr-only">Edit</span>
</fwb-table-head-cell>
</fwb-table-head>
<fwb-table-body>
<fwb-table-row v-for="d in decisions" :key="d.id">
<fwb-table-cell>{{ d.id }}</fwb-table-cell>
<fwb-table-cell>{{ d.name }}</fwb-table-cell>
<fwb-table-cell>{{ d.color_tag }}</fwb-table-cell>
<fwb-table-cell>{{ d.actions.length }}</fwb-table-cell>
<fwb-table-cell>
<button class="px-2" @click="openEditDrawer(d)"><EditIcon size="md" css="text-gray-500" /></button>
</fwb-table-cell>
</fwb-table-row>
</fwb-table-body>
</fwb-table>
<Drawer
:show="drawerEdit"
@close="closeEditDrawer"
>
<template #title>
<span>Spremeni odločitev</span>
</template>
<template #content>
<form @submit.prevent="update">
<div class="col-span-6 sm:col-span-4">
<InputLabel for="name" value="Ime"/>
<TextInput
id="name"
v-model="form.name"
type="text"
class="mt-1 block w-full"
autocomplete="name"
/>
</div>
<div class="col-span-6 sm:col-span-4">
<InputLabel for="colorTag" value="Barva"/>
<div class="mt-1 w-full border flex p-1">
<TextInput
id="colorTag"
v-model="form.color_tag"
type="color"
class="mr-2"
autocomplete="color-tag"
/>
<span>{{ form.color_tag }}</span>
</div>
</div>
<div class="col-span-6 sm:col-span-4">
<InputLabel for="actionsSelect" value="Akcije"/>
<multiselect
id="actionsSelect"
v-model="form.actions"
:options="actionOptions"
:multiple="true"
track-by="id"
:taggable="true"
placeholder="Dodaj akcijo"
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>
<Drawer
:show="drawerCreate"
@close="closeCreateDrawer"
>
<template #title>
<span>Dodaj odločitev</span>
</template>
<template #content>
<form @submit.prevent="store">
<div class="col-span-6 sm:col-span-4">
<InputLabel for="nameCreate" value="Ime"/>
<TextInput
id="nameCreate"
v-model="createForm.name"
type="text"
class="mt-1 block w-full"
autocomplete="name"
/>
</div>
<div class="col-span-6 sm:col-span-4">
<InputLabel for="colorTagCreate" value="Barva"/>
<div class="mt-1 w-full border flex p-1">
<TextInput
id="colorTagCreate"
v-model="createForm.color_tag"
type="color"
class="mr-2"
autocomplete="color-tag"
/>
<span>{{ createForm.color_tag }}</span>
</div>
</div>
<div class="col-span-6 sm:col-span-4">
<InputLabel for="actionsCreate" value="Akcije"/>
<multiselect
id="actionsCreate"
v-model="createForm.actions"
:options="actionOptions"
:multiple="true"
track-by="id"
:taggable="true"
placeholder="Dodaj akcijo"
label="name"
/>
</div>
<div class="flex justify-end mt-4">
<ActionMessage :on="createForm.recentlySuccessful" class="me-3">
Shranjuje.
</ActionMessage>
<PrimaryButton :class="{ 'opacity-25': createForm.processing }" :disabled="createForm.processing">
Dodaj
</PrimaryButton>
</div>
</form>
</template>
</Drawer>
</template>

View File

@ -112,7 +112,10 @@
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::post('settings/actions', [SettingController::class, 'storeAction'])->name('settings.actions.store');
Route::put('settings/actions/{id}', [SettingController::class, 'updateAction'])->name('settings.actions.update');
Route::post('settings/decisions', [SettingController::class, 'storeDecision'])->name('settings.decisions.store');
Route::put('settings/decisions/{id}', [SettingController::class, 'updateDecision'])->name('settings.decisions.update');
//Route::put()
//types