add view for single text
This commit is contained in:
parent
5b2d85fb92
commit
68da48aedd
4 changed files with 30 additions and 0 deletions
|
|
@ -21,4 +21,12 @@ class ViewController
|
|||
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function text(Response $response): Response
|
||||
{
|
||||
$html = file_get_contents(__DIR__.'/../../views/templates/text.php', true);
|
||||
$response->getBody()->write($html);
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,8 +14,10 @@ $app->addErrorMiddleware(true, true, true);
|
|||
|
||||
$app->get('/admin', [ViewController::class, 'admin']);
|
||||
$app->get('/admin/texts', [ViewController::class, 'texts']);
|
||||
$app->get('/admin/texts/{textId}', [ViewController::class, 'text']);
|
||||
|
||||
$app->get('/api/texts', [TextController::class, 'getTexts']);
|
||||
$app->get('/api/texts/{textId}', [TextController::class, 'getText']);
|
||||
$app->post('/api/texts', [TextController::class, 'createText']);
|
||||
|
||||
return $app;
|
||||
|
|
|
|||
9
public/js/text.js
Normal file
9
public/js/text.js
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const textId = window.location.pathname.split('/').pop();
|
||||
|
||||
fetch('/api/texts/' + textId)
|
||||
.then(res => res.json())
|
||||
.then(text => {
|
||||
document.getElementById('text-detail').textContent = text.name;
|
||||
});
|
||||
});
|
||||
11
views/templates/text.php
Normal file
11
views/templates/text.php
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Daily Goals - Text</title>
|
||||
</head>
|
||||
<body>
|
||||
<a href="/admin/texts" id="back">Back to Texts</a>
|
||||
<div id="text-detail"></div>
|
||||
<script src="/js/text.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Add a link
Reference in a new issue