5 changed files with 213 additions and 0 deletions
@ -0,0 +1,108 @@ |
|||||
|
// app/controllers/broadcast-show.ts
|
||||
|
// Copyright (C) 2025 DTP Technologies, LLC
|
||||
|
// All Rights Reserved
|
||||
|
|
||||
|
import { NextFunction, Request, Response } from "express"; |
||||
|
|
||||
|
import { WebController, WebServer } from "../../lib/dtplib.js"; |
||||
|
|
||||
|
import BroadcastShowService from "../services/broadcast-show.js"; |
||||
|
import { populateBroadcastShow } from "./lib/populators.js"; |
||||
|
|
||||
|
export default class BroadcastShowController extends WebController { |
||||
|
static get name(): string { |
||||
|
return "BroadcastShowController"; |
||||
|
} |
||||
|
static get slug(): string { |
||||
|
return "broadcastShow"; |
||||
|
} |
||||
|
|
||||
|
constructor(server: WebServer) { |
||||
|
super(server, BroadcastShowController); |
||||
|
} |
||||
|
|
||||
|
get route(): string { |
||||
|
return "/show"; |
||||
|
} |
||||
|
|
||||
|
async start(): Promise<void> { |
||||
|
this.router.param("showId", populateBroadcastShow(this)); |
||||
|
|
||||
|
this.router.post("/:showId", this.postUpdate.bind(this)); |
||||
|
this.router.post("/", this.postCreate.bind(this)); |
||||
|
|
||||
|
this.router.get("/create", this.getEditor.bind(this)); |
||||
|
|
||||
|
this.router.get("/:showId/edit", this.getEditor.bind(this)); |
||||
|
this.router.get("/:showId", this.getShowView.bind(this)); |
||||
|
|
||||
|
this.router.get("/", this.getHome.bind(this)); |
||||
|
} |
||||
|
|
||||
|
async postCreate( |
||||
|
req: Request, |
||||
|
res: Response, |
||||
|
next: NextFunction |
||||
|
): Promise<void> { |
||||
|
const showService = this.getService<BroadcastShowService>("broadcastShow"); |
||||
|
try { |
||||
|
res.locals.show = await showService.create(req.body); |
||||
|
res.redirect(`/show/${res.locals.show._id}/edit`); |
||||
|
} catch (error) { |
||||
|
this.log.error("failed to process show create request", { error }); |
||||
|
return next(error); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
async postUpdate( |
||||
|
req: Request, |
||||
|
res: Response, |
||||
|
next: NextFunction |
||||
|
): Promise<void> { |
||||
|
const showService = this.getService<BroadcastShowService>("broadcastShow"); |
||||
|
try { |
||||
|
res.locals.show = await showService.update(res.locals.show, req.body); |
||||
|
res.redirect(`/show/${res.locals.show._id}/edit`); |
||||
|
} catch (error) { |
||||
|
this.log.error("failed to process show update request", { error }); |
||||
|
return next(error); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
async getEditor(_req: Request, res: Response): Promise<void> { |
||||
|
res.render("broadcast-show/editor"); |
||||
|
} |
||||
|
|
||||
|
async getShowView( |
||||
|
_req: Request, |
||||
|
res: Response, |
||||
|
next: NextFunction |
||||
|
): Promise<void> { |
||||
|
const showService = this.getService<BroadcastShowService>("broadcastShow"); |
||||
|
try { |
||||
|
res.locals.recommendedShows = await showService.getRecommended( |
||||
|
3, |
||||
|
res.locals.show |
||||
|
); |
||||
|
res.render("broadcast-show/view"); |
||||
|
} catch (error) { |
||||
|
this.log.error("failed to present the Show Home view", { error }); |
||||
|
return next(error); |
||||
|
} |
||||
|
} |
||||
|
async getHome( |
||||
|
req: Request, |
||||
|
res: Response, |
||||
|
next: NextFunction |
||||
|
): Promise<void> { |
||||
|
const showService = this.getService<BroadcastShowService>("broadcastShow"); |
||||
|
try { |
||||
|
res.locals.pagination = this.getPaginationParameters(req, 12); |
||||
|
res.locals.showLibrary = await showService.getLive(res.locals.pagination); |
||||
|
res.render("broadcast-show/home"); |
||||
|
} catch (error) { |
||||
|
this.log.error("failed to present the Show Home view", { error }); |
||||
|
return next(error); |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,34 @@ |
|||||
|
extends ../layouts/main-sidebar |
||||
|
block content |
||||
|
|
||||
|
- var actionUrl = show ? `/show/${show._id}` : "/show"; |
||||
|
|
||||
|
form(method="POST", action= actionUrl).uk-form |
||||
|
.uk-card.uk-card-default.uk-card-small |
||||
|
.uk-card-header |
||||
|
h1.uk-card-title #{show ? "Edit" : "Create New"} Broadcast Show |
||||
|
.uk-card-body |
||||
|
.uk-margin |
||||
|
label(for="title").uk-form-label Title |
||||
|
input(id="title", name="title", type="text", placeholder="Enter show title", required).uk-input |
||||
|
.uk-margin |
||||
|
label(for="description").uk-form-label Description |
||||
|
textarea( |
||||
|
id="description", |
||||
|
name="description", |
||||
|
rows="4", |
||||
|
placeholder="Enter show description", |
||||
|
required, |
||||
|
).uk-textarea.uk-resize-vertical |
||||
|
.uk-card-footer |
||||
|
div(uk-grid).uk-grid-small |
||||
|
.uk-width-expand |
||||
|
+renderBackButton() |
||||
|
.uk-width-auto |
||||
|
button(type="submit").uk-button.uk-button-primary.uk-border-rounded |
||||
|
span |
||||
|
if show |
||||
|
i.fa-solid.fa-save |
||||
|
else |
||||
|
i.fa-solid.fa-plus |
||||
|
span.uk-margin-small-left #{show ? "Update" : "Create"} Show |
@ -0,0 +1,13 @@ |
|||||
|
extends ../layouts/main-sidebar |
||||
|
block content |
||||
|
|
||||
|
div(uk-grid).uk-grid-small.uk-flex-middle |
||||
|
.uk-width-expand |
||||
|
h1 Show Directory |
||||
|
.uk-width-auto |
||||
|
a(href="/show/create").uk-button.uk-button-default.uk-button-small.uk-border-rounded |
||||
|
span |
||||
|
i.fa-solid.fa-plus |
||||
|
span.uk-margin-small-left Create Show |
||||
|
|
||||
|
pre= JSON.stringify(showLibrary, null, 2) |
Loading…
Reference in new issue