Skip to content

Commit

Permalink
Merge pull request #2011 from bcgov/feature/ALCS-1858-update-conditio…
Browse files Browse the repository at this point in the history
…n-pills

Feature/alcs 1858 update condition pills
  • Loading branch information
fbarreta authored Dec 13, 2024
2 parents 0573c26 + 32c2663 commit 12ce000
Show file tree
Hide file tree
Showing 25 changed files with 415 additions and 117 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
<div class="header">
<h4 *ngIf="condition.type">{{ condition.type.label }}</h4>
<ng-container *ngIf="condition.status === CONDITION_STATUS.INCOMPLETE">
<app-application-type-pill [type]="incompleteLabel"></app-application-type-pill>
</ng-container>
<ng-container *ngIf="condition.status === CONDITION_STATUS.COMPLETE">
<app-application-type-pill [type]="completeLabel"></app-application-type-pill>
</ng-container>
<h4 *ngIf="condition.type">{{ stringIndex }}. {{ condition.type.label }}</h4>
<app-application-type-pill [type]="statusLabel"></app-application-type-pill>
</div>
<div class="grid-3">
<div>
Expand All @@ -22,6 +17,14 @@ <h4 *ngIf="condition.type">{{ condition.type.label }}</h4>
></app-no-data>
</div>

<div *ngIf="showSingleDateField">
<div class="subheading2">{{ singleDateLabel }}</div>
{{ singleDateFormated }}
<app-no-data
*ngIf="singleDateFormated === null || singleDateFormated === undefined"
></app-no-data>
</div>

