Added ability to edit hardware components

This commit is contained in:
Gregory Ballantine
2025-06-26 12:17:05 -04:00
parent 1a7e41edb2
commit e9e43187e4
4 changed files with 75 additions and 1 deletions

View File

@ -59,4 +59,31 @@ class ComponentController extends Controller {
->withStatus(302);
}
public function getEdit(Request $request, Response $response, array $args): Response {
$component = Component::where('id', $args['component_id'])->first();
$view = Twig::fromRequest($request);
return $view->render($response, 'component/edit.twig', [
'component' => $component,
]);
}
public function postEdit(Request $request, Response $response, array $args): Response {
$component = Component::where('id', $args['component_id'])->first();
$params = (array)$request->getParsedBody();
$component->name = $params['component_name'];
$component->type = $params['component_type'];
$component->save();
// redirect the user back to the home page
$routeContext = RouteContext::fromRequest($request);
$routeParser = $routeContext->getRouteParser();
return $response
->withHeader('Location', $routeParser->urlFor('component.view', ['component_id' => $component->id]))
->withStatus(302);
}
}

View File

@ -17,7 +17,13 @@ $app->group('/component', function(RouteCollectorProxy $group) {
$group->get('/list', '\\BitGoblin\\Colossus\\Controllers\\ComponentController:getList')->setName('component.list');
$group->get('/add', '\\BitGoblin\\Colossus\\Controllers\\ComponentController:getAdd')->setName('component.add');
$group->post('/add', '\\BitGoblin\\Colossus\\Controllers\\ComponentController:postAdd');
$group->get('/{component_id}', '\\BitGoblin\\Colossus\\Controllers\\ComponentController:getView')->setName('component.view');
$group->group('/{component_id}', function(RouteCollectorProxy $component) {
$component->get('', '\\BitGoblin\\Colossus\\Controllers\\ComponentController:getView')->setName('component.view');
$component->get('/edit', '\\BitGoblin\\Colossus\\Controllers\\ComponentController:getEdit')->setName('component.edit');
$component->post('/edit', '\\BitGoblin\\Colossus\\Controllers\\ComponentController:postEdit');
});
});
$app->group('/test', function(RouteCollectorProxy $group) {