Commit 785d5aaa authored by Florent POITTEVIN's avatar Florent POITTEVIN
Browse files

fix: 1326 download orders with dip size provided

parent 20b5404d
......@@ -45,6 +45,7 @@ import {AppAuthorizedOrganizationalUnitState} from "@app/stores/authorized-organ
import {AppCartState} from "@app/stores/cart/app-cart.state";
import {AppCartArchiveState} from "@app/stores/cart/archive/app-cart-archive.state";
import {AppCartDipState} from "@app/stores/cart/dip/app-cart-dip.state";
import {AppCartDipDataFileState} from "@app/stores/cart/dip/data-file/app-cart-dip-data-file.state";
import {AppCartOrderState} from "@app/stores/cart/order/app-cart-order.state";
import {AppNotificationInboxState} from "@app/stores/notification-inbox/app-notification-inbox.state";
import {AppOrganizationalUnitPersonRoleState} from "@app/stores/organizational-unit-person-role/app-organizational-unit-person-role.state";
......@@ -120,6 +121,7 @@ export const appModuleState = [
AppCartArchiveState,
AppCartOrderState,
AppCartDipState,
AppCartDipDataFileState,
AppTocState,
AppNotificationInboxState,
];
......
......@@ -12,6 +12,7 @@ export enum LocalStateEnum {
application_cart_archive = "application_cart_archive",
application_cart_order = "application_cart_order",
application_cart_dip = "application_cart_dip",
application_cart_dip_dataFile = "application_cart_dip_dataFile",
home = "home",
home_organizationalUnit = "home_organizationalUnit",
......
......@@ -6,19 +6,27 @@ import {
AppCartDipAction,
appCartDipActionNameSpace,
} from "@app/stores/cart/dip/app-cart-dip.action";
import {AppCartDipDataFileAction} from "@app/stores/cart/dip/data-file/app-cart-dip-data-file.action";
import {AppCartDipDataFileState} from "@app/stores/cart/dip/data-file/app-cart-dip-data-file.state";
import {Dip} from "@models";
import {
Action,
Actions,
ofActionCompleted,
State,
StateContext,
Store,
} from "@ngxs/store";
import {ApiActionEnum} from "@shared/enums/api-action.enum";
import {DownloadService} from "@shared/services/download.service";
import {
take,
tap,
} from "rxjs/operators";
import {
ApiService,
defaultResourceStateInitValue,
isFalse,
NotificationService,
ResourceState,
ResourceStateModel,
......@@ -34,7 +42,9 @@ export interface AppCartDipStateModel extends ResourceStateModel<Dip> {
defaults: {
...defaultResourceStateInitValue(),
},
children: [],
children: [
AppCartDipDataFileState,
],
})
export class AppCartDipState extends ResourceState<AppCartDipStateModel, Dip> {
constructor(protected apiService: ApiService,
......@@ -56,8 +66,24 @@ export class AppCartDipState extends ResourceState<AppCartDipStateModel, Dip> {
download(ctx: StateContext<AppCartDipStateModel>, action: AppCartDipAction.Download): void {
const fileName = "dip_" + action.id + ".zip";
this.notificationService.showInformation(TRANSLATE("notification.dip.file.download"), true);
this.downloadService.download(`${this._urlResource}/${action.id}/${ApiActionEnum.DL}`, fileName).subscribe(() => {
this.notificationService.showInformation(TRANSLATE("notification.dip.file.downloadWithSuccess"), true);
});
this.actions$.pipe(
ofActionCompleted(AppCartDipDataFileAction.GetAllSuccess),
take(1),
tap(actionGetByIdSuccess => {
if (isFalse(actionGetByIdSuccess.result.successful)) {
return;
}
const listDipDataFile = (actionGetByIdSuccess.action as AppCartDipDataFileAction.GetAllSuccess).list;
let size = 0;
listDipDataFile._data.forEach(dipDataFile => {
size += dipDataFile.fileSize;
});
this.downloadService.download(`${this._urlResource}/${action.id}/${ApiActionEnum.DL}`, fileName, size).subscribe(() => {
this.notificationService.showInformation(TRANSLATE("notification.dip.file.downloadWithSuccess"), true);
});
}),
).subscribe();
ctx.dispatch(new AppCartDipDataFileAction.GetAll(action.id));
}
}
import {DipDataFile} from "@preservation/dip/models/dip-data-file.model";
import {LocalStateEnum} from "@shared/enums/local-state.enum";
import {
CompositionAction,
CompositionNameSpace,
TypeDefaultAction,
} from "solidify-frontend";
const state = LocalStateEnum.application_cart_dip_dataFile;
export namespace AppCartDipDataFileAction {
@TypeDefaultAction(state)
export class GetAll extends CompositionAction.GetAll {
}
@TypeDefaultAction(state)
export class GetAllSuccess extends CompositionAction.GetAllSuccess<DipDataFile> {
}
@TypeDefaultAction(state)
export class GetAllFail extends CompositionAction.GetAllFail {
}
@TypeDefaultAction(state)
export class GetById extends CompositionAction.GetById {
}
@TypeDefaultAction(state)
export class GetByIdSuccess extends CompositionAction.GetByIdSuccess<DipDataFile> {
}
@TypeDefaultAction(state)
export class GetByIdFail extends CompositionAction.GetByIdFail {
}
@TypeDefaultAction(state)
export class Update extends CompositionAction.Update<DipDataFile> {
}
@TypeDefaultAction(state)
export class UpdateSuccess extends CompositionAction.UpdateSuccess<DipDataFile> {
}
@TypeDefaultAction(state)
export class UpdateFail extends CompositionAction.UpdateFail<DipDataFile> {
}
@TypeDefaultAction(state)
export class Create extends CompositionAction.Create<DipDataFile> {
}
@TypeDefaultAction(state)
export class CreateSuccess extends CompositionAction.CreateSuccess<DipDataFile> {
}
@TypeDefaultAction(state)
export class CreateFail extends CompositionAction.CreateFail<DipDataFile> {
}
@TypeDefaultAction(state)
export class Delete extends CompositionAction.Delete<DipDataFile> {
}
@TypeDefaultAction(state)
export class DeleteSuccess extends CompositionAction.DeleteSuccess<DipDataFile> {
}
@TypeDefaultAction(state)
export class DeleteFail extends CompositionAction.DeleteFail<DipDataFile> {
}
@TypeDefaultAction(state)
export class ChangeQueryParameters extends CompositionAction.ChangeQueryParameters {
}
export class Download {
static readonly type: string = `[${state}] Download`;
constructor(public parentId: string, public dataFile: DipDataFile) {
}
}
}
export const appCartDipDataFileActionNameSpace: CompositionNameSpace = AppCartDipDataFileAction;
import {
Inject,
Injectable,
} from "@angular/core";
import {WINDOW} from "@app/app.module";
import {appCartDipDataFileActionNameSpace} from "@app/stores/cart/dip/data-file/app-cart-dip-data-file.action";
import {
Action,
Actions,
State,
StateContext,
Store,
} from "@ngxs/store";
import {DipDataFile} from "@preservation/dip/models/dip-data-file.model";
import {PreservationDipDataFileAction} from "@preservation/dip/stores/data-file/dip-data-file.action";
import {ApiActionEnum} from "@shared/enums/api-action.enum";
import {ApiResourceNameEnum} from "@shared/enums/api-resource-name.enum";
import {AccessResourceApiEnum} from "@shared/enums/api.enum";
import {LocalStateEnum} from "@shared/enums/local-state.enum";
import {DownloadService} from "@shared/services/download.service";
import {
ApiService,
CompositionState,
CompositionStateModel,
defaultCompositionStateInitValue,
NotificationService,
TRANSLATE,
} from "solidify-frontend";
export const defaultAppCartDipDataFileValue: () => AppCartDipDataFileStateModel = () =>
({
...defaultCompositionStateInitValue(),
});
export interface AppCartDipDataFileStateModel extends CompositionStateModel<DipDataFile> {
}
@Injectable()
@State<AppCartDipDataFileStateModel>({
name: LocalStateEnum.application_cart_dip_dataFile,
defaults: {
...defaultAppCartDipDataFileValue(),
},
children: [],
})
export class AppCartDipDataFileState extends CompositionState<AppCartDipDataFileStateModel, DipDataFile> {
constructor(protected apiService: ApiService,
protected store: Store,
protected notificationService: NotificationService,
protected actions$: Actions,
@Inject(WINDOW) private _window: Window,
private downloadService: DownloadService) {
super(apiService, store, notificationService, actions$, {
nameSpace: appCartDipDataFileActionNameSpace,
resourceName: ApiResourceNameEnum.DATAFILE,
});
}
protected get _urlResource(): string {
return AccessResourceApiEnum.dip;
}
@Action(PreservationDipDataFileAction.Download)
download(ctx: StateContext<AppCartDipDataFileStateModel>, action: PreservationDipDataFileAction.Download): void {
const url = `${this._urlResource}/${action.parentId}/${this._resourceName}/${action.dataFile.resId}/${ApiActionEnum.DL}`;
this.notificationService.showInformation(TRANSLATE("notification.deposit.file.download"), true);
this.downloadService.download(url, action.dataFile.fileName, action.dataFile.fileSize).subscribe(() => {
this.notificationService.showSuccess(TRANSLATE("notification.deposit.file.downloadWithSuccess"));
});
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment