AutoRole #134 #222

Merged
edraft merged 8 commits from #134 into 1.0.0 2023-02-21 09:54:35 +01:00
7 changed files with 81 additions and 37 deletions
Showing only changes of commit ec9bc80392 - Show all commits

View File

@ -89,7 +89,7 @@ class AutoRoleRule(TableABC):
INSERT INTO `AutoRoleRules` (
`AutoRoleId`, `DiscordEmojiName`, `DiscordRoleId`, `CreatedAt`, `LastModifiedAt`
) VALUES (
{self._auto_role},
{self._auto_role.id},
'{self._discord_emoji_name}',
{self._discord_role_id},
'{self._created_at}',
@ -103,8 +103,8 @@ class AutoRoleRule(TableABC):
return str(
f"""
UPDATE `AutoRoleRules`
SET `AutoRoleId` = {self._auto_role},
`DiscordEmojiName` = {self._discord_emoji_name},
SET `AutoRoleId` = {self._auto_role.id},
`DiscordEmojiName` = '{self._discord_emoji_name}',
`DiscordRoleId` = {self._discord_role_id},
`LastModifiedAt` = '{self._modified_at}'
WHERE `AutoRoleRuleId` = {self._auto_role_rule_id};

View File

@ -35,9 +35,9 @@ class AutoRoleRuleMutation(QueryABC):
def get_new(x: AutoRoleRule):
return (
x.auto_role.id == input["autoRoleId"]
x.auto_role.id == int(input["autoRoleId"])
and x.emoji_name == input["emojiName"]
and x.role_id == input["roleId"]
and x.role_id == int(input["roleId"])
)
return self._auto_roles.get_auto_role_rules_by_auto_role_id(auto_role_rule.auto_role.id).where(get_new).last()

View File

@ -42,7 +42,7 @@ export class Mutations {
`;
static createAutoRoleRule = `
mutation createAutoRoleRule($autoRoleId: ID, $emojiName: String, roleId: String) {
mutation createAutoRoleRule($autoRoleId: ID, $emojiName: String, $roleId: String) {
autoRoleRule {
createAutoRoleRule(input: { autoRoleId: $autoRoleId, emojiName: $emojiName, roleId: $roleId }) {
id
@ -54,6 +54,19 @@ export class Mutations {
}
`;
static updateAutoRoleRule = `
mutation updateAutoRoleRule($id: ID, $emojiName: String, $roleId: String) {
autoRoleRule {
updateAutoRoleRule(input: { id: $id, emojiName: $emojiName, roleId: $roleId }) {
id
emojiName
roleId
roleName
}
}
}
`;
static deleteAutoRoleRule = `
mutation deleteAutoRoleRule($id: ID) {
autoRoleRule {

View File

@ -1,5 +1,5 @@
import { User } from "../data/user.model";
import { AutoRole } from "../data/auto_role.model";
import { AutoRole, AutoRoleRule } from "../data/auto_role.model";
export interface GraphQLResult {
data: any;
@ -15,6 +15,7 @@ export interface UpdateUserMutationResult {
updateUser: User
};
}
export interface AutoRoleMutationResult {
autoRole: {
createAutoRole?: AutoRole
@ -22,3 +23,11 @@ export interface AutoRoleMutationResult {
deleteAutoRole?: AutoRole
};
}
export interface AutoRoleRuleMutationResult {
autoRoleRule: {
createAutoRoleRule?: AutoRoleRule
updateAutoRoleRule?: AutoRoleRule
deleteAutoRoleRule?: AutoRoleRule
};
}

View File

@ -102,7 +102,7 @@
<td>
<p-cellEditor>
<ng-template pTemplate="input">
<p-dropdown [options]="roles" optionValue="value.name" [(ngModel)]="autoRoleRule.roleName"
<p-dropdown [options]="roles" optionValue="value.id" [(ngModel)]="autoRoleRule.roleId"
placeholder="{{'view.server.auto_roles.rules.headers.role' | translate}}"></p-dropdown>
</ng-template>
<ng-template pTemplate="output">

View File

@ -19,7 +19,7 @@ import { Queries } from "../../../../../../models/graphql/queries.model";
import { Server } from "../../../../../../models/data/server.model";
import { catchError, debounceTime } from "rxjs/operators";
import { Table } from "primeng/table";
import { AutoRoleMutationResult } from "../../../../../../models/graphql/result.model";
import { AutoRoleMutationResult, AutoRoleRuleMutationResult } from "../../../../../../models/graphql/result.model";
import { Mutations } from "../../../../../../models/graphql/mutations.model";
import { throwError } from "rxjs";
@ -32,8 +32,8 @@ export class AutoRolesRulesComponent implements OnInit {
rules!: AutoRoleRule[];
guild!: Guild;
emojis!: MenuItem[];
roles!: MenuItem[];
emojis: MenuItem[] = [];
roles: MenuItem[] = [];
loading = true;
autoRoleId!: number;
@ -80,7 +80,7 @@ export class AutoRolesRulesComponent implements OnInit {
}
getEmojiUrl(name: string): string {
return this.guild.emojis.filter(x => x.name == name)[0].url ?? "";
return this.guild?.emojis.filter(x => x.name == name)[0].url ?? "";
}
ngOnInit(): void {
@ -191,30 +191,50 @@ export class AutoRolesRulesComponent implements OnInit {
this.clonedUsers[index] = { ...autoRoleRule };
}
onRowEditSave(table: Table, newAutoRole: AutoRoleRule, index: number) {
if (this.isEditingNew && JSON.stringify(newAutoRole) === JSON.stringify(this.newAutoRoleTemplate)) {
onRowEditSave(table: Table, newAutoRoleRule: AutoRoleRule, index: number) {
if (this.isEditingNew && JSON.stringify(newAutoRoleRule) === JSON.stringify(this.newAutoRoleTemplate)) {
this.isEditingNew = false;
this.rules.splice(index, 1);
return;
}
if (!newAutoRole.id || !newAutoRole.emojiName && !newAutoRole.roleId) {
if (!newAutoRoleRule.id && !this.isEditingNew || !newAutoRoleRule.emojiName && !newAutoRoleRule.roleId) {
return;
}
if (this.isEditingNew) {
this.spinner.showSpinner();
this.data.mutation<AutoRoleRuleMutationResult>(Mutations.createAutoRoleRule, {
autoRoleId: this.autoRoleId,
emojiName: newAutoRoleRule.emojiName,
roleId: newAutoRoleRule.roleId
}
).pipe(catchError(err => {
this.spinner.hideSpinner();
this.toastService.error(this.translate.instant("view.server.auto_roles.rules.message.auto_role_rule_create_failed"), this.translate.instant("view.server.auto_roles.rules.message.auto_role_rule_create_failed_d"));
return throwError(err);
})).subscribe(result => {
this.spinner.hideSpinner();
this.toastService.success(this.translate.instant("view.server.auto_roles.rules.message.auto_role_rule_created"), this.translate.instant("view.server.auto_roles.rules.message.auto_role_rule_create_d", { id: result.autoRoleRule.createAutoRoleRule?.id }));
this.isEditingNew = false;
this.loadNextPage();
});
return;
}
this.spinner.showSpinner();
this.data.mutation<AutoRoleMutationResult>(Mutations.createAutoRoleRule, {
serverId: this.sidebar.server$.value?.id,
emojiName: newAutoRole.emojiName,
roleId: newAutoRole.roleId
this.data.mutation<AutoRoleMutationResult>(Mutations.updateAutoRoleRule, {
id: newAutoRoleRule.id,
emojiName: newAutoRoleRule.emojiName,
roleId: newAutoRoleRule.roleId
}
).pipe(catchError(err => {
this.spinner.hideSpinner();
this.toastService.error(this.translate.instant("view.server.auto_roles.message.auto_role_create_failed"), this.translate.instant("view.server.auto_roles.message.auto_role_create_failed_d"));
this.toastService.error(this.translate.instant("view.server.auto_roles.rules.message.auto_role_rule_update_failed"), this.translate.instant("view.server.auto_roles.rules.message.auto_role_rule_update_failed_d"));
return throwError(err);
})).subscribe(result => {
this.spinner.hideSpinner();
this.toastService.success(this.translate.instant("view.server.auto_roles.message.auto_role_created"), this.translate.instant("view.server.auto_roles.message.auto_role_create_d", { id: result.autoRole.createAutoRole?.id }));
this.toastService.success(this.translate.instant("view.server.auto_roles.rules.message.auto_role_rule_updated"), this.translate.instant("view.server.auto_roles.rules.message.auto_role_rule_update_d", { id: result.autoRole.createAutoRole?.id }));
this.loadNextPage();
});
}
@ -233,24 +253,22 @@ export class AutoRolesRulesComponent implements OnInit {
deleteAutoRoleRule(autoRoleRule: AutoRoleRule) {
this.confirmDialog.confirmDialog(
this.translate.instant("view.server.auto_roles.message.auto_role_delete"), this.translate.instant("view.server.auto_roles.message.auto_role_delete_q", { id: autoRoleRule.id }),
this.translate.instant("view.server.auto_roles.rules.message.auto_role_rule_delete"), this.translate.instant("view.server.auto_roles.rules.message.auto_role_rule_delete_q", { id: autoRoleRule.id }),
() => {
this.spinner.showSpinner();
this.data.mutation<AutoRoleMutationResult>(Mutations.deleteAutoRole, {
this.data.mutation<AutoRoleMutationResult>(Mutations.deleteAutoRoleRule, {
id: autoRoleRule.id
}
).pipe(catchError(err => {
this.spinner.hideSpinner();
this.toastService.error(this.translate.instant("view.server.auto_roles.message.auto_role_delete_failed"), this.translate.instant("view.server.auto_roles.message.auto_role_delete_failed_d", { id: autoRoleRule.id }));
this.toastService.error(this.translate.instant("view.server.auto_roles.rules.message.auto_role_rule_delete_failed"), this.translate.instant("view.server.auto_roles.rules.message.auto_role_rule_delete_failed_d", { id: autoRoleRule.id }));
return throwError(err);
})).subscribe(_ => {
this.spinner.hideSpinner();
this.toastService.success(this.translate.instant("view.server.auto_roles.message.auto_role_deleted"), this.translate.instant("view.server.auto_roles.message.auto_role_deleted_d", { id: autoRoleRule.id }));
this.toastService.success(this.translate.instant("view.server.auto_roles.rules.message.auto_role_rule_deleted"), this.translate.instant("view.server.auto_roles.rules.message.auto_role_rule_deleted_d", { id: autoRoleRule.id }));
this.loadNextPage();
});
});
}
addAutoRoleRule(table: Table) {

View File

@ -261,16 +261,20 @@
},
"no_entries_found": "Keine Einträge gefunden",
"message": {
"auto_role_create": "Auto Rolle erstellt",
"auto_role_create_d": "Auto Rolle {{id}} erfolgreich erstellt",
"auto_role_create_failed": "Auto Rolle Erstellung fehlgeschlagen",
"auto_role_create_failed_d": "Die Erstellung der Auto Rolle ist fehlgeschlagen!",
"auto_role_delete": "Auto Rolle löschen",
"auto_role_delete_q": "Sind Sie sich sicher, dass Sie die Auto Rolle {{id}} löschen möchten?",
"auto_role_deleted": "Auto Rolle gelöscht",
"auto_role_deleted_d": "Auto Rolle {{id}} erfolgreich gelöscht",
"auto_role_delete_failed": "Auto Rolle Löschung fehlgeschlagen",
"auto_role_delete_failed_d": "Die Löschung der Auto Rolle {{id}} ist fehlgeschlagen!"
"auto_role_rule_create": "Auto Rollen Regel erstellt",
"auto_role_rule_create_d": "Auto Rollen Regel {{id}} erfolgreich erstellt",
"auto_role_rule_create_failed": "Auto Rollen Regel Erstellung fehlgeschlagen",
"auto_role_rule_create_failed_d": "Die Erstellung der Auto Rollen Regel ist fehlgeschlagen!",
"auto_role_rule_update": "Auto Rollen Regel bearbeitet",
"auto_role_rule_update_d": "Auto Rollen Regel {{id}} erfolgreich bearbeitet",
"auto_role_rule_update_failed": "Auto Rollen Regel Bearbeitung fehlgeschlagen",
"auto_role_rule_update_failed_d": "Die Bearbeitung der Auto Rollen Regel ist fehlgeschlagen!",
"auto_role_rule_delete": "Auto Rollen Regel löschen",
"auto_role_rule_delete_q": "Sind Sie sich sicher, dass Sie die Auto Rollen Regel {{id}} löschen möchten?",
"auto_role_rule_deleted": "Auto Rollen Regel gelöscht",
"auto_role_rule_deleted_d": "Auto Rollen Regel {{id}} erfolgreich gelöscht",
"auto_role_rule_delete_failed": "Auto Rollen Regel Löschung fehlgeschlagen",
"auto_role_rule_delete_failed_d": "Die Löschung der Auto Rollen Regel {{id}} ist fehlgeschlagen!"
}
}
}