Sprint 1: Auth, metro map canvas, services, and retro UI
Authentication: - Laravel Fortify + Sanctum with Inertia views - RBAC middleware (admin, project_owner, team_member, viewer) - Retro terminal-styled login/register/forgot-password pages Metro Map (core UI): - D3.js zoomable SVG canvas with metro line rendering - Station nodes with glow-on-hover, status coloring, tooltips - Breadcrumb navigation for multi-level drill-down - Node preview panel with zoom-in action - C64-style CLI bar with blinking cursor at bottom Backend services: - ProjectService (CRUD, phase transitions, park/stop, audit logging) - ThemaService (CRUD with audit) - MapDataService (strategy map L1, project map L2) - Thin controllers: MapController, ProjectController, ThemaController - 32 routes total (auth + app + API) Style foundation: - Retro-futurism theme: VT323, Press Start 2P, IBM Plex Mono fonts - Dark palette with cyan/orange/green/purple neon accents - Comprehensive seed data (4 themes, 12 projects, commitments, deps) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
50
app/Actions/Fortify/CreateNewUser.php
Normal file
50
app/Actions/Fortify/CreateNewUser.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions\Fortify;
|
||||
|
||||
use App\Models\Role;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Laravel\Fortify\Contracts\CreatesNewUsers;
|
||||
|
||||
class CreateNewUser implements CreatesNewUsers
|
||||
{
|
||||
/**
|
||||
* Validate and create a newly registered user.
|
||||
*
|
||||
* @param array<string, string> $input
|
||||
*
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function create(array $input): User
|
||||
{
|
||||
Validator::make($input, [
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'email' => [
|
||||
'required',
|
||||
'string',
|
||||
'email',
|
||||
'max:255',
|
||||
Rule::unique(User::class),
|
||||
],
|
||||
'password' => ['required', 'string', 'min:8', 'confirmed'],
|
||||
])->validate();
|
||||
|
||||
$user = User::create([
|
||||
'name' => $input['name'],
|
||||
'email' => $input['email'],
|
||||
'password' => Hash::make($input['password']),
|
||||
]);
|
||||
|
||||
// Assign default 'viewer' role
|
||||
$viewerRole = Role::where('naam', 'viewer')->first();
|
||||
if ($viewerRole) {
|
||||
$user->roles()->attach($viewerRole);
|
||||
}
|
||||
|
||||
return $user;
|
||||
}
|
||||
}
|
||||
19
app/Actions/Fortify/PasswordValidationRules.php
Normal file
19
app/Actions/Fortify/PasswordValidationRules.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions\Fortify;
|
||||
|
||||
use Illuminate\Contracts\Validation\Rule;
|
||||
use Illuminate\Validation\Rules\Password;
|
||||
|
||||
trait PasswordValidationRules
|
||||
{
|
||||
/**
|
||||
* Get the validation rules used to validate passwords.
|
||||
*
|
||||
* @return array<int, Rule|array<mixed>|string>
|
||||
*/
|
||||
protected function passwordRules(): array
|
||||
{
|
||||
return ['required', 'string', Password::default(), 'confirmed'];
|
||||
}
|
||||
}
|
||||
32
app/Actions/Fortify/ResetUserPassword.php
Normal file
32
app/Actions/Fortify/ResetUserPassword.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions\Fortify;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Laravel\Fortify\Contracts\ResetsUserPasswords;
|
||||
|
||||
class ResetUserPassword implements ResetsUserPasswords
|
||||
{
|
||||
use PasswordValidationRules;
|
||||
|
||||
/**
|
||||
* Validate and reset the user's forgotten password.
|
||||
*
|
||||
* @param array<string, string> $input
|
||||
*
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function reset(User $user, array $input): void
|
||||
{
|
||||
Validator::make($input, [
|
||||
'password' => $this->passwordRules(),
|
||||
])->validate();
|
||||
|
||||
$user->forceFill([
|
||||
'password' => Hash::make($input['password']),
|
||||
])->save();
|
||||
}
|
||||
}
|
||||
31
app/Actions/Fortify/UpdateUserPassword.php
Normal file
31
app/Actions/Fortify/UpdateUserPassword.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions\Fortify;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Laravel\Fortify\Contracts\UpdatesUserPasswords;
|
||||
|
||||
class UpdateUserPassword implements UpdatesUserPasswords
|
||||
{
|
||||
/**
|
||||
* Validate and update the user's password.
|
||||
*
|
||||
* @param array<string, string> $input
|
||||
*
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function update(User $user, array $input): void
|
||||
{
|
||||
Validator::make($input, [
|
||||
'current_password' => ['required', 'string', 'current_password:web'],
|
||||
'password' => ['required', 'string', 'min:8', 'confirmed'],
|
||||
])->validate();
|
||||
|
||||
$user->forceFill([
|
||||
'password' => Hash::make($input['password']),
|
||||
])->save();
|
||||
}
|
||||
}
|
||||
42
app/Actions/Fortify/UpdateUserProfileInformation.php
Normal file
42
app/Actions/Fortify/UpdateUserProfileInformation.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions\Fortify;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Laravel\Fortify\Contracts\UpdatesUserProfileInformation;
|
||||
|
||||
class UpdateUserProfileInformation implements UpdatesUserProfileInformation
|
||||
{
|
||||
/**
|
||||
* Validate and update the given user's profile information.
|
||||
*
|
||||
* @param array<string, string> $input
|
||||
*
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function update(User $user, array $input): void
|
||||
{
|
||||
Validator::make($input, [
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'email' => [
|
||||
'required',
|
||||
'string',
|
||||
'email',
|
||||
'max:255',
|
||||
Rule::unique('users')->ignore($user->id),
|
||||
],
|
||||
'functie' => ['nullable', 'string', 'max:255'],
|
||||
'afdeling' => ['nullable', 'string', 'max:255'],
|
||||
])->validate();
|
||||
|
||||
$user->forceFill([
|
||||
'name' => $input['name'],
|
||||
'email' => $input['email'],
|
||||
'functie' => $input['functie'] ?? $user->functie,
|
||||
'afdeling' => $input['afdeling'] ?? $user->afdeling,
|
||||
])->save();
|
||||
}
|
||||
}
|
||||
42
app/Http/Controllers/MapController.php
Normal file
42
app/Http/Controllers/MapController.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Services\MapDataService;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
|
||||
class MapController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private MapDataService $mapDataService
|
||||
) {}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$mapData = $this->mapDataService->getStrategyMap();
|
||||
|
||||
return Inertia::render('Map/MetroMap', [
|
||||
'mapData' => $mapData,
|
||||
]);
|
||||
}
|
||||
|
||||
public function project(int $projectId)
|
||||
{
|
||||
$mapData = $this->mapDataService->getProjectMap($projectId);
|
||||
|
||||
return Inertia::render('Map/MetroMap', [
|
||||
'mapData' => $mapData,
|
||||
]);
|
||||
}
|
||||
|
||||
public function apiStrategy(Request $request)
|
||||
{
|
||||
return response()->json($this->mapDataService->getStrategyMap());
|
||||
}
|
||||
|
||||
public function apiProject(int $projectId)
|
||||
{
|
||||
return response()->json($this->mapDataService->getProjectMap($projectId));
|
||||
}
|
||||
}
|
||||
91
app/Http/Controllers/ProjectController.php
Normal file
91
app/Http/Controllers/ProjectController.php
Normal file
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Enums\ProjectStatus;
|
||||
use App\Models\Project;
|
||||
use App\Services\ProjectService;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
|
||||
class ProjectController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private ProjectService $projectService
|
||||
) {}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'naam' => 'required|string|max:255',
|
||||
'beschrijving' => 'nullable|string',
|
||||
'speerpunt_id' => 'nullable|exists:speerpunten,id',
|
||||
'prioriteit' => 'nullable|string',
|
||||
'startdatum' => 'nullable|date',
|
||||
'streef_einddatum' => 'nullable|date|after:startdatum',
|
||||
]);
|
||||
|
||||
$project = $this->projectService->create($validated);
|
||||
|
||||
return back()->with('success', "Project '{$project->naam}' aangemaakt.");
|
||||
}
|
||||
|
||||
public function show(Project $project)
|
||||
{
|
||||
$project = $this->projectService->getWithDetails($project->id);
|
||||
|
||||
return Inertia::render('Project/Show', [
|
||||
'project' => $project,
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(Request $request, Project $project)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'naam' => 'sometimes|string|max:255',
|
||||
'beschrijving' => 'nullable|string',
|
||||
'prioriteit' => 'nullable|string',
|
||||
'speerpunt_id' => 'nullable|exists:speerpunten,id',
|
||||
'streef_einddatum' => 'nullable|date',
|
||||
]);
|
||||
|
||||
$this->projectService->update($project, $validated);
|
||||
|
||||
return back()->with('success', 'Project bijgewerkt.');
|
||||
}
|
||||
|
||||
public function transition(Request $request, Project $project)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'status' => 'required|string',
|
||||
]);
|
||||
|
||||
$newStatus = ProjectStatus::from($validated['status']);
|
||||
$this->projectService->transitionPhase($project, $newStatus);
|
||||
|
||||
return back()->with('success', 'Projectfase bijgewerkt.');
|
||||
}
|
||||
|
||||
public function park(Request $request, Project $project)
|
||||
{
|
||||
$reason = $request->input('reason', '');
|
||||
$this->projectService->park($project, $reason);
|
||||
|
||||
return back()->with('success', 'Project geparkeerd.');
|
||||
}
|
||||
|
||||
public function stop(Request $request, Project $project)
|
||||
{
|
||||
$reason = $request->input('reason', '');
|
||||
$this->projectService->stop($project, $reason);
|
||||
|
||||
return back()->with('success', 'Project gestopt.');
|
||||
}
|
||||
|
||||
public function destroy(Project $project)
|
||||
{
|
||||
$project->delete();
|
||||
|
||||
return redirect('/map')->with('success', 'Project verwijderd.');
|
||||
}
|
||||
}
|
||||
52
app/Http/Controllers/ThemaController.php
Normal file
52
app/Http/Controllers/ThemaController.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Thema;
|
||||
use App\Services\ThemaService;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
|
||||
class ThemaController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private ThemaService $themaService
|
||||
) {}
|
||||
|
||||
public function index()
|
||||
{
|
||||
return Inertia::render('Thema/Index', [
|
||||
'themas' => $this->themaService->getAll(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'naam' => 'required|string|max:255',
|
||||
'beschrijving' => 'nullable|string',
|
||||
'prioriteit' => 'nullable|string',
|
||||
'periode_start' => 'nullable|date',
|
||||
'periode_eind' => 'nullable|date|after:periode_start',
|
||||
]);
|
||||
|
||||
$this->themaService->create($validated);
|
||||
|
||||
return back()->with('success', 'Thema aangemaakt.');
|
||||
}
|
||||
|
||||
public function update(Request $request, Thema $thema)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'naam' => 'sometimes|string|max:255',
|
||||
'beschrijving' => 'nullable|string',
|
||||
'prioriteit' => 'nullable|string',
|
||||
'periode_start' => 'nullable|date',
|
||||
'periode_eind' => 'nullable|date',
|
||||
]);
|
||||
|
||||
$this->themaService->update($thema, $validated);
|
||||
|
||||
return back()->with('success', 'Thema bijgewerkt.');
|
||||
}
|
||||
}
|
||||
19
app/Http/Middleware/CheckRole.php
Normal file
19
app/Http/Middleware/CheckRole.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class CheckRole
|
||||
{
|
||||
public function handle(Request $request, Closure $next, string ...$roles): Response
|
||||
{
|
||||
if (! $request->user() || ! $request->user()->roles()->whereIn('naam', $roles)->exists()) {
|
||||
abort(403, 'Je hebt geen toegang tot deze functie.');
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
@@ -37,7 +37,21 @@ class HandleInertiaRequests extends Middleware
|
||||
{
|
||||
return [
|
||||
...parent::share($request),
|
||||
//
|
||||
'auth' => [
|
||||
'user' => $request->user() ? [
|
||||
'id' => $request->user()->id,
|
||||
'name' => $request->user()->name,
|
||||
'email' => $request->user()->email,
|
||||
'functie' => $request->user()->functie,
|
||||
'afdeling' => $request->user()->afdeling,
|
||||
'roles' => $request->user()->roles->pluck('naam'),
|
||||
] : null,
|
||||
],
|
||||
'flash' => [
|
||||
'success' => $request->session()->get('success'),
|
||||
'error' => $request->session()->get('error'),
|
||||
],
|
||||
'locale' => app()->getLocale(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,11 +9,12 @@ use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
/** @use HasFactory<UserFactory> */
|
||||
use HasFactory, Notifiable;
|
||||
use HasApiTokens, HasFactory, Notifiable;
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
|
||||
58
app/Providers/FortifyServiceProvider.php
Normal file
58
app/Providers/FortifyServiceProvider.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Actions\Fortify\CreateNewUser;
|
||||
use App\Actions\Fortify\ResetUserPassword;
|
||||
use App\Actions\Fortify\UpdateUserPassword;
|
||||
use App\Actions\Fortify\UpdateUserProfileInformation;
|
||||
use Illuminate\Cache\RateLimiting\Limit;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\RateLimiter;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Illuminate\Support\Str;
|
||||
use Inertia\Inertia;
|
||||
use Laravel\Fortify\Fortify;
|
||||
|
||||
class FortifyServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Register any application services.
|
||||
*/
|
||||
public function register(): void
|
||||
{
|
||||
app()->singleton(\Laravel\Fortify\Contracts\CreatesNewUsers::class, CreateNewUser::class);
|
||||
app()->singleton(\Laravel\Fortify\Contracts\UpdatesUserProfileInformation::class, UpdateUserProfileInformation::class);
|
||||
app()->singleton(\Laravel\Fortify\Contracts\UpdatesUserPasswords::class, UpdateUserPassword::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
Fortify::createUsersUsing(CreateNewUser::class);
|
||||
Fortify::updateUserProfileInformationUsing(UpdateUserProfileInformation::class);
|
||||
Fortify::updateUserPasswordsUsing(UpdateUserPassword::class);
|
||||
Fortify::resetUserPasswordsUsing(ResetUserPassword::class);
|
||||
|
||||
Fortify::loginView(fn () => Inertia::render('Auth/Login'));
|
||||
Fortify::registerView(fn () => Inertia::render('Auth/Register'));
|
||||
Fortify::requestPasswordResetLinkView(fn () => Inertia::render('Auth/ForgotPassword'));
|
||||
Fortify::resetPasswordView(fn ($request) => Inertia::render('Auth/ResetPassword', [
|
||||
'token' => $request->route('token'),
|
||||
'email' => $request->query('email'),
|
||||
]));
|
||||
Fortify::verifyEmailView(fn () => Inertia::render('Auth/VerifyEmail'));
|
||||
|
||||
RateLimiter::for('login', function (Request $request) {
|
||||
$throttleKey = Str::transliterate(Str::lower($request->input(Fortify::username())).'|'.$request->ip());
|
||||
|
||||
return Limit::perMinute(5)->by($throttleKey);
|
||||
});
|
||||
|
||||
RateLimiter::for('two-factor', function (Request $request) {
|
||||
return Limit::perMinute(5)->by($request->session()->get('login.id'));
|
||||
});
|
||||
}
|
||||
}
|
||||
165
app/Services/MapDataService.php
Normal file
165
app/Services/MapDataService.php
Normal file
@@ -0,0 +1,165 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Thema;
|
||||
use App\Models\Project;
|
||||
use App\Models\Afhankelijkheid;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class MapDataService
|
||||
{
|
||||
/**
|
||||
* Build the Level 1 (Strategy) metro map data.
|
||||
* Each theme = a metro line, each project = a station.
|
||||
*/
|
||||
public function getStrategyMap(): array
|
||||
{
|
||||
$themas = Thema::with([
|
||||
'speerpunten.projects' => function ($q) {
|
||||
$q->with('eigenaar')
|
||||
->withCount(['documents', 'commitments', 'risicos', 'fases']);
|
||||
}
|
||||
])->get();
|
||||
|
||||
$lines = [];
|
||||
$nodes = [];
|
||||
$connections = [];
|
||||
|
||||
$lineColors = ['#00d2ff', '#e94560', '#00ff88', '#7b68ee', '#ff6b6b', '#ffd93d', '#6bcb77', '#4d96ff'];
|
||||
$yOffset = 0;
|
||||
|
||||
foreach ($themas as $index => $thema) {
|
||||
$color = $lineColors[$index % count($lineColors)];
|
||||
$lines[] = [
|
||||
'id' => "thema-{$thema->id}",
|
||||
'name' => $thema->naam,
|
||||
'color' => $color,
|
||||
];
|
||||
|
||||
$projects = $thema->speerpunten->flatMap->projects;
|
||||
$xOffset = -200;
|
||||
|
||||
foreach ($projects as $order => $project) {
|
||||
$nodes[] = [
|
||||
'id' => "project-{$project->id}",
|
||||
'entityId' => $project->id,
|
||||
'entityType' => 'project',
|
||||
'name' => $project->naam,
|
||||
'lineId' => "thema-{$thema->id}",
|
||||
'x' => $xOffset + ($order * 200),
|
||||
'y' => $yOffset,
|
||||
'order' => $order + 1,
|
||||
'status' => $project->status->value,
|
||||
'description' => Str::limit($project->beschrijving, 100),
|
||||
'owner' => $project->eigenaar?->name,
|
||||
'badge' => ucfirst(str_replace('_', ' ', $project->status->value)),
|
||||
'children' => $project->documents_count + $project->commitments_count,
|
||||
];
|
||||
}
|
||||
|
||||
$yOffset += 130;
|
||||
}
|
||||
|
||||
// Get dependencies as connections
|
||||
$dependencies = Afhankelijkheid::all();
|
||||
foreach ($dependencies as $dep) {
|
||||
$connections[] = [
|
||||
'from' => "project-{$dep->project_id}",
|
||||
'to' => "project-{$dep->afhankelijk_van_project_id}",
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'lines' => $lines,
|
||||
'nodes' => $nodes,
|
||||
'connections' => $connections,
|
||||
'level' => 1,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Build Level 2 (Project) metro map data.
|
||||
* The project's lifecycle phases = a metro line, milestones = stations.
|
||||
*/
|
||||
public function getProjectMap(int $projectId): array
|
||||
{
|
||||
$project = Project::with([
|
||||
'fases',
|
||||
'commitments' => fn ($q) => $q->with('eigenaar'),
|
||||
'documents',
|
||||
'risicos',
|
||||
'besluiten',
|
||||
])->findOrFail($projectId);
|
||||
|
||||
$lines = [
|
||||
['id' => 'lifecycle', 'name' => $project->naam, 'color' => '#00d2ff'],
|
||||
['id' => 'commitments', 'name' => 'Commitments', 'color' => '#e94560'],
|
||||
['id' => 'documents', 'name' => 'Documenten', 'color' => '#7b68ee'],
|
||||
];
|
||||
|
||||
$nodes = [];
|
||||
$xOffset = -300;
|
||||
|
||||
// Phase nodes on lifecycle line
|
||||
foreach ($project->fases->sortBy('type') as $order => $fase) {
|
||||
$nodes[] = [
|
||||
'id' => "fase-{$fase->id}",
|
||||
'entityId' => $fase->id,
|
||||
'entityType' => 'fase',
|
||||
'name' => ucfirst(str_replace('_', ' ', $fase->type->value)),
|
||||
'lineId' => 'lifecycle',
|
||||
'x' => $xOffset + ($order * 180),
|
||||
'y' => -50,
|
||||
'order' => $order + 1,
|
||||
'status' => $fase->status->value,
|
||||
'badge' => ucfirst($fase->status->value),
|
||||
];
|
||||
}
|
||||
|
||||
// Commitment nodes
|
||||
foreach ($project->commitments as $order => $commitment) {
|
||||
$nodes[] = [
|
||||
'id' => "commitment-{$commitment->id}",
|
||||
'entityId' => $commitment->id,
|
||||
'entityType' => 'commitment',
|
||||
'name' => Str::limit($commitment->beschrijving, 40),
|
||||
'lineId' => 'commitments',
|
||||
'x' => $xOffset + ($order * 180),
|
||||
'y' => 80,
|
||||
'order' => $order + 1,
|
||||
'status' => $commitment->status->value,
|
||||
'owner' => $commitment->eigenaar?->name,
|
||||
'badge' => $commitment->deadline?->format('d M'),
|
||||
];
|
||||
}
|
||||
|
||||
// Document nodes
|
||||
foreach ($project->documents as $order => $doc) {
|
||||
$nodes[] = [
|
||||
'id' => "document-{$doc->id}",
|
||||
'entityId' => $doc->id,
|
||||
'entityType' => 'document',
|
||||
'name' => $doc->titel,
|
||||
'lineId' => 'documents',
|
||||
'x' => $xOffset + ($order * 180),
|
||||
'y' => 210,
|
||||
'order' => $order + 1,
|
||||
'status' => 'active',
|
||||
'badge' => "v{$doc->versie}",
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'lines' => $lines,
|
||||
'nodes' => $nodes,
|
||||
'connections' => [],
|
||||
'level' => 2,
|
||||
'project' => [
|
||||
'id' => $project->id,
|
||||
'naam' => $project->naam,
|
||||
'status' => $project->status->value,
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
186
app/Services/ProjectService.php
Normal file
186
app/Services/ProjectService.php
Normal file
@@ -0,0 +1,186 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Project;
|
||||
use App\Models\AuditLog;
|
||||
use App\Enums\ProjectStatus;
|
||||
use App\Enums\FaseType;
|
||||
use App\Enums\FaseStatus;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ProjectService
|
||||
{
|
||||
/**
|
||||
* Get all projects with their relationships for the metro map.
|
||||
*/
|
||||
public function getAllForMap(): Collection
|
||||
{
|
||||
return Project::with(['eigenaar', 'speerpunt.thema', 'fases', 'risicos', 'commitments'])
|
||||
->withCount(['documents', 'commitments', 'risicos'])
|
||||
->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single project with full details.
|
||||
*/
|
||||
public function getWithDetails(int $id): Project
|
||||
{
|
||||
return Project::with([
|
||||
'eigenaar',
|
||||
'speerpunt.thema',
|
||||
'fases',
|
||||
'risicos',
|
||||
'commitments.acties',
|
||||
'commitments.eigenaar',
|
||||
'documents',
|
||||
'besluiten',
|
||||
'teamleden',
|
||||
'afhankelijkheden.afhankelijkVan',
|
||||
'overdrachtsplannen.criteria',
|
||||
])->findOrFail($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new project with initial phase.
|
||||
*/
|
||||
public function create(array $data): Project
|
||||
{
|
||||
return DB::transaction(function () use ($data) {
|
||||
$project = Project::create([
|
||||
'naam' => $data['naam'],
|
||||
'beschrijving' => $data['beschrijving'] ?? '',
|
||||
'eigenaar_id' => $data['eigenaar_id'] ?? Auth::id(),
|
||||
'speerpunt_id' => $data['speerpunt_id'] ?? null,
|
||||
'status' => ProjectStatus::Signaal,
|
||||
'prioriteit' => $data['prioriteit'] ?? \App\Enums\Prioriteit::Midden,
|
||||
'startdatum' => $data['startdatum'] ?? now(),
|
||||
'streef_einddatum' => $data['streef_einddatum'] ?? null,
|
||||
]);
|
||||
|
||||
// Create initial "signaal" phase
|
||||
$project->fases()->create([
|
||||
'type' => FaseType::Signaal,
|
||||
'status' => FaseStatus::Actief,
|
||||
'startdatum' => now(),
|
||||
]);
|
||||
|
||||
// Assign creator as project owner
|
||||
$project->teamleden()->attach(Auth::id(), ['rol' => \App\Enums\ProjectRol::Eigenaar]);
|
||||
|
||||
$this->audit('created', $project);
|
||||
|
||||
return $project;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Update project details.
|
||||
*/
|
||||
public function update(Project $project, array $data): Project
|
||||
{
|
||||
$project->update(array_filter([
|
||||
'naam' => $data['naam'] ?? null,
|
||||
'beschrijving' => $data['beschrijving'] ?? null,
|
||||
'prioriteit' => $data['prioriteit'] ?? null,
|
||||
'speerpunt_id' => $data['speerpunt_id'] ?? null,
|
||||
'streef_einddatum' => $data['streef_einddatum'] ?? null,
|
||||
], fn ($v) => $v !== null));
|
||||
|
||||
$this->audit('updated', $project);
|
||||
|
||||
return $project->fresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* Transition a project to the next phase.
|
||||
*/
|
||||
public function transitionPhase(Project $project, ProjectStatus $newStatus): Project
|
||||
{
|
||||
return DB::transaction(function () use ($project, $newStatus) {
|
||||
$oldStatus = $project->status;
|
||||
|
||||
// Close current active phase
|
||||
$project->fases()
|
||||
->where('status', FaseStatus::Actief)
|
||||
->update([
|
||||
'status' => FaseStatus::Afgerond->value,
|
||||
'einddatum' => now(),
|
||||
]);
|
||||
|
||||
// Create new phase (if it maps to a FaseType)
|
||||
$faseType = FaseType::tryFrom($newStatus->value);
|
||||
if ($faseType) {
|
||||
$project->fases()->create([
|
||||
'type' => $faseType,
|
||||
'status' => FaseStatus::Actief,
|
||||
'startdatum' => now(),
|
||||
]);
|
||||
}
|
||||
|
||||
// Update project status
|
||||
$project->update(['status' => $newStatus]);
|
||||
|
||||
$this->audit('phase_transition', $project, [
|
||||
'from' => $oldStatus->value,
|
||||
'to' => $newStatus->value,
|
||||
]);
|
||||
|
||||
return $project->fresh(['fases']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Park a project (temporarily halt).
|
||||
*/
|
||||
public function park(Project $project, string $reason = ''): Project
|
||||
{
|
||||
return $this->transitionToSpecialStatus($project, ProjectStatus::Geparkeerd, $reason);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop a project permanently.
|
||||
*/
|
||||
public function stop(Project $project, string $reason = ''): Project
|
||||
{
|
||||
return $this->transitionToSpecialStatus($project, ProjectStatus::Gestopt, $reason);
|
||||
}
|
||||
|
||||
private function transitionToSpecialStatus(Project $project, ProjectStatus $status, string $reason): Project
|
||||
{
|
||||
return DB::transaction(function () use ($project, $status, $reason) {
|
||||
$oldStatus = $project->status;
|
||||
|
||||
$project->fases()
|
||||
->where('status', FaseStatus::Actief)
|
||||
->update([
|
||||
'status' => FaseStatus::Afgerond->value,
|
||||
'einddatum' => now(),
|
||||
'opmerkingen' => $reason,
|
||||
]);
|
||||
|
||||
$project->update(['status' => $status]);
|
||||
|
||||
$this->audit('status_change', $project, [
|
||||
'from' => $oldStatus->value,
|
||||
'to' => $status->value,
|
||||
'reason' => $reason,
|
||||
]);
|
||||
|
||||
return $project->fresh();
|
||||
});
|
||||
}
|
||||
|
||||
private function audit(string $action, Project $project, ?array $extra = null): void
|
||||
{
|
||||
AuditLog::create([
|
||||
'user_id' => Auth::id(),
|
||||
'action' => "project.{$action}",
|
||||
'entity_type' => 'project',
|
||||
'entity_id' => $project->id,
|
||||
'payload' => $extra,
|
||||
]);
|
||||
}
|
||||
}
|
||||
60
app/Services/ThemaService.php
Normal file
60
app/Services/ThemaService.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Thema;
|
||||
use App\Models\AuditLog;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class ThemaService
|
||||
{
|
||||
public function getAll(): Collection
|
||||
{
|
||||
return Thema::with(['speerpunten.projects'])->get();
|
||||
}
|
||||
|
||||
public function getForMap(): Collection
|
||||
{
|
||||
return Thema::with([
|
||||
'speerpunten.projects' => function ($q) {
|
||||
$q->with('eigenaar')
|
||||
->withCount(['documents', 'commitments', 'risicos']);
|
||||
}
|
||||
])->get();
|
||||
}
|
||||
|
||||
public function create(array $data): Thema
|
||||
{
|
||||
$thema = Thema::create([
|
||||
'naam' => $data['naam'],
|
||||
'beschrijving' => $data['beschrijving'] ?? '',
|
||||
'prioriteit' => $data['prioriteit'] ?? \App\Enums\Prioriteit::Midden,
|
||||
'periode_start' => $data['periode_start'] ?? null,
|
||||
'periode_eind' => $data['periode_eind'] ?? null,
|
||||
]);
|
||||
|
||||
AuditLog::create([
|
||||
'user_id' => Auth::id(),
|
||||
'action' => 'thema.created',
|
||||
'entity_type' => 'thema',
|
||||
'entity_id' => $thema->id,
|
||||
]);
|
||||
|
||||
return $thema;
|
||||
}
|
||||
|
||||
public function update(Thema $thema, array $data): Thema
|
||||
{
|
||||
$thema->update(array_filter($data, fn ($v) => $v !== null));
|
||||
|
||||
AuditLog::create([
|
||||
'user_id' => Auth::id(),
|
||||
'action' => 'thema.updated',
|
||||
'entity_type' => 'thema',
|
||||
'entity_id' => $thema->id,
|
||||
]);
|
||||
|
||||
return $thema->fresh();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user