Skip to content

Commit

Permalink
Added more comments
Browse files Browse the repository at this point in the history
  • Loading branch information
atarix83 committed Mar 17, 2019
1 parent d90f69d commit 299c7f7
Show file tree
Hide file tree
Showing 6 changed files with 604 additions and 24 deletions.
74 changes: 72 additions & 2 deletions src/app/submission/objects/submission-objects.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
SaveSubmissionFormSuccessAction,
SaveSubmissionSectionFormAction,
SaveSubmissionSectionFormErrorAction,
SaveSubmissionSectionFormSuccessAction,
SaveSubmissionSectionFormSuccessAction, SubmissionObjectAction,
SubmissionObjectActionTypes,
UpdateSectionDataAction
} from './submission-objects.actions';
Expand All @@ -48,6 +48,9 @@ import { SubmissionJsonPatchOperationsService } from '../../core/submission/subm
@Injectable()
export class SubmissionObjectEffects {

/**
* Dispatch a [InitSectionAction] for every submission sections and dispatch a [CompleteInitSubmissionFormAction]
*/
@Effect() loadForm$ = this.actions$.pipe(
ofType(SubmissionObjectActionTypes.INIT_SUBMISSION_FORM),
map((action: InitSubmissionFormAction) => {
Expand Down Expand Up @@ -83,6 +86,9 @@ export class SubmissionObjectEffects {
));
}));

/**
* Dispatch a [InitSubmissionFormAction]
*/
@Effect() resetForm$ = this.actions$.pipe(
ofType(SubmissionObjectActionTypes.RESET_SUBMISSION_FORM),
map((action: ResetSubmissionFormAction) =>
Expand All @@ -95,6 +101,9 @@ export class SubmissionObjectEffects {
null
)));

/**
* Dispatch a [SaveSubmissionFormSuccessAction] or a [SaveSubmissionFormErrorAction] on error
*/
@Effect() saveSubmission$ = this.actions$.pipe(
ofType(SubmissionObjectActionTypes.SAVE_SUBMISSION_FORM),
switchMap((action: SaveSubmissionFormAction) => {
Expand All @@ -106,6 +115,9 @@ export class SubmissionObjectEffects {
catchError(() => observableOf(new SaveSubmissionFormErrorAction(action.payload.submissionId))));
}));

/**
* Dispatch a [SaveForLaterSubmissionFormSuccessAction] or a [SaveSubmissionFormErrorAction] on error
*/
@Effect() saveForLaterSubmission$ = this.actions$.pipe(
ofType(SubmissionObjectActionTypes.SAVE_FOR_LATER_SUBMISSION_FORM),
switchMap((action: SaveForLaterSubmissionFormAction) => {
Expand All @@ -117,6 +129,9 @@ export class SubmissionObjectEffects {
catchError(() => observableOf(new SaveSubmissionFormErrorAction(action.payload.submissionId))));
}));

/**
* Call parseSaveResponse and dispatch actions
*/
@Effect() saveSubmissionSuccess$ = this.actions$.pipe(
ofType(SubmissionObjectActionTypes.SAVE_SUBMISSION_FORM_SUCCESS, SubmissionObjectActionTypes.SAVE_SUBMISSION_SECTION_FORM_SUCCESS),
withLatestFrom(this.store$),
Expand All @@ -125,6 +140,9 @@ export class SubmissionObjectEffects {
}),
mergeMap((actions) => observableFrom(actions)));

/**
* Dispatch a [SaveSubmissionSectionFormSuccessAction] or a [SaveSubmissionSectionFormErrorAction] on error
*/
@Effect() saveSection$ = this.actions$.pipe(
ofType(SubmissionObjectActionTypes.SAVE_SUBMISSION_SECTION_FORM),
switchMap((action: SaveSubmissionSectionFormAction) => {
Expand All @@ -137,11 +155,17 @@ export class SubmissionObjectEffects {
catchError(() => observableOf(new SaveSubmissionSectionFormErrorAction(action.payload.submissionId))));
}));

