Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/IOT-1583-MoveApplication #178

Merged
merged 4 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/app/admin/permission/permission.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ export interface PermissionGetManyResponse {
count: number;
}

export type PermissionsSlimDto = Pick<
PermissionResponse,
"id" | "name" | "automaticallyAddNewApplications" | "organization"
>;

export interface PermissionGetManySlimResponse {
data: PermissionsSlimDto[];
count: number;
}

export interface PermissionTypes {
type: PermissionType;
}
Expand Down
29 changes: 29 additions & 0 deletions src/app/admin/permission/permission.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
PermissionResponse,
PermissionRequest,
PermissionRequestAcceptUser,
PermissionGetManySlimResponse,
} from "./permission.model";
import { map } from "rxjs/operators";
import { UserMinimalService } from "../users/user-minimal.service";
Expand All @@ -15,6 +16,7 @@ import { UserMinimalService } from "../users/user-minimal.service";
})
export class PermissionService {
endpoint = "permission";
applicationAdmin = "/applicationAdmin";
constructor(private restService: RestService, private userMinimalService: UserMinimalService) {}

createPermission(body: PermissionRequest): Observable<PermissionResponse> {
Expand Down Expand Up @@ -75,6 +77,33 @@ export class PermissionService {
}
}

getPermissionsWhereApplicationAdmin(
limit: number = 1000,
offset: number = 0,
orderByColumn?: string,
orderByDirection?: string,
userId?: number,
organisationId?: number
): Observable<PermissionGetManySlimResponse> {
if (userId || organisationId) {
return this.restService.get(this.endpoint + this.applicationAdmin, {
limit: limit,
offset: offset,
orderOn: orderByColumn,
sort: orderByDirection,
userId: userId,
organisationId: organisationId,
});
} else {
return this.restService.get(this.endpoint + this.applicationAdmin, {
limit: limit,
offset: offset,
orderOn: orderByColumn,
sort: orderByDirection,
});
}
}

getPermissionsWithoutUsers(userId?: number): Observable<PermissionGetManyResponse> {
return this.restService.get(this.endpoint + "/getAllPermissionsWithoutUsers", {
limit: 1000,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ <h1 mat-dialog-title>{{ "APPLICATION.CHANGE-ORGANIZATION.TITLE" | translate }}</
<mat-hint>{{ "APPLICATION.CHANGE-ORGANIZATION.USER-GROUP-AUTO-SELECT" | translate }}</mat-hint>
</div>
</div>
<div mat-dialog-actions class="d-flex flex-row">
<div mat-dialog-actions class="d-flex flex-row mat-dialog-actions">
<button (click)="onSubmit()" class="btn btn-primary">
{{ "GEN.SAVE" | translate }}
</button>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
.application-change-organization-dialog {
width: 50vw;
}

.mat-dialog-actions {
margin-left: 13px;
margin-bottom: 13px;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { MAT_DIALOG_DATA, MatDialogRef } from "@angular/material/dialog";
import { MatSnackBar } from "@angular/material/snack-bar";
import { Organisation } from "@app/admin/organisation/organisation.model";
import { OrganisationService } from "@app/admin/organisation/organisation.service";
import { PermissionResponse } from "@app/admin/permission/permission.model";
import { PermissionResponse, PermissionsSlimDto } from "@app/admin/permission/permission.model";
import { PermissionService } from "@app/admin/permission/permission.service";
import { Application, UpdateApplicationOrganization } from "@applications/application.model";
import { ApplicationService } from "@applications/application.service";
Expand All @@ -23,9 +23,9 @@ export class ApplicationChangeOrganizationDialogComponent implements OnInit {
public permissionsSubscription: Subscription;
public organizationsSubscription: Subscription;
public application: UpdateApplicationOrganization;
public permissions: PermissionResponse[];
public permissions: PermissionsSlimDto[];
public organizations: Organisation[];
public filteredPermissionsMulti: ReplaySubject<PermissionResponse[]> = new ReplaySubject<PermissionResponse[]>(1);
public filteredPermissionsMulti: ReplaySubject<PermissionsSlimDto[]> = new ReplaySubject<PermissionsSlimDto[]>(1);
public filteredOrganizations: ReplaySubject<Organisation[]> = new ReplaySubject<Organisation[]>(1);

constructor(
Expand Down Expand Up @@ -61,18 +61,20 @@ export class ApplicationChangeOrganizationDialogComponent implements OnInit {

getOrganizations() {
this.organizationsSubscription = this.organizationService.getMultipleWithApplicationAdmin().subscribe(res => {
this.organizations = res.data;
this.organizations = res.data.sort((a, b) => a.name.localeCompare(b.name, "da-DK", { numeric: true }));
this.filteredOrganizations.next(this.organizations.slice());
});
}

getPermissions() {
this.permissionsSubscription = this.permissionService.getPermissions(1000, 0).subscribe(res => {
this.permissions = res.data.sort((a, b) => a.name.localeCompare(b.name, "da-DK", { numeric: true }));
this.filteredPermissionsMulti.next(
this.permissions.filter(p => p?.organization?.id === this?.application?.organizationId)
);
});
this.permissionsSubscription = this.permissionService
.getPermissionsWhereApplicationAdmin(1000, 0)
.subscribe(res => {
this.permissions = res.data.sort((a, b) => a.name.localeCompare(b.name, "da-DK", { numeric: true }));
this.filteredPermissionsMulti.next(
this.permissions.filter(p => p?.organization?.id === this?.application?.organizationId)
);
});
}

public compare(o1: any, o2: any): boolean {
Expand All @@ -99,12 +101,13 @@ export class ApplicationChangeOrganizationDialogComponent implements OnInit {
applicationName: savedApplication.name,
organizationName: savedApplication.belongsTo.name,
}),
"",
this.translate.instant("DIALOG.OK"),
{
duration: 10000,
}
);
this.dialog.close(true);
this.snackBar._openedSnackBarRef.afterDismissed().subscribe(() => location.reload());
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -273,17 +273,11 @@ export class ApplicationsTableComponent implements AfterViewInit, OnInit {
}

onOpenChangeOrganizationDialog(id: number) {
const dialog = this.changeOrganizationDialog.open(ApplicationChangeOrganizationDialogComponent, {
this.changeOrganizationDialog.open(ApplicationChangeOrganizationDialogComponent, {
data: {
applicationId: id,
} as ApplicationDialogModel,
});

dialog.afterClosed().subscribe(res => {
if (!res) return;

location.reload();
});
}

protected readonly columnDefinitions = columnDefinitions;
Expand Down
Loading