From a69c223a332b503134f542abd76e51b7b94c4c3c Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Mon, 17 Oct 2022 18:12:43 +0200 Subject: [PATCH] Added server list to dashboard #72 --- .../src/bot_api/model/discord/server_dto.py | 13 +++- .../src/bot_api/service/discord_service.py | 28 ++++++-- .../bot_api/transformer/server_transformer.py | 7 +- .../service/server_repository_service.py | 3 - kdb-web/src/app/models/discord/server.dto.ts | 1 + .../dashboard/dashboard.component.html | 48 +++++++++++-- kdb-web/src/assets/i18n/de.json | 11 ++- kdb-web/src/styles.scss | 67 +++++++++++++++++-- .../src/styles/themes/default-dark-theme.scss | 2 +- .../styles/themes/sh-edraft-dark-theme.scss | 43 +++++++++--- 10 files changed, 190 insertions(+), 33 deletions(-) diff --git a/kdb-bot/src/bot_api/model/discord/server_dto.py b/kdb-bot/src/bot_api/model/discord/server_dto.py index e7115dd2..07cd4365 100644 --- a/kdb-bot/src/bot_api/model/discord/server_dto.py +++ b/kdb-bot/src/bot_api/model/discord/server_dto.py @@ -1,3 +1,5 @@ +from typing import Optional + from bot_api.abc.dto_abc import DtoABC @@ -8,7 +10,8 @@ class ServerDTO(DtoABC): server_id: int, discord_id: int, name: str, - member_count: int + member_count: int, + icon_url: Optional[str] ): DtoABC.__init__(self) @@ -17,6 +20,7 @@ class ServerDTO(DtoABC): self._discord_id = discord_id self._name = name self._member_count = member_count + self._icon_url = icon_url @property def server_id(self) -> int: @@ -34,11 +38,15 @@ class ServerDTO(DtoABC): def member_count(self) -> int: return self._member_count + @property + def icon_url(self) -> Optional[str]: + return self._icon_url + def from_dict(self, values: dict): self._server_id = int(values['serverId']) self._discord_id = int(values['discordId']) self._name = values['name'] - self._member_count = int(values['memberCount']) + self._icon_url = int(values['iconURL']) def to_dict(self) -> dict: return { @@ -46,4 +54,5 @@ class ServerDTO(DtoABC): 'discordId': self._discord_id, 'name': self._name, 'memberCount': self._member_count, + 'iconURL': self._icon_url, } diff --git a/kdb-bot/src/bot_api/service/discord_service.py b/kdb-bot/src/bot_api/service/discord_service.py index 6f8e5f13..a0163dcc 100644 --- a/kdb-bot/src/bot_api/service/discord_service.py +++ b/kdb-bot/src/bot_api/service/discord_service.py @@ -33,9 +33,12 @@ class DiscordService: async def get_all_servers(self) -> List[ServerDTO]: servers = self._servers.get_servers() - return servers.select( - lambda x: ServerTransformer.to_dto(x, self._bot.get_guild(x.discord_server_id).name, self._bot.get_guild(x.discord_server_id).member_count) - ) + return servers.select(lambda x: ServerTransformer.to_dto( + x, + self._bot.get_guild(x.discord_server_id).name, + self._bot.get_guild(x.discord_server_id).member_count, + self._bot.get_guild(x.discord_server_id).icon + )) async def get_all_servers_by_user(self) -> List[ServerDTO]: token = self._auth.get_decoded_token_from_request() @@ -50,9 +53,12 @@ class DiscordService: user_from_db = self._users.find_user_by_id(0 if user.user_id is None else user.user_id) servers = self._servers.get_servers().where(lambda x: user_from_db is not None and x.server_id == user_from_db.server.server_id) - return servers.select( - lambda x: ServerTransformer.to_dto(x, self._bot.get_guild(x.discord_server_id).name, self._bot.get_guild(x.discord_server_id).member_count) - ) + return servers.select(lambda x: ServerTransformer.to_dto( + x, + self._bot.get_guild(x.discord_server_id).name, + self._bot.get_guild(x.discord_server_id).member_count, + self._bot.get_guild(x.discord_server_id).icon + )) async def get_filtered_servers_async(self, criteria: ServerSelectCriteria) -> ServerFilteredResultDTO: token = self._auth.get_decoded_token_from_request() @@ -68,9 +74,17 @@ class DiscordService: servers = servers.where(lambda x: user_from_db is not None and x.server_id == user_from_db.server.server_id) result = servers.select( - lambda x: ServerTransformer.to_dto(x, self._bot.get_guild(x.discord_server_id).name, self._bot.get_guild(x.discord_server_id).member_count) + lambda x: ServerTransformer.to_dto( + x, + self._bot.get_guild(x.discord_server_id).name, + self._bot.get_guild(x.discord_server_id).member_count, + self._bot.get_guild(x.discord_server_id).icon + ) ) + if criteria.name is not None and criteria.name != '': + result = result.where(lambda x: criteria.name.lower() in x.name.lower() or x.name.lower() == criteria.name.lower()) + return ServerFilteredResultDTO( List(ServerDTO, result), filtered_result.total_count diff --git a/kdb-bot/src/bot_api/transformer/server_transformer.py b/kdb-bot/src/bot_api/transformer/server_transformer.py index 920fd506..d883c42d 100644 --- a/kdb-bot/src/bot_api/transformer/server_transformer.py +++ b/kdb-bot/src/bot_api/transformer/server_transformer.py @@ -1,3 +1,7 @@ +from typing import Optional + +import discord + from bot_api.abc.transformer_abc import TransformerABC from bot_api.model.discord.server_dto import ServerDTO from bot_data.model.server import Server @@ -10,10 +14,11 @@ class ServerTransformer(TransformerABC): return Server(dto.discord_id) @staticmethod - def to_dto(db: Server, name: str, member_count: int) -> ServerDTO: + def to_dto(db: Server, name: str, member_count: int, icon_url: Optional[discord.Asset]) -> ServerDTO: return ServerDTO( db.server_id, db.discord_server_id, name, member_count, + icon_url.url if icon_url is not None else None, ) diff --git a/kdb-bot/src/bot_data/service/server_repository_service.py b/kdb-bot/src/bot_data/service/server_repository_service.py index 37b2918e..210a6dee 100644 --- a/kdb-bot/src/bot_data/service/server_repository_service.py +++ b/kdb-bot/src/bot_data/service/server_repository_service.py @@ -35,9 +35,6 @@ class ServerRepositoryService(ServerRepositoryABC): self._logger.trace(__name__, f'Send SQL command: {Server.get_select_all_string()}') query = servers - if criteria.name is not None and criteria.name != '': - query = query.where(lambda x: criteria.name in x.first_name or x.first_name == criteria.name) - # sort if criteria.sort_column is not None and criteria.sort_column != '' and criteria.sort_direction is not None and criteria.sort_direction: crit_sort_direction = criteria.sort_direction.lower() diff --git a/kdb-web/src/app/models/discord/server.dto.ts b/kdb-web/src/app/models/discord/server.dto.ts index 4cba26ac..a97625b5 100644 --- a/kdb-web/src/app/models/discord/server.dto.ts +++ b/kdb-web/src/app/models/discord/server.dto.ts @@ -3,4 +3,5 @@ export interface ServerDTO { discordId: number; name: string; memberCount: number; + iconURL: string | null; } \ No newline at end of file diff --git a/kdb-web/src/app/modules/view/dashboard/components/dashboard/dashboard.component.html b/kdb-web/src/app/modules/view/dashboard/components/dashboard/dashboard.component.html index e4139bac..c7dd5fdf 100644 --- a/kdb-web/src/app/modules/view/dashboard/components/dashboard/dashboard.component.html +++ b/kdb-web/src/app/modules/view/dashboard/components/dashboard/dashboard.component.html @@ -2,11 +2,49 @@ {{'view.dashboard.header' | translate}}
+
+