/**
* Show a notification on error
*/
@Effect({dispatch: false}) saveError$ = this.actions$.pipe(
ofType(SubmissionObjectActionTypes.SAVE_SUBMISSION_FORM_ERROR, SubmissionObjectActionTypes.SAVE_SUBMISSION_SECTION_FORM_ERROR),
withLatestFrom(this.store$),
tap(() => this.notificationsService.error(null, this.translate.get('submission.sections.general.save_error_notice'))));

/**
* Call parseSaveResponse and dispatch actions or dispatch [SaveSubmissionFormErrorAction] on error
*/
@Effect() saveAndDeposit$ = this.actions$.pipe(
ofType(SubmissionObjectActionTypes.SAVE_AND_DEPOSIT_SUBMISSION),
withLatestFrom(this.store$),
Expand All @@ -161,6 +185,9 @@ export class SubmissionObjectEffects {
catchError(() => observableOf(new SaveSubmissionFormErrorAction(action.payload.submissionId))));
}));

/**
* Dispatch a [DepositSubmissionSuccessAction] or a [DepositSubmissionErrorAction] on error
*/
@Effect() depositSubmission$ = this.actions$.pipe(
ofType(SubmissionObjectActionTypes.DEPOSIT_SUBMISSION),
withLatestFrom(this.store$),
Expand All @@ -170,20 +197,32 @@ export class SubmissionObjectEffects {
catchError(() => observableOf(new DepositSubmissionErrorAction(action.payload.submissionId))));
}));

/**
* Show a notification on success and redirect to MyDSpace page
*/
@Effect({dispatch: false}) saveForLaterSubmissionSuccess$ = this.actions$.pipe(
ofType(SubmissionObjectActionTypes.SAVE_FOR_LATER_SUBMISSION_FORM_SUCCESS),
tap(() => this.notificationsService.success(null, this.translate.get('submission.sections.general.save_success_notice'))),
tap(() => this.submissionService.redirectToMyDSpace()));

/**
* Show a notification on success and redirect to MyDSpace page
*/
@Effect({dispatch: false}) depositSubmissionSuccess$ = this.actions$.pipe(
ofType(SubmissionObjectActionTypes.DEPOSIT_SUBMISSION_SUCCESS),
tap(() => this.notificationsService.success(null, this.translate.get('submission.sections.general.deposit_success_notice'))),
tap(() => this.submissionService.redirectToMyDSpace()));

/**
* Show a notification on error
*/
@Effect({dispatch: false}) depositSubmissionError$ = this.actions$.pipe(
ofType(SubmissionObjectActionTypes.DEPOSIT_SUBMISSION_ERROR),
tap(() => this.notificationsService.error(null, this.translate.get('submission.sections.general.deposit_error_notice'))));

/**
* Dispatch a [DiscardSubmissionSuccessAction] or a [DiscardSubmissionErrorAction] on error
*/
@Effect() discardSubmission$ = this.actions$.pipe(
ofType(SubmissionObjectActionTypes.DISCARD_SUBMISSION),
switchMap((action: DepositSubmissionAction) => {
Expand All @@ -192,11 +231,17 @@ export class SubmissionObjectEffects {
catchError(() => observableOf(new DiscardSubmissionErrorAction(action.payload.submissionId))));
}));

/**
* Show a notification on success and redirect to MyDSpace page
*/
@Effect({dispatch: false}) discardSubmissionSuccess$ = this.actions$.pipe(
ofType(SubmissionObjectActionTypes.DISCARD_SUBMISSION_SUCCESS),
tap(() => this.notificationsService.success(null, this.translate.get('submission.sections.general.discard_success_notice'))),
tap(() => this.submissionService.redirectToMyDSpace()));

