Changes 0128092025
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\FieldJobSetting;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
|
||||
class FieldJobSettingController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$settings = FieldJobSetting::query()
|
||||
->with(['segment', 'asignDecision', 'completeDecision'])
|
||||
->get();
|
||||
|
||||
return Inertia::render('Settings/FieldJob/Index', [
|
||||
'settings' => $settings,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -2,9 +2,17 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Segment;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
|
||||
class SegmentController extends Controller
|
||||
{
|
||||
//
|
||||
public function settings(Request $request)
|
||||
{
|
||||
return Inertia::render('Settings/Segments/Index', [
|
||||
'segments' => Segment::query()->get(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,127 +10,8 @@ class SettingController extends Controller
|
||||
//
|
||||
|
||||
public function index(Request $request){
|
||||
|
||||
return Inertia::render('Settings/Index', [
|
||||
'actions' => \App\Models\Action::query()
|
||||
->with(['decisions', 'segment'])
|
||||
->get(),
|
||||
'decisions' => \App\Models\Decision::query()
|
||||
->with('actions')
|
||||
->get(),
|
||||
'segments' => \App\Models\Segment::query()
|
||||
->get()
|
||||
]
|
||||
);
|
||||
return Inertia::render('Settings/Index');
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
$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, $row) {
|
||||
$row->update([
|
||||
'name' => $attributes['name'],
|
||||
'color_tag' => $attributes['color_tag'],
|
||||
'segment_id' => $attributes['segment_id'] ?? null,
|
||||
]);
|
||||
|
||||
$row->decisions()->sync($decisionIds);
|
||||
});
|
||||
logger()->info('Model updated successfully', ['model_id' => $row->id]);
|
||||
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!');
|
||||
}
|
||||
// Workflow actions/decisions moved to WorkflowController
|
||||
}
|
||||
|
||||
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Action;
|
||||
use App\Models\Decision;
|
||||
use App\Models\Segment;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Inertia\Inertia;
|
||||
|
||||
class WorkflowController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
return Inertia::render('Settings/Workflow/Index', [
|
||||
'actions' => Action::query()->with(['decisions', 'segment'])->get(),
|
||||
'decisions' => Decision::query()->with('actions')->get(),
|
||||
'segments' => 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 = 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.workflow')->with('success', 'Action created successfully!');
|
||||
}
|
||||
|
||||
public function updateAction(int $id, Request $request)
|
||||
{
|
||||
$row = Action::findOrFail($id);
|
||||
|
||||
$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, $row) {
|
||||
$row->update([
|
||||
'name' => $attributes['name'],
|
||||
'color_tag' => $attributes['color_tag'],
|
||||
'segment_id' => $attributes['segment_id'] ?? null,
|
||||
]);
|
||||
$row->decisions()->sync($decisionIds);
|
||||
});
|
||||
|
||||
return to_route('settings.workflow')->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 = Decision::create([
|
||||
'name' => $attributes['name'],
|
||||
'color_tag' => $attributes['color_tag'] ?? null,
|
||||
]);
|
||||
|
||||
if (!empty($actionIds)) {
|
||||
$row->actions()->sync($actionIds);
|
||||
}
|
||||
});
|
||||
|
||||
return to_route('settings.workflow')->with('success', 'Decision created successfully!');
|
||||
}
|
||||
|
||||
public function updateDecision(int $id, Request $request)
|
||||
{
|
||||
$row = 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.workflow')->with('success', 'Decision updated successfully!');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user