Added achievements to user profile #268_achievements

This commit is contained in:
Sven Heidemann 2023-07-15 15:16:01 +02:00
parent 67baf350fa
commit 9dcb75109f
9 changed files with 121 additions and 40 deletions

View File

@ -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))

View File

@ -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

View File

@ -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)

View File

@ -13,6 +13,8 @@ export interface Achievement extends DataWithHistory {
operator?: string;
value?: string;
server?: Server;
createdAt?: string;
}
export interface AchievementFilter {

View File

@ -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 {

View File

@ -222,6 +222,12 @@ export class Queries {
joinedOn
leavedOn
}
achievements {
id
name
createdAt
}
}
}
}

View File

@ -78,6 +78,27 @@
<div class="content-divider"></div>
<p-panel header="{{'view.server.profile.achievements.header' | translate}}" [toggleable]="true">
<div *ngFor="let achievement of user.achievements;">
<div class="content-row">
<div class="content-column">
<div class="content-data-name">{{'common.name' | translate}}:</div>
<div class="content-data-value">{{achievement.name}}</div>
</div>
<div class="content-column">
<div class="content-data-name">{{'common.name' | translate}}:</div>
<div class="content-data-value">{{achievement.name}}</div>
</div>
<div class="content-column">
<div class="content-data-name">{{'view.server.profile.achievements.time' | translate}}:</div>
<div class="content-data-value">{{achievement.createdAt | date:'dd.MM.yyyy HH:mm:ss'}}</div>
</div>
</div>
</div>
</p-panel>
<p-panel header="{{'view.server.profile.joined_voice_channel.header' | translate}}" [toggleable]="true">
<div *ngFor="let join of user.joinedVoiceChannels;">
<div class="content-row">
@ -102,8 +123,8 @@
</div>
</div>
</div>
</p-panel>
<p-panel header="{{'view.server.profile.joined_game_server.header' | translate}}" [toggleable]="true">
<div *ngFor="let join of user.userJoinedGameServers;">
<div class="content-row">

View File

@ -97,6 +97,7 @@
"wrong_password": "Falsches Passwort"
},
"register": {
"confirm_privacy": "Ich erkläre mich mit der <a href=\"{{url}}\">Datenschutzerklärung</a> 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 <a href=\"{{url}}\">Datenschutzerklärung</a> 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",

View File

@ -97,6 +97,7 @@
"wrong_password": "Wrong password"
},
"register": {
"confirm_privacy": "I agree to the <a href=\"{{url}}\">Privacy Policy</a>.",
"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 <a href=\"{{url}}\">Privacy Policy</a>."
"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",