/**
* Show a notification on error
*/
@Effect({dispatch: false}) discardSubmissionError$ = this.actions$.pipe(
ofType(SubmissionObjectActionTypes.DISCARD_SUBMISSION_ERROR),
tap(() => this.notificationsService.error(null, this.translate.get('submission.sections.general.discard_error_notice'))));
Expand All @@ -210,6 +255,12 @@ export class SubmissionObjectEffects {
private translate: TranslateService) {
}

/**
* Check if the submission object retrieved from REST haven't section errors
*
* @param response
* The submission object retrieved from REST
*/
protected canDeposit(response: SubmissionObject[]) {
let canDeposit = true;

Expand All @@ -225,7 +276,26 @@ export class SubmissionObjectEffects {
return canDeposit;
}

protected parseSaveResponse(currentState: SubmissionObjectEntry, response: SubmissionObject[], submissionId: string, notify: boolean = true) {
/**
* Parse the submission object retrieved from REST haven't section errors and return actions to dispatch
*
* @param currentState
* The current SubmissionObjectEntry
* @param response
* The submission object retrieved from REST
* @param submissionId
* The submission id
* @param notify
* A boolean that indicate if show notification or not
* @return SubmissionObjectAction[]
* List of SubmissionObjectAction to dispatch
*/
protected parseSaveResponse(
currentState: SubmissionObjectEntry,
response: SubmissionObject[],
submissionId: string,
notify: boolean = true): SubmissionObjectAction[] {

const mappedActions = [];

if (isNotEmpty(response)) {
Expand Down
96 changes: 96 additions & 0 deletions src/app/submission/objects/submission-objects.reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,42 +38,138 @@ import { WorkspaceitemSectionDataType } from '../../core/submission/models/works
import { WorkspaceitemSectionUploadObject } from '../../core/submission/models/workspaceitem-section-upload.model';
import { SectionsType } from '../sections/sections-type';

/**
* An interface to represent section visibility
*/
export interface SectionVisibility {
main: any;
other: any;
}

/**
* An interface to represent section object state
*/
export interface SubmissionSectionObject {
/**
* The section header
*/
header: string;

/**
* The section configuration url
*/
config: string;

/**
* A boolean representing if this section is mandatory
*/
mandatory: boolean;

/**
* The section type
*/
sectionType: SectionsType;

/**
* The section visibility
*/
visibility: SectionVisibility;

/**
* A boolean representing if this section is collapsed
*/
collapsed: boolean,

/**
* A boolean representing if this section is enabled
*/
enabled: boolean;

/**
* The section data object
*/
data: WorkspaceitemSectionDataType;

/**
* The list of the section errors
*/
errors: SubmissionSectionError[];

/**
* A boolean representing if this section is loading
*/
isLoading: boolean;

/**
* A boolean representing if this section is valid
*/
isValid: boolean;
}

/**
* An interface to represent section error
*/
export interface SubmissionSectionError {
/**
* A string representing error path
*/
path: string;

/**
* The error message
*/
message: string;
}

/**
* An interface to represent SubmissionSectionObject entry
*/
export interface SubmissionSectionEntry {
[sectionId: string]: SubmissionSectionObject;
}

/**
* An interface to represent submission object state
*/
export interface SubmissionObjectEntry {
/**
* The collection this submission belonging to
*/
collection?: string,

/**
* The configuration name tha define this submission
*/
definition?: string,

/**
* The submission self url
*/
selfUrl?: string;

/**
* The submission active section
*/
activeSection?: string;

/**
* The list of submission's sections
*/
sections?: SubmissionSectionEntry;

/**
* A boolean representing if this submission is loading
*/
isLoading?: boolean;

/**
* A boolean representing if a submission save operation is pending
*/
savePending?: boolean;

/**
* A boolean representing if a submission deposit operation is pending
*/
depositPending?: boolean;
}

Expand Down
Loading

0 comments on commit 299c7f7

Please sign in to comment.