From 166dd37359f2c736b82404092df55b948eacc0c5 Mon Sep 17 00:00:00 2001 From: Holly Date: Sun, 13 Oct 2024 14:24:34 +0100 Subject: [PATCH] implement hints --- server/controller/AdminController.ts | 4 +++- server/entities/Badge.ts | 2 ++ server/models/admin/AdminBadgeViewModel.ts | 1 + server/repos/BadgeRepo.ts | 9 +++++---- server/services/BadgeService.ts | 3 ++- server/views/admin/badge.ejs | 8 +++++++- server/views/home/home.ejs | 2 +- 7 files changed, 21 insertions(+), 8 deletions(-) diff --git a/server/controller/AdminController.ts b/server/controller/AdminController.ts index 15289ad..367329a 100644 --- a/server/controller/AdminController.ts +++ b/server/controller/AdminController.ts @@ -123,12 +123,14 @@ export default class AdminController_Auth$Admin extends Controller { if (typeof(adminBadgeViewModel.id) !== "undefined" && badge) { adminBadgeViewModel.name = badge.Name; adminBadgeViewModel.description = badge.Description; + adminBadgeViewModel.hint = badge.Hint; adminBadgeViewModel.imageUrl = badge.ImageUrl; adminBadgeViewModel.forUrl = badge.ForUrl; adminBadgeViewModel.isSecret = badge.IsSecret; } else { adminBadgeViewModel.name = ""; adminBadgeViewModel.description = ""; + adminBadgeViewModel.hint = ""; adminBadgeViewModel.imageUrl = ""; adminBadgeViewModel.forUrl = ""; adminBadgeViewModel.isSecret = false; @@ -142,7 +144,7 @@ export default class AdminController_Auth$Admin extends Controller { 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"); } diff --git a/server/entities/Badge.ts b/server/entities/Badge.ts index 29bcc0a..f20c4eb 100644 --- a/server/entities/Badge.ts +++ b/server/entities/Badge.ts @@ -2,6 +2,7 @@ export default class Badge { public Id: number; public Name: string; public Description: string; + public Hint: string; public ImageUrl: string; public ForUrl: string; public IsSecret: boolean; @@ -17,6 +18,7 @@ export default class Badge { this.Id = Number.MIN_VALUE; this.Name = ""; this.Description = ""; + this.Hint = ""; this.ImageUrl = ""; this.ForUrl = ""; this.IsSecret = false; diff --git a/server/models/admin/AdminBadgeViewModel.ts b/server/models/admin/AdminBadgeViewModel.ts index b370d6e..a00ad07 100644 --- a/server/models/admin/AdminBadgeViewModel.ts +++ b/server/models/admin/AdminBadgeViewModel.ts @@ -2,6 +2,7 @@ export default interface AdminBadgeViewModel { id?: string, name?: string, description?: string, + hint?: string, imageUrl?: string, forUrl?: string, isSecret?: boolean diff --git a/server/repos/BadgeRepo.ts b/server/repos/BadgeRepo.ts index 95a07da..02a361f 100644 --- a/server/repos/BadgeRepo.ts +++ b/server/repos/BadgeRepo.ts @@ -48,12 +48,12 @@ export default abstract class BadgeRepo { public static async insertUpdate(badge:Badge) { 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.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 = (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.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"]; } else { - await Database.Instance.query(`UPDATE Badge SET Name = ?, Description = ?, 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 + 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.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.Name = dbBadge.Name; badge.Description = dbBadge.Description; + badge.Hint = dbBadge.Hint; badge.ImageUrl = dbBadge.ImageUrl; badge.ForUrl = dbBadge.ForUrl; badge.IsSecret = dbBadge.IsSecret[0] === 1; diff --git a/server/services/BadgeService.ts b/server/services/BadgeService.ts index 985051b..3219b4e 100644 --- a/server/services/BadgeService.ts +++ b/server/services/BadgeService.ts @@ -5,7 +5,7 @@ import BadgeCache from "../objects/BadgeCache"; import UserBadgeRepo from "../repos/UserBadgeRepo"; 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 { let badge = id ? await BadgeRepo.selectById(id) : null; if (badge === null) { @@ -19,6 +19,7 @@ export default abstract class BadgeService { badge.Name = name; badge.Description = description; + badge.Hint = hint; badge.ImageUrl = imageUrl; badge.ForUrl = forUrl; badge.IsSecret = isSecret; diff --git a/server/views/admin/badge.ejs b/server/views/admin/badge.ejs index 497a114..b1f6631 100644 --- a/server/views/admin/badge.ejs +++ b/server/views/admin/badge.ejs @@ -30,7 +30,13 @@
- + +
+
+
+
+ +
diff --git a/server/views/home/home.ejs b/server/views/home/home.ejs index 1eb9fcd..ebfc4a6 100644 --- a/server/views/home/home.ejs +++ b/server/views/home/home.ejs @@ -73,7 +73,7 @@ <% } else if (!badge.IsSecret) { %> - + <% } %>