From 9c8b822be7e566c95bb36b6992acae9f1aa16ee1 Mon Sep 17 00:00:00 2001 From: joeevanshmcts Date: Mon, 12 Feb 2024 15:09:42 +0000 Subject: [PATCH 01/75] Work in progress regarding CSFD-16 --- .../case-edit-page.component.ts | 31 ++++- .../case-edit-page/case-edit-page.html | 2 +- .../case-editor/case-editor.module.ts | 4 +- .../abstract-field-write-journey.component.ts | 79 ++++++++++++ .../base-field/abstract-journey.component.ts | 72 +++++++++++ .../components/palette/base-field/index.ts | 2 + .../add-comments/add-comments.component.html | 6 +- .../add-comments/add-comments.component.ts | 13 +- .../select-flag-location.component.html | 6 +- .../select-flag-location.component.ts | 13 +- .../select-flag-type.component.html | 3 - .../select-flag-type.component.ts | 19 ++- .../write-case-flag-field.component.html | 51 ++++++-- .../write-case-flag-field.component.ts | 53 +++++++- .../src/lib/shared/domain/index.ts | 1 + .../src/lib/shared/domain/journey/index.ts | 2 + .../journey/journey-instigator.model.ts | 4 + .../shared/domain/journey/journey.model.ts | 13 ++ .../src/lib/shared/services/index.ts | 1 + .../src/lib/shared/services/journey/index.ts | 1 + .../multipage-component-state.service.spec.ts | 114 ++++++++++++++++++ .../multipage-component-state.service.ts | 111 +++++++++++++++++ 22 files changed, 557 insertions(+), 44 deletions(-) create mode 100644 projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/base-field/abstract-field-write-journey.component.ts create mode 100644 projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/base-field/abstract-journey.component.ts create mode 100644 projects/ccd-case-ui-toolkit/src/lib/shared/domain/journey/index.ts create mode 100644 projects/ccd-case-ui-toolkit/src/lib/shared/domain/journey/journey-instigator.model.ts create mode 100644 projects/ccd-case-ui-toolkit/src/lib/shared/domain/journey/journey.model.ts create mode 100644 projects/ccd-case-ui-toolkit/src/lib/shared/services/journey/index.ts create mode 100644 projects/ccd-case-ui-toolkit/src/lib/shared/services/journey/multipage-component-state.service.spec.ts create mode 100644 projects/ccd-case-ui-toolkit/src/lib/shared/services/journey/multipage-component-state.service.ts diff --git a/projects/ccd-case-ui-toolkit/src/lib/shared/components/case-editor/case-edit-page/case-edit-page.component.ts b/projects/ccd-case-ui-toolkit/src/lib/shared/components/case-editor/case-edit-page/case-edit-page.component.ts index ec4f9d5fa0..b09282b8f7 100644 --- a/projects/ccd-case-ui-toolkit/src/lib/shared/components/case-editor/case-edit-page/case-edit-page.component.ts +++ b/projects/ccd-case-ui-toolkit/src/lib/shared/components/case-editor/case-edit-page/case-edit-page.component.ts @@ -9,7 +9,7 @@ import { CaseEventData } from '../../../domain/case-event-data.model'; import { CaseEventTrigger } from '../../../domain/case-view/case-event-trigger.model'; import { CaseField } from '../../../domain/definition'; import { DRAFT_PREFIX } from '../../../domain/draft.model'; -import { LoadingService } from '../../../services'; +import { LoadingService, MultipageComponentStateService } from '../../../services'; import { CaseFieldService } from '../../../services/case-fields/case-field.service'; import { FieldsUtils } from '../../../services/fields'; import { FormErrorService } from '../../../services/form/form-error.service'; @@ -22,13 +22,14 @@ import { WizardPage } from '../domain/wizard-page.model'; import { Wizard } from '../domain/wizard.model'; import { PageValidationService } from '../services/page-validation.service'; import { ValidPageListCaseFieldsService } from '../services/valid-page-list-caseFields.service'; +import { JourneyInstigator } from '../../../domain/journey'; @Component({ selector: 'ccd-case-edit-page', templateUrl: 'case-edit-page.html', styleUrls: ['./case-edit-page.scss'] }) -export class CaseEditPageComponent implements OnInit, AfterViewChecked, OnDestroy { +export class CaseEditPageComponent implements OnInit, AfterViewChecked, OnDestroy, JourneyInstigator { public static readonly RESUMED_FORM_DISCARD = 'RESUMED_FORM_DISCARD'; public static readonly NEW_FORM_DISCARD = 'NEW_FORM_DISCARD'; public static readonly NEW_FORM_SAVE = 'NEW_FORM_CHANGED_SAVE'; @@ -83,8 +84,32 @@ export class CaseEditPageComponent implements OnInit, AfterViewChecked, OnDestro private readonly caseFieldService: CaseFieldService, private readonly caseEditDataService: CaseEditDataService, private readonly loadingService: LoadingService, - private readonly validPageListCaseFieldsService: ValidPageListCaseFieldsService + private readonly validPageListCaseFieldsService: ValidPageListCaseFieldsService, + private readonly multipageComponentStateService: MultipageComponentStateService ) { + //this.pageStateService.resetJourneyCollection(); + this.multipageComponentStateService.setInstigator(this); + } + + public onFinalNext(): void { + this.submit(); + } + + public onFinalPrevious(): void { + this.cancel(); + } + + // This method will be triggered by the next button in the app component + public nextStep(): void { + // TODO: Debug why the state isn't persisting. + // - Check the AbstractJourneyComponent for more details. + // - Compare to prototype. + this.multipageComponentStateService.next(); + } + + // This method will be triggered by the previous button in the app component + public previousStep(): void { + this.multipageComponentStateService.previous(); } public ngOnInit(): void { diff --git a/projects/ccd-case-ui-toolkit/src/lib/shared/components/case-editor/case-edit-page/case-edit-page.html b/projects/ccd-case-ui-toolkit/src/lib/shared/components/case-editor/case-edit-page/case-edit-page.html index ed618a16fa..a7e154adff 100644 --- a/projects/ccd-case-ui-toolkit/src/lib/shared/components/case-editor/case-edit-page/case-edit-page.html +++ b/projects/ccd-case-ui-toolkit/src/lib/shared/components/case-editor/case-edit-page/case-edit-page.html @@ -40,7 +40,7 @@

(callbackErrorsContext)="callbackErrorsNotify($event)">
-
+
diff --git a/projects/ccd-case-ui-toolkit/src/lib/shared/components/case-editor/case-editor.module.ts b/projects/ccd-case-ui-toolkit/src/lib/shared/components/case-editor/case-editor.module.ts index 659bfacfdd..a93c41b532 100644 --- a/projects/ccd-case-ui-toolkit/src/lib/shared/components/case-editor/case-editor.module.ts +++ b/projects/ccd-case-ui-toolkit/src/lib/shared/components/case-editor/case-editor.module.ts @@ -55,6 +55,7 @@ import { import { CaseEditWizardGuard } from './services/case-edit-wizard.guard'; import { CaseworkerService } from './services/case-worker.service'; import { ValidPageListCaseFieldsService } from './services/valid-page-list-caseFields.service'; +import { MultipageComponentStateService } from '../../services'; @NgModule({ imports: [ @@ -123,7 +124,8 @@ import { ValidPageListCaseFieldsService } from './services/valid-page-list-caseF CaseworkerService, SessionStorageService, EventCompletionStateMachineService, - ValidPageListCaseFieldsService + ValidPageListCaseFieldsService, + MultipageComponentStateService ] }) export class CaseEditorModule { } diff --git a/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/base-field/abstract-field-write-journey.component.ts b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/base-field/abstract-field-write-journey.component.ts new file mode 100644 index 0000000000..3893f50d8c --- /dev/null +++ b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/base-field/abstract-field-write-journey.component.ts @@ -0,0 +1,79 @@ +import { Directive, Input, OnChanges, ViewChild } from "@angular/core"; +import { AbstractFieldWriteComponent } from "./abstract-field-write.component"; +import { Journey } from "../../../domain"; +import { MultipageComponentStateService } from "../../../services"; + +@Directive() +export abstract class AbstractFieldWriteJourneyComponent extends AbstractFieldWriteComponent implements OnChanges, Journey { + public journeyStartPageNumber: number = 0; + public journeyEndPageNumber: number = 0; + public journeyPageNumber: number = 0; + + @Input() + public journeyId: string = 'journey'; + + // todo... + @ViewChild('journeyChild') + public childJourney!: Journey; + + public constructor(protected readonly multipageComponentStateService: MultipageComponentStateService) { + super(); + this.multipageComponentStateService.addTojourneyCollection(this); + this.journeyPageNumber = this.journeyStartPageNumber; + } + + public next(): void { + if (!this.hasNext()) { + return; + } + + this.childJourney.next(); + } + + public previous(): void { + if (!this.hasPrevious()) { + return; + } + this.previousPage(); + } + + protected previousPage(): void { + if (this.hasPrevious()) { + this.journeyPageNumber--; + } + } + + protected nextPage(): void { + if (this.hasNext()) { + this.journeyPageNumber++; + } + } + + public ngOnInit(): void { + this.journeyPageNumber = this.journeyStartPageNumber; + + const state = this.multipageComponentStateService.getJourneyState(this); + + if (state) { + const { journeyPageNumber, journeyStartPageNumber, journeyEndPageNumber } = state; + + this.journeyPageNumber = journeyPageNumber; + this.journeyStartPageNumber = journeyStartPageNumber; + this.journeyEndPageNumber = journeyEndPageNumber; + } + } + + public ngOnDestroy(): void { + this.multipageComponentStateService.setJourneyState(this); + } + + public hasNext(): boolean { return this.journeyPageNumber < this.journeyEndPageNumber }; + + public hasPrevious(): boolean { return this.journeyPageNumber > this.journeyStartPageNumber }; + + public isFinished(): boolean { return this.journeyPageNumber === this.journeyEndPageNumber }; + + public isStart(): boolean { return this.journeyPageNumber === this.journeyStartPageNumber }; + + public getId(): string { return this.journeyId }; +} diff --git a/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/base-field/abstract-journey.component.ts b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/base-field/abstract-journey.component.ts new file mode 100644 index 0000000000..8e55edc528 --- /dev/null +++ b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/base-field/abstract-journey.component.ts @@ -0,0 +1,72 @@ +import { Directive, Input, ViewChild } from "@angular/core"; +import { Journey } from "../../../domain"; +import { MultipageComponentStateService } from "../../../services"; + +@Directive() +export abstract class AbstractJourneyComponent implements Journey { + + public journeyStartPageNumber: number = 0; + public journeyEndPageNumber: number = 0; + public journeyPageNumber: number = 0; + + @Input() + public journeyId: string = 'journey'; + + // todo... + @ViewChild('journeyChild') + public childJourney!: Journey; + + public constructor(protected readonly pageStateService: MultipageComponentStateService) { + this.pageStateService.addTojourneyCollection(this); + this.journeyPageNumber = this.journeyStartPageNumber; + } + + public next(): void { + if (!this.hasNext()) { + return; + } + + this.childJourney.next(); + } + + public previous(): void { + if (!this.hasPrevious()) { + return; + } + this.previousPage(); + } + + protected previousPage(): void { + if (this.hasPrevious()) { + this.journeyPageNumber--; + } + } + + public ngOnInit(): void { + this.journeyPageNumber = this.journeyStartPageNumber; + + const state = this.pageStateService.getJourneyState(this); + + if (state) { + const { journeyPageNumber, journeyStartPageNumber, journeyEndPageNumber } = state; + + this.journeyPageNumber = journeyPageNumber; + this.journeyStartPageNumber = journeyStartPageNumber; + this.journeyEndPageNumber = journeyEndPageNumber; + } + } + + public ngOnDestroy(): void { + this.pageStateService.setJourneyState(this); + } + + public hasNext(): boolean { return this.journeyPageNumber < this.journeyEndPageNumber }; + + public hasPrevious(): boolean { return this.journeyPageNumber > this.journeyStartPageNumber }; + + public isFinished(): boolean { return this.journeyPageNumber === this.journeyEndPageNumber }; + + public isStart(): boolean { return this.journeyPageNumber === this.journeyStartPageNumber }; + + public getId(): string { return this.journeyId }; +} \ No newline at end of file diff --git a/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/base-field/index.ts b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/base-field/index.ts index 70ae56ca4f..b13b4854f9 100644 --- a/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/base-field/index.ts +++ b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/base-field/index.ts @@ -1,5 +1,7 @@ export * from './abstract-field-read.component'; +export * from './abstract-field-write-journey.component'; export * from './abstract-field-write.component'; +export * from './abstract-journey.component'; export * from './field-read.component'; export * from './field-write.component'; export * from './field-read-label.component'; diff --git a/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/case-flag/components/add-comments/add-comments.component.html b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/case-flag/components/add-comments/add-comments.component.html index 37c72c0473..c5ac92751e 100644 --- a/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/case-flag/components/add-comments/add-comments.component.html +++ b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/case-flag/components/add-comments/add-comments.component.html @@ -24,8 +24,4 @@

- - -
- -
+ \ No newline at end of file diff --git a/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/case-flag/components/add-comments/add-comments.component.ts b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/case-flag/components/add-comments/add-comments.component.ts index f3d706ccd2..3baaf37082 100644 --- a/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/case-flag/components/add-comments/add-comments.component.ts +++ b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/case-flag/components/add-comments/add-comments.component.ts @@ -1,14 +1,15 @@ import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; import { FormControl, FormGroup } from '@angular/forms'; -import { ErrorMessage } from '../../../../../domain'; +import { ErrorMessage, Journey } from '../../../../../domain'; import { CaseFlagState } from '../../domain'; import { AddCommentsErrorMessage, AddCommentsStep, CaseFlagFieldState, CaseFlagWizardStepTitle } from '../../enums'; +import { AbstractJourneyComponent } from '../../../base-field'; @Component({ selector: 'ccd-add-comments', templateUrl: './add-comments.component.html' }) -export class AddCommentsComponent implements OnInit { +export class AddCommentsComponent extends AbstractJourneyComponent implements OnInit, Journey { @Input() public formGroup: FormGroup; @Input() public optional = false; @@ -60,4 +61,12 @@ export class AddCommentsComponent implements OnInit { }); } } + + public next() { + this.onNext(); + + if (this.errorMessages.length === 0) { + super.next(); + } + } } diff --git a/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/case-flag/components/select-flag-location/select-flag-location.component.html b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/case-flag/components/select-flag-location/select-flag-location.component.html index 443d4ed00c..72db6b113e 100644 --- a/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/case-flag/components/select-flag-location/select-flag-location.component.html +++ b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/case-flag/components/select-flag-location/select-flag-location.component.html @@ -29,8 +29,4 @@

- - -
- -
+ \ No newline at end of file diff --git a/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/case-flag/components/select-flag-location/select-flag-location.component.ts b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/case-flag/components/select-flag-location/select-flag-location.component.ts index ff2c40e66e..bd7395d69a 100644 --- a/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/case-flag/components/select-flag-location/select-flag-location.component.ts +++ b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/case-flag/components/select-flag-location/select-flag-location.component.ts @@ -1,14 +1,15 @@ import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; import { FormControl, FormGroup } from '@angular/forms'; -import { ErrorMessage } from '../../../../../domain'; +import { ErrorMessage, Journey } from '../../../../../domain'; import { CaseFlagState, FlagsWithFormGroupPath } from '../../domain'; import { CaseFlagFieldState, CaseFlagWizardStepTitle, SelectFlagLocationErrorMessage } from '../../enums'; +import { AbstractJourneyComponent } from '../../../base-field/abstract-journey.component'; @Component({ selector: 'ccd-select-flag-location', templateUrl: './select-flag-location.component.html' }) -export class SelectFlagLocationComponent implements OnInit { +export class SelectFlagLocationComponent extends AbstractJourneyComponent implements OnInit, Journey { @Input() public formGroup: FormGroup; @Input() public flagsData: FlagsWithFormGroupPath[]; @@ -80,4 +81,12 @@ export class SelectFlagLocationComponent implements OnInit { // Return case flag field state and error messages to the parent this.caseFlagStateEmitter.emit({ currentCaseFlagFieldState: CaseFlagFieldState.FLAG_TYPE, errorMessages: this.errorMessages }); } + + public next() { + this.onNext(); + + if (this.errorMessages.length === 0) { + super.next(); + } + } } diff --git a/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/case-flag/components/select-flag-type/select-flag-type.component.html b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/case-flag/components/select-flag-type/select-flag-type.component.html index bdcd1cab35..716e2c53bf 100644 --- a/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/case-flag/components/select-flag-type/select-flag-type.component.html +++ b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/case-flag/components/select-flag-type/select-flag-type.component.html @@ -35,7 +35,4 @@

-
- -
diff --git a/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/case-flag/components/select-flag-type/select-flag-type.component.ts b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/case-flag/components/select-flag-type/select-flag-type.component.ts index 5d222d8347..2bb3c5df03 100644 --- a/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/case-flag/components/select-flag-type/select-flag-type.component.ts +++ b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/case-flag/components/select-flag-type/select-flag-type.component.ts @@ -2,19 +2,20 @@ import { Component, EventEmitter, Input, OnDestroy, OnInit, Output } from '@angu import { FormControl, FormGroup } from '@angular/forms'; import { Subscription } from 'rxjs'; import { catchError, switchMap } from 'rxjs/operators'; -import { ErrorMessage } from '../../../../../domain'; +import { ErrorMessage, Journey } from '../../../../../domain'; import { FlagType } from '../../../../../domain/case-flag'; -import { CaseFlagRefdataService } from '../../../../../services'; +import { CaseFlagRefdataService, MultipageComponentStateService } from '../../../../../services'; import { RefdataCaseFlagType } from '../../../../../services/case-flag/refdata-case-flag-type.enum'; import { CaseFlagState } from '../../domain'; import { CaseFlagFieldState, CaseFlagWizardStepTitle, SelectFlagTypeErrorMessage } from '../../enums'; +import { AbstractJourneyComponent } from '../../../base-field/abstract-journey.component'; @Component({ selector: 'ccd-select-flag-type', templateUrl: './select-flag-type.component.html', styleUrls: ['./select-flag-type.component.scss'] }) -export class SelectFlagTypeComponent implements OnInit, OnDestroy { +export class SelectFlagTypeComponent extends AbstractJourneyComponent implements OnInit, OnDestroy, Journey { @Input() public formGroup: FormGroup; @@ -54,7 +55,9 @@ export class SelectFlagTypeComponent implements OnInit, OnDestroy { return CaseFlagWizardStepTitle; } - constructor(private readonly caseFlagRefdataService: CaseFlagRefdataService) { } + constructor(private readonly caseFlagRefdataService: CaseFlagRefdataService, pageStateService: MultipageComponentStateService) { + super(pageStateService); + } public ngOnInit(): void { this.flagTypes = []; @@ -165,4 +168,12 @@ export class SelectFlagTypeComponent implements OnInit, OnDestroy { // Return case flag field state and error messages to the parent this.caseFlagStateEmitter.emit({ currentCaseFlagFieldState: CaseFlagFieldState.FLAG_TYPE, errorMessages: this.errorMessages }); } + + public next() { + this.onNext(); + + if (this.errorMessages.length === 0) { + super.next(); + } + } } diff --git a/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/case-flag/write-case-flag-field.component.html b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/case-flag/write-case-flag-field.component.html index 2783cd4eb6..6f47e7bf05 100644 --- a/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/case-flag/write-case-flag-field.component.html +++ b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/case-flag/write-case-flag-field.component.html @@ -17,34 +17,61 @@

{{createFlagCaption | rpxTranslate}} - + + - + (flagCommentsOptionalEmitter)="onFlagCommentsOptionalEmitted($event)"> + - + + - + +
- + + - + +
diff --git a/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/case-flag/write-case-flag-field.component.ts b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/case-flag/write-case-flag-field.component.ts index 13341ebdc1..9f2cff69ae 100644 --- a/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/case-flag/write-case-flag-field.component.ts +++ b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/case-flag/write-case-flag-field.component.ts @@ -1,19 +1,20 @@ -import { Component, OnInit } from '@angular/core'; +import { Component, OnDestroy, OnInit } from '@angular/core'; import { AbstractControl, FormGroup } from '@angular/forms'; import { ActivatedRoute } from '@angular/router'; import { CaseEditDataService } from '../../../commons/case-edit-data/case-edit-data.service'; -import { CaseField, ErrorMessage } from '../../../domain'; +import { CaseField, ErrorMessage, Journey } from '../../../domain'; import { FieldsUtils } from '../../../services/fields'; -import { AbstractFieldWriteComponent } from '../base-field/abstract-field-write.component'; import { CaseFlagState, FlagDetail, FlagDetailDisplayWithFormGroupPath, FlagPath, FlagsWithFormGroupPath } from './domain'; import { CaseFlagFieldState, CaseFlagStatus, CaseFlagText } from './enums'; +import { MultipageComponentStateService } from '../../../services'; +import { AbstractFieldWriteJourneyComponent } from '../base-field/abstract-field-write-journey.component'; @Component({ selector: 'ccd-write-case-flag-field', templateUrl: './write-case-flag-field.component.html', styleUrls: ['./write-case-flag-field.component.scss'] }) -export class WriteCaseFlagFieldComponent extends AbstractFieldWriteComponent implements OnInit { +export class WriteCaseFlagFieldComponent extends AbstractFieldWriteJourneyComponent implements OnInit, OnDestroy, Journey { public formGroup: FormGroup; public fieldState: number; @@ -43,9 +44,14 @@ export class WriteCaseFlagFieldComponent extends AbstractFieldWriteComponent imp constructor( private readonly route: ActivatedRoute, - private readonly caseEditDataService: CaseEditDataService + private readonly caseEditDataService: CaseEditDataService, + multipageComponentStateService: MultipageComponentStateService ) { - super(); + super(multipageComponentStateService); + } + + public ngOnDestroy(): void { + this.multipageComponentStateService.setJourneyState(this); } public ngOnInit(): void { @@ -106,6 +112,39 @@ export class WriteCaseFlagFieldComponent extends AbstractFieldWriteComponent imp }); } } + + // CSFD-16. + // Setup the page number to initially be the same value as + // the start page number. Provided that some state exists within + // the page state service, use that instaead. + // + // If isDisplayContextParameterUpdate is true, then the starting page must be + // the value of 4. Otherwise, it's 0. However, we're using an enum to simplify + // this process. + // + // It might help to take a look at the template file. + if (this.isDisplayContextParameterUpdate) { + this.journeyStartPageNumber = CaseFlagFieldState.FLAG_MANAGE_CASE_FLAGS; + this.journeyEndPageNumber = CaseFlagFieldState.FLAG_UPDATE; + } else { + this.journeyStartPageNumber = CaseFlagFieldState.FLAG_LOCATION; + this.journeyEndPageNumber = CaseFlagFieldState.FLAG_COMMENTS; + } + + // Now that we've set the start page number, let's set the current page number. + this.journeyPageNumber = this.journeyStartPageNumber; + + // Provided we have some stored state, i.e. when going backwards, we want + // to get the last visited page, etc. + const state = this.multipageComponentStateService.getJourneyState(this); + + if (state) { + const { journeyPageNumber, journeyStartPageNumber, journeyEndPageNumber } = state; + + this.journeyPageNumber = journeyPageNumber; + this.journeyStartPageNumber = journeyStartPageNumber; + this.journeyEndPageNumber = journeyEndPageNumber; + } } public setDisplayContextParameterUpdate(caseFields: CaseField[]): boolean { @@ -169,6 +208,8 @@ export class WriteCaseFlagFieldComponent extends AbstractFieldWriteComponent imp } else { this.fieldState++; } + + this.nextPage(); } } diff --git a/projects/ccd-case-ui-toolkit/src/lib/shared/domain/index.ts b/projects/ccd-case-ui-toolkit/src/lib/shared/domain/index.ts index 29ff143fcc..9a13f186f8 100644 --- a/projects/ccd-case-ui-toolkit/src/lib/shared/domain/index.ts +++ b/projects/ccd-case-ui-toolkit/src/lib/shared/domain/index.ts @@ -10,6 +10,7 @@ export * from './document'; export * from './draft.model'; export * from './error-message.model'; export * from './http'; +export * from './journey'; export * from './order'; export * from './organisation'; export * from './pagination-metadata.model'; diff --git a/projects/ccd-case-ui-toolkit/src/lib/shared/domain/journey/index.ts b/projects/ccd-case-ui-toolkit/src/lib/shared/domain/journey/index.ts new file mode 100644 index 0000000000..f92657094c --- /dev/null +++ b/projects/ccd-case-ui-toolkit/src/lib/shared/domain/journey/index.ts @@ -0,0 +1,2 @@ +export * from './journey.model'; +export * from './journey-instigator.model'; \ No newline at end of file diff --git a/projects/ccd-case-ui-toolkit/src/lib/shared/domain/journey/journey-instigator.model.ts b/projects/ccd-case-ui-toolkit/src/lib/shared/domain/journey/journey-instigator.model.ts new file mode 100644 index 0000000000..158f6a9b1e --- /dev/null +++ b/projects/ccd-case-ui-toolkit/src/lib/shared/domain/journey/journey-instigator.model.ts @@ -0,0 +1,4 @@ +export interface JourneyInstigator { + onFinalNext(): void; + onFinalPrevious(): void; +} diff --git a/projects/ccd-case-ui-toolkit/src/lib/shared/domain/journey/journey.model.ts b/projects/ccd-case-ui-toolkit/src/lib/shared/domain/journey/journey.model.ts new file mode 100644 index 0000000000..2c5f761081 --- /dev/null +++ b/projects/ccd-case-ui-toolkit/src/lib/shared/domain/journey/journey.model.ts @@ -0,0 +1,13 @@ +export interface Journey { + next(): void; + previous(): void; + hasNext(): boolean; + hasPrevious(): boolean; + isFinished(): boolean; + isStart(): boolean; + journeyId: string; + journeyPageNumber: number; + journeyStartPageNumber: number; + journeyEndPageNumber: number; + childJourney: Journey; +} diff --git a/projects/ccd-case-ui-toolkit/src/lib/shared/services/index.ts b/projects/ccd-case-ui-toolkit/src/lib/shared/services/index.ts index f36a406324..6936a275a3 100644 --- a/projects/ccd-case-ui-toolkit/src/lib/shared/services/index.ts +++ b/projects/ccd-case-ui-toolkit/src/lib/shared/services/index.ts @@ -12,6 +12,7 @@ export * from './eventStatusService'; export * from './fields'; export * from './form'; export * from './http'; +export * from './journey'; export * from './jurisdiction'; export * from './banners'; export * from './navigation'; diff --git a/projects/ccd-case-ui-toolkit/src/lib/shared/services/journey/index.ts b/projects/ccd-case-ui-toolkit/src/lib/shared/services/journey/index.ts new file mode 100644 index 0000000000..8041f8271f --- /dev/null +++ b/projects/ccd-case-ui-toolkit/src/lib/shared/services/journey/index.ts @@ -0,0 +1 @@ +export * from './multipage-component-state.service'; \ No newline at end of file diff --git a/projects/ccd-case-ui-toolkit/src/lib/shared/services/journey/multipage-component-state.service.spec.ts b/projects/ccd-case-ui-toolkit/src/lib/shared/services/journey/multipage-component-state.service.spec.ts new file mode 100644 index 0000000000..030c768c55 --- /dev/null +++ b/projects/ccd-case-ui-toolkit/src/lib/shared/services/journey/multipage-component-state.service.spec.ts @@ -0,0 +1,114 @@ +import { TestBed } from '@angular/core/testing'; + +import { MultipageComponentStateService } from './multipage-component-state.service'; +import { Journey, JourneyInstigator } from '../../domain'; + +describe('PageStateService', () => { + let service: MultipageComponentStateService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(MultipageComponentStateService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); + + it('should set and get journey collection', () => { + const journeys: Journey[] = []; + service.setJourneyCollection(journeys); + expect(service.getJourneyCollection()).toEqual(journeys); + }); + + it('should set and get instigator', () => { + const instigator: JourneyInstigator = { + onFinalNext: () => { }, + onFinalPrevious: () => { } + }; + + service.setInstigator(instigator); + expect(service.getInstigator()).toEqual(instigator); + }); + + it('should get and set the journey state', () => { + const journey: Journey = { + journeyId: 'test', + journeyPageNumber: 1, + journeyStartPageNumber: 0, + journeyEndPageNumber: 5, + next: () => { }, + previous: () => { }, + hasNext: () => true, + hasPrevious: () => true, + isFinished: () => false, + isStart: () => false, + childJourney: undefined + }; + + service.setJourneyState(journey); + expect(service.getJourneyState(journey)).toEqual(journey); + }); + + it('should reset journey state', () => { + const journey: Journey = { + journeyId: 'test', + journeyPageNumber: 1, + journeyStartPageNumber: 0, + journeyEndPageNumber: 5, + next: () => { }, + previous: () => { }, + hasNext: () => true, + hasPrevious: () => true, + isFinished: () => false, + isStart: () => false, + childJourney: undefined + }; + + service.setJourneyState(journey); + service.resetJourneyState(); + expect(service.getJourneyState(journey)).toBeNull(); + }); + + it('should invoke next method of journey', () => { + const journey: Journey = { + journeyId: 'test', + journeyPageNumber: 1, + journeyStartPageNumber: 0, + journeyEndPageNumber: 5, + next: () => { }, + previous: () => { }, + hasNext: () => true, + hasPrevious: () => true, + isFinished: () => false, + isStart: () => false, + childJourney: undefined + }; + + service.setJourneyCollection([journey]); + spyOn(journey, 'next'); + service.next(); + expect(journey.next).toHaveBeenCalled(); + }); + + it('should invoke previous method of journey', () => { + const journey: Journey = { + journeyId: 'test', + journeyPageNumber: 1, + journeyStartPageNumber: 0, + journeyEndPageNumber: 5, + next: () => { }, + previous: () => { }, + hasNext: () => true, + hasPrevious: () => true, + isFinished: () => false, + isStart: () => false, + childJourney: undefined + }; + + service.setJourneyCollection([journey]); + spyOn(journey, 'previous'); + service.previous(); + expect(journey.previous).toHaveBeenCalled(); + }); +}); diff --git a/projects/ccd-case-ui-toolkit/src/lib/shared/services/journey/multipage-component-state.service.ts b/projects/ccd-case-ui-toolkit/src/lib/shared/services/journey/multipage-component-state.service.ts new file mode 100644 index 0000000000..52a64b1ec2 --- /dev/null +++ b/projects/ccd-case-ui-toolkit/src/lib/shared/services/journey/multipage-component-state.service.ts @@ -0,0 +1,111 @@ +import { Injectable } from '@angular/core'; +import { Journey, JourneyInstigator } from '../../domain'; + +@Injectable({ + providedIn: 'root' +}) +export class MultipageComponentStateService { + + //journey collection references an upto date list of all the journey components currently rendered!!!! + private journeyCollection: Journey[] = new Array(); + //the instigator references the case-edit-page component that will invoke the next and previous methods + private instigator: JourneyInstigator | null = null; + //each journey will store its state here. this could include form data if needed + private journeyState: Map = new Map(); + + //setJourneyComponent will be called by the app component to update the journey collection + setJourneyCollection(journeyCollection: Journey[]): void { + this.journeyCollection = journeyCollection; + } + + //getJourneyCollection will be called by the app component to get the journey collection + getJourneyCollection(): Journey[] { + return this.journeyCollection; + } + + //addToJourneyCollection will be called from the journey + addTojourneyCollection(journey: Journey): void { + this.journeyCollection.push(journey); + } + + //resetJourneyCollection will be called + resetJourneyCollection(): void { + this.journeyCollection = []; + } + + //setInstigator will be called by the app component to update the instigator + setInstigator(instigator: JourneyInstigator): void { + this.instigator = instigator; + } + + //getInstigator will be called by the app component to get the instigator + getInstigator(): JourneyInstigator | null { + return this.instigator; + } + + //setJourneyState will be called by the journey component to update the journey state + setJourneyState(journey: Journey): void { + this.journeyState.set(journey.journeyId, journey); + } + + //getJourneyState will be called by the journey component to get the journey state + getJourneyState(journey: Journey): Journey | null { + return this.journeyState.get(journey.journeyId) || null; + } + + //resetJourneyState will be called by the journey component to reset the journey state + resetJourneyState(): void { + this.journeyState.clear(); + } + + //next will be called by the instigator that will invoke the next method of the journey component that will invoke the next method of the childpage component + public next(): void { + if (this.journeyCollection.length <= 0) { + this.instigator?.onFinalNext(); + return; + } + + const isAnyObjectNotFinished: boolean = this.journeyCollection.some(journey => !journey.isFinished()); + + if (!isAnyObjectNotFinished) { + this.instigator?.onFinalNext(); + return; + } + + for (const journey of this.journeyCollection) { + if (!journey) { + continue; + } + + if (!journey?.isFinished()) { + journey?.next(); + break; + } + } + } + + //previous will be called by the instigator that will invoke the previous method of the journey component that will invoke the previous method of the childpage component + public previous(): void { + if (this.journeyCollection.length <= 0) { + this.instigator?.onFinalPrevious(); + return; + } + + const isAnyObjectNotAtStart: boolean = this.journeyCollection.some(journey => !journey.isStart()); + + if (!isAnyObjectNotAtStart) { + this.instigator?.onFinalPrevious(); + return; + } + + for (const journey of this.journeyCollection.slice().reverse()) { + if (!journey) { + continue; + } + if (!journey?.isStart()) { + journey?.previous(); + break; + } + } + } +} From 500d76257c6b0befa5424ee88134c7df69d6fc73 Mon Sep 17 00:00:00 2001 From: joeevanshmcts Date: Tue, 13 Feb 2024 12:21:18 +0000 Subject: [PATCH 02/75] Resolved a couple of bugs associated with the changes for CSFD-16 --- .../case-editor/case-edit-page/case-edit-page.component.ts | 4 ++++ .../palette/case-flag/write-case-flag-field.component.ts | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/projects/ccd-case-ui-toolkit/src/lib/shared/components/case-editor/case-edit-page/case-edit-page.component.ts b/projects/ccd-case-ui-toolkit/src/lib/shared/components/case-editor/case-edit-page/case-edit-page.component.ts index f5d89e05f9..3472fd16cb 100644 --- a/projects/ccd-case-ui-toolkit/src/lib/shared/components/case-editor/case-edit-page/case-edit-page.component.ts +++ b/projects/ccd-case-ui-toolkit/src/lib/shared/components/case-editor/case-edit-page/case-edit-page.component.ts @@ -113,6 +113,8 @@ export class CaseEditPageComponent implements OnInit, AfterViewChecked, OnDestro } public ngOnInit(): void { + this.multipageComponentStateService.resetJourneyCollection(); + this.multipageComponentStateService.resetJourneyState(); initDialog(); this.eventTrigger = this.caseEdit.eventTrigger; this.editForm = this.caseEdit.form; @@ -446,6 +448,8 @@ export class CaseEditPageComponent implements OnInit, AfterViewChecked, OnDestro } this.caseEditDataService.clearFormValidationErrors(); + this.multipageComponentStateService.resetJourneyCollection(); + this.multipageComponentStateService.resetJourneyState(); } public submitting(): boolean { diff --git a/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/case-flag/write-case-flag-field.component.ts b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/case-flag/write-case-flag-field.component.ts index 8e84217c61..7cff8fc5f5 100644 --- a/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/case-flag/write-case-flag-field.component.ts +++ b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/case-flag/write-case-flag-field.component.ts @@ -160,10 +160,10 @@ export class WriteCaseFlagFieldComponent extends AbstractFieldWriteJourneyCompon // It might help to take a look at the template file. if (this.isDisplayContextParameterUpdate) { this.journeyStartPageNumber = CaseFlagFieldState.FLAG_MANAGE_CASE_FLAGS; - this.journeyEndPageNumber = CaseFlagFieldState.FLAG_UPDATE; + this.journeyEndPageNumber = CaseFlagFieldState.FLAG_UPDATE_WELSH_TRANSLATION; } else { this.journeyStartPageNumber = CaseFlagFieldState.FLAG_LOCATION; - this.journeyEndPageNumber = CaseFlagFieldState.FLAG_COMMENTS; + this.journeyEndPageNumber = CaseFlagFieldState.FLAG_STATUS; } // Now that we've set the start page number, let's set the current page number. From cafd3e1e15e4fcbd74fe7cf2da3f09ff57b7d5f2 Mon Sep 17 00:00:00 2001 From: joeevanshmcts Date: Tue, 13 Feb 2024 14:54:34 +0000 Subject: [PATCH 03/75] Work in progress regarding CSFD-8 --- .../case-edit-page.component.ts | 1 - .../before-you-start.component.html | 3 --- .../before-you-start.component.ts | 16 +++++++++++++-- .../link-cases/link-cases.component.html | 3 --- .../link-cases/link-cases.component.ts | 20 ++++++++++++++++--- .../write-linked-cases-field.component.html | 20 ++++++++++++++----- .../write-linked-cases-field.component.ts | 17 +++++++++++----- .../multipage-component-state.service.ts | 2 +- 8 files changed, 59 insertions(+), 23 deletions(-) diff --git a/projects/ccd-case-ui-toolkit/src/lib/shared/components/case-editor/case-edit-page/case-edit-page.component.ts b/projects/ccd-case-ui-toolkit/src/lib/shared/components/case-editor/case-edit-page/case-edit-page.component.ts index 3472fd16cb..fdc590ee6d 100644 --- a/projects/ccd-case-ui-toolkit/src/lib/shared/components/case-editor/case-edit-page/case-edit-page.component.ts +++ b/projects/ccd-case-ui-toolkit/src/lib/shared/components/case-editor/case-edit-page/case-edit-page.component.ts @@ -87,7 +87,6 @@ export class CaseEditPageComponent implements OnInit, AfterViewChecked, OnDestro private readonly validPageListCaseFieldsService: ValidPageListCaseFieldsService, private readonly multipageComponentStateService: MultipageComponentStateService ) { - //this.pageStateService.resetJourneyCollection(); this.multipageComponentStateService.setInstigator(this); } diff --git a/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/linked-cases/components/before-you-start/before-you-start.component.html b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/linked-cases/components/before-you-start/before-you-start.component.html index 04b55ba576..e6e68f0531 100644 --- a/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/linked-cases/components/before-you-start/before-you-start.component.html +++ b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/linked-cases/components/before-you-start/before-you-start.component.html @@ -19,8 +19,5 @@

Before you start

If there are linked hearings for the case you need to un-link then you must unlink the hearing first.

-
- -
diff --git a/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/linked-cases/components/before-you-start/before-you-start.component.ts b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/linked-cases/components/before-you-start/before-you-start.component.ts index 7e9ca8670b..f3793c966e 100644 --- a/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/linked-cases/components/before-you-start/before-you-start.component.ts +++ b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/linked-cases/components/before-you-start/before-you-start.component.ts @@ -4,12 +4,14 @@ import { ErrorMessage } from '../../../../../domain'; import { LinkedCasesState } from '../../domain'; import { LinkedCasesPages } from '../../enums'; import { LinkedCasesService } from '../../services/linked-cases.service'; +import { AbstractJourneyComponent } from '../../../base-field'; +import { MultipageComponentStateService } from '../../../../../services'; @Component({ selector: 'ccd-linked-cases-before-you-start', templateUrl: './before-you-start.component.html' }) -export class BeforeYouStartComponent { +export class BeforeYouStartComponent extends AbstractJourneyComponent { @Output() public linkedCasesStateEmitter: EventEmitter = new EventEmitter(); @@ -19,7 +21,9 @@ export class BeforeYouStartComponent { public serverLinkedApiError: { id: string, message: string }; constructor(private readonly router: Router, - private readonly linkedCasesService: LinkedCasesService) { + private readonly linkedCasesService: LinkedCasesService, + multipageComponentStateService: MultipageComponentStateService) { + super(multipageComponentStateService); this.isLinkCasesJourney = this.linkedCasesService.isLinkedCasesEventTrigger; this.serverLinkedApiError = this.linkedCasesService.serverLinkedApiError; // re-initiate the state based on the casefield value @@ -37,6 +41,14 @@ export class BeforeYouStartComponent { }); } + public next() { + this.onNext(); + + if (this.errorMessages.length === 0) { + super.next(); + } + } + public onBack(): void { this.router.navigate(['cases', 'case-details', this.linkedCasesService.caseId], { fragment: 'Linked cases' }); } diff --git a/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/linked-cases/components/link-cases/link-cases.component.html b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/linked-cases/components/link-cases/link-cases.component.html index 6f77529d8a..91a8ceebc7 100644 --- a/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/linked-cases/components/link-cases/link-cases.component.html +++ b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/linked-cases/components/link-cases/link-cases.component.html @@ -90,9 +90,6 @@

Comments

-
- -
diff --git a/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/linked-cases/components/link-cases/link-cases.component.ts b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/linked-cases/components/link-cases/link-cases.component.ts index a7a359a54c..54098ed0f1 100644 --- a/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/linked-cases/components/link-cases/link-cases.component.ts +++ b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/linked-cases/components/link-cases/link-cases.component.ts @@ -2,7 +2,7 @@ import { Component, EventEmitter, OnInit, Output } from '@angular/core'; import { FormArray, FormBuilder, FormGroup, Validators } from '@angular/forms'; import moment from 'moment'; import { throwError } from 'rxjs'; -import { CaseView, ErrorMessage, HttpError } from '../../../../../domain'; +import { CaseView, ErrorMessage, HttpError, Journey } from '../../../../../domain'; import { LovRefDataModel } from '../../../../../services/common-data-service/common-data-service'; import { CasesService } from '../../../../case-editor/services/cases.service'; import { LinkedCasesState } from '../../domain'; @@ -15,13 +15,15 @@ import { import { LinkedCasesErrorMessages, LinkedCasesPages, Patterns } from '../../enums'; import { LinkedCasesService } from '../../services/linked-cases.service'; import { ValidatorsUtils } from '../../utils/validators.utils'; +import { AbstractJourneyComponent } from '../../../base-field'; +import { MultipageComponentStateService } from '../../../../../services'; @Component({ selector: 'ccd-link-cases', styleUrls: ['./link-cases.component.scss'], templateUrl: './link-cases.component.html', }) -export class LinkCasesComponent implements OnInit { +export class LinkCasesComponent extends AbstractJourneyComponent implements OnInit, Journey { @Output() public linkedCasesStateEmitter: EventEmitter = new EventEmitter(); @@ -43,7 +45,11 @@ export class LinkCasesComponent implements OnInit { private readonly casesService: CasesService, private readonly fb: FormBuilder, private readonly validatorsUtils: ValidatorsUtils, - private readonly linkedCasesService: LinkedCasesService) { } + private readonly linkedCasesService: LinkedCasesService, + multipageComponentStateService: MultipageComponentStateService + ) { + super(multipageComponentStateService); + } public ngOnInit(): void { this.caseId = this.linkedCasesService.caseId; @@ -311,4 +317,12 @@ export class LinkCasesComponent implements OnInit { } this.emitLinkedCasesState(navigateToNextPage); } + + public next() { + this.onNext(); + + if (this.errorMessages.length === 0) { + super.next(); + } + } } diff --git a/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/linked-cases/write-linked-cases-field.component.html b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/linked-cases/write-linked-cases-field.component.html index 4fb4e21393..1fb8df57eb 100644 --- a/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/linked-cases/write-linked-cases-field.component.html +++ b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/linked-cases/write-linked-cases-field.component.html @@ -2,23 +2,33 @@
+ #journeyChild + (linkedCasesStateEmitter)="onLinkedCasesStateEmitted($event)"> + + #journeyChild + (linkedCasesStateEmitter)="onLinkedCasesStateEmitted($event)"> + + #journeyChild + (linkedCasesStateEmitter)="onLinkedCasesStateEmitted($event)"> + + #journeyChild + (linkedCasesStateEmitter)="onLinkedCasesStateEmitted($event)"> + + #journeyChild + (linkedCasesStateEmitter)="onLinkedCasesStateEmitted($event)"> +
diff --git a/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/linked-cases/write-linked-cases-field.component.ts b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/linked-cases/write-linked-cases-field.component.ts index 92135e8159..c5eb034961 100644 --- a/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/linked-cases/write-linked-cases-field.component.ts +++ b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/linked-cases/write-linked-cases-field.component.ts @@ -6,17 +6,18 @@ import { ErrorMessage } from '../../../domain'; import { CaseView } from '../../../domain/case-view'; import { CommonDataService } from '../../../services/common-data-service/common-data-service'; import { CasesService } from '../../case-editor/services/cases.service'; -import { AbstractFieldWriteComponent } from '../base-field'; +import { AbstractFieldWriteJourneyComponent } from '../base-field'; import { CaseLink, LinkedCasesState } from './domain'; import { LinkedCasesErrorMessages, LinkedCasesEventTriggers, LinkedCasesPages } from './enums'; import { LinkedCasesService } from './services'; import { Subscription } from 'rxjs'; +import { MultipageComponentStateService } from '../../../services'; @Component({ selector: 'ccd-write-linked-cases-field', templateUrl: './write-linked-cases-field.component.html' }) -export class WriteLinkedCasesFieldComponent extends AbstractFieldWriteComponent implements OnInit, AfterViewInit, OnDestroy { +export class WriteLinkedCasesFieldComponent extends AbstractFieldWriteJourneyComponent implements OnInit, AfterViewInit, OnDestroy { public caseEditForm: FormGroup; public caseDetails: CaseView; public linkedCasesPage: number; @@ -30,8 +31,9 @@ export class WriteLinkedCasesFieldComponent extends AbstractFieldWriteComponent private readonly commonDataService: CommonDataService, private readonly casesService: CasesService, private readonly linkedCasesService: LinkedCasesService, - private readonly caseEditDataService: CaseEditDataService) { - super(); + private readonly caseEditDataService: CaseEditDataService, + multipageComponentStateService: MultipageComponentStateService) { + super(multipageComponentStateService); } public ngOnInit(): void { @@ -53,6 +55,9 @@ export class WriteLinkedCasesFieldComponent extends AbstractFieldWriteComponent this.subscriptions.add(this.caseEditDataService.caseEditForm$.subscribe({ next: editForm => this.caseEditForm = editForm })); + + this.journeyPageNumber = this.journeyStartPageNumber = LinkedCasesPages.BEFORE_YOU_START; + this.journeyEndPageNumber = LinkedCasesPages.CHECK_YOUR_ANSWERS; } public initialiseCaseDetails(caseDetails: CaseView): void { @@ -79,7 +84,7 @@ export class WriteLinkedCasesFieldComponent extends AbstractFieldWriteComponent public onLinkedCasesStateEmitted(linkedCasesState: LinkedCasesState): void { // Clear validation errors this.caseEditDataService.clearFormValidationErrors(); - + if (linkedCasesState.navigateToNextPage) { this.linkedCasesPage = this.getNextPage(linkedCasesState); this.proceedToNextPage(); @@ -128,6 +133,8 @@ export class WriteLinkedCasesFieldComponent extends AbstractFieldWriteComponent // Continue button event must not be allowed if not in final page this.caseEditDataService.setLinkedCasesJourneyAtFinalStep(false); } + + this.journeyPageNumber = this.linkedCasesPage; } public submitLinkedCases(): void { diff --git a/projects/ccd-case-ui-toolkit/src/lib/shared/services/journey/multipage-component-state.service.ts b/projects/ccd-case-ui-toolkit/src/lib/shared/services/journey/multipage-component-state.service.ts index 52a64b1ec2..9937aca2e7 100644 --- a/projects/ccd-case-ui-toolkit/src/lib/shared/services/journey/multipage-component-state.service.ts +++ b/projects/ccd-case-ui-toolkit/src/lib/shared/services/journey/multipage-component-state.service.ts @@ -66,7 +66,7 @@ export class MultipageComponentStateService { } const isAnyObjectNotFinished: boolean = this.journeyCollection.some(journey => !journey.isFinished()); - + if (!isAnyObjectNotFinished) { this.instigator?.onFinalNext(); return; From 52889ba399f338d9021851e84cf6f4984e719712 Mon Sep 17 00:00:00 2001 From: joeevanshmcts Date: Tue, 13 Feb 2024 15:26:16 +0000 Subject: [PATCH 04/75] Included changes for the case unlink component, regarding CSFD-8 --- .../unlink-cases/unlink-cases.component.html | 3 --- .../unlink-cases/unlink-cases.component.ts | 17 +++++++++++++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/linked-cases/components/unlink-cases/unlink-cases.component.html b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/linked-cases/components/unlink-cases/unlink-cases.component.html index 284cc7c01a..84b8593773 100644 --- a/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/linked-cases/components/unlink-cases/unlink-cases.component.html +++ b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/linked-cases/components/unlink-cases/unlink-cases.component.html @@ -15,8 +15,5 @@

Select the cases you want to unlink from this case< -
- -
diff --git a/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/linked-cases/components/unlink-cases/unlink-cases.component.ts b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/linked-cases/components/unlink-cases/unlink-cases.component.ts index a0e15b9df2..ba8842cfd0 100644 --- a/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/linked-cases/components/unlink-cases/unlink-cases.component.ts +++ b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/linked-cases/components/unlink-cases/unlink-cases.component.ts @@ -6,12 +6,15 @@ import { CasesService } from '../../../../case-editor/services/cases.service'; import { CaseLink, LinkedCasesState } from '../../domain'; import { LinkedCasesErrorMessages, LinkedCasesPages } from '../../enums/write-linked-cases-field.enum'; import { LinkedCasesService } from '../../services/linked-cases.service'; +import { AbstractFieldWriteJourneyComponent } from '../../../base-field'; +import { Journey } from '../../../../../domain'; +import { MultipageComponentStateService } from '../../../../../services'; @Component({ selector: 'ccd-unlink-cases', templateUrl: './unlink-cases.component.html' }) -export class UnLinkCasesComponent implements OnInit { +export class UnLinkCasesComponent extends AbstractFieldWriteJourneyComponent implements OnInit, Journey { private static readonly LINKED_CASES_TAB_ID = 'linked_cases_sscs'; private static readonly CASE_NAME_MISSING_TEXT = 'Case name missing'; @@ -31,7 +34,9 @@ export class UnLinkCasesComponent implements OnInit { constructor(private readonly fb: FormBuilder, private readonly casesService: CasesService, - private readonly linkedCasesService: LinkedCasesService) { + private readonly linkedCasesService: LinkedCasesService, + multipageComponentStateService: MultipageComponentStateService) { + super(multipageComponentStateService); } public ngOnInit(): void { @@ -130,6 +135,14 @@ export class UnLinkCasesComponent implements OnInit { this.emitLinkedCasesState(navigateToNextPage); } + public next() { + this.onNext(); + + if (this.errorMessages.length === 0) { + super.next(); + } + } + // Return linked cases state and error messages to the parent public emitLinkedCasesState(isNavigateToNextPage: boolean): void { this.linkedCasesStateEmitter.emit({ From e847534b5e4e313432b0373d7c02ccc85acb2ba3 Mon Sep 17 00:00:00 2001 From: joeevanshmcts Date: Tue, 13 Feb 2024 17:25:26 +0000 Subject: [PATCH 05/75] Work in progress regarding CSFD-15, ungrey back button We're in the process of debugging an issue where the user hits the review page & then hits change, the previous button is not always accessible. --- .../case-edit-page/case-edit-page.component.ts | 6 +++++- .../case-editor/case-edit-page/case-edit-page.html | 2 +- .../case-flag/read-case-flag-field.component.ts | 1 + .../case-flag/write-case-flag-field.component.ts | 10 ++++++++++ .../journey/multipage-component-state.service.ts | 10 ++++++++++ 5 files changed, 27 insertions(+), 2 deletions(-) diff --git a/projects/ccd-case-ui-toolkit/src/lib/shared/components/case-editor/case-edit-page/case-edit-page.component.ts b/projects/ccd-case-ui-toolkit/src/lib/shared/components/case-editor/case-edit-page/case-edit-page.component.ts index fdc590ee6d..384c0c4319 100644 --- a/projects/ccd-case-ui-toolkit/src/lib/shared/components/case-editor/case-edit-page/case-edit-page.component.ts +++ b/projects/ccd-case-ui-toolkit/src/lib/shared/components/case-editor/case-edit-page/case-edit-page.component.ts @@ -98,6 +98,10 @@ export class CaseEditPageComponent implements OnInit, AfterViewChecked, OnDestro this.cancel(); } + public isAtStart(): boolean { + return this.multipageComponentStateService.isJourneyAtStart(); + } + // This method will be triggered by the next button in the app component public nextStep(): void { // TODO: Debug why the state isn't persisting. @@ -198,11 +202,11 @@ export class CaseEditPageComponent implements OnInit, AfterViewChecked, OnDestro */ public toPreviousPage(): void { this.caseEditDataService.clearFormValidationErrors(); - const caseEventData: CaseEventData = this.buildCaseEventData(true); caseEventData.data = caseEventData.event_data; this.updateFormData(caseEventData); this.previous(); + this.previousStep(); CaseEditPageComponent.setFocusToTop(); } diff --git a/projects/ccd-case-ui-toolkit/src/lib/shared/components/case-editor/case-edit-page/case-edit-page.html b/projects/ccd-case-ui-toolkit/src/lib/shared/components/case-editor/case-edit-page/case-edit-page.html index a7e154adff..059313e555 100644 --- a/projects/ccd-case-ui-toolkit/src/lib/shared/components/case-editor/case-edit-page/case-edit-page.html +++ b/projects/ccd-case-ui-toolkit/src/lib/shared/components/case-editor/case-edit-page/case-edit-page.html @@ -62,7 +62,7 @@