implement hints

This commit is contained in:
Holly Stubbs 2024-10-13 14:24:34 +01:00
parent 1b99440d70
commit 166dd37359
Signed by: tgpholly
GPG key ID: B8583C4B7D18119E
7 changed files with 21 additions and 8 deletions

View file

@ -123,12 +123,14 @@ export default class AdminController_Auth$Admin extends Controller {
if (typeof(adminBadgeViewModel.id) !== "undefined" && badge) { if (typeof(adminBadgeViewModel.id) !== "undefined" && badge) {
adminBadgeViewModel.name = badge.Name; adminBadgeViewModel.name = badge.Name;
adminBadgeViewModel.description = badge.Description; adminBadgeViewModel.description = badge.Description;
adminBadgeViewModel.hint = badge.Hint;
adminBadgeViewModel.imageUrl = badge.ImageUrl; adminBadgeViewModel.imageUrl = badge.ImageUrl;
adminBadgeViewModel.forUrl = badge.ForUrl; adminBadgeViewModel.forUrl = badge.ForUrl;
adminBadgeViewModel.isSecret = badge.IsSecret; adminBadgeViewModel.isSecret = badge.IsSecret;
} else { } else {
adminBadgeViewModel.name = ""; adminBadgeViewModel.name = "";
adminBadgeViewModel.description = ""; adminBadgeViewModel.description = "";
adminBadgeViewModel.hint = "";
adminBadgeViewModel.imageUrl = ""; adminBadgeViewModel.imageUrl = "";
adminBadgeViewModel.forUrl = ""; adminBadgeViewModel.forUrl = "";
adminBadgeViewModel.isSecret = false; adminBadgeViewModel.isSecret = false;
@ -142,7 +144,7 @@ export default class AdminController_Auth$Admin extends Controller {
return this.badRequest(); return this.badRequest();
} }
await BadgeService.SaveBadge(this.session.userId, parseInt(adminBadgeViewModel.id), adminBadgeViewModel.name ?? "", adminBadgeViewModel.description ?? "", adminBadgeViewModel.imageUrl ?? "", adminBadgeViewModel.forUrl ?? "", (adminBadgeViewModel.isSecret?.toString() ?? "") === "on"); await BadgeService.SaveBadge(this.session.userId, parseInt(adminBadgeViewModel.id), adminBadgeViewModel.name ?? "", adminBadgeViewModel.description ?? "", adminBadgeViewModel.hint ?? "", adminBadgeViewModel.imageUrl ?? "", adminBadgeViewModel.forUrl ?? "", (adminBadgeViewModel.isSecret?.toString() ?? "") === "on");
return this.redirectToAction("badges"); return this.redirectToAction("badges");
} }

View file

