Browse Source

Refactoring

pull/5566/head
Thomas Kaul 4 weeks ago
parent
commit
0760abc428
  1. 5
      apps/api/src/app/access/access.controller.ts
  2. 6
      apps/client/src/app/components/access-table/access-table.component.html
  3. 6
      apps/client/src/app/components/user-account-access/create-or-update-access-dialog/create-or-update-access-dialog.component.ts
  4. 18
      apps/client/src/app/components/user-account-access/create-or-update-access-dialog/create-or-update-access-dialog.html
  5. 21
      apps/client/src/app/components/user-account-access/user-account-access.component.ts

5
apps/api/src/app/access/access.controller.ts

@ -41,10 +41,7 @@ export class AccessController {
include: { include: {
granteeUser: true granteeUser: true
}, },
orderBy: [ orderBy: [{ granteeUserId: 'desc' }, { createdAt: 'asc' }],
{ granteeUserId: 'desc' }, // NULL values first (public access), then user IDs
{ createdAt: 'asc' } // Within each group, order by creation time
],
where: { userId: this.request.user.id } where: { userId: this.request.user.id }
}); });

6
apps/client/src/app/components/access-table/access-table.component.html

@ -72,7 +72,6 @@
<span i18n>Edit</span> <span i18n>Edit</span>
</span> </span>
</button> </button>
<hr class="my-0" />
} }
@if (element.type === 'PUBLIC') { @if (element.type === 'PUBLIC') {
<button mat-menu-item (click)="onCopyUrlToClipboard(element.id)"> <button mat-menu-item (click)="onCopyUrlToClipboard(element.id)">
@ -82,6 +81,11 @@
</span> </span>
</button> </button>
} }
@if (
user?.settings?.isExperimentalFeatures || element.type === 'PUBLIC'
) {
<hr class="my-0" />
}
<button mat-menu-item (click)="onDeleteAccess(element.id)"> <button mat-menu-item (click)="onDeleteAccess(element.id)">
<span class="align-items-center d-flex"> <span class="align-items-center d-flex">
<ion-icon class="mr-2" name="remove-circle-outline" /> <ion-icon class="mr-2" name="remove-circle-outline" />

6
apps/client/src/app/components/user-account-access/create-or-update-access-dialog/create-or-update-access-dialog.component.ts

@ -107,10 +107,10 @@ export class GfCreateOrUpdateAccessDialogComponent
} }
public async onSubmit() { public async onSubmit() {
if (this.mode === 'update') { if (this.mode === 'create') {
await this.updateAccess();
} else {
await this.createAccess(); await this.createAccess();
} else {
await this.updateAccess();
} }
} }

18
apps/client/src/app/components/user-account-access/create-or-update-access-dialog/create-or-update-access-dialog.html

@ -5,10 +5,10 @@
(ngSubmit)="onSubmit()" (ngSubmit)="onSubmit()"
> >
<h1 mat-dialog-title> <h1 mat-dialog-title>
@if (mode === 'update') { @if (mode === 'create') {
<span i18n>Edit access</span>
} @else {
<span i18n>Grant access</span> <span i18n>Grant access</span>
} @else {
<span i18n>Edit access</span>
} }
</h1> </h1>
<div class="flex-grow-1 py-3" mat-dialog-content> <div class="flex-grow-1 py-3" mat-dialog-content>
@ -73,15 +73,15 @@
mat-flat-button mat-flat-button
type="submit" type="submit"
[disabled]=" [disabled]="
mode === 'update' mode === 'create'
? !accessForm.valid ? !(accessForm.dirty && accessForm.valid)
: !(accessForm.dirty && accessForm.valid) : !accessForm.valid
" "
> >
@if (mode === 'update') { @if (mode === 'create') {
<ng-container i18n>Update</ng-container>
} @else {
<ng-container i18n>Save</ng-container> <ng-container i18n>Save</ng-container>
} @else {
<ng-container i18n>Update</ng-container>
} }
</button> </button>
</div> </div>

21
apps/client/src/app/components/user-account-access/user-account-access.component.ts

@ -209,27 +209,24 @@ export class GfUserAccountAccessComponent implements OnDestroy, OnInit {
} }
private openUpdateAccessDialog(accessId: string) { private openUpdateAccessDialog(accessId: string) {
// Find the access details in the already loaded data const access = this.accessesGive?.find(({ id }) => {
const accessDetails = this.accessesGive.find(({ id }) => {
return id === accessId; return id === accessId;
}); });
if (!accessDetails) { if (!access) {
this.notificationService.alert({ console.log('Could not find access.');
title: $localize`Oops! Could not find access details.`
});
return; return;
} }
const dialogRef = this.dialog.open(GfCreateOrUpdateAccessDialogComponent, { const dialogRef = this.dialog.open(GfCreateOrUpdateAccessDialogComponent, {
data: { data: {
access: { access: {
alias: accessDetails.alias, alias: access.alias,
id: accessDetails.id, id: access.id,
grantee: grantee: access.grantee === 'Public' ? null : access.grantee,
accessDetails.grantee === 'Public' ? null : accessDetails.grantee, permissions: access.permissions,
permissions: accessDetails.permissions, type: access.type
type: accessDetails.type
} }
}, },
height: this.deviceType === 'mobile' ? '98vh' : undefined, height: this.deviceType === 'mobile' ? '98vh' : undefined,

Loading…
Cancel
Save