Checkpoint · Lesson 1.4
HTML pages with EJS: checkpoint files
Compare your folder with the reference using Git, if you cloned it: git diff lesson/m01-l04 -- src.
Files changed in this lesson
package-lock.json changed
Generated by npm from package.json. Do not edit it by hand; run the npm commands from the lesson.
package.json changed
package.json{
"name": "caretaker",
"version": "1.0.0",
"description": "",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node src/server.js",
"dev": "node --watch src/server.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"type": "module",
"dependencies": {
"ejs": "7.0.2",
"express": "5.3.0"
}
}
{ "name": "caretaker", "version": "1.0.0", "description": "", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "start": "node src/server.js", "dev": "node --watch src/server.js" }, "keywords": [], "author": "", "license": "ISC", "type": "module", "dependencies": { "ejs": "7.0.2", "express": "5.3.0" }}public/css/style.css added
public/css/style.css:root {
--bg: #f6f7f9; --surface: #fff; --text: #1c2026; --muted: #646b75; --border: #dde1e6;
--accent: #1f56d1; --accent-dark: #1844a8; --danger: #b42318; --ok: #17784a; --warn: #9a5b00;
--radius: 8px; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); line-height: 1.5; font-size: 15px; }
a { color: var(--accent); }
code { font-family: ui-monospace, Menlo, monospace; font-size: .9em; }
.container { max-width: 1080px; margin: 0 auto; padding: 0 20px; }
main.container { padding-top: 28px; padding-bottom: 48px; min-height: calc(100vh - 140px); }
.site-header { background: #14181f; color: #fff; }
.header-inner { display: flex; align-items: center; gap: 24px; min-height: 56px; flex-wrap: wrap; }
.brand { color: #fff; font-weight: 700; text-decoration: none; letter-spacing: -.01em; font-size: 17px; }
.main-nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.main-nav a { color: #c9d1dc; text-decoration: none; padding: 6px 10px; border-radius: 6px; }
.main-nav a:hover { background: #262c36; color: #fff; }
.user-nav { display: flex; align-items: center; gap: 10px; color: #c9d1dc; font-size: 14px; }
.user-nav form { margin: 0; }
.link-button { background: none; border: 0; color: #c9d1dc; cursor: pointer; font: inherit; padding: 6px 10px; border-radius: 6px; }
.link-button:hover { background: #262c36; color: #fff; }
.site-footer { color: var(--muted); font-size: 13px; padding: 20px 0 32px; }
h1 { font-size: 26px; margin: 0 0 16px; letter-spacing: -.01em; }
h2 { font-size: 19px; margin: 28px 0 12px; }
.page-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-header h1 { margin: 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.actions form { margin: 0; }
.breadcrumbs { color: var(--muted); font-size: 14px; margin: 0 0 6px; }
.btn { display: inline-block; padding: 8px 14px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); color: var(--text); text-decoration: none; font: inherit; font-weight: 550; cursor: pointer; }
.btn:hover { border-color: #b9c0c9; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-danger { color: var(--danger); border-color: #f0c7c3; }
.btn-danger:hover { background: #fdecea; }
.btn-small { padding: 4px 10px; font-size: 13px; }
table.data { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
table.data th, table.data td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
table.data th { background: #f0f2f5; font-size: 13px; color: #3c434d; font-weight: 600; }
table.data th a { color: inherit; text-decoration: none; }
table.data th a:hover { text-decoration: underline; }
table.data tr:last-child td { border-bottom: 0; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12.5px; font-weight: 600; background: #eceff3; color: #3c434d; white-space: nowrap; }
.sev-low { background: #eef4ff; color: #2b4f99; }
.sev-medium { background: #fff6dc; color: #7a5300; }
.sev-high { background: #ffe9d6; color: #9a4100; }
.sev-critical { background: #fde3e1; color: #a1170e; }
.status-open, .status-submitted { background: #e7f0ff; color: #1d4ab3; }
.status-investigating, .status-draft { background: #fff3d6; color: #7a5300; }
.status-closed, .status-approved { background: #e5f5ec; color: #17653f; }
.role-badge { background: #f1ecfb; color: #5b34a0; }
.form { max-width: 560px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.field { margin-bottom: 16px; }
.field label { display: block; font-weight: 600; margin-bottom: 4px; font-size: 14px; }
.field input, .field select, .field textarea { width: 100%; padding: 8px 10px; border: 1px solid #c4cad2; border-radius: 6px; font: inherit; background: #fff; }
.field textarea { min-height: 110px; resize: vertical; }
.field.has-error input, .field.has-error select, .field.has-error textarea { border-color: var(--danger); }
.field-error { color: var(--danger); font-size: 13.5px; margin: 4px 0 0; }
.hint { color: var(--muted); font-size: 13px; margin: 4px 0 0; }
.form-actions { display: flex; gap: 8px; }
.error-summary { border: 1px solid #f0c7c3; background: #fdecea; color: #7f1d14; padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px; }
.error-summary p { margin: 0; }
.flash { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px; border: 1px solid; }
.flash-success { background: #e8f6ee; border-color: #b9e2c9; color: #155b37; }
.flash-error { background: #fdecea; border-color: #f0c7c3; color: #7f1d14; }
.details { display: grid; grid-template-columns: max-content 1fr; gap: 8px 20px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 20px; margin: 0 0 20px; }
.details dt { color: var(--muted); font-weight: 600; font-size: 14px; }
.details dd { margin: 0; }
.prose { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 20px; white-space: pre-wrap; margin: 0 0 20px; }
.empty { color: var(--muted); background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); padding: 24px; text-align: center; }
.muted { color: var(--muted); }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; margin-bottom: 14px; }
.filters label { font-size: 12.5px; font-weight: 600; color: var(--muted); display: flex; flex-direction: column; gap: 3px; }
.filters select, .filters input { padding: 6px 8px; border: 1px solid #c4cad2; border-radius: 6px; font: inherit; }
.pagination { display: flex; gap: 6px; align-items: center; margin-top: 14px; flex-wrap: wrap; color: var(--muted); font-size: 14px; }
.pagination a, .pagination span.current { padding: 4px 10px; border: 1px solid var(--border); border-radius: 6px; text-decoration: none; background: var(--surface); }
.pagination span.current { background: var(--accent); border-color: var(--accent); color: #fff; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; margin-bottom: 24px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.card h3 { margin: 0 0 4px; font-size: 15px; }
.card .stat { font-size: 28px; font-weight: 700; }
.inline-form { display: inline; }
@media (max-width: 640px) {
table.data { display: block; overflow-x: auto; }
.details { grid-template-columns: 1fr; }
}
:root { --bg: #f6f7f9; --surface: #fff; --text: #1c2026; --muted: #646b75; --border: #dde1e6; --accent: #1f56d1; --accent-dark: #1844a8; --danger: #b42318; --ok: #17784a; --warn: #9a5b00; --radius: 8px; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;}* { box-sizing: border-box; }body { margin: 0; background: var(--bg); color: var(--text); line-height: 1.5; font-size: 15px; }a { color: var(--accent); }code { font-family: ui-monospace, Menlo, monospace; font-size: .9em; }.container { max-width: 1080px; margin: 0 auto; padding: 0 20px; }main.container { padding-top: 28px; padding-bottom: 48px; min-height: calc(100vh - 140px); }.site-header { background: #14181f; color: #fff; }.header-inner { display: flex; align-items: center; gap: 24px; min-height: 56px; flex-wrap: wrap; }.brand { color: #fff; font-weight: 700; text-decoration: none; letter-spacing: -.01em; font-size: 17px; }.main-nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }.main-nav a { color: #c9d1dc; text-decoration: none; padding: 6px 10px; border-radius: 6px; }.main-nav a:hover { background: #262c36; color: #fff; }.user-nav { display: flex; align-items: center; gap: 10px; color: #c9d1dc; font-size: 14px; }.user-nav form { margin: 0; }.link-button { background: none; border: 0; color: #c9d1dc; cursor: pointer; font: inherit; padding: 6px 10px; border-radius: 6px; }.link-button:hover { background: #262c36; color: #fff; }.site-footer { color: var(--muted); font-size: 13px; padding: 20px 0 32px; }h1 { font-size: 26px; margin: 0 0 16px; letter-spacing: -.01em; }h2 { font-size: 19px; margin: 28px 0 12px; }.page-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }.page-header h1 { margin: 0; }.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }.actions form { margin: 0; }.breadcrumbs { color: var(--muted); font-size: 14px; margin: 0 0 6px; }.btn { display: inline-block; padding: 8px 14px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); color: var(--text); text-decoration: none; font: inherit; font-weight: 550; cursor: pointer; }.btn:hover { border-color: #b9c0c9; }.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }.btn-primary:hover { background: var(--accent-dark); }.btn-danger { color: var(--danger); border-color: #f0c7c3; }.btn-danger:hover { background: #fdecea; }.btn-small { padding: 4px 10px; font-size: 13px; }table.data { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }table.data th, table.data td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }table.data th { background: #f0f2f5; font-size: 13px; color: #3c434d; font-weight: 600; }table.data th a { color: inherit; text-decoration: none; }table.data th a:hover { text-decoration: underline; }table.data tr:last-child td { border-bottom: 0; }.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12.5px; font-weight: 600; background: #eceff3; color: #3c434d; white-space: nowrap; }.sev-low { background: #eef4ff; color: #2b4f99; }.sev-medium { background: #fff6dc; color: #7a5300; }.sev-high { background: #ffe9d6; color: #9a4100; }.sev-critical { background: #fde3e1; color: #a1170e; }.status-open, .status-submitted { background: #e7f0ff; color: #1d4ab3; }.status-investigating, .status-draft { background: #fff3d6; color: #7a5300; }.status-closed, .status-approved { background: #e5f5ec; color: #17653f; }.role-badge { background: #f1ecfb; color: #5b34a0; }.form { max-width: 560px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }.field { margin-bottom: 16px; }.field label { display: block; font-weight: 600; margin-bottom: 4px; font-size: 14px; }.field input, .field select, .field textarea { width: 100%; padding: 8px 10px; border: 1px solid #c4cad2; border-radius: 6px; font: inherit; background: #fff; }.field textarea { min-height: 110px; resize: vertical; }.field.has-error input, .field.has-error select, .field.has-error textarea { border-color: var(--danger); }.field-error { color: var(--danger); font-size: 13.5px; margin: 4px 0 0; }.hint { color: var(--muted); font-size: 13px; margin: 4px 0 0; }.form-actions { display: flex; gap: 8px; }.error-summary { border: 1px solid #f0c7c3; background: #fdecea; color: #7f1d14; padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px; }.error-summary p { margin: 0; }.flash { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px; border: 1px solid; }.flash-success { background: #e8f6ee; border-color: #b9e2c9; color: #155b37; }.flash-error { background: #fdecea; border-color: #f0c7c3; color: #7f1d14; }.details { display: grid; grid-template-columns: max-content 1fr; gap: 8px 20px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 20px; margin: 0 0 20px; }.details dt { color: var(--muted); font-weight: 600; font-size: 14px; }.details dd { margin: 0; }.prose { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 20px; white-space: pre-wrap; margin: 0 0 20px; }.empty { color: var(--muted); background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); padding: 24px; text-align: center; }.muted { color: var(--muted); }.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; margin-bottom: 14px; }.filters label { font-size: 12.5px; font-weight: 600; color: var(--muted); display: flex; flex-direction: column; gap: 3px; }.filters select, .filters input { padding: 6px 8px; border: 1px solid #c4cad2; border-radius: 6px; font: inherit; }.pagination { display: flex; gap: 6px; align-items: center; margin-top: 14px; flex-wrap: wrap; color: var(--muted); font-size: 14px; }.pagination a, .pagination span.current { padding: 4px 10px; border: 1px solid var(--border); border-radius: 6px; text-decoration: none; background: var(--surface); }.pagination span.current { background: var(--accent); border-color: var(--accent); color: #fff; }.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; margin-bottom: 24px; }.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }.card h3 { margin: 0 0 4px; font-size: 15px; }.card .stat { font-size: 28px; font-weight: 700; }.inline-form { display: inline; }@media (max-width: 640px) { table.data { display: block; overflow-x: auto; } .details { grid-template-columns: 1fr; }}src/server.js changed
src/server.jsimport express from 'express';
import path from 'node:path';
const app = express();
const port = 3000;
app.set('view engine', 'ejs');
app.set('views', path.join(import.meta.dirname, '..', 'views'));
app.locals.formatDate = (iso) => new Date(iso).toLocaleString('en-IE', { dateStyle: 'medium', timeStyle: 'short', timeZone: 'UTC' });
app.use((req, res, next) => {
const started = Date.now();
res.on('finish', () => {
console.log(`${req.method} ${req.originalUrl} -> ${res.statusCode} (${Date.now() - started} ms)`);
});
next();
});
app.use(express.static(path.join(import.meta.dirname, '..', 'public')));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
const issues = [
{ id: 1, title: 'Lift stuck between floors 2 and 3', priority: 'high', status: 'open', building: 'Dublin Offices', occurredAt: '2026-11-02T09:15:00.000Z' },
{ id: 2, title: 'Dripping tap in the second-floor kitchen', priority: 'medium', status: 'closed', building: 'Dublin Offices', occurredAt: '2026-11-05T14:40:00.000Z' },
{ id: 3, title: 'Front door lock sticks at entrance 4', priority: 'critical', status: 'open', building: 'Cork Apartments', occurredAt: '2026-11-08T07:05:00.000Z' },
];
const PRIORITIES = ['low', 'medium', 'high', 'critical'];
function validateIssue(input) {
const errors = {};
const title = typeof input.title === 'string' ? input.title.trim() : '';
const building = typeof input.building === 'string' ? input.building.trim() : '';
if (title.length < 3 || title.length > 200) {
errors.title = 'Title must be between 3 and 200 characters.';
}
if (!PRIORITIES.includes(input.priority)) {
errors.priority = `Priority must be one of: ${PRIORITIES.join(', ')}.`;
}
if (building.length === 0) {
errors.building = 'Building is required.';
}
return { errors, values: { title, priority: input.priority, building } };
}
app.get('/', (req, res) => {
res.redirect('/issues');
});
app.get('/api/issues', (req, res) => {
const { status } = req.query;
const result = status ? issues.filter((issue) => issue.status === status) : issues;
res.json(result);
});
app.get('/api/issues/:id', (req, res) => {
const id = Number(req.params.id);
const issue = issues.find((e) => e.id === id);
if (!issue) {
return res.status(404).json({ error: 'Issue not found' });
}
res.json(issue);
});
let nextId = 4;
app.post('/api/issues', (req, res) => {
const { errors, values } = validateIssue(req.body ?? {});
if (Object.keys(errors).length > 0) {
return res.status(400).json({ errors });
}
const issue = { id: nextId++, ...values, status: 'open', occurredAt: new Date().toISOString() };
issues.push(issue);
res.status(201).location(`/api/issues/${issue.id}`).json(issue);
});
app.get('/issues', (req, res) => {
res.render('issues/index', { title: 'Maintenance issues', issues });
});
app.get('/issues/new', (req, res) => {
res.render('issues/new', { title: 'Report an issue', values: {}, errors: {}, priorities: PRIORITIES });
});
app.post('/issues', (req, res) => {
const { errors, values } = validateIssue(req.body ?? {});
if (Object.keys(errors).length > 0) {
return res.status(400).render('issues/new', { title: 'Report an issue', values, errors, priorities: PRIORITIES });
}
const issue = { id: nextId++, ...values, status: 'open', occurredAt: new Date().toISOString() };
issues.push(issue);
res.redirect(303, `/issues/${issue.id}`);
});
app.get('/issues/:id', (req, res) => {
const issue = issues.find((e) => e.id === Number(req.params.id));
if (!issue) {
return res.status(404).render('not-found', { title: 'Not found', path: req.path });
}
res.render('issues/show', { title: issue.title, issue });
});
app.use((req, res) => {
if (req.path.startsWith('/api/')) {
return res.status(404).json({ error: `No route for ${req.method} ${req.path}` });
}
res.status(404).render('not-found', { title: 'Not found', path: req.path });
});
app.use((err, req, res, next) => {
const status = err.status ?? 500;
if (status >= 500) {
console.error(err);
}
const message = err.expose ? err.message : 'Something went wrong';
if (req.path.startsWith('/api/')) {
return res.status(status).json({ error: message });
}
res.status(status).render('error', { title: 'Error', status, message });
});
app.listen(port, () => {
console.log(`Caretaker listening on http://localhost:${port}`);
});
import express from 'express';import path from 'node:path'; const app = express();const port = 3000; app.set('view engine', 'ejs');app.set('views', path.join(import.meta.dirname, '..', 'views'));app.locals.formatDate = (iso) => new Date(iso).toLocaleString('en-IE', { dateStyle: 'medium', timeStyle: 'short', timeZone: 'UTC' }); app.use((req, res, next) => { const started = Date.now(); res.on('finish', () => { console.log(`${req.method} ${req.originalUrl} -> ${res.statusCode} (${Date.now() - started} ms)`); }); next();}); app.use(express.static(path.join(import.meta.dirname, '..', 'public')));app.use(express.json());app.use(express.urlencoded({ extended: false })); const issues = [ { id: 1, title: 'Lift stuck between floors 2 and 3', priority: 'high', status: 'open', building: 'Dublin Offices', occurredAt: '2026-11-02T09:15:00.000Z' }, { id: 2, title: 'Dripping tap in the second-floor kitchen', priority: 'medium', status: 'closed', building: 'Dublin Offices', occurredAt: '2026-11-05T14:40:00.000Z' }, { id: 3, title: 'Front door lock sticks at entrance 4', priority: 'critical', status: 'open', building: 'Cork Apartments', occurredAt: '2026-11-08T07:05:00.000Z' },]; const PRIORITIES = ['low', 'medium', 'high', 'critical']; function validateIssue(input) { const errors = {}; const title = typeof input.title === 'string' ? input.title.trim() : ''; const building = typeof input.building === 'string' ? input.building.trim() : ''; if (title.length < 3 || title.length > 200) { errors.title = 'Title must be between 3 and 200 characters.'; } if (!PRIORITIES.includes(input.priority)) { errors.priority = `Priority must be one of: ${PRIORITIES.join(', ')}.`; } if (building.length === 0) { errors.building = 'Building is required.'; } return { errors, values: { title, priority: input.priority, building } };} app.get('/', (req, res) => { res.redirect('/issues');}); app.get('/api/issues', (req, res) => { const { status } = req.query; const result = status ? issues.filter((issue) => issue.status === status) : issues; res.json(result);}); app.get('/api/issues/:id', (req, res) => { const id = Number(req.params.id); const issue = issues.find((e) => e.id === id); if (!issue) { return res.status(404).json({ error: 'Issue not found' }); } res.json(issue);}); let nextId = 4; app.post('/api/issues', (req, res) => { const { errors, values } = validateIssue(req.body ?? {}); if (Object.keys(errors).length > 0) { return res.status(400).json({ errors }); } const issue = { id: nextId++, ...values, status: 'open', occurredAt: new Date().toISOString() }; issues.push(issue); res.status(201).location(`/api/issues/${issue.id}`).json(issue);}); app.get('/issues', (req, res) => { res.render('issues/index', { title: 'Maintenance issues', issues });}); app.get('/issues/new', (req, res) => { res.render('issues/new', { title: 'Report an issue', values: {}, errors: {}, priorities: PRIORITIES });}); app.post('/issues', (req, res) => { const { errors, values } = validateIssue(req.body ?? {}); if (Object.keys(errors).length > 0) { return res.status(400).render('issues/new', { title: 'Report an issue', values, errors, priorities: PRIORITIES }); } const issue = { id: nextId++, ...values, status: 'open', occurredAt: new Date().toISOString() }; issues.push(issue); res.redirect(303, `/issues/${issue.id}`);}); app.get('/issues/:id', (req, res) => { const issue = issues.find((e) => e.id === Number(req.params.id)); if (!issue) { return res.status(404).render('not-found', { title: 'Not found', path: req.path }); } res.render('issues/show', { title: issue.title, issue });}); app.use((req, res) => { if (req.path.startsWith('/api/')) { return res.status(404).json({ error: `No route for ${req.method} ${req.path}` }); } res.status(404).render('not-found', { title: 'Not found', path: req.path });}); app.use((err, req, res, next) => { const status = err.status ?? 500; if (status >= 500) { console.error(err); } const message = err.expose ? err.message : 'Something went wrong'; if (req.path.startsWith('/api/')) { return res.status(status).json({ error: message }); } res.status(status).render('error', { title: 'Error', status, message });}); app.listen(port, () => { console.log(`Caretaker listening on http://localhost:${port}`);});views/error.ejs added
views/error.ejs<%- include('partials/head') %>
<h1><%= status === 500 ? 'Something went wrong' : 'Request failed' %></h1>
<p><%= message %></p>
<p><a href="/issues">Go to the issues list</a></p>
<%- include('partials/foot') %>
<%- include('partials/head') %><h1><%= status === 500 ? 'Something went wrong' : 'Request failed' %></h1><p><%= message %></p><p><a href="/issues">Go to the issues list</a></p><%- include('partials/foot') %>views/issues/index.ejs added
views/issues/index.ejs<%- include('../partials/head') %>
<div class="page-header">
<h1>Maintenance issues</h1>
<a class="btn btn-primary" href="/issues/new">Report an issue</a>
</div>
<% if (issues.length === 0) { %>
<p class="empty">No issues yet.</p>
<% } else { %>
<table class="data">
<thead>
<tr><th>Title</th><th>Building</th><th>Priority</th><th>Status</th><th>Occurred</th></tr>
</thead>
<tbody>
<% for (const issue of issues) { %>
<tr>
<td><a href="/issues/<%= issue.id %>"><%= issue.title %></a></td>
<td><%= issue.building %></td>
<td><span class="badge sev-<%= issue.priority %>"><%= issue.priority %></span></td>
<td><span class="badge status-<%= issue.status %>"><%= issue.status %></span></td>
<td><%= formatDate(issue.occurredAt) %></td>
</tr>
<% } %>
</tbody>
</table>
<% } %>
<%- include('../partials/foot') %>
<%- include('../partials/head') %><div class="page-header"> <h1>Maintenance issues</h1> <a class="btn btn-primary" href="/issues/new">Report an issue</a></div> <% if (issues.length === 0) { %> <p class="empty">No issues yet.</p><% } else { %> <table class="data"> <thead> <tr><th>Title</th><th>Building</th><th>Priority</th><th>Status</th><th>Occurred</th></tr> </thead> <tbody> <% for (const issue of issues) { %> <tr> <td><a href="/issues/<%= issue.id %>"><%= issue.title %></a></td> <td><%= issue.building %></td> <td><span class="badge sev-<%= issue.priority %>"><%= issue.priority %></span></td> <td><span class="badge status-<%= issue.status %>"><%= issue.status %></span></td> <td><%= formatDate(issue.occurredAt) %></td> </tr> <% } %> </tbody> </table><% } %><%- include('../partials/foot') %>views/issues/new.ejs added
views/issues/new.ejs<%- include('../partials/head') %>
<h1>Report a maintenance issue</h1>
<% if (Object.keys(errors).length > 0) { %>
<div class="error-summary" role="alert">
<p>Please fix the highlighted fields.</p>
</div>
<% } %>
<form method="post" action="/issues" class="form" novalidate>
<div class="field<%= errors.title ? ' has-error' : '' %>">
<label for="title">Title</label>
<input id="title" name="title" value="<%= values.title ?? '' %>" maxlength="200" required>
<% if (errors.title) { %><p class="field-error"><%= errors.title %></p><% } %>
</div>
<div class="field<%= errors.building ? ' has-error' : '' %>">
<label for="building">Building</label>
<input id="building" name="building" value="<%= values.building ?? '' %>" required>
<% if (errors.building) { %><p class="field-error"><%= errors.building %></p><% } %>
</div>
<div class="field<%= errors.priority ? ' has-error' : '' %>">
<label for="priority">Priority</label>
<select id="priority" name="priority">
<option value="">Choose…</option>
<% for (const s of priorities) { %>
<option value="<%= s %>"<%= values.priority === s ? ' selected' : '' %>><%= s %></option>
<% } %>
</select>
<% if (errors.priority) { %><p class="field-error"><%= errors.priority %></p><% } %>
</div>
<div class="form-actions">
<button type="submit" class="btn btn-primary">Save issue</button>
<a class="btn" href="/issues">Cancel</a>
</div>
</form>
<%- include('../partials/foot') %>
<%- include('../partials/head') %><h1>Report a maintenance issue</h1> <% if (Object.keys(errors).length > 0) { %> <div class="error-summary" role="alert"> <p>Please fix the highlighted fields.</p> </div><% } %> <form method="post" action="/issues" class="form" novalidate> <div class="field<%= errors.title ? ' has-error' : '' %>"> <label for="title">Title</label> <input id="title" name="title" value="<%= values.title ?? '' %>" maxlength="200" required> <% if (errors.title) { %><p class="field-error"><%= errors.title %></p><% } %> </div> <div class="field<%= errors.building ? ' has-error' : '' %>"> <label for="building">Building</label> <input id="building" name="building" value="<%= values.building ?? '' %>" required> <% if (errors.building) { %><p class="field-error"><%= errors.building %></p><% } %> </div> <div class="field<%= errors.priority ? ' has-error' : '' %>"> <label for="priority">Priority</label> <select id="priority" name="priority"> <option value="">Choose…</option> <% for (const s of priorities) { %> <option value="<%= s %>"<%= values.priority === s ? ' selected' : '' %>><%= s %></option> <% } %> </select> <% if (errors.priority) { %><p class="field-error"><%= errors.priority %></p><% } %> </div> <div class="form-actions"> <button type="submit" class="btn btn-primary">Save issue</button> <a class="btn" href="/issues">Cancel</a> </div></form><%- include('../partials/foot') %>views/issues/show.ejs added
views/issues/show.ejs<%- include('../partials/head') %>
<p class="breadcrumbs"><a href="/issues">Issues</a> / #<%= issue.id %></p>
<div class="page-header">
<h1><%= issue.title %></h1>
</div>
<dl class="details">
<dt>Building</dt><dd><%= issue.building %></dd>
<dt>Priority</dt><dd><span class="badge sev-<%= issue.priority %>"><%= issue.priority %></span></dd>
<dt>Status</dt><dd><span class="badge status-<%= issue.status %>"><%= issue.status %></span></dd>
<dt>Occurred</dt><dd><%= formatDate(issue.occurredAt) %></dd>
</dl>
<%- include('../partials/foot') %>
<%- include('../partials/head') %><p class="breadcrumbs"><a href="/issues">Issues</a> / #<%= issue.id %></p><div class="page-header"> <h1><%= issue.title %></h1></div><dl class="details"> <dt>Building</dt><dd><%= issue.building %></dd> <dt>Priority</dt><dd><span class="badge sev-<%= issue.priority %>"><%= issue.priority %></span></dd> <dt>Status</dt><dd><span class="badge status-<%= issue.status %>"><%= issue.status %></span></dd> <dt>Occurred</dt><dd><%= formatDate(issue.occurredAt) %></dd></dl><%- include('../partials/foot') %>views/not-found.ejs added
views/not-found.ejs<%- include('partials/head') %>
<h1>Page not found</h1>
<p>We could not find <code><%= path %></code>.</p>
<p><a href="/issues">Go to the issues list</a></p>
<%- include('partials/foot') %>
<%- include('partials/head') %><h1>Page not found</h1><p>We could not find <code><%= path %></code>.</p><p><a href="/issues">Go to the issues list</a></p><%- include('partials/foot') %>views/partials/foot.ejs added
views/partials/foot.ejs</main>
<footer class="site-footer">
<div class="container">Caretaker · a learning application with synthetic data</div>
</footer>
</body>
</html>
</main><footer class="site-footer"> <div class="container">Caretaker · a learning application with synthetic data</div></footer></body></html>views/partials/head.ejs added
views/partials/head.ejs<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title><%= title %> · Caretaker</title>
<link rel="stylesheet" href="/css/style.css">
</head>
<body>
<%- include('nav') %>
<main class="container">
<!doctype html><html lang="en"><head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title><%= title %> · Caretaker</title> <link rel="stylesheet" href="/css/style.css"></head><body><%- include('nav') %><main class="container">views/partials/nav.ejs added
views/partials/nav.ejs<header class="site-header">
<div class="container header-inner">
<a class="brand" href="/">Caretaker</a>
<nav class="main-nav" aria-label="Main">
<a href="/issues">Issues</a>
</nav>
</div>
</header>
<header class="site-header"> <div class="container header-inner"> <a class="brand" href="/">Caretaker</a> <nav class="main-nav" aria-label="Main"> <a href="/issues">Issues</a> </nav> </div></header>Project tree at this checkpoint
.gitignore
.npmrc
package-lock.json
package.json
public/css/style.css
src/server.js
views/error.ejs
views/issues/index.ejs
views/issues/new.ejs
views/issues/show.ejs
views/not-found.ejs
views/partials/foot.ejs
views/partials/head.ejs
views/partials/nav.ejs