<div *ngIf="showSecurityAmountField">
<div class="subheading2">Security Amount</div>
{{ condition.securityAmount }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,19 @@ import {
} from '../../../../../services/application/decision/application-decision-v2/application-decision-v2.dto';
import {
DECISION_CONDITION_COMPLETE_LABEL,
DECISION_CONDITION_INCOMPLETE_LABEL,
DECISION_CONDITION_ONGOING_LABEL,
DECISION_CONDITION_PASTDUE_LABEL,
DECISION_CONDITION_PENDING_LABEL,
DECISION_CONDITION_EXPIRED_LABEL,
} from '../../../../../shared/application-type-pill/application-type-pill.constants';
import {
ApplicationDecisionConditionWithStatus,
ConditionComponentLabels,
CONDITION_STATUS,
} from '../conditions.component';
import { environment } from '../../../../../../environments/environment';
import { countToString } from '../../../../../shared/utils/count-to-string';
import { ApplicationDecisionV2Service } from '../../../../../services/application/decision/application-decision-v2/application-decision-v2.service';

type Condition = ApplicationDecisionConditionWithStatus & {
componentLabelsStr?: string;
Expand All @@ -35,19 +40,20 @@ export class ConditionComponent implements OnInit, AfterViewInit {
@Input() condition!: Condition;
@Input() isDraftDecision!: boolean;
@Input() fileNumber!: string;
@Input() index!: number;

DateType = DateType;

dates: ApplicationDecisionConditionDateDto[] = [];

incompleteLabel = DECISION_CONDITION_INCOMPLETE_LABEL;
completeLabel = DECISION_CONDITION_COMPLETE_LABEL;
statusLabel = DECISION_CONDITION_ONGOING_LABEL;

singleDateLabel = 'End Date';
showSingleDateField = false;
showAdmFeeField = false;
showSecurityAmountField = false;
singleDateFormated: string | undefined = undefined;
stringIndex: string = '';

CONDITION_STATUS = CONDITION_STATUS;

Expand All @@ -62,10 +68,13 @@ export class ConditionComponent implements OnInit, AfterViewInit {
private conditionLotService: ApplicationDecisionComponentToConditionLotService,
) {}

ngOnInit() {
async ngOnInit() {
this.stringIndex = countToString(this.index);
if (this.condition) {
this.fetchDates(this.condition.uuid);

this.dates = this.condition.dates ?? [];
this.singleDateFormated =
this.dates[0] && this.dates[0].date ? moment(this.dates[0].date).format(environment.dateFormat) : undefined;
this.setPillLabel(this.condition.status);
this.singleDateLabel = this.condition.type?.singleDateLabel ? this.condition.type?.singleDateLabel : 'End Date';
this.showSingleDateField = this.condition.type?.dateType === DateType.SINGLE;
this.showAdmFeeField = this.condition.type?.isAdministrativeFeeAmountChecked
Expand Down Expand Up @@ -188,14 +197,26 @@ export class ConditionComponent implements OnInit, AfterViewInit {
return this.condition.conditionComponentsLabels?.find((e) => e.componentUuid === componentUuid)?.label;
}

async fetchDates(uuid: string | undefined) {
if (!uuid) {
return;
private setPillLabel(status: string) {
switch (status) {
case 'ONGOING':
this.statusLabel = DECISION_CONDITION_ONGOING_LABEL;
break;
case 'COMPLETED':
this.statusLabel = DECISION_CONDITION_COMPLETE_LABEL;
break;
case 'PASTDUE':
this.statusLabel = DECISION_CONDITION_PASTDUE_LABEL;
break;
case 'PENDING':
this.statusLabel = DECISION_CONDITION_PENDING_LABEL;
break;
case 'EXPIRED':
this.statusLabel = DECISION_CONDITION_EXPIRED_LABEL;
break;
default:
this.statusLabel = DECISION_CONDITION_ONGOING_LABEL;
break;
}

this.dates = await this.conditionService.getDates(uuid);

this.singleDateFormated =
this.dates[0] && this.dates[0].date ? moment(this.dates[0].date).format(environment.dateFormat) : undefined;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ <h3>View Conditions</h3>
[routerLink]="['../../']"
[queryParams]="{ uuid: decision.uuid }"
>
back to decision view
back to decision #{{ decision.index }}
</button>
</div>
<section class="body" *ngIf="decision">
Expand All @@ -28,7 +28,7 @@ <h3>View Conditions</h3>
</div>
<div class="header">
<div class="subheading1 title">
<h5>Decision #{{ decision.index }}</h5>
<h5>Decision</h5>
<div *ngIf="decision.index === decisions.length - 1 && application">
<span class="days" matTooltip="Active Days">
<mat-icon class="icon">calendar_month</mat-icon>
Expand Down Expand Up @@ -63,6 +63,7 @@ <h5>Decision #{{ decision.index }}</h5>
[condition]="condition"
[isDraftDecision]="decision.isDraft"
[fileNumber]="fileNumber"
[index]="j+1"
></app-condition>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@ export type ApplicationDecisionWithConditionComponentLabels = ApplicationDecisio
};

export const CONDITION_STATUS = {
INCOMPLETE: 'incomplete',
COMPLETE: 'complete',
COMPLETE: 'COMPLETE',
ONGOING: 'ONGOING',
PENDING: 'PENDING',
PASTDUE: 'PASTDUE',
EXPIRED: 'EXPIRED',
};

@Component({
Expand Down Expand Up @@ -97,18 +100,17 @@ export class ConditionsComponent implements OnInit {
),
),
)
.subscribe(({ decisions, datesByConditionUuid }) => {
this.decisions = decisions.map((decision) => {
.subscribe(async ({ decisions }) => {
this.decisions = await Promise.all(decisions.map(async (decision) => {
if (decision.uuid === this.decisionUuid) {
const conditions = this.mapConditions(decision, datesByConditionUuid, decisions);

const conditions = await this.mapConditions(decision, decisions);
this.sortConditions(decision, conditions);

this.decision = decision as ApplicationDecisionWithConditionComponentLabels;
}

return decision as ApplicationDecisionWithConditionComponentLabels;
});
}));
});

this.decisionService.loadDecisions(fileNumber);
Expand All @@ -133,7 +135,7 @@ export class ConditionsComponent implements OnInit {
conditions: ApplicationDecisionConditionWithStatus[],
) {
decision.conditions = conditions.sort((a, b) => {
const order = [CONDITION_STATUS.INCOMPLETE, CONDITION_STATUS.COMPLETE];
const order = [CONDITION_STATUS.ONGOING, CONDITION_STATUS.COMPLETE, CONDITION_STATUS.PASTDUE, CONDITION_STATUS.EXPIRED];
if (a.status === b.status) {
if (a.type && b.type) {
return a.type?.label.localeCompare(b.type.label);
Expand All @@ -146,18 +148,15 @@ export class ConditionsComponent implements OnInit {
});
}

private mapConditions(
private async mapConditions(
decision: ApplicationDecisionWithLinkedResolutionDto,
datesByConditionUuid: Map<string, ApplicationDecisionConditionDateDto[]>,
decisions: ApplicationDecisionWithLinkedResolutionDto[],
) {
return decision.conditions.map((condition) => {
const dates = datesByConditionUuid.get(condition.uuid) ?? [];
const status = this.getStatus(dates, decision);

return Promise.all(decision.conditions.map(async (condition) => {
const conditionStatus = await this.decisionService.getStatus(condition.uuid);
return {
...condition,
status,
status: conditionStatus.status,
conditionComponentsLabels: condition.components?.map((c) => {
const matchingType = this.codes.decisionComponentTypes.find(
(type) => type.code === c.applicationDecisionComponentTypeCode,
Expand All @@ -177,22 +176,6 @@ export class ConditionsComponent implements OnInit {
return { label, conditionUuid: condition.uuid, componentUuid: c.uuid };
}),
} as ApplicationDecisionConditionWithStatus;
});
}

private getStatus(
dates: ApplicationDecisionConditionDateDto[],
decision: ApplicationDecisionWithLinkedResolutionDto,
) {
let status = '';
status = CONDITION_STATUS.COMPLETE;
if (dates.length > 0 && dates.every((date) => date.completedDate && date.completedDate <= this.today)) {
status = CONDITION_STATUS.COMPLETE;
} else if (decision.isDraft === false) {
status = CONDITION_STATUS.INCOMPLETE;
} else {
status = '';
}
return status;
}));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ export class DecisionConditionComponent implements OnInit, OnChanges {

form = new FormGroup({
securityAmount: this.securityAmount,
singleDate: this.singleDate,
administrativeFee: this.administrativeFee,
description: this.description,
componentsToCondition: this.componentsToCondition,
singleDate: this.singleDate,
});

constructor(protected dialog: MatDialog) {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
<div class="header">
<h4 *ngIf="condition.type">{{ condition.type.label }}</h4>
<ng-container *ngIf="condition.status === CONDITION_STATUS.INCOMPLETE">
<app-application-type-pill [type]="incompleteLabel"></app-application-type-pill>
</ng-container>
<ng-container *ngIf="condition.status === CONDITION_STATUS.COMPLETE">
<app-application-type-pill [type]="completeLabel"></app-application-type-pill>
</ng-container>
<h4 *ngIf="condition.type">{{ stringIndex }}. {{ condition.type.label }}</h4>
<app-application-type-pill [type]="statusLabel"></app-application-type-pill>
</div>
<div class="grid-3">
<div>
Expand All @@ -22,6 +17,14 @@ <h4 *ngIf="condition.type">{{ condition.type.label }}</h4>
></app-no-data>
</div>

<div *ngIf="showSingleDateField">
<div class="subheading2">{{ singleDateLabel }}</div>
{{ singleDateFormated }}
<app-no-data
*ngIf="singleDateFormated === null || singleDateFormated === undefined"
></app-no-data>
</div>

<div *ngIf="showSecurityAmountField">
<div class="subheading2">Security Amount</div>
{{ condition.securityAmount }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ import {
} from '../../../../../services/notice-of-intent/decision-v2/notice-of-intent-decision.dto';
import {
DECISION_CONDITION_COMPLETE_LABEL,
DECISION_CONDITION_INCOMPLETE_LABEL,
DECISION_CONDITION_SUPERSEDED_LABEL,
DECISION_CONDITION_ONGOING_LABEL,
DECISION_CONDITION_PASTDUE_LABEL,
DECISION_CONDITION_PENDING_LABEL,
DECISION_CONDITION_EXPIRED_LABEL,
} from '../../../../../shared/application-type-pill/application-type-pill.constants';
import { CONDITION_STATUS, ConditionComponentLabels, DecisionConditionWithStatus } from '../conditions.component';
import { environment } from '../../../../../../environments/environment';
import { DateType } from '../../../../../services/application/decision/application-decision-v2/application-decision-v2.dto';
import { countToString } from '../../../../../shared/utils/count-to-string';
import { NoticeOfIntentDecisionV2Service } from '../../../../../services/notice-of-intent/decision-v2/notice-of-intent-decision-v2.service';

type Condition = DecisionConditionWithStatus & {
componentLabelsStr?: string;
Expand All @@ -28,14 +32,13 @@ export class ConditionComponent implements OnInit, AfterViewInit {
@Input() condition!: Condition;
@Input() isDraftDecision!: boolean;
@Input() fileNumber!: string;
@Input() index!: number;

DateType = DateType;

dates: NoticeOfIntentDecisionConditionDateDto[] = [];

incompleteLabel = DECISION_CONDITION_INCOMPLETE_LABEL;
completeLabel = DECISION_CONDITION_COMPLETE_LABEL;
supersededLabel = DECISION_CONDITION_SUPERSEDED_LABEL;
statusLabel = DECISION_CONDITION_ONGOING_LABEL;

singleDateLabel = 'End Date';
showSingleDateField = false;
Expand All @@ -48,12 +51,17 @@ export class ConditionComponent implements OnInit, AfterViewInit {
isReadMoreClicked = false;
isReadMoreVisible = false;
conditionStatus: string = '';
stringIndex: string = '';

constructor(private conditionService: NoticeOfIntentDecisionConditionService) {}

ngOnInit() {
async ngOnInit() {
this.stringIndex = countToString(this.index);
if (this.condition) {
this.fetchDates(this.condition.uuid);
this.dates = this.condition.dates ?? [];
this.singleDateFormated =
this.dates[0] && this.dates[0].date ? moment(this.dates[0].date).format(environment.dateFormat) : undefined;
this.setPillLabel(this.condition.status);

this.singleDateLabel = this.condition.type?.singleDateLabel ? this.condition.type?.singleDateLabel : 'End Date';
this.showSingleDateField = this.condition.type?.dateType === DateType.SINGLE;
Expand Down Expand Up @@ -104,15 +112,26 @@ export class ConditionComponent implements OnInit, AfterViewInit {
return this.isReadMoreClicked || this.isEllipsisActive(this.condition.uuid + 'Description');
}

async fetchDates(uuid: string | undefined) {
if (!uuid) {
return;
private setPillLabel(status: string) {
switch (status) {
case 'ONGOING':
this.statusLabel = DECISION_CONDITION_ONGOING_LABEL;
break;
case 'COMPLETED':
this.statusLabel = DECISION_CONDITION_COMPLETE_LABEL;
break;
case 'PASTDUE':
this.statusLabel = DECISION_CONDITION_PASTDUE_LABEL;
break;
case 'PENDING':
this.statusLabel = DECISION_CONDITION_PENDING_LABEL;
break;
case 'EXPIRED':
this.statusLabel = DECISION_CONDITION_EXPIRED_LABEL;
break;
default:
this.statusLabel = DECISION_CONDITION_ONGOING_LABEL;
break;
}

this.dates = await this.conditionService.getDates(uuid);

this.singleDateFormated = this.dates[0].date
? moment(this.dates[0].date).format(environment.dateFormat)
: undefined;
}
}
Loading

0 comments on commit 12ce000

Please sign in to comment.