#268_achievements #325

Merged
edraft merged 23 commits from #268_achievements into 1.1.0 2023-08-14 09:36:20 +02:00
5 changed files with 31 additions and 20 deletions
Showing only changes of commit 8aa96482c1 - Show all commits

View File

@ -5,12 +5,21 @@ from bot_data.model.server import Server
class CacheService:
def __init__(self):
self._cached_server = List(Server)
self._cached_servers = List(Server)
@property
def cached_server(self) -> List[Server]:
return self._cached_server
return self._cached_servers
@cached_server.setter
def cached_server(self, value: List[Server]):
self._cached_server = value
def add_server(self, server: Server):
if self._cached_servers.where(lambda x: x.id == server.id).count() > 0:
return
self._cached_servers.add(server)
def add_servers(self, servers: List[Server]):
new_ids = servers.select(lambda x: x.id)
for s in self._cached_servers:
if s.id in new_ids:
return
self._cached_servers.extend(servers)

View File

@ -26,7 +26,7 @@ class ServerRepositoryService(ServerRepositoryABC):
for result in results:
servers.append(Server(result[1], result[2], result[3], id=result[0]))
self._cache.cached_server = List(Server, servers)
self._cache.add_servers(servers)
return servers
def get_filtered_servers(self, criteria: ServerSelectCriteria) -> FilteredResult:
@ -56,13 +56,14 @@ class ServerRepositoryService(ServerRepositoryABC):
def get_server_by_id(self, server_id: int) -> Server:
cs = self._cache.cached_server.where(lambda x: x.id == server_id).single_or_default()
if cs is not None:
return cs
self._logger.trace(__name__, f"Send SQL command: {Server.get_select_by_id_string(server_id)}")
result = self._context.select(Server.get_select_by_id_string(server_id))[0]
server = Server(result[1], result[2], result[3], id=result[0])
self._cache.cached_server.add(server)
self._cache.add_server(server)
return server
def get_server_by_discord_id(self, discord_id: int) -> Server:

View File

@ -124,7 +124,7 @@ export class Mutations {
static createAchievement = `
mutation createAchievement($name: String, $attribute: String, $operator: String, $value: String, $serverId: ID) {
level {
achievement {
createAchievement(input: { name: $name, attribute: $attribute, operator: $operator, value: $value, serverId: $serverId}) {
id
name
@ -140,9 +140,9 @@ export class Mutations {
`;
static updateAchievement = `
mutation updateAchievement($name: String, $attribute: String, $operator: String, $value: String, $serverId: ID) {
level {
updateAchievement(input: { name: $name, attribute: $attribute, operator: $operator, value: $value}) {
mutation updateAchievement($id: ID, $name: String, $attribute: String, $operator: String, $value: String) {
achievement {
updateAchievement(input: { id: $id, name: $name, attribute: $attribute, operator: $operator, value: $value}) {
id
name
attribute
@ -155,8 +155,8 @@ export class Mutations {
static deleteAchievement = `
mutation deleteAchievement($id: ID) {
level {
deleteLevel(id: $id) {
achievement {
deleteAchievement(id: $id) {
id
name
}

View File

@ -18,7 +18,7 @@
<div class="table-caption-btn-wrapper btn-wrapper">
<button pButton label="{{'common.add' | translate}}" class="icon-btn btn"
icon="pi pi-user-plus" (click)="addAchievement(dt)" [disabled]="isEditingNew || user?.isModerator && !user?.isAdmin">
icon="pi pi-user-plus" (click)="addAchievement(dt)" [disabled]="isEditingNew || !user?.isModerator && !user?.isAdmin">
</button>
<button pButton label="{{'common.reset_filters' | translate}}" icon="pi pi-undo"
class="icon-btn btn" (click)="resetFilters()">
@ -143,7 +143,7 @@
<td>
<p-cellEditor>
<ng-template pTemplate="input">
<input class="table-edit-input" pInputText min="0" type="number" [(ngModel)]="achievement.operator">
<input class="table-edit-input" pInputText type="text" [(ngModel)]="achievement.operator">
</ng-template>
<ng-template pTemplate="output">
{{achievement.operator}}
@ -186,14 +186,14 @@
<div class="btn-wrapper">
<app-history-btn *ngIf="!isEditingNew" [id]="achievement.id" [query]="query" translationKey="view.server.achievements.header"></app-history-btn>
<button *ngIf="!editing" pButton pInitEditableRow class="btn icon-btn" icon="pi pi-pencil"
(click)="onRowEditInit(dt, achievement, ri)" [disabled]="!user || user.isModerator && !user.isAdmin"></button>
(click)="onRowEditInit(dt, achievement, ri)" [disabled]="!user || !user.isModerator && !user.isAdmin"></button>
<button *ngIf="!editing" pButton class="btn icon-btn danger-icon-btn" icon="pi pi-trash"
(click)="deleteAchievement(achievement)" [disabled]="!user || user.isModerator && !user.isAdmin"></button>
(click)="deleteAchievement(achievement)" [disabled]="!user || !user.isModerator && !user.isAdmin"></button>
<button *ngIf="editing" pButton pSaveEditableRow class="btn icon-btn"
icon="pi pi-check-circle" (click)="onRowEditSave(dt, achievement, ri)" [disabled]="!user || user.isModerator && !user.isAdmin"></button>
icon="pi pi-check-circle" (click)="onRowEditSave(dt, achievement, ri)" [disabled]="!user || !user.isModerator && !user.isAdmin"></button>
<button *ngIf="editing" pButton pCancelEditableRow class="btn icon-btn danger-icon-btn"
icon="pi pi-times-circle" (click)="onRowEditCancel(ri)" [disabled]="!user || user.isModerator && !user.isAdmin"></button>
icon="pi pi-times-circle" (click)="onRowEditCancel(ri)" [disabled]="!user || !user.isModerator && !user.isAdmin"></button>
</div>
</td>
</tr>

View File

@ -280,7 +280,8 @@
"dashboard": "Dashboard",
"levels": "Level",
"members": "Mitglieder",
"profile": "Dein Profil"
"profile": "Dein Profil",
"achievements": "Errungenschaften"
},
"server_empty": "Kein Server ausgewählt",
"settings": "Einstellungen",