Skip to content

Commit

Permalink
portalicious: export selected registrations
Browse files Browse the repository at this point in the history
AB#31003
  • Loading branch information
aberonni committed Oct 29, 2024
1 parent 4e43a8b commit 6d64058
Show file tree
Hide file tree
Showing 19 changed files with 608 additions and 21 deletions.
2 changes: 2 additions & 0 deletions interfaces/Portalicious/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ module.exports = tseslint.config(
'p-dropdown[appendTo]',
'p-iconField[iconPosition]',
'p-sidebar[position]',
'p-splitButton[icon]',
'p-splitButton[menuStyleClass]',
'p-table[stateKey]',
'p-table[stateStorage]',
'styleClass',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import { FormErrorComponent } from '~/components/form-error/form-error.component
export class ConfirmationDialogComponent<TMutationData = unknown> {
private confirmationService = inject(ConfirmationService);

mutation =
input.required<CreateMutationResult<unknown, Error, TMutationData>>();
// eslint-disable-next-line @typescript-eslint/no-explicit-any
mutation = input.required<CreateMutationResult<any, Error, TMutationData>>();
mutationData = input.required<TMutationData>();
header = input($localize`:@@confirmation-dialog-header:Are you sure?`);
headerIcon = input<string>('pi pi-question');
Expand Down
36 changes: 36 additions & 0 deletions interfaces/Portalicious/src/app/domains/event/event.api.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { HttpParams } from '@angular/common/http';
import { Injectable, Signal } from '@angular/core';

import { DomainApiService } from '~/domains/domain-api.service';

const BASE_ENDPOINT = (projectId: Signal<number>) => [
'programs',
projectId,
'events',
];

@Injectable({
providedIn: 'root',
})
export class EventApiService extends DomainApiService {
getEvents({
projectId,
params,
}: {
projectId: Signal<number>;
params: HttpParams;
}) {
return this.httpWrapperService.perform121ServiceRequest<Blob>({
method: 'GET',
endpoint: this.pathToQueryKey([...BASE_ENDPOINT(projectId)]).join('/'),
params,
responseAsBlob: true,
});
}

public invalidateCache(projectId: Signal<number>): Promise<void> {
return this.queryClient.invalidateQueries({
queryKey: this.pathToQueryKey(BASE_ENDPOINT(projectId)),
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { HttpParams } from '@angular/common/http';
import { inject, Injectable, Signal } from '@angular/core';

import { ExportType } from '@121-service/src/metrics/enum/export-type.enum';

import { DomainApiService } from '~/domains/domain-api.service';
import { ProjectMetrics } from '~/domains/metric/metric.model';
import { PaginateQueryService } from '~/services/paginate-query.service';

const BASE_ENDPOINT = (projectId: Signal<number>) => [
'programs',
projectId,
'metrics',
];

@Injectable({
providedIn: 'root',
})
export class MetricApiService extends DomainApiService {
paginateQueryService = inject(PaginateQueryService);

getProjectSummaryMetrics(projectId: Signal<number>) {
return this.generateQueryOptions<ProjectMetrics>({
path: [...BASE_ENDPOINT(projectId), 'program-stats-summary'],
});
}

exportMetrics({
projectId,
type,
params,
}: {
projectId: Signal<number>;
type: ExportType;
params: HttpParams;
}) {
return this.httpWrapperService.perform121ServiceRequest<Blob>({
method: 'GET',
endpoint: this.pathToQueryKey([
...BASE_ENDPOINT(projectId),
'export-list',
type,
]).join('/'),
params,
responseAsBlob: true,
});
}

public invalidateCache(projectId: Signal<number>): Promise<void> {
return this.queryClient.invalidateQueries({
queryKey: this.pathToQueryKey(BASE_ENDPOINT(projectId)),
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { ProgramStats } from '@121-service/src/metrics/dto/program-stats.dto';

import { Dto } from '~/utils/dto-type';
// TODO: AB#30152 This type should be refactored to use Dto121Service
export type ProjectMetrics = Dto<ProgramStats>;
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,22 @@ import { inject, Injectable, Signal } from '@angular/core';

import { uniqBy } from 'lodash';

import { ActionReturnDto } from '@121-service/src/actions/dto/action-return.dto';
import { ExportType } from '@121-service/src/metrics/enum/export-type.enum';

import { DomainApiService } from '~/domains/domain-api.service';
import { ATTRIBUTE_LABELS } from '~/domains/project/project.helper';
import {
Attribute,
AttributeWithTranslatedLabel,
Project,
ProjectMetrics,
ProjectUser,
ProjectUserAssignment,
ProjectUserWithRolesLabel,
} from '~/domains/project/project.model';
import { Role } from '~/domains/role/role.model';
import { TranslatableStringService } from '~/services/translatable-string.service';
import { Dto } from '~/utils/dto-type';

const BASE_ENDPOINT = 'programs';

Expand Down Expand Up @@ -54,12 +57,6 @@ export class ProjectApiService extends DomainApiService {
});
}

getProjectSummaryMetrics(projectId: Signal<number>) {
return this.generateQueryOptions<ProjectMetrics>({
path: [BASE_ENDPOINT, projectId, 'metrics/program-stats-summary'],
});
}

getProjectUsers(projectId: Signal<number>) {
return this.generateQueryOptions<
ProjectUser[],
Expand Down Expand Up @@ -260,6 +257,26 @@ export class ProjectApiService extends DomainApiService {
});
}

getLatestAction({
projectId,
actionType,
}: {
projectId: Signal<number>;
actionType: ExportType;
}) {
const params = new HttpParams({
fromObject: {
actionType,
},
});
return this.generateQueryOptions<Dto<ActionReturnDto>>({
path: [BASE_ENDPOINT, projectId, 'actions'],
requestOptions: {
params,
},
});
}

public invalidateCache(projectId?: Signal<number>): Promise<void> {
const path: (Signal<number> | string)[] = [BASE_ENDPOINT];

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { ProgramStats } from '@121-service/src/metrics/dto/program-stats.dto';
import { FoundProgramDto } from '@121-service/src/programs/dto/found-program.dto';
import { ProgramController } from '@121-service/src/programs/programs.controller';
import { UserController } from '@121-service/src/user/user.controller';
Expand All @@ -9,9 +8,6 @@ import { ArrayElement } from '~/utils/type-helpers';
// TODO: AB#30152 This type should be refactored to use Dto121Service
export type Project = Dto<FoundProgramDto>;

// TODO: AB#30152 This type should be refactored to use Dto121Service
export type ProjectMetrics = Dto<ProgramStats>;

export type ProjectUser = ArrayElement<
Dto121Service<UserController['getUsersInProgram']>
>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
import { InfoTooltipComponent } from '~/components/info-tooltip/info-tooltip.component';
import { PageLayoutComponent } from '~/components/page-layout/page-layout.component';
import { SkeletonInlineComponent } from '~/components/skeleton-inline/skeleton-inline.component';
import { MetricApiService } from '~/domains/metric/metric.api.service';
import { PaymentApiService } from '~/domains/payment/payment.api.service';
import { ProjectApiService } from '~/domains/project/project.api.service';
import { MetricTileComponent } from '~/pages/project-monitoring/components/metric-tile/metric-tile.component';
Expand Down Expand Up @@ -52,13 +53,14 @@ export class ProjectMonitoringPageComponent {
projectId = input.required<number>();

readonly locale = inject(LOCALE_ID);
readonly metricApiService = inject(MetricApiService);
readonly projectApiService = inject(ProjectApiService);
readonly paymentApiService = inject(PaymentApiService);
readonly translatableStringService = inject(TranslatableStringService);

project = injectQuery(this.projectApiService.getProject(this.projectId));
metrics = injectQuery(() => ({
...this.projectApiService.getProjectSummaryMetrics(this.projectId)(),
...this.metricApiService.getProjectSummaryMetrics(this.projectId)(),
enabled: !!this.project.data()?.id,
}));
payments = injectQuery(() => ({
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<p-splitButton
label="Export"
i18n-label="@@export"
icon="pi pi-upload"
rounded
outlined
[model]="exportOptions"
(onClick)="exportSelectedRegistrations()"
menuStyleClass="!left-auto right-0 w-auto [&_.p-menuitem-text]:whitespace-nowrap"
/>
<app-confirmation-dialog
#exportSelectedDialog
header="Export selected registrations"
i18n-header="@@export-selected"
headerIcon="pi pi-upload"
[mutation]="exportRegistrationsMutation"
[mutationData]="{
type: ExportType.allPeopleAffected,
paginateQuery: exportSelectedActionData()?.query,
}"
>
<p i18n>
You're about to download an Excel file for
{{ exportSelectedActionData()?.count }} selected registrations.
</p>
<app-latest-export-date
[projectId]="projectId()"
[exportType]="ExportType.allPeopleAffected"
/>
</app-confirmation-dialog>
<app-confirmation-dialog
#exportAllDialog
header="Export all registrations"
i18n-header="@@export-all"
headerIcon="pi pi-upload"
[mutation]="exportRegistrationsMutation"
[mutationData]="{
type: ExportType.allPeopleAffected,
}"
>
<p i18n>You're about to download an Excel file for all registrations.</p>
<app-latest-export-date
[projectId]="projectId()"
[exportType]="ExportType.allPeopleAffected"
/>
</app-confirmation-dialog>
Loading

0 comments on commit 6d64058

Please sign in to comment.