Commit 3d04bc32 authored by Simon Esposito's avatar Simon Esposito Committed by Mo Firouz
Browse files

Console minor improvements and source linting. (#545)

parent 0fbf2354
Loading
Loading
Loading
Loading
+2 −2

File changed.

Preview size limit exceeded, changes collapsed.

+18 −17
Original line number Diff line number Diff line
@@ -35,10 +35,11 @@ export class AccountComponent implements OnInit {
    {label: 'Wallet', path: 'wallet'},
  ];

  constructor(private readonly route: ActivatedRoute,
  constructor(
    private readonly route: ActivatedRoute,
    private readonly router: Router,
    private readonly consoleService: ConsoleService,
    private readonly authService: AuthenticationService
    private readonly authService: AuthenticationService,
  ) {}

  ngOnInit(): void {
@@ -51,7 +52,7 @@ export class AccountComponent implements OnInit {
      });
  }

  deleteAccount(event, recorded: boolean) {
  deleteAccount(event, recorded: boolean): void {
    event.target.disabled = true;
    this.error = '';
    this.consoleService.deleteAccount('', this.account.user.id, recorded).subscribe(() => {
@@ -59,10 +60,10 @@ export class AccountComponent implements OnInit {
      this.router.navigate(['/accounts']);
    }, err => {
      this.error = err;
    })
    });
  }

  banUnbanAccount(event) {
  banUnbanAccount(event): void {
    event.target.disabled = true;
    this.error = '';
    if (this.account.disable_time) {
@@ -73,7 +74,7 @@ export class AccountComponent implements OnInit {
      }, err => {
        this.error = err;
        event.target.disabled = false;
      })
      });
    } else {
      this.consoleService.banAccount('', this.account.user.id).subscribe(() => {
        this.error = '';
@@ -82,43 +83,43 @@ export class AccountComponent implements OnInit {
      }, err => {
        this.error = err;
        event.target.disabled = false;
      })
      });
    }
  }

  exportAccount(event) {
  exportAccount(event): void {
    event.target.disabled = true;
    this.error = '';
    this.consoleService.exportAccount('', this.account.user.id).subscribe(accountExport => {
      this.error = '';
      const fileName = this.account.user.id + "-export.json"
      const fileName = this.account.user.id + '-export.json';
      const json = JSON.stringify(accountExport, null, 2);
      const bytes = new TextEncoder().encode(json);
      let blob = new Blob([bytes], {type: "application/json;charset=utf-8"});
      const blob = new Blob([bytes], {type: 'application/json;charset=utf-8'});
      saveAs(blob, fileName);
      event.target.disabled = false;
    }, err => {
      event.target.disabled = false;
      this.error = err;
    })
    });
  }

  updateAllowed() {
  updateAllowed(): boolean {
    // only admin and developers are allowed.
    return this.authService.sessionRole <= UserRole.USER_ROLE_MAINTAINER;
  }

  exportAllowed() {
  exportAllowed(): boolean {
    // only admin and developers are allowed.
    return this.authService.sessionRole <= UserRole.USER_ROLE_DEVELOPER;
  }

  banAllowed() {
  banAllowed(): boolean {
    // only admin and developers are allowed.
    return this.authService.sessionRole <= UserRole.USER_ROLE_MAINTAINER;
  }

  deleteAllowed() {
  deleteAllowed(): boolean {
    // only admin and developers are allowed.
    return this.authService.sessionRole <= UserRole.USER_ROLE_DEVELOPER;
  }
@@ -129,7 +130,7 @@ export class AccountResolver implements Resolve<ApiAccount> {
  constructor(private readonly consoleService: ConsoleService) {}

  resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<ApiAccount> {
    const userId = route.paramMap.get("id");
    return this.consoleService.getAccount('', userId)
    const userId = route.paramMap.get('id');
    return this.consoleService.getAccount('', userId);
  }
}
+4 −3
Original line number Diff line number Diff line
<script src="friends.component.ts"></script>
<ngb-alert [dismissible]="false" type="danger" class="mb-3" *ngIf="error">
  <img src="/static/svg/red-triangle.svg" alt="" width="16" height="" class="mr-2">
  <h6 class="mr-2 d-inline font-weight-bold">An error occurred: {{error}}</h6>
</ngb-alert>

<div class="row no-gutters">
  <table class="table table-sm table-bordered">
  <table class="table table-sm table-hover table-bordered">
    <thead class="thead-light">
      <tr>
        <th style="width: 300px">User ID</th>
        <th style="width: 320px">User ID</th>
        <th>Username</th>
        <th style="width: 300px">State</th>
        <th style="width: 180px">Update Time</th>
@@ -29,7 +30,7 @@
          <span *ngIf="f.state === 3">Blocked (3)</span>
        </td>
        <td>{{f.update_time}}</td>
        <td *ngIf="deleteAllowed()"><button type="button" class="btn btn-sm btn-danger" (click)="deleteFriend($event, i, f);">Delete</button></td>
        <td *ngIf="deleteAllowed()" class="text-center"><button type="button" class="btn btn-sm btn-danger" (click)="deleteFriend($event, i, f);">Delete</button></td>
      </tr>
    </tbody>
  </table>
+3 −0
Original line number Diff line number Diff line
.table-hover {
  cursor: pointer;
}
+4 −4
Original line number Diff line number Diff line
@@ -57,20 +57,20 @@ export class FriendsComponent implements OnInit {
      });
  }

  deleteAllowed() {
  deleteAllowed(): boolean {
    return this.authService.sessionRole <= UserRole.USER_ROLE_MAINTAINER;
  }

  deleteFriend(event, i: number, f: ApiFriend) {
  deleteFriend(event, i: number, f: ApiFriend): void {
    event.target.disabled = true;
    event.preventDefault();
    this.error = '';
    this.consoleService.deleteFriend('', this.account.user.id, f.user.id).subscribe(() => {
      this.error = '';
      this.friends.splice(i, 1)
      this.friends.splice(i, 1);
    }, err => {
      this.error = err;
    })
    });
  }
}

Loading