diff --git a/bot/src/bot_data/model/level.py b/bot/src/bot_data/model/level.py index a20d268b..378d7fc6 100644 --- a/bot/src/bot_data/model/level.py +++ b/bot/src/bot_data/model/level.py @@ -2,6 +2,10 @@ from datetime import datetime from typing import Optional from cpl_core.database import TableABC +from cpl_core.dependency_injection import ServiceProviderABC +from cpl_discord.service import DiscordBotServiceABC +from cpl_query.extension import List +from discord import Role from bot_data.model.server import Server @@ -33,6 +37,13 @@ class Level(TableABC): def id(self) -> int: return self._id + @property + @ServiceProviderABC.inject + def icon_url(self, bot: DiscordBotServiceABC) -> str: + guild = bot.get_guild(self.server.discord_id) + role = List(Role, guild.roles).where(lambda x: x.name == self._name).first_or_default() + return None if role is None else role.icon + @property def name(self) -> str: return self._name diff --git a/bot/src/bot_graphql/graphql/level.gql b/bot/src/bot_graphql/graphql/level.gql index cc937291..15be156a 100644 --- a/bot/src/bot_graphql/graphql/level.gql +++ b/bot/src/bot_graphql/graphql/level.gql @@ -1,5 +1,6 @@ type Level implements TableWithHistoryQuery { id: ID + iconURL: String name: String color: String minXp: Int diff --git a/bot/src/bot_graphql/queries/level_query.py b/bot/src/bot_graphql/queries/level_query.py index 5f726c5b..d0762f95 100644 --- a/bot/src/bot_graphql/queries/level_query.py +++ b/bot/src/bot_graphql/queries/level_query.py @@ -1,6 +1,5 @@ from cpl_core.database.context import DatabaseContextABC -from bot_data.model.level import Level from bot_data.model.level_history import LevelHistory from bot_graphql.abc.data_query_with_history_abc import DataQueryWithHistoryABC @@ -9,33 +8,13 @@ class LevelQuery(DataQueryWithHistoryABC): def __init__(self, db: DatabaseContextABC): DataQueryWithHistoryABC.__init__(self, "Level", "LevelsHistory", LevelHistory, db) - self.set_field("id", self.resolve_id) - self.set_field("name", self.resolve_name) - self.set_field("color", self.resolve_color) - self.set_field("minXp", self.resolve_min_xp) - self.set_field("permissions", self.resolve_permissions) - self.set_field("server", self.resolve_server) - - @staticmethod - def resolve_id(level: Level, *_): - return level.id - - @staticmethod - def resolve_name(level: Level, *_): - return level.name - - @staticmethod - def resolve_color(level: Level, *_): - return level.color - - @staticmethod - def resolve_min_xp(level: Level, *_): - return level.min_xp - - @staticmethod - def resolve_permissions(level: Level, *_): - return level.permissions - - @staticmethod - def resolve_server(level: Level, *_): - return level.server + self.set_field("id", lambda x, *_: x.id) + self.set_field( + "iconURL", + lambda x, *_: "https://cdn.discordapp.com/emojis/1170348708894875659.webp?size=32&quality=lossless", + ) + self.set_field("name", lambda x, *_: x.name) + self.set_field("color", lambda x, *_: x.color) + self.set_field("minXp", lambda x, *_: x.min_xp) + self.set_field("permissions", lambda x, *_: x.permissions) + self.set_field("server", lambda x, *_: x.server) diff --git a/web/src/app/models/graphql/queries.model.ts b/web/src/app/models/graphql/queries.model.ts index a387b22e..afa3ab68 100644 --- a/web/src/app/models/graphql/queries.model.ts +++ b/web/src/app/models/graphql/queries.model.ts @@ -155,6 +155,7 @@ export class Queries { levelCount levels(filter: $filter, page: $page, sort: $sort) { id + iconURL name color minXp diff --git a/web/src/app/modules/view/server/levels/components/levels/levels.component.html b/web/src/app/modules/view/server/levels/components/levels/levels.component.html index 0af4809d..1668d850 100644 --- a/web/src/app/modules/view/server/levels/components/levels/levels.component.html +++ b/web/src/app/modules/view/server/levels/components/levels/levels.component.html @@ -1,238 +1,251 @@

- {{'view.server.levels.header' | translate}} + {{'view.server.levels.header' | translate}}

-
- +
+ - -
-
-
- {{levels.length}} {{'common.of' | translate}} - {{dt.totalRecords}} - - {{'view.server.levels.levels' | translate}} -
+ +
+
+
+ {{levels.length}} {{'common.of' | translate}} + {{dt.totalRecords}} + + {{'view.server.levels.levels' | translate}} +
- -
+ +
-
- - - -
-
- +
+ + + +
+
+
- - - -
-
{{'common.id' | translate}}
- -
- + + + +
+
{{'common.id' | translate}}
+ +
+ - -
-
{{'common.name' | translate}}
- -
- + +
+
{{'common.icon' | translate}}
+ +
+ - -
-
{{'common.color' | translate}}
- -
- + +
+
{{'common.name' | translate}}
+ +
+ - -
-
{{'common.min_xp' | translate}}
- -
- + +
+
{{'common.color' | translate}}
+ +
+ - -
-
{{'common.permissions' | translate}}
- -
- + +
+
{{'common.min_xp' | translate}}
+ +
+ - -
-
{{'common.created_at' | translate}}
-
- + +
+
{{'common.permissions' | translate}}
+ +
+ - -
-
{{'common.modified_at' | translate}}
-
- + +
+
{{'common.created_at' | translate}}
+
+ - -
-
{{'common.actions' | translate}}
-
- - + +
+
{{'common.modified_at' | translate}}
+
+ - - -
- -
- - -
- -
- - - - - - - - -
+ +
+
{{'common.actions' | translate}}
+
+ + - - - - {{'common.id' | translate}}: - - - {{level.id}} - - - {{level.id}} - - - + + +
+ +
+ + + + +
+ +
+ + + + + + + + +
- - {{'common.name' | translate}}: - - - - - - {{level.name}} - - - + + + + {{'common.id' | translate}}: + + + {{level.id}} + + + {{level.id}} + + + - - {{'common.color' | translate}}: - - - - - - {{level.color}} - - - + + + - - {{'common.min_xp' | translate}}: - - - - - - {{level.minXp}} - - - + + {{'common.name' | translate}}: + + + + + + {{level.name}} + + + - - {{'common.permissions' | translate}}: - - - - - - {{level.permissions}} - - - + + {{'common.color' | translate}}: + + + + + + {{level.color}} + + + - - {{'common.created_at' | translate}}: - - - {{level.createdAt | date:'dd.MM.yy HH:mm'}} - - - {{level.createdAt | date:'dd.MM.yy HH:mm'}} - - - - - {{'common.modified_at' | translate}}: - - - {{level.modifiedAt | date:'dd.MM.yy HH:mm'}} - - - {{level.modifiedAt | date:'dd.MM.yy HH:mm'}} - - - - -
- - - + + {{'common.min_xp' | translate}}: + + + + + + {{level.minXp}} + + + - - -
- - -
+ + {{'common.permissions' | translate}}: + + + + + + {{level.permissions}} + + + - - - - {{'common.no_entries_found' | translate}} - - - + + {{'common.created_at' | translate}}: + + + {{level.createdAt | date:'dd.MM.yy HH:mm'}} + + + {{level.createdAt | date:'dd.MM.yy HH:mm'}} + + + + + {{'common.modified_at' | translate}}: + + + {{level.modifiedAt | date:'dd.MM.yy HH:mm'}} + + + {{level.modifiedAt | date:'dd.MM.yy HH:mm'}} + + + + +
+ + + - - - -
+ + +
+ + + + + + + + {{'common.no_entries_found' | translate}} + + + + + + +
+
diff --git a/web/src/app/modules/view/server/levels/components/levels/levels.component.ts b/web/src/app/modules/view/server/levels/components/levels/levels.component.ts index 85558bc0..19cb3469 100644 --- a/web/src/app/modules/view/server/levels/components/levels/levels.component.ts +++ b/web/src/app/modules/view/server/levels/components/levels/levels.component.ts @@ -19,7 +19,7 @@ import { Table } from "primeng/table"; import { User } from "../../../../../../models/data/user.model"; import { LevelMutationResult, UpdateUserMutationResult } from "../../../../../../models/graphql/result.model"; import { Mutations } from "../../../../../../models/graphql/mutations.model"; -import { forkJoin, Subject, throwError } from "rxjs"; +import { Subject, throwError } from "rxjs"; import { Server } from "../../../../../../models/data/server.model"; import { UserDTO } from "../../../../../../models/auth/auth-user.dto"; import { ComponentWithTable } from "../../../../../../base/component-with-table"; @@ -72,7 +72,7 @@ export class LevelsComponent extends ComponentWithTable implements OnInit, OnDes private sidebar: SidebarService, private route: ActivatedRoute ) { - super("level", ["id", "name", "color", "min_xp", "permissions"], (oldElement: Level, newElement: Level) => { + super("level", ["id", "icon", "name", "color", "min_xp", "permissions"], (oldElement: Level, newElement: Level) => { return oldElement.name === newElement.name; }); } diff --git a/web/src/assets/i18n/de.json b/web/src/assets/i18n/de.json index 8c8e20e2..008d1ab5 100644 --- a/web/src/assets/i18n/de.json +++ b/web/src/assets/i18n/de.json @@ -180,6 +180,7 @@ "value": "Wert", "xp": "XP" }, + "icon": "Icon", "id": "Id", "import": "Importieren", "interval": "Interval", diff --git a/web/src/assets/i18n/en.json b/web/src/assets/i18n/en.json index ec26f08d..2a5b0632 100644 --- a/web/src/assets/i18n/en.json +++ b/web/src/assets/i18n/en.json @@ -180,6 +180,7 @@ "value": "Value", "xp": "XP" }, + "icon": "Icon", "id": "Id", "import": "Import", "interval": "interval",