Commit 335d754d authored by Florent POITTEVIN's avatar Florent POITTEVIN
Browse files

fix: avoid random infinite spinner when form loading

parent a5af6daf
......@@ -34,12 +34,12 @@ import {
defaultAssociationStateInitValue,
defaultResourceStateInitValue,
isNullOrUndefined,
MARK_AS_TRANSLATABLE,
NotificationService,
OverrideDefaultAction,
ResourceState,
ResourceStateModel,
StoreUtil,
MARK_AS_TRANSLATABLE,
urlSeparator,
} from "solidify-frontend";
......@@ -110,26 +110,28 @@ export class AdminFundingAgenciesState extends ResourceState<AdminFundingAgencie
}
@Action(AdminFundingAgenciesAction.LoadResource)
loadResource(ctx: StateContext<AdminFundingAgenciesStateModel>, action: AdminFundingAgenciesAction.LoadResource): void {
loadResource(ctx: StateContext<AdminFundingAgenciesStateModel>, action: AdminFundingAgenciesAction.LoadResource): Observable<any> {
ctx.patchState({
isLoadingCounter: ctx.getState().isLoadingCounter + 1,
});
StoreUtil.dispatchParallelActionAndWaitForSubActionsCompletion(ctx, [
return StoreUtil.dispatchParallelActionAndWaitForSubActionsCompletion(ctx, [
{
action: new SharedOrgUnitAction.GetAll(),
action: new SharedOrgUnitAction.GetAll(undefined, false, false),
subActionCompletions: [
this.actions$.pipe(ofActionCompleted(SharedOrgUnitAction.GetAllSuccess)),
this.actions$.pipe(ofActionCompleted(SharedOrgUnitAction.GetAllFail)),
],
},
]).subscribe(success => {
if (success) {
ctx.dispatch(new AdminFundingAgenciesAction.LoadResourceSuccess(action));
} else {
ctx.dispatch(new AdminFundingAgenciesAction.LoadResourceFail(action));
}
});
]).pipe(
tap(success => {
if (success) {
ctx.dispatch(new AdminFundingAgenciesAction.LoadResourceSuccess(action));
} else {
ctx.dispatch(new AdminFundingAgenciesAction.LoadResourceFail(action));
}
}),
);
}
@OverrideDefaultAction()
......@@ -183,10 +185,10 @@ export class AdminFundingAgenciesState extends ResourceState<AdminFundingAgencie
@OverrideDefaultAction()
@Action(AdminFundingAgenciesAction.Delete)
delete(ctx: StateContext<AdminFundingAgenciesStateModel>, action: AdminFundingAgenciesAction.Delete): Observable<FundingAgencyExtended> | any {
delete(ctx: StateContext<AdminFundingAgenciesStateModel>, action: AdminFundingAgenciesAction.Delete): Observable<any> {
const oldOrgUnit = _.map(ctx.getState().admin_fundingAgencies_organizationalUnit.selected, LocalModelAttributeEnum.resId);
StoreUtil.dispatchParallelActionAndWaitForSubActionsCompletion(
return StoreUtil.dispatchParallelActionAndWaitForSubActionsCompletion(
ctx,
[
{
......@@ -197,12 +199,14 @@ export class AdminFundingAgenciesState extends ResourceState<AdminFundingAgencie
],
},
],
).subscribe(deleteSubResourceWithSuccess => {
if (deleteSubResourceWithSuccess) {
super.delete(ctx, action).subscribe();
} else {
super.deleteFail(ctx, action);
}
});
).pipe(
tap(deleteSubResourceWithSuccess => {
if (deleteSubResourceWithSuccess) {
super.delete(ctx, action).subscribe();
} else {
super.deleteFail(ctx, action);
}
}),
);
}
}
......@@ -18,15 +18,17 @@ import {AdminResourceApiEnum} from "@shared/enums/api.enum";
import {LocalStateEnum} from "@shared/enums/local-state.enum";
import {RoutesEnum} from "@shared/enums/routes.enum";
import {SharedLanguageAction} from "@shared/stores/language/shared-language.action";
import {Observable} from "rxjs";
import {tap} from "rxjs/operators";
import {
ApiService,
defaultResourceStateInitValue,
isNullOrUndefined,
MARK_AS_TRANSLATABLE,
NotificationService,
ResourceState,
ResourceStateModel,
StoreUtil,
MARK_AS_TRANSLATABLE,
} from "solidify-frontend";
export interface AdminLanguageStateModel extends ResourceStateModel<Language> {
......@@ -88,12 +90,12 @@ export class AdminLanguageState extends ResourceState<AdminLanguageStateModel, L
}
@Action(AdminLanguageAction.LoadResource)
loadResource(ctx: StateContext<DepositStateModel>, action: AdminLanguageAction.LoadResource): void {
loadResource(ctx: StateContext<DepositStateModel>, action: AdminLanguageAction.LoadResource): Observable<any> {
ctx.patchState({
isLoadingCounter: ctx.getState().isLoadingCounter + 1,
});
StoreUtil.dispatchParallelActionAndWaitForSubActionsCompletion(ctx, [
return StoreUtil.dispatchParallelActionAndWaitForSubActionsCompletion(ctx, [
{
action: new SharedLanguageAction.GetAll(null, false, false),
subActionCompletions: [
......@@ -101,12 +103,14 @@ export class AdminLanguageState extends ResourceState<AdminLanguageStateModel, L
this.actions$.pipe(ofActionCompleted(SharedLanguageAction.GetAllFail)),
],
},
]).subscribe(success => {
if (success) {
ctx.dispatch(new AdminLanguageAction.LoadResourceSuccess(action));
} else {
ctx.dispatch(new AdminLanguageAction.LoadResourceFail(action));
}
});
]).pipe(
tap(success => {
if (success) {
ctx.dispatch(new AdminLanguageAction.LoadResourceSuccess(action));
} else {
ctx.dispatch(new AdminLanguageAction.LoadResourceFail(action));
}
}),
);
}
}
......@@ -26,11 +26,11 @@ import {
ApiService,
defaultResourceStateInitValue,
isNullOrUndefined,
MARK_AS_TRANSLATABLE,
NotificationService,
ResourceState,
ResourceStateModel,
StoreUtil,
MARK_AS_TRANSLATABLE,
} from "solidify-frontend";
import {ActionSubActionCompletionsWrapper} from "solidify-frontend/lib/models/stores/base.action";
......@@ -94,26 +94,28 @@ export class AdminOaiSetState extends ResourceState<AdminOaiSetStateModel, OaiSe
}
@Action(AdminOaiSetAction.LoadResource)
loadResource(ctx: StateContext<AdminOaiSetStateModel>, action: AdminOaiSetAction.LoadResource): void {
loadResource(ctx: StateContext<AdminOaiSetStateModel>, action: AdminOaiSetAction.LoadResource): Observable<any> {
ctx.patchState({
isLoadingCounter: ctx.getState().isLoadingCounter + 1,
});
StoreUtil.dispatchParallelActionAndWaitForSubActionsCompletion(ctx, [
return StoreUtil.dispatchParallelActionAndWaitForSubActionsCompletion(ctx, [
{
action: new SharedOrgUnitAction.GetAll(),
action: new SharedOrgUnitAction.GetAll(undefined, false, false),
subActionCompletions: [
this.actions$.pipe(ofActionCompleted(SharedOrgUnitAction.GetAllSuccess)),
this.actions$.pipe(ofActionCompleted(SharedOrgUnitAction.GetAllFail)),
],
},
]).subscribe(success => {
if (success) {
ctx.dispatch(new AdminOaiSetAction.LoadResourceSuccess(action));
} else {
ctx.dispatch(new AdminOaiSetAction.LoadResourceFail(action));
}
});
]).pipe(
tap(success => {
if (success) {
ctx.dispatch(new AdminOaiSetAction.LoadResourceSuccess(action));
} else {
ctx.dispatch(new AdminOaiSetAction.LoadResourceFail(action));
}
}),
);
}
@Action(AdminOaiSetAction.BulkCreate)
......
......@@ -37,13 +37,13 @@ import {
defaultResourceStateInitValue,
isArray,
isNullOrUndefined,
MARK_AS_TRANSLATABLE,
NotificationService,
OverrideDefaultAction,
Relation3TiersForm,
ResourceState,
ResourceStateModel,
StoreUtil,
MARK_AS_TRANSLATABLE,
urlSeparator,
} from "solidify-frontend";
......@@ -119,26 +119,28 @@ export class AdminPersonState extends ResourceState<AdminPersonStateModel, Perso
}
@Action(AdminPersonAction.LoadResource)
loadResource(ctx: StateContext<DepositStateModel>, action: AdminPersonAction.LoadResource): void {
loadResource(ctx: StateContext<DepositStateModel>, action: AdminPersonAction.LoadResource): Observable<any> {
ctx.patchState({
isLoadingCounter: ctx.getState().isLoadingCounter + 1,
});
StoreUtil.dispatchParallelActionAndWaitForSubActionsCompletion(ctx, [
return StoreUtil.dispatchParallelActionAndWaitForSubActionsCompletion(ctx, [
{
action: new SharedRoleAction.GetAll(),
action: new SharedRoleAction.GetAll(undefined, false, false),
subActionCompletions: [
this.actions$.pipe(ofActionCompleted(SharedRoleAction.GetAllSuccess)),
this.actions$.pipe(ofActionCompleted(SharedRoleAction.GetAllFail)),
],
},
]).subscribe(success => {
if (success) {
ctx.dispatch(new AdminPersonAction.LoadResourceSuccess(action));
} else {
ctx.dispatch(new AdminPersonAction.LoadResourceFail(action));
}
});
]).pipe(
tap(success => {
if (success) {
ctx.dispatch(new AdminPersonAction.LoadResourceSuccess(action));
} else {
ctx.dispatch(new AdminPersonAction.LoadResourceFail(action));
}
}),
);
}
@OverrideDefaultAction()
......
......@@ -18,15 +18,17 @@ import {AdminResourceApiEnum} from "@shared/enums/api.enum";
import {LocalStateEnum} from "@shared/enums/local-state.enum";
import {RoutesEnum} from "@shared/enums/routes.enum";
import {SharedLanguageAction} from "@shared/stores/language/shared-language.action";
import {Observable} from "rxjs";
import {tap} from "rxjs/operators";
import {
ApiService,
defaultResourceStateInitValue,
isNullOrUndefined,
MARK_AS_TRANSLATABLE,
NotificationService,
ResourceState,
ResourceStateModel,
StoreUtil,
MARK_AS_TRANSLATABLE,
} from "solidify-frontend";
export interface AdminResearchDomainStateModel extends ResourceStateModel<ResearchDomain> {
......@@ -88,12 +90,12 @@ export class AdminResearchDomainState extends ResourceState<AdminResearchDomainS
}
@Action(AdminResearchDomainAction.LoadResource)
loadResource(ctx: StateContext<DepositStateModel>, action: AdminResearchDomainAction.LoadResource): void {
loadResource(ctx: StateContext<DepositStateModel>, action: AdminResearchDomainAction.LoadResource): Observable<any> {
ctx.patchState({
isLoadingCounter: ctx.getState().isLoadingCounter + 1,
});
StoreUtil.dispatchParallelActionAndWaitForSubActionsCompletion(ctx, [
return StoreUtil.dispatchParallelActionAndWaitForSubActionsCompletion(ctx, [
{
action: new SharedLanguageAction.GetAll(null, false, false),
subActionCompletions: [
......@@ -101,12 +103,14 @@ export class AdminResearchDomainState extends ResourceState<AdminResearchDomainS
this.actions$.pipe(ofActionCompleted(SharedLanguageAction.GetAllFail)),
],
},
]).subscribe(success => {
if (success) {
ctx.dispatch(new AdminResearchDomainAction.LoadResourceSuccess(action));
} else {
ctx.dispatch(new AdminResearchDomainAction.LoadResourceFail(action));
}
});
]).pipe(
tap(success => {
if (success) {
ctx.dispatch(new AdminResearchDomainAction.LoadResourceSuccess(action));
} else {
ctx.dispatch(new AdminResearchDomainAction.LoadResourceFail(action));
}
}),
);
}
}
......@@ -17,6 +17,8 @@ import {AdminResourceApiEnum} from "@shared/enums/api.enum";
import {LocalStateEnum} from "@shared/enums/local-state.enum";
import {RoutesEnum} from "@shared/enums/routes.enum";
import {SharedPersonAction} from "@shared/stores/person/shared-person.action";
import {Observable} from "rxjs";
import {tap} from "rxjs/operators";
import {
ApiService,
defaultResourceStateInitValue,
......@@ -90,25 +92,27 @@ export class AdminUserState extends ResourceState<AdminUserStateModel, User> {
}
@Action(AdminUserAction.LoadResource)
loadResource(ctx: StateContext<AdminUserStateModel>, action: AdminUserAction.LoadResource): void {
loadResource(ctx: StateContext<AdminUserStateModel>, action: AdminUserAction.LoadResource): Observable<any> {
ctx.patchState({
isLoadingCounter: ctx.getState().isLoadingCounter + 1,
});
StoreUtil.dispatchParallelActionAndWaitForSubActionsCompletion(ctx, [
return StoreUtil.dispatchParallelActionAndWaitForSubActionsCompletion(ctx, [
{
action: new SharedPersonAction.GetAll(),
action: new SharedPersonAction.GetAll(undefined, false, false),
subActionCompletions: [
this.actions$.pipe(ofActionCompleted(SharedPersonAction.GetAllSuccess)),
this.actions$.pipe(ofActionCompleted(SharedPersonAction.GetAllFail)),
],
},
]).subscribe(success => {
if (success) {
ctx.dispatch(new AdminUserAction.LoadResourceSuccess(action));
} else {
ctx.dispatch(new AdminUserAction.LoadResourceFail(action));
}
});
]).pipe(
tap(success => {
if (success) {
ctx.dispatch(new AdminUserAction.LoadResourceSuccess(action));
} else {
ctx.dispatch(new AdminUserAction.LoadResourceFail(action));
}
}),
);
}
}
......@@ -38,7 +38,7 @@ export class DepositRootRoutable extends SharedAbstractRoutable implements OnIni
ngOnInit(): void {
this.subscribe(StoreUtil.dispatchParallelActionAndWaitForSubActionsCompletion(this._store, [
{
action: new AppAuthorizedOrganizationalUnitAction.GetAll(),
action: new AppAuthorizedOrganizationalUnitAction.GetAll(undefined, false, false),
subActionCompletions: [
this._actions$.pipe(ofActionCompleted(AppAuthorizedOrganizationalUnitAction.GetAllSuccess)),
this._actions$.pipe(ofActionCompleted(AppAuthorizedOrganizationalUnitAction.GetAllFail)),
......
......@@ -86,12 +86,12 @@ export class DepositCollectionState extends AssociationRemoteState<DepositCollec
}
@Action(DepositCollectionAction.Refresh)
refresh(ctx: StateContext<DepositCollectionStateModel>, action: DepositCollectionAction.Refresh): void {
refresh(ctx: StateContext<DepositCollectionStateModel>, action: DepositCollectionAction.Refresh): Observable<any> {
ctx.patchState({
isLoadingCounter: ctx.getState().isLoadingCounter + 1,
});
StoreUtil.dispatchParallelActionAndWaitForSubActionsCompletion(ctx, [
return StoreUtil.dispatchParallelActionAndWaitForSubActionsCompletion(ctx, [
{
action: new DepositCollectionAction.GetAll(action.parentId, undefined, true),
subActionCompletions: [
......@@ -106,13 +106,15 @@ export class DepositCollectionState extends AssociationRemoteState<DepositCollec
this.actions$.pipe(ofActionCompleted(DepositCollectionAction.GetNumberCollectionsFail)),
],
},
]).subscribe(success => {
if (success) {
ctx.dispatch(new DepositCollectionAction.RefreshSuccess(action));
} else {
ctx.dispatch(new DepositCollectionAction.RefreshFail(action));
}
});
]).pipe(
tap(success => {
if (success) {
ctx.dispatch(new DepositCollectionAction.RefreshSuccess(action));
} else {
ctx.dispatch(new DepositCollectionAction.RefreshFail(action));
}
}),
);
}
@Action(DepositCollectionAction.RefreshSuccess)
......
import {HttpClient, HttpParams} from "@angular/common/http";
import {HttpClient} from "@angular/common/http";
import {
Inject,
Injectable,
......@@ -50,6 +50,7 @@ import {
defaultResourceStateInitValue,
isNullOrUndefined,
MappingObjectUtil,
MARK_AS_TRANSLATABLE,
NotificationService,
OverrideDefaultAction,
QueryParameters,
......@@ -57,7 +58,6 @@ import {
ResourceState,
SolidifyStateError,
StoreUtil,
MARK_AS_TRANSLATABLE,
} from "solidify-frontend";
export const defaultDepositDataFileValue: () => DepositDataFileStateModel = () =>
......@@ -155,12 +155,12 @@ export class DepositDataFileState extends CompositionState<DepositDataFileStateM
}
@Action(DepositDataFileAction.Refresh)
refresh(ctx: StateContext<DepositDataFileStateModel>, action: DepositDataFileAction.Refresh): void {
refresh(ctx: StateContext<DepositDataFileStateModel>, action: DepositDataFileAction.Refresh): Observable<any> {
ctx.patchState({
isLoadingCounter: ctx.getState().isLoadingCounter + 1,
});
StoreUtil.dispatchParallelActionAndWaitForSubActionsCompletion(ctx, [
return StoreUtil.dispatchParallelActionAndWaitForSubActionsCompletion(ctx, [
{
action: new DepositDataFileAction.GetAll(action.parentId, undefined, true),
subActionCompletions: [
......@@ -189,13 +189,15 @@ export class DepositDataFileState extends CompositionState<DepositDataFileStateM
this.actions$.pipe(ofActionCompleted(DepositDataFileAction.GetNumberFilesFail)),
],
},
]).subscribe(success => {
if (success) {
ctx.dispatch(new DepositDataFileAction.RefreshSuccess(action));
} else {
ctx.dispatch(new DepositDataFileAction.RefreshFail(action));
}
});
]).pipe(
tap(success => {
if (success) {
ctx.dispatch(new DepositDataFileAction.RefreshSuccess(action));
} else {
ctx.dispatch(new DepositDataFileAction.RefreshFail(action));
}
}),
);
}
@Action(DepositDataFileAction.RefreshSuccess)
......
......@@ -248,12 +248,12 @@ export class DepositState extends ResourceState<DepositStateModel, Deposit> {
}
@Action(DepositAction.LoadResource)
loadResource(ctx: StateContext<DepositStateModel>, action: DepositAction.LoadResource): void {
loadResource(ctx: StateContext<DepositStateModel>, action: DepositAction.LoadResource): Observable<any> {
ctx.patchState({
isLoadingCounter: ctx.getState().isLoadingCounter + 1,
});
StoreUtil.dispatchParallelActionAndWaitForSubActionsCompletion(ctx, [
return StoreUtil.dispatchParallelActionAndWaitForSubActionsCompletion(ctx, [
{
action: new SharedLanguageAction.GetAll(null, false, false),
subActionCompletions: [
......@@ -261,13 +261,15 @@ export class DepositState extends ResourceState<DepositStateModel, Deposit> {
this.actions$.pipe(ofActionCompleted(SharedLanguageAction.GetAllFail)),
],
},
]).subscribe(success => {
if (success) {
ctx.dispatch(new DepositAction.LoadResourceSuccess(action));
} else {
ctx.dispatch(new DepositAction.LoadResourceFail(action));
}
});
]).pipe(
tap(success => {
if (success) {
ctx.dispatch(new DepositAction.LoadResourceSuccess(action));
} else {
ctx.dispatch(new DepositAction.LoadResourceFail(action));
}
}),
);
}
@Action(DepositAction.SetOrganizationalUnit)
......@@ -661,7 +663,7 @@ export class DepositState extends ResourceState<DepositStateModel, Deposit> {
}
@Action(DepositAction.RefreshAllCounterStatusTab)
refreshAllCounterStatusTab(ctx: StateContext<DepositStateModel>, action: DepositAction.RefreshAllCounterStatusTab): void {
refreshAllCounterStatusTab(ctx: StateContext<DepositStateModel>, action: DepositAction.RefreshAllCounterStatusTab): Observable<any> {
const listActionsWrappper = [];
action.list.forEach(status => {
listActionsWrappper.push({
......@@ -673,13 +675,16 @@ export class DepositState extends ResourceState<DepositStateModel, Deposit> {
});
});
StoreUtil.dispatchParallelActionAndWaitForSubActionsCompletion(ctx, listActionsWrappper).subscribe(success => {
if (success) {
ctx.dispatch(new DepositAction.RefreshAllCounterStatusTabSuccess(action));
} else {
ctx.dispatch(new DepositAction.RefreshAllCounterStatusTabFail(action));
}
});
return StoreUtil.dispatchParallelActionAndWaitForSubActionsCompletion(ctx, listActionsWrappper)
.pipe(
tap(success => {
if (success) {
ctx.dispatch(new DepositAction.RefreshAllCounterStatusTabSuccess(action));
} else {
ctx.dispatch(new DepositAction.RefreshAllCounterStatusTabFail(action));
}
}),
);
}
@Action(DepositAction.RefreshCounterStatusTab)
......
......@@ -41,13 +41,13 @@ import {
isNullOrUndefined,
isTrue,
isUndefined,
MARK_AS_TRANSLATABLE,
NotificationService,
OverrideDefaultAction,
Relation3TiersForm,
ResourceState,
ResourceStateModel,
StoreUtil,
MARK_AS_TRANSLATABLE,
urlSeparator,
} from "solidify-frontend";
......@@ -136,26 +136,28 @@ export class OrganizationalUnitState extends ResourceState<OrganizationalUnitSta
}
@Action(OrgUnitAction.LoadResource)
loadResource(ctx: StateContext<DepositStateModel>, action: OrgUnitAction.LoadResource): void {
loadResource(ctx: StateContext<DepositStateModel>, action: OrgUnitAction.LoadResource): Observable<any> {
ctx.patchState({
isLoadingCounter: ctx.getState().isLoadingCounter + 1,
});
StoreUtil.dispatchParallelActionAndWaitForSubActionsCompletion(ctx, [
return StoreUtil.dispatchParallelActionAndWaitForSubActionsCompletion(ctx, [
{
action: new SharedRoleAction.GetAll(),
action: new SharedRoleAction.GetAll(undefined, false, false),
subActionCompletions: [
this.actions$.pipe(ofActionCompleted(SharedRoleAction.GetAllSuccess)),
this.actions$.pipe(ofActionCompleted(SharedRoleAction.GetAllFail)),
],
},
]).subscribe(success => {
if (success) {
ctx.dispatch(new OrgUnitAction.LoadResourceSuccess(action));
} else {
ctx.dispatch(new OrgUnitAction.LoadResourceFail(action));
}
});
]).pipe(
tap(success => {
if (success) {
ctx.dispatch(new OrgUnitAction.LoadResourceSuccess(action));