From 9dcb75109f5db345e66ca53a11fb2a5a25e490c6 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Sat, 15 Jul 2023 15:16:01 +0200 Subject: [PATCH] Added achievements to user profile #268_achievements --- .../achievements_repository_service.py | 2 +- kdb-bot/src/bot_graphql/model/user.gql | 3 + kdb-bot/src/bot_graphql/queries/user_query.py | 8 +++ .../src/app/models/data/achievement.model.ts | 2 + kdb-web/src/app/models/data/user.model.ts | 4 ++ .../src/app/models/graphql/queries.model.ts | 6 ++ .../server/profile/profile.component.html | 35 ++++++++-- kdb-web/src/assets/i18n/de.json | 65 ++++++++++--------- kdb-web/src/assets/i18n/en.json | 36 +++++++++- 9 files changed, 121 insertions(+), 40 deletions(-) diff --git a/kdb-bot/src/bot_data/service/achievements_repository_service.py b/kdb-bot/src/bot_data/service/achievements_repository_service.py index 6ee69abc..130da9c8 100644 --- a/kdb-bot/src/bot_data/service/achievements_repository_service.py +++ b/kdb-bot/src/bot_data/service/achievements_repository_service.py @@ -76,7 +76,7 @@ class AchievementRepositoryService(AchievementRepositoryABC): achievements = List(Achievement) achievements_joins = List(UserGotAchievement) self._logger.trace(__name__, f"Send SQL command: {UserGotAchievement.get_select_by_user_id_string(user_id)}") - results = self._context.select(UserGotAchievement.get_select_all_string()) + results = self._context.select(UserGotAchievement.get_select_by_user_id_string(user_id)) for result in results: self._logger.trace(__name__, f"Got UserGotAchievement with id {result[0]}") achievements_joins.append(self._join_from_result(result)) diff --git a/kdb-bot/src/bot_graphql/model/user.gql b/kdb-bot/src/bot_graphql/model/user.gql index 2925e223..38db3573 100644 --- a/kdb-bot/src/bot_graphql/model/user.gql +++ b/kdb-bot/src/bot_graphql/model/user.gql @@ -17,6 +17,9 @@ type User implements TableWithHistoryQuery { userJoinedGameServerCount: Int userJoinedGameServers(filter: UserJoinedGameServerFilter, page: Page, sort: Sort): [UserJoinedGameServer] + achievementCount: Int + achievements(filter: AchievementFilter, page: Page, sort: Sort): [Achievement] + server: Server leftServer: Boolean diff --git a/kdb-bot/src/bot_graphql/queries/user_query.py b/kdb-bot/src/bot_graphql/queries/user_query.py index 53c6a7c1..9bb4a48b 100644 --- a/kdb-bot/src/bot_graphql/queries/user_query.py +++ b/kdb-bot/src/bot_graphql/queries/user_query.py @@ -2,12 +2,14 @@ from cpl_core.database.context import DatabaseContextABC from cpl_discord.service import DiscordBotServiceABC from bot_core.abc.client_utils_abc import ClientUtilsABC +from bot_data.abc.achievement_repository_abc import AchievementRepositoryABC from bot_data.abc.user_joined_game_server_repository_abc import UserJoinedGameServerRepositoryABC from bot_data.abc.user_joined_server_repository_abc import UserJoinedServerRepositoryABC from bot_data.abc.user_joined_voice_channel_repository_abc import UserJoinedVoiceChannelRepositoryABC from bot_data.model.user import User from bot_data.model.user_history import UserHistory from bot_graphql.abc.data_query_with_history_abc import DataQueryWithHistoryABC +from bot_graphql.filter.achievement_filter import AchievementFilter from bot_graphql.filter.user_joined_game_server_filter import UserJoinedGameServerFilter from bot_graphql.filter.user_joined_server_filter import UserJoinedServerFilter from bot_graphql.filter.user_joined_voice_channel_filter import UserJoinedVoiceChannelFilter @@ -26,6 +28,7 @@ class UserQuery(DataQueryWithHistoryABC): ujvs: UserJoinedVoiceChannelRepositoryABC, user_joined_game_server: UserJoinedGameServerRepositoryABC, permissions: PermissionServiceABC, + achievements: AchievementRepositoryABC, ): DataQueryWithHistoryABC.__init__(self, "User", "UsersHistory", UserHistory, db) @@ -36,6 +39,7 @@ class UserQuery(DataQueryWithHistoryABC): self._ujs = ujs self._ujvs = ujvs self._permissions = permissions + self._achievements = achievements self.set_field("id", self.resolve_id) self.set_field("discordId", self.resolve_discord_id) @@ -60,6 +64,10 @@ class UserQuery(DataQueryWithHistoryABC): lambda user, *_: self._user_joined_game_server.get_user_joined_game_servers_by_user_id(user.id), UserJoinedGameServerFilter, ) + self.add_collection( + "achievement", lambda user, *_: achievements.get_achievements_by_user_id(user.id), AchievementFilter + ) + self.set_field("server", self.resolve_server) self.set_field("leftServer", self.resolve_left_server) diff --git a/kdb-web/src/app/models/data/achievement.model.ts b/kdb-web/src/app/models/data/achievement.model.ts index 23037847..84f6f88e 100644 --- a/kdb-web/src/app/models/data/achievement.model.ts +++ b/kdb-web/src/app/models/data/achievement.model.ts @@ -13,6 +13,8 @@ export interface Achievement extends DataWithHistory { operator?: string; value?: string; server?: Server; + + createdAt?: string; } export interface AchievementFilter { diff --git a/kdb-web/src/app/models/data/user.model.ts b/kdb-web/src/app/models/data/user.model.ts index 0b054cc6..6d649da4 100644 --- a/kdb-web/src/app/models/data/user.model.ts +++ b/kdb-web/src/app/models/data/user.model.ts @@ -4,6 +4,7 @@ import { Server, ServerFilter } from "./server.model"; import { UserJoinedServer } from "./user_joined_server.model"; import { UserJoinedVoiceChannel } from "./user_joined_voice_channel.model"; import { UserJoinedGameServer } from "./user_joined_game_server.model"; +import { Achievement } from "./achievement.model"; export interface User extends DataWithHistory { id?: number; @@ -25,6 +26,9 @@ export interface User extends DataWithHistory { userJoinedGameServerCount?: number; userJoinedGameServers?: UserJoinedGameServer[]; + + achievementCount?: number; + achievements?: Achievement[]; } export interface UserFilter { diff --git a/kdb-web/src/app/models/graphql/queries.model.ts b/kdb-web/src/app/models/graphql/queries.model.ts index fd46191b..453b7b64 100644 --- a/kdb-web/src/app/models/graphql/queries.model.ts +++ b/kdb-web/src/app/models/graphql/queries.model.ts @@ -222,6 +222,12 @@ export class Queries { joinedOn leavedOn } + + achievements { + id + name + createdAt + } } } } diff --git a/kdb-web/src/app/modules/view/server/profile/profile.component.html b/kdb-web/src/app/modules/view/server/profile/profile.component.html index 05d3ccc5..175be4ae 100644 --- a/kdb-web/src/app/modules/view/server/profile/profile.component.html +++ b/kdb-web/src/app/modules/view/server/profile/profile.component.html @@ -41,12 +41,12 @@ - - - - - - + + + + + +
@@ -78,6 +78,27 @@
+ +
+
+
+
{{'common.name' | translate}}:
+
{{achievement.name}}
+
+ +
+
{{'common.name' | translate}}:
+
{{achievement.name}}
+
+ +
+
{{'view.server.profile.achievements.time' | translate}}:
+
{{achievement.createdAt | date:'dd.MM.yyyy HH:mm:ss'}}
+
+
+
+
+
@@ -102,8 +123,8 @@
- +
diff --git a/kdb-web/src/assets/i18n/de.json b/kdb-web/src/assets/i18n/de.json index 70139bd4..6bcc1328 100644 --- a/kdb-web/src/assets/i18n/de.json +++ b/kdb-web/src/assets/i18n/de.json @@ -97,6 +97,7 @@ "wrong_password": "Falsches Passwort" }, "register": { + "confirm_privacy": "Ich erkläre mich mit der Datenschutzerklärung einverstanden.", "email_required": "E-Mail benötigt", "emails_not_match": "E-Mails stimmen nicht überein", "first_name": "Vorname", @@ -113,8 +114,7 @@ "register_with_discord": "Mit Discord Registrieren", "repeat_email": "E-Mail wiederholen", "repeat_password": "Passwort wiederholen", - "user_already_exists": "Benutzer existiert bereits", - "confirm_privacy": "Ich erkläre mich mit der Datenschutzerklärung einverstanden." + "user_already_exists": "Benutzer existiert bereits" } }, "common": { @@ -153,6 +153,7 @@ "joined_at": "Beigetreten am", "leaved_at": "Verlassen am", "modified_at": "Bearbeitet am", + "name": "Name", "no_entries_found": "Keine Einträge gefunden", "of": "von", "reset_filters": "Filter zurücksetzen" @@ -276,12 +277,12 @@ "dashboard": "Dashboard", "members": "Mitglieder", "server": { + "achievements": "Errungenschaften", "auto_roles": "Auto Rollen", "dashboard": "Dashboard", "levels": "Level", "members": "Mitglieder", - "profile": "Dein Profil", - "achievements": "Errungenschaften" + "profile": "Dein Profil" }, "server_empty": "Kein Server ausgewählt", "settings": "Einstellungen", @@ -316,6 +317,32 @@ "servers": "Server" }, "server": { + "achievements": { + "achievements": "Errungenschaften", + "header": "Errungenschaften", + "headers": { + "attribute": "Attribut", + "name": "Name", + "operator": "Operator", + "value": "Wert" + }, + "message": { + "achievement_create": "Errungenschaft erstellt", + "achievement_create_d": "Errungenschaft {{name}} erfolgreich erstellt", + "achievement_create_failed": "Errungenschaft Erstellung fehlgeschlagen", + "achievement_create_failed_d": "Die Erstellung der Errungenschaft ist fehlgeschlagen!", + "achievement_delete": "Errungenschaft löschen", + "achievement_delete_failed": "Errungenschaft Löschung fehlgeschlagen", + "achievement_delete_failed_d": "Die Löschung der Errungenschaft {{name}} ist fehlgeschlagen!", + "achievement_delete_q": "Sind Sie sich sicher, dass Sie das Errungenschaft {{name}} löschen möchten?", + "achievement_deleted": "Errungenschaft gelöscht", + "achievement_deleted_d": "Errungenschaft {{name}} erfolgreich gelöscht", + "achievement_update": "Errungenschaft bearbeitet", + "achievement_update_d": "Errungenschaft {{name}} erfolgreich bearbeitet", + "achievement_update_failed": "Errungenschaft Bearbeitung fehlgeschlagen", + "achievement_update_failed_d": "Die Bearbeitung der Errungenschaft ist fehlgeschlagen!" + } + }, "auto_roles": { "auto_roles": "Auto Rollen", "header": "Auto Rollen", @@ -398,32 +425,6 @@ "level_update_failed_d": "Die Bearbeitung des Levels ist fehlgeschlagen!" } }, - "achievements": { - "header": "Errungenschaften", - "headers": { - "name": "Name", - "attribute": "Attribut", - "operator": "Operator", - "value": "Wert" - }, - "achievements": "Errungenschaften", - "message": { - "achievement_create": "Errungenschaft erstellt", - "achievement_create_d": "Errungenschaft {{name}} erfolgreich erstellt", - "achievement_create_failed": "Errungenschaft Erstellung fehlgeschlagen", - "achievement_create_failed_d": "Die Erstellung der Errungenschaft ist fehlgeschlagen!", - "achievement_delete": "Errungenschaft löschen", - "achievement_delete_failed": "Errungenschaft Löschung fehlgeschlagen", - "achievement_delete_failed_d": "Die Löschung der Errungenschaft {{name}} ist fehlgeschlagen!", - "achievement_delete_q": "Sind Sie sich sicher, dass Sie das Errungenschaft {{name}} löschen möchten?", - "achievement_deleted": "Errungenschaft gelöscht", - "achievement_deleted_d": "Errungenschaft {{name}} erfolgreich gelöscht", - "achievement_update": "Errungenschaft bearbeitet", - "achievement_update_d": "Errungenschaft {{name}} erfolgreich bearbeitet", - "achievement_update_failed": "Errungenschaft Bearbeitung fehlgeschlagen", - "achievement_update_failed_d": "Die Bearbeitung der Errungenschaft ist fehlgeschlagen!" - } - }, "members": { "header": "Mitglieder", "headers": { @@ -442,6 +443,10 @@ } }, "profile": { + "achievements": { + "header": "Errungeschaften", + "time": "Erreicht am" + }, "header": "Dein Profil", "joined_game_server": { "header": "Gameserver-beitritte", diff --git a/kdb-web/src/assets/i18n/en.json b/kdb-web/src/assets/i18n/en.json index 62a3f623..862fcf4a 100644 --- a/kdb-web/src/assets/i18n/en.json +++ b/kdb-web/src/assets/i18n/en.json @@ -97,6 +97,7 @@ "wrong_password": "Wrong password" }, "register": { + "confirm_privacy": "I agree to the Privacy Policy.", "email_required": "E-Mail required", "emails_not_match": "E-Mails do not match", "first_name": "First name", @@ -113,8 +114,7 @@ "register_with_discord": "Register with discord", "repeat_email": "Repeat E-mail", "repeat_password": "Repeat password", - "user_already_exists": "User already exists", - "confirm_privacy": "I agree to the Privacy Policy." + "user_already_exists": "User already exists" } }, "common": { @@ -153,6 +153,7 @@ "joined_at": "Joined at", "leaved_at": "Leaved at", "modified_at": "Modified at", + "name": "Name", "no_entries_found": "No entries found", "of": "of", "reset_filters": "Reset filters" @@ -276,6 +277,7 @@ "dashboard": "Dashboard", "members": "Members", "server": { + "achievements": "Achievements", "auto_roles": "Auto role", "dashboard": "Dashboard", "levels": "Level", @@ -315,6 +317,32 @@ "servers": "Server" }, "server": { + "achievements": { + "achievements": "Achievements", + "header": "Achievements", + "headers": { + "attribute": "Attribute", + "name": "Namer", + "operator": "Operator", + "value": "Value" + }, + "message": { + "achievement_create": "Achievement created", + "achievement_create_d": "Achievement {{name}} successfully created", + "achievement_create_failed": "Achievement creation failed", + "achievement_create_failed_d": "Creation of achievement failed!", + "achievement_delete": "Delete achievement", + "achievement_delete_failed": "Achievement deletion failed", + "achievement_delete_failed_d": "Deletion of achievement {{name}} failed!", + "achievement_delete_q": "Are you sure you want to delete the {{name}} achievement?", + "achievement_deleted": "Achievement deleted", + "achievement_deleted_d": "Achievement {{name}} successfully deleted\t", + "achievement_update": "Achievement edited", + "achievement_update_d": "Achievement {{name}} edited successfully", + "achievement_update_failed": "Achievement editing failed", + "achievement_update_failed_d": "Achievement editing failed!" + } + }, "auto_roles": { "auto_roles": "Auto roles", "header": "Auto roles", @@ -415,6 +443,10 @@ } }, "profile": { + "achievements": { + "header": "Achievements", + "time": "Reached at" + }, "header": "Profile", "joined_game_server": { "header": "Game server accessions",