Improved auto-role data loading #300
This commit is contained in:
		@@ -153,10 +153,10 @@ export class Queries {
 | 
			
		||||
  `;
 | 
			
		||||
 | 
			
		||||
  static userQueryWithHistory = `
 | 
			
		||||
    query UsersWithHistory($serverId: ID, $userId: ID) {
 | 
			
		||||
    query UsersWithHistory($serverId: ID, $id: ID) {
 | 
			
		||||
      servers(filter: {id: $serverId}) {
 | 
			
		||||
        userCount
 | 
			
		||||
        users(filter: {id: $userId}) {
 | 
			
		||||
        users(filter: {id: $id}) {
 | 
			
		||||
          id
 | 
			
		||||
 | 
			
		||||
          history {
 | 
			
		||||
@@ -190,6 +190,17 @@ export class Queries {
 | 
			
		||||
 | 
			
		||||
          createdAt
 | 
			
		||||
          modifiedAt
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  `;
 | 
			
		||||
 | 
			
		||||
  static autoRolesWithHistoryQuery = `
 | 
			
		||||
    query AutoRoleWithHistoryQuery($serverId: ID, $id: ID) {
 | 
			
		||||
      servers(filter: {id: $serverId}) {
 | 
			
		||||
        autoRoleCount
 | 
			
		||||
        autoRoles(filter: {id: $id}) {
 | 
			
		||||
          id
 | 
			
		||||
 | 
			
		||||
          history {
 | 
			
		||||
            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 ?? {};
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  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 {
 | 
			
		||||
    this.showSidebar = true;
 | 
			
		||||
    this.data.query<UserListQuery>(this.query, {
 | 
			
		||||
        serverId: this.server.id, userId: this.id
 | 
			
		||||
        serverId: this.server.id, id: this.id
 | 
			
		||||
      },
 | 
			
		||||
      (x: { servers: Server[] }) => {
 | 
			
		||||
        return x.servers[0];
 | 
			
		||||
      }
 | 
			
		||||
    ).subscribe(data => {
 | 
			
		||||
      this.history = data.users[0].history ?? [];
 | 
			
		||||
      this.history = this.findVal(data, "history") ?? [];
 | 
			
		||||
      this.spinner.hideSpinner();
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -160,7 +160,7 @@
 | 
			
		||||
 | 
			
		||||
          <td>
 | 
			
		||||
            <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 class="btn icon-btn danger-icon-btn" icon="pi pi-trash"
 | 
			
		||||
                      (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 { ActivatedRoute, Router } from "@angular/router";
 | 
			
		||||
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 server: Server = {};
 | 
			
		||||
 | 
			
		||||
  query: string = Queries.autoRoleRulesHistoryQuery;
 | 
			
		||||
 | 
			
		||||
  constructor(
 | 
			
		||||
    private authService: AuthService,
 | 
			
		||||
    private spinner: SpinnerService,
 | 
			
		||||
 
 | 
			
		||||
@@ -126,7 +126,8 @@
 | 
			
		||||
          <td>
 | 
			
		||||
            <p-cellEditor>
 | 
			
		||||
              <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 pTemplate="output">
 | 
			
		||||
                {{autoRole.channelId}}
 | 
			
		||||
@@ -191,9 +192,9 @@
 | 
			
		||||
 | 
			
		||||
          <td>
 | 
			
		||||
            <div class="btn-wrapper">
 | 
			
		||||
<!--              <button *ngIf="!editing" pButton pInitEditableRow class="btn icon-btn" icon="pi pi-pencil"-->
 | 
			
		||||
<!--                      (click)="onRowEditInit(dt, autoRole, ri)"></button>-->
 | 
			
		||||
              <app-history-btn *ngIf="!isEditingNew" [id] ="autoRole.history" translationKey="view.server.auto_roles.header"></app-history-btn>
 | 
			
		||||
              <!--              <button *ngIf="!editing" pButton pInitEditableRow class="btn icon-btn" icon="pi pi-pencil"-->
 | 
			
		||||
              <!--                      (click)="onRowEditInit(dt, autoRole, ri)"></button>-->
 | 
			
		||||
              <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 class="btn icon-btn danger-icon-btn" icon="pi pi-trash"
 | 
			
		||||
                      (click)="deleteAutoRole(autoRole)"></button>
 | 
			
		||||
 
 | 
			
		||||
@@ -63,6 +63,8 @@ export class AutoRolesComponent implements OnInit, OnDestroy {
 | 
			
		||||
  private unsubscriber = new Subject<void>();
 | 
			
		||||
  private server: Server = {};
 | 
			
		||||
 | 
			
		||||
  query: string = Queries.autoRolesWithHistoryQuery;
 | 
			
		||||
 | 
			
		||||
  constructor(
 | 
			
		||||
    private authService: AuthService,
 | 
			
		||||
    private spinner: SpinnerService,
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user