add today view route and template
This commit is contained in:
parent
0b4d7238af
commit
bfacb5b62c
5 changed files with 60 additions and 1 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -2,3 +2,5 @@ vendor/
|
|||
node_modules/
|
||||
data/*.json
|
||||
.direnv/
|
||||
cypress/screenshots/
|
||||
cypress/videos/
|
||||
|
|
@ -38,6 +38,16 @@ class ViewController
|
|||
return $response;
|
||||
}
|
||||
|
||||
public function today(Response $response): Response
|
||||
{
|
||||
$html = file_get_contents(
|
||||
__DIR__ . '/../../views/templates/today.php'
|
||||
);
|
||||
$response->getBody()->write($html);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function login(Response $response): Response
|
||||
{
|
||||
$html = file_get_contents(
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ $app->post('/api/auth/register', [AuthController::class, 'register']);
|
|||
// Authenticated routes (any logged-in user)
|
||||
$app->group('', function (RouteCollectorProxy $group) {
|
||||
$group->get('/home', [ViewController::class, 'home']);
|
||||
$group->get('/today', [ViewController::class, 'today']);
|
||||
|
||||
$group->post('/api/auth/logout', [AuthController::class, 'logout']);
|
||||
$group->get('/api/auth/me', [AuthController::class, 'me']);
|
||||
|
|
|
|||
33
public/js/today.js
Normal file
33
public/js/today.js
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const scheduledNodesList = document.getElementById(
|
||||
'scheduled-nodes-list'
|
||||
);
|
||||
|
||||
function todayDateString() {
|
||||
const today = new Date();
|
||||
const year = today.getFullYear();
|
||||
const month = String(today.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(today.getDate()).padStart(2, '0');
|
||||
return year + '-' + month + '-' + day;
|
||||
}
|
||||
|
||||
async function loadScheduledNodes() {
|
||||
const date = todayDateString();
|
||||
const response = await fetch(
|
||||
'/api/scheduled-nodes?date=' + date,
|
||||
{ credentials: 'same-origin' }
|
||||
);
|
||||
if (!response.ok) {
|
||||
return;
|
||||
}
|
||||
const scheduledNodes = await response.json();
|
||||
scheduledNodesList.innerHTML = scheduledNodes
|
||||
.map((scheduledNode) =>
|
||||
'<li>' + scheduledNode.planName + ': ' +
|
||||
scheduledNode.nodeTitle + '</li>'
|
||||
)
|
||||
.join('');
|
||||
}
|
||||
|
||||
loadScheduledNodes();
|
||||
});
|
||||
13
views/templates/today.php
Normal file
13
views/templates/today.php
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Daily Goals - Today</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Today</h1>
|
||||
<ul id="scheduled-nodes-list">
|
||||
</ul>
|
||||
<script src="/js/auth.js"></script>
|
||||
<script src="/js/today.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Add a link
Reference in a new issue