@ -2,6 +2,7 @@ export default class Badge {
public Id: number; public Id: number;
public Name: string; public Name: string;
public Description: string; public Description: string;
public Hint: string;
public ImageUrl: string; public ImageUrl: string;
public ForUrl: string; public ForUrl: string;
public IsSecret: boolean; public IsSecret: boolean;
@ -17,6 +18,7 @@ export default class Badge {
this.Id = Number.MIN_VALUE; this.Id = Number.MIN_VALUE;
this.Name = ""; this.Name = "";
this.Description = ""; this.Description = "";
this.Hint = "";
this.ImageUrl = ""; this.ImageUrl = "";
this.ForUrl = ""; this.ForUrl = "";
this.IsSecret = false; this.IsSecret = false;

View file

@ -2,6 +2,7 @@ export default interface AdminBadgeViewModel {
id?: string, id?: string,
name?: string, name?: string,
description?: string, description?: string,
hint?: string,
imageUrl?: string, imageUrl?: string,
forUrl?: string, forUrl?: string,
isSecret?: boolean isSecret?: boolean

View file

@ -48,12 +48,12 @@ export default abstract class BadgeRepo {
public static async insertUpdate(badge:Badge) { public static async insertUpdate(badge:Badge) {
if (badge.Id === Number.MIN_VALUE) { if (badge.Id === Number.MIN_VALUE) {
badge.Id = (await Database.Instance.query("INSERT Badge (Name, Description, ImageUrl, ForUrl, IsSecret, CreatedByUserId, CreatedDatetime, LastModifiedByUserId, LastModifiedDatetime, DeletedByUserId, DeletedDatetime, IsDeleted) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING Id;", [ badge.Id = (await Database.Instance.query("INSERT Badge (Name, Description, Hint, ImageUrl, ForUrl, IsSecret, CreatedByUserId, CreatedDatetime, LastModifiedByUserId, LastModifiedDatetime, DeletedByUserId, DeletedDatetime, IsDeleted) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING Id;", [
badge.Name, badge.Description, badge.ImageUrl, badge.ForUrl, Number(badge.IsSecret), badge.CreatedByUserId, badge.CreatedDatetime.getTime(), badge.LastModifiedByUserId ?? null, badge.LastModifiedDatetime?.getTime() ?? null, badge.DeletedByUserId ?? null, badge.DeletedDatetime?.getTime() ?? null, Number(badge.IsDeleted) badge.Name, badge.Description, badge.Hint, badge.ImageUrl, badge.ForUrl, Number(badge.IsSecret), badge.CreatedByUserId, badge.CreatedDatetime.getTime(), badge.LastModifiedByUserId ?? null, badge.LastModifiedDatetime?.getTime() ?? null, badge.DeletedByUserId ?? null, badge.DeletedDatetime?.getTime() ?? null, Number(badge.IsDeleted)
]))[0]["Id"]; ]))[0]["Id"];
} else { } else {
await Database.Instance.query(`UPDATE Badge SET Name = ?, Description = ?, ImageUrl = ?, ForUrl = ?, IsSecret = ?, CreatedByUserId = ?, CreatedDatetime = ?, LastModifiedByUserId = ?, LastModifiedDatetime = ?, DeletedByUserId = ?, DeletedDatetime = ?, IsDeleted = ? WHERE Id = ?`, [ await Database.Instance.query(`UPDATE Badge SET Name = ?, Description = ?, Hint = ?, ImageUrl = ?, ForUrl = ?, IsSecret = ?, CreatedByUserId = ?, CreatedDatetime = ?, LastModifiedByUserId = ?, LastModifiedDatetime = ?, DeletedByUserId = ?, DeletedDatetime = ?, IsDeleted = ? WHERE Id = ?`, [
badge.Name, badge.Description, badge.ImageUrl, badge.ForUrl, Number(badge.IsSecret), badge.CreatedByUserId, badge.CreatedDatetime.getTime(), badge.LastModifiedByUserId ?? null, badge.LastModifiedDatetime?.getTime() ?? null, badge.DeletedByUserId ?? null, badge.DeletedDatetime?.getTime() ?? null, Number(badge.IsDeleted), badge.Id badge.Name, badge.Description, badge.Hint, badge.ImageUrl, badge.ForUrl, Number(badge.IsSecret), badge.CreatedByUserId, badge.CreatedDatetime.getTime(), badge.LastModifiedByUserId ?? null, badge.LastModifiedDatetime?.getTime() ?? null, badge.DeletedByUserId ?? null, badge.DeletedDatetime?.getTime() ?? null, Number(badge.IsDeleted), badge.Id
]); ]);
} }
@ -65,6 +65,7 @@ function populateBadgeFromDB(badge:Badge, dbBadge:any) {
badge.Id = dbBadge.Id; badge.Id = dbBadge.Id;
badge.Name = dbBadge.Name; badge.Name = dbBadge.Name;
badge.Description = dbBadge.Description; badge.Description = dbBadge.Description;
badge.Hint = dbBadge.Hint;
badge.ImageUrl = dbBadge.ImageUrl; badge.ImageUrl = dbBadge.ImageUrl;
badge.ForUrl = dbBadge.ForUrl; badge.ForUrl = dbBadge.ForUrl;
badge.IsSecret = dbBadge.IsSecret[0] === 1; badge.IsSecret = dbBadge.IsSecret[0] === 1;

View file

@ -5,7 +5,7 @@ import BadgeCache from "../objects/BadgeCache";
import UserBadgeRepo from "../repos/UserBadgeRepo"; import UserBadgeRepo from "../repos/UserBadgeRepo";
export default abstract class BadgeService { export default abstract class BadgeService {
public static async SaveBadge(currentUserId:number, id:number | undefined, name:string, description:string, imageUrl: string, forUrl:string, isSecret: boolean) { public static async SaveBadge(currentUserId:number, id:number | undefined, name:string, description:string, hint: string, imageUrl: string, forUrl:string, isSecret: boolean) {
try { try {
let badge = id ? await BadgeRepo.selectById(id) : null; let badge = id ? await BadgeRepo.selectById(id) : null;
if (badge === null) { if (badge === null) {
@ -19,6 +19,7 @@ export default abstract class BadgeService {
badge.Name = name; badge.Name = name;
badge.Description = description; badge.Description = description;
badge.Hint = hint;
badge.ImageUrl = imageUrl; badge.ImageUrl = imageUrl;
badge.ForUrl = forUrl; badge.ForUrl = forUrl;
badge.IsSecret = isSecret; badge.IsSecret = isSecret;

View file

@ -30,7 +30,13 @@
<div class="row mb-3"> <div class="row mb-3">
<div class="col"> <div class="col">
<label for="description" class="form-label">Description</label> <label for="description" class="form-label">Description</label>
<textarea class="form-control" name="description" required><%= typeof(description) === "undefined" ? "" : description %></textarea> <textarea class="form-control" id="description" name="description" required><%= typeof(description) === "undefined" ? "" : description %></textarea>
</div>
</div>
<div class="row mb-3">
<div class="col">
<label for="hint" class="form-label">Hint</label>
<textarea class="form-control" id="hint" name="hint" required><%= typeof(hint) === "undefined" ? "" : hint %></textarea>
</div> </div>
</div> </div>
<div class="row mb-3"> <div class="row mb-3">

View file

@ -73,7 +73,7 @@
<img width="32" height="32" src="<%= badge.ImageUrl %>"> <img width="32" height="32" src="<%= badge.ImageUrl %>">
</span> </span>
<% } else if (!badge.IsSecret) { %> <% } else if (!badge.IsSecret) { %>
<span class="d-inline-block mb-3" tabindex="0" data-bs-toggle="popover" data-bs-trigger="hover focus" data-bs-placement="top" data-bs-title="???"> <span class="d-inline-block mb-3" tabindex="0" data-bs-toggle="popover" data-bs-trigger="hover focus" data-bs-placement="top" data-bs-title="???" data-bs-content="<%= badge.Hint %>">
<img src="https://eusv.net/Mu6LedXkxrZDUB"> <img src="https://eusv.net/Mu6LedXkxrZDUB">
</span> </span>
<% } %> <% } %>