feat: session detail page

This commit is contained in:
wancat committed 2023-10-14 19:15:07 +08:00
1 parent a4f1c9fef1
commit 2257b4b809
4 files changed
+70 -3

No files matched your search

@@ -1,7 +1,12 @@
import { sessionList } from '../models/sessions.js'
import { sessionList, sessionDetail } from '../models/sessions.js'
// eslint-disable-next-line import/prefer-default-export
export async function sessionListController(req, res) {
const sessions = await sessionList()
res.render('sessions', { sessions })
}
export async function sessionDetailController(req, res) {
const { id } = req.params
const session = await sessionDetail(id)
res.render('sessionDetail', { session })
}
+5 -1
View File
@@ -3,7 +3,10 @@ import { Router } from 'express'
import { homeController } from './controllers/index.js'
import { userListController } from './controllers/users.js'
import { commandListController } from './controllers/commands.js'
import { sessionListController } from './controllers/sessions.js'
import {
sessionDetailController,
sessionListController,
} from './controllers/sessions.js'
const router = Router()
@@ -11,5 +14,6 @@ router.get('/', homeController)
router.get('/users', userListController)
router.get('/commands', commandListController)
router.get('/sessions', sessionListController)
router.get('/sessions/:id', sessionDetailController)
export default router
@@ -0,0 +1,56 @@
<h1>{{title}}</h1>
<div>
{{#with session}}
<table>
<tr>
<th>Quest</th>
<td>{{quest}}</td>
</tr>
<tr>
<th>User</th>
<td>{{user}}</td>
</tr>
<tr>
<th>Status</th>
<td>{{status}}</td>
</tr>
<tr>
<th>Created At</th>
<td>{{createdAt}}</td>
</tr>
<tr>
<th>Finished At</th>
<td>{{finishedAt}}</td>
</tr>
<tr>
<th>Used Time</th>
<td>{{usedTime}}</td>
</tr>
<tr>
<th>Command Count</th>
<td>{{commands.length}}</td>
</tr>
</table>
<h2>Commands</h2>
<table>
<tr>
<th>Command</th>
<th>PWD</th>
<th>Output</th>
<th>Error</th>
<th>Created At</th>
</tr>
{{#each commands}}
<tr>
<td>{{command}}</td>
<td>{{pwd}}</td>
<td>{{output}}</td>
<td>{{error}}</td>
<td>{{createdAt}}</td>
</tr>
{{/each}}
</table>
{{/with}}
</div>
@@ -4,6 +4,7 @@
<tr>
<th>User</th>
<th>Quest</th>
<th></th>
<th>Status</th>
<th>Created At</th>
<th>Finished At</th>
@@ -14,6 +15,7 @@
<tr>
<td>{{user}}</td>
<td>{{quest}}</td>
<td><a href='/sessions/{{_id}}'>Detail</a></td>
<td>{{status}}</td>
<td>{{createdAt}}</td>
<td>{{finishedAt}}</td>