+ + {{'view.dashboard.server.header' | translate}} +

+
+
-
    -
  • - {{server.name}} -
  • -
+
+
+
+
+ +
+
+
+ +
+ {{servers.length}} {{'view.dashboard.of' | translate}} {{totalRecords}} {{'view.dashboard.servers' | translate}}: +
+
+ +
+
+ + +
+

+ {{server.name}} +

+ +
+ + {{server.memberCount}} + {{'view.dashboard.server.member_count' | translate}} +
+
+ +
+
+
\ No newline at end of file diff --git a/kdb-web/src/assets/i18n/de.json b/kdb-web/src/assets/i18n/de.json index ae0a0f4c..83fd1ae3 100644 --- a/kdb-web/src/assets/i18n/de.json +++ b/kdb-web/src/assets/i18n/de.json @@ -107,7 +107,16 @@ }, "view": { "dashboard": { - "header": "Dashboard" + "header": "Dashboard", + "of": "von", + "servers": "Server", + "server": { + "header": "Server", + "member_count": "Mitglid(er)" + }, + "filter": { + "name": "Name" + } }, "user-list": {}, "change-password": { diff --git a/kdb-web/src/styles.scss b/kdb-web/src/styles.scss index ee146861..8bbd6cd8 100644 --- a/kdb-web/src/styles.scss +++ b/kdb-web/src/styles.scss @@ -10,6 +10,8 @@ body { height: 100%; padding: 0; margin: 0; + + font-size: 1rem; } main { @@ -18,15 +20,19 @@ main { min-height: 100vh; } -h1, -h2 { +h1 { margin: 0; - font-size: 30px; + font-size: 1.75rem; } h2 { margin: 0; - font-size: 25px; + font-size: 1.5rem; +} + +h3 { + margin: 0; + font-size: 1.25rem; } header { @@ -207,6 +213,59 @@ header { .table-header-small-dropdown { width: 150px; } + + .server-list-wrapper { + display: flex; + flex-direction: column; + gap: 10px; + + .server-filter { + } + + .server-count { + } + + .server-list { + display: flex; + flex-direction: column; + + gap: 15px; + + .server { + display: flex; + gap: 15px; + + padding: 20px; + + .logo { + overflow: hidden; + + img { + width: 4rem; + height: 4rem; + object-fit: contain; + } + } + + .info { + display: flex; + flex-direction: column; + + gap: 10px; + + .name { + margin: 0px; + + justify-content: center; + align-items: center; + } + + .data { + } + } + } + } + } } } } diff --git a/kdb-web/src/styles/themes/default-dark-theme.scss b/kdb-web/src/styles/themes/default-dark-theme.scss index 7507a6cb..1a3bd5d1 100644 --- a/kdb-web/src/styles/themes/default-dark-theme.scss +++ b/kdb-web/src/styles/themes/default-dark-theme.scss @@ -432,7 +432,7 @@ color: $primaryTextColor !important; border: 0 !important; padding: 0px !important; - + &:hover { background-color: transparent !important; color: $primaryHeaderColor !important; diff --git a/kdb-web/src/styles/themes/sh-edraft-dark-theme.scss b/kdb-web/src/styles/themes/sh-edraft-dark-theme.scss index ee2da9f4..8fa192f1 100644 --- a/kdb-web/src/styles/themes/sh-edraft-dark-theme.scss +++ b/kdb-web/src/styles/themes/sh-edraft-dark-theme.scss @@ -15,17 +15,10 @@ $primaryErrorColor: #b00020; $secondaryErrorColor: #e94948; - $default-border: 1px solid $secondaryBackgroundColor3; + $default-border: 2px solid $secondaryBackgroundColor3; background-color: $primaryBackgroundColor !important; - html, - body { - margin: 0; - - font-size: 16px; - } - h1, h2 { color: $primaryHeaderColor; @@ -122,6 +115,35 @@ .content-divider { border-bottom: $default-border; } + + .server-list-wrapper { + .server-filter { + } + + .server-count { + } + + .server-list { + .server { + border: $default-border; + border-radius: 15px; + + .logo { + img { + border-radius: 100%; + } + } + + .name { + color: $primaryHeaderColor; + } + + &:hover { + border-color: $primaryHeaderColor !important; + } + } + } + } } } } @@ -390,6 +412,9 @@ input, .p-password { + border-radius: 10px; + border: $default-border; + &:focus { box-shadow: none !important; } @@ -434,7 +459,7 @@ color: $primaryTextColor !important; border: 0 !important; padding: 0px !important; - + &:hover { background-color: transparent !important; color: $primaryHeaderColor !important;