Skip to content

Commit

Permalink
Update gallery with active image toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
ezrichards committed Aug 12, 2024
1 parent ee5bc74 commit ebc59e4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
8 changes: 8 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,14 @@ app.get(
}),
);

app.post(
"/gallery",
fallible(async (req, res) => {
await db.query("UDPATE images SET active = $1 WHERE id = $2", [req.body.active, req.body.image_id]);
res.redirect("/gallery");
}),
);

app.get(
"/uploads/:id",
fallible(async (req, res) => {
Expand Down
20 changes: 20 additions & 0 deletions views/gallery.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,26 @@
<img src="uploads/<%= image.id %>" alt="<%= image.caption %>" class="mt-2 img-fluid mx-auto d-block rounded shadow" />
<p class="gallery-image-caption"><%= image.caption %></p>
<!-- TODO find a better way to do this check -->
<% if(typeof user=='object' && user) { %>
<% if(user.is_admin) { %>
<p>Admin Actions</p>
<form method="POST" action="/gallery">
<input type="hidden" name="image_id" value="<%= image.id %>">
<div class="modal-body">
<div class="mb-3">
<input class="form-check-input" type="checkbox" checked="<%= image.active %>" role="switch" name="active" id="activeImage">
<label class="form-check-label" for="activeImage">Active</label>
</div>
</div>
<div class="modal-footer">
<button type="reset" class="btn btn-outline-secondary" data-bs-dismiss="modal">Discard</button>
<button class="btn btn-success">Update</button>
</div>
</form>
<% } %>
<% } %>
</div>
</div>
</div>
Expand Down

0 comments on commit ebc59e4

Please sign in to comment.