-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Csfd 15 ungrey back button #1706
base: master
Are you sure you want to change the base?
Changes from 111 commits
9c8b822
cc20f76
500d762
cafd3e1
52889ba
e847534
ce26aa4
b19805a
7aed3d3
97c0fd5
994bf2d
4925d68
d43ab0d
9a6e777
4d8be9d
815661a
7989911
bbd3def
4e92e80
206b342
a2adad0
9f93d04
2718944
e1c22f7
0caac8f
1204083
56dba5d
37dd646
ad08e1b
e3b6d57
ecc5a97
40a9749
9ab2310
c603a6a
6668e63
6854e7a
3438afa
500e7d3
9b3eb74
3d7dba0
1aab82f
a752f70
763cd65
3941532
398cbd3
071b2ed
00928bc
1198ce7
25937b4
c140bd8
9f49840
3960bb4
4cfa3f5
7dc3b0c
54e014b
26a15d0
73eb8f7
e50d25a
2f2b707
434773f
61e2d0a
9cb2033
6c9c31b
bbdb0ca
2b00237
24c0e70
3cb9415
4470a5f
7d97943
02373c7
a9ed864
46700e9
729787c
d3f5173
d68b2a2
037f65e
b20d3fa
2980b1c
4ccd198
85bbd74
bdc05ee
259391a
55cd544
8fd59d3
ef639f5
bc5f4ff
698af49
0c140fe
718ab59
53742f9
ffa917b
39ff4a1
a8fe846
58795a2
944aade
4b142ee
5192946
c99fa77
29489c0
6d2aff9
a38da03
7932c8d
a85c0ed
7958e59
16db69e
a9afc94
2019d1e
add984e
9451fb6
0301872
e19bbdb
5547123
700aad8
00f599b
d6ea212
cf08b70
b2f6985
3e0fde6
612f36e
270f121
0b66143
81a4f98
83836a0
3de5864
49f1cf0
072d9f3
689db24
154a9ef
5e17bbb
aeb16c4
7a0887f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 { AddressesService, LoadingService } from '../../../services'; | ||
import { AddressesService, 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,16 @@ 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'; | ||
import { LinkedCasesService } from '../../palette/linked-cases/services/linked-cases.service'; | ||
import { CaseFlagStateService } from '../services/case-flag-state.service'; | ||
|
||
@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'; | ||
|
@@ -85,8 +88,39 @@ export class CaseEditPageComponent implements OnInit, AfterViewChecked, OnDestro | |
private readonly caseEditDataService: CaseEditDataService, | ||
private readonly loadingService: LoadingService, | ||
private readonly validPageListCaseFieldsService: ValidPageListCaseFieldsService, | ||
private readonly addressService: AddressesService | ||
private readonly multipageComponentStateService: MultipageComponentStateService, | ||
private readonly addressService: AddressesService, | ||
private readonly linkedCasesService: LinkedCasesService, | ||
private readonly caseFlagStateService: CaseFlagStateService | ||
) { | ||
this.multipageComponentStateService.setInstigator(this); | ||
} | ||
|
||
public onFinalNext(): void { | ||
this.submit(); | ||
} | ||
|
||
public onFinalPrevious(): void { | ||
this.cancel(); | ||
} | ||
|
||
public isAtStart(): boolean { | ||
const pageNumberToUse = this.multipageComponentStateService.getJourneyCollection()[0]?.linkedCasesPage !== undefined ? this.multipageComponentStateService.getJourneyCollection()[0]?.linkedCasesPage : this.multipageComponentStateService.getJourneyCollection()[0]?.fieldState; | ||
return pageNumberToUse === this.multipageComponentStateService.getJourneyCollection()[0]?.journeyStartPageNumber; | ||
} | ||
|
||
public isAtEnd(): boolean { | ||
return this.multipageComponentStateService.getJourneyCollection()[0]?.fieldState === this.multipageComponentStateService.getJourneyCollection()[0]?.journeyEndPageNumber; | ||
} | ||
|
||
// This method will be triggered by the next button in the app component | ||
public nextStep(): void { | ||
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 { | ||
|
@@ -148,6 +182,7 @@ export class CaseEditPageComponent implements OnInit, AfterViewChecked, OnDestro | |
this.dialogRefAfterClosedSub?.unsubscribe(); | ||
this.saveDraftSub?.unsubscribe(); | ||
this.caseFormValidationErrorsSub?.unsubscribe(); | ||
this.multipageComponentStateService.reset(); | ||
} | ||
|
||
public applyValuesChanged(valuesChanged: boolean): void { | ||
|
@@ -159,6 +194,7 @@ export class CaseEditPageComponent implements OnInit, AfterViewChecked, OnDestro | |
} | ||
|
||
public currentPageIsNotValid(): boolean { | ||
this.editForm.updateValueAndValidity(); | ||
this.failingCaseFields = this.pageValidationService.getInvalidFields(this.currentPage, this.editForm); | ||
return this.failingCaseFields.length > 0 || | ||
(this.isLinkedCasesJourney() && !this.isLinkedCasesJourneyAtFinalStep); | ||
|
@@ -175,11 +211,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(); | ||
} | ||
|
||
|
@@ -289,8 +325,31 @@ export class CaseEditPageComponent implements OnInit, AfterViewChecked, OnDestro | |
} | ||
} | ||
|
||
public checkForStagesCompleted() { | ||
const dataControls = this.editForm.controls['data']; | ||
if (dataControls) { | ||
const flagLauncher = dataControls.get('flagLauncherInternal'); | ||
if (flagLauncher) { | ||
if (flagLauncher.hasError('notAllCaseFlagStagesCompleted') && this.isAtEnd()) { | ||
flagLauncher.setErrors(null); | ||
} | ||
} | ||
} | ||
} | ||
|
||
public submit(): void { | ||
// in some scenarios the fieldstate can be set to 0 even though the user is at the end of a journey, check for this case and set vars | ||
const journeyPageNumber = this.multipageComponentStateService.getJourneyCollection()[0]?.journeyPageNumber; | ||
const fieldState = this.caseFlagStateService?.fieldStateToNavigate; | ||
if (this.eventTrigger.id === 'c100ManageFlags'){ | ||
if ((fieldState === 0 || fieldState === undefined || journeyPageNumber > fieldState) && fieldState !== journeyPageNumber) { | ||
this.caseFlagStateService.fieldStateToNavigate = journeyPageNumber; | ||
this.caseFlagStateService.lastPageFieldState = journeyPageNumber; | ||
} | ||
} | ||
|
||
this.caseEditDataService.clearFormValidationErrors(); | ||
this.checkForStagesCompleted(); | ||
if (this.currentPageIsNotValid()) { | ||
// The generateErrorMessage method filters out the hidden fields. | ||
// The error message for LinkedCases journey will never get displayed because the | ||
|
@@ -434,6 +493,20 @@ export class CaseEditPageComponent implements OnInit, AfterViewChecked, OnDestro | |
} | ||
|
||
public cancel(): void { | ||
if (this.isLinkedCasesJourney()){ | ||
// if the user cancels the journey we need to clean up the data | ||
const linkedCasesTab = this.caseEdit.caseDetails.tabs.find((tab) => | ||
tab?.fields?.some((field) => field.id === 'caseLinks') | ||
)?.fields?.[0] ?? null; | ||
const initalLinks = this.linkedCasesService.initialCaseLinkRefs; | ||
if (linkedCasesTab && linkedCasesTab?.value.length !== initalLinks.length){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another minor comment - a few assumptions made here, i.e. that there is this.caseEdit.caseDetails.tabs and that linkedCasesTab.value exists, just check that they definitely will There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added additional checks for properties |
||
const initialCaseRefs = this.linkedCasesService.initialCaseLinkRefs; | ||
linkedCasesTab.value = linkedCasesTab.value.filter((item) => | ||
initialCaseRefs.includes(item.value.CaseReference) | ||
); | ||
} | ||
this.linkedCasesService.resetLinkedCaseData(); | ||
} | ||
if (this.eventTrigger.can_save_draft) { | ||
if (this.formValuesChanged) { | ||
const dialogRef = this.dialog.open(SaveOrDiscardDialogComponent, this.dialogConfig); | ||
|
@@ -457,6 +530,7 @@ export class CaseEditPageComponent implements OnInit, AfterViewChecked, OnDestro | |
} | ||
|
||
this.caseEditDataService.clearFormValidationErrors(); | ||
this.multipageComponentStateService.reset(); | ||
} | ||
|
||
public submitting(): boolean { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor comment - add cleanUpData method so that this can be used elsewhere if needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or at least think about it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have moved it to its own reset function