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