Improved auto-role data loading #300
This commit is contained in:
parent
1ebad89c97
commit
4da87ae3cb
@ -153,10 +153,10 @@ export class Queries {
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
static userQueryWithHistory = `
|
static userQueryWithHistory = `
|
||||||
query UsersWithHistory($serverId: ID, $userId: ID) {
|
query UsersWithHistory($serverId: ID, $id: ID) {
|
||||||
servers(filter: {id: $serverId}) {
|
servers(filter: {id: $serverId}) {
|
||||||
userCount
|
userCount
|
||||||
users(filter: {id: $userId}) {
|
users(filter: {id: $id}) {
|
||||||
id
|
id
|
||||||
|
|
||||||
history {
|
history {
|
||||||
@ -190,6 +190,17 @@ export class Queries {
|
|||||||
|
|
||||||
createdAt
|
createdAt
|
||||||
modifiedAt
|
modifiedAt
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
static autoRolesWithHistoryQuery = `
|
||||||
|
query AutoRoleWithHistoryQuery($serverId: ID, $id: ID) {
|
||||||
|
servers(filter: {id: $serverId}) {
|
||||||
|
autoRoleCount
|
||||||
|
autoRoles(filter: {id: $id}) {
|
||||||
|
id
|
||||||
|
|
||||||
history {
|
history {
|
||||||
id
|
id
|
||||||
@ -237,4 +248,27 @@ export class Queries {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
static autoRoleRulesHistoryQuery = `
|
||||||
|
query AutoRoleRuleHistoryQuery($serverId: ID, $autoRoleId: ID, $id: ID) {
|
||||||
|
servers(filter: {id: $serverId}) {
|
||||||
|
autoRoles(filter: {id: $autoRoleId}) {
|
||||||
|
autoRoleRuleCount
|
||||||
|
autoRoleRules(filter: {id: $id}) {
|
||||||
|
id
|
||||||
|
|
||||||
|
history {
|
||||||
|
id
|
||||||
|
emojiName
|
||||||
|
roleId
|
||||||
|
autoRole
|
||||||
|
deleted
|
||||||
|
dateFrom
|
||||||
|
dateTo
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
}
|
}
|
||||||
|
@ -45,16 +45,32 @@ export class HistoryBtnComponent implements OnInit {
|
|||||||
this.server = this.sidebar.server$.value ?? {};
|
this.server = this.sidebar.server$.value ?? {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private findVal(object: any, key: string) {
|
||||||
|
var value;
|
||||||
|
Object.keys(object).some((k: string) => {
|
||||||
|
if (k === key) {
|
||||||
|
value = object[k];
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (object[k] && typeof object[k] === "object") {
|
||||||
|
value = this.findVal(object[k], key);
|
||||||
|
return value !== undefined;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
public openHistory(): void {
|
public openHistory(): void {
|
||||||
this.showSidebar = true;
|
this.showSidebar = true;
|
||||||
this.data.query<UserListQuery>(this.query, {
|
this.data.query<UserListQuery>(this.query, {
|
||||||
serverId: this.server.id, userId: this.id
|
serverId: this.server.id, id: this.id
|
||||||
},
|
},
|
||||||
(x: { servers: Server[] }) => {
|
(x: { servers: Server[] }) => {
|
||||||
return x.servers[0];
|
return x.servers[0];
|
||||||
}
|
}
|
||||||
).subscribe(data => {
|
).subscribe(data => {
|
||||||
this.history = data.users[0].history ?? [];
|
this.history = this.findVal(data, "history") ?? [];
|
||||||
this.spinner.hideSpinner();
|
this.spinner.hideSpinner();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -160,7 +160,7 @@
|
|||||||
|
|
||||||
<td>
|
<td>
|
||||||
<div class="btn-wrapper">
|
<div class="btn-wrapper">
|
||||||
<app-history-btn *ngIf="!isEditingNew" [id] ="autoRoleRule.history" translationKey="view.server.auto_roles.rules.header"></app-history-btn>
|
<app-history-btn *ngIf="!isEditingNew" [id] ="autoRoleRule.id" [query]="query" translationKey="view.server.auto_roles.rules.header"></app-history-btn>
|
||||||
<button *ngIf="!editing" pButton pInitEditableRow class="btn icon-btn" icon="pi pi-pencil" (click)="onRowEditInit(dt, autoRoleRule, ri)"></button>
|
<button *ngIf="!editing" pButton pInitEditableRow class="btn icon-btn" icon="pi pi-pencil" (click)="onRowEditInit(dt, autoRoleRule, ri)"></button>
|
||||||
<button *ngIf="!editing" pButton class="btn icon-btn danger-icon-btn" icon="pi pi-trash"
|
<button *ngIf="!editing" pButton class="btn icon-btn danger-icon-btn" icon="pi pi-trash"
|
||||||
(click)="deleteAutoRoleRule(autoRoleRule)"></button>
|
(click)="deleteAutoRoleRule(autoRoleRule)"></button>
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { Component, OnDestroy, OnInit } from "@angular/core";
|
import { Component, OnDestroy, OnInit, Query } from "@angular/core";
|
||||||
import { DataService } from "../../../../../../services/data/data.service";
|
import { DataService } from "../../../../../../services/data/data.service";
|
||||||
import { ActivatedRoute, Router } from "@angular/router";
|
import { ActivatedRoute, Router } from "@angular/router";
|
||||||
import { AutoRoleRule, AutoRoleRuleFilter } from "../../../../../../models/data/auto_role.model";
|
import { AutoRoleRule, AutoRoleRuleFilter } from "../../../../../../models/data/auto_role.model";
|
||||||
@ -66,6 +66,8 @@ export class AutoRolesRulesComponent implements OnInit, OnDestroy {
|
|||||||
private unsubscriber = new Subject<void>();
|
private unsubscriber = new Subject<void>();
|
||||||
private server: Server = {};
|
private server: Server = {};
|
||||||
|
|
||||||
|
query: string = Queries.autoRoleRulesHistoryQuery;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private authService: AuthService,
|
private authService: AuthService,
|
||||||
private spinner: SpinnerService,
|
private spinner: SpinnerService,
|
||||||
|
@ -126,7 +126,8 @@
|
|||||||
<td>
|
<td>
|
||||||
<p-cellEditor>
|
<p-cellEditor>
|
||||||
<ng-template pTemplate="input">
|
<ng-template pTemplate="input">
|
||||||
<p-dropdown [options]="channels" optionValue="value.id" [(ngModel)]="autoRole.channelId" placeholder="{{'view.server.auto_roles.headers.channel_id' | translate}}"></p-dropdown>
|
<p-dropdown [options]="channels" optionValue="value.id" [(ngModel)]="autoRole.channelId"
|
||||||
|
placeholder="{{'view.server.auto_roles.headers.channel_id' | translate}}"></p-dropdown>
|
||||||
</ng-template>
|
</ng-template>
|
||||||
<ng-template pTemplate="output">
|
<ng-template pTemplate="output">
|
||||||
{{autoRole.channelId}}
|
{{autoRole.channelId}}
|
||||||
@ -191,9 +192,9 @@
|
|||||||
|
|
||||||
<td>
|
<td>
|
||||||
<div class="btn-wrapper">
|
<div class="btn-wrapper">
|
||||||
<!-- <button *ngIf="!editing" pButton pInitEditableRow class="btn icon-btn" icon="pi pi-pencil"-->
|
<!-- <button *ngIf="!editing" pButton pInitEditableRow class="btn icon-btn" icon="pi pi-pencil"-->
|
||||||
<!-- (click)="onRowEditInit(dt, autoRole, ri)"></button>-->
|
<!-- (click)="onRowEditInit(dt, autoRole, ri)"></button>-->
|
||||||
<app-history-btn *ngIf="!isEditingNew" [id] ="autoRole.history" translationKey="view.server.auto_roles.header"></app-history-btn>
|
<app-history-btn *ngIf="!isEditingNew" [id]="autoRole.id" [query]="query" translationKey="view.server.auto_roles.header"></app-history-btn>
|
||||||
<button *ngIf="!editing" pButton pInitEditableRow class="btn icon-btn" icon="pi pi-sliders-h" [routerLink]="[autoRole.id, 'rules']"></button>
|
<button *ngIf="!editing" pButton pInitEditableRow class="btn icon-btn" icon="pi pi-sliders-h" [routerLink]="[autoRole.id, 'rules']"></button>
|
||||||
<button *ngIf="!editing" pButton class="btn icon-btn danger-icon-btn" icon="pi pi-trash"
|
<button *ngIf="!editing" pButton class="btn icon-btn danger-icon-btn" icon="pi pi-trash"
|
||||||
(click)="deleteAutoRole(autoRole)"></button>
|
(click)="deleteAutoRole(autoRole)"></button>
|
||||||
|
@ -63,6 +63,8 @@ export class AutoRolesComponent implements OnInit, OnDestroy {
|
|||||||
private unsubscriber = new Subject<void>();
|
private unsubscriber = new Subject<void>();
|
||||||
private server: Server = {};
|
private server: Server = {};
|
||||||
|
|
||||||
|
query: string = Queries.autoRolesWithHistoryQuery;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private authService: AuthService,
|
private authService: AuthService,
|
||||||
private spinner: SpinnerService,
|
private spinner: SpinnerService,
|
||||||
|
Loading…
Reference in New Issue
Block a user