Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/bcgov/nr-bcws-wfprev into W…
Browse files Browse the repository at this point in the history
…FPREV-100_1
  • Loading branch information
ssylver93 committed Jan 22, 2025
2 parents 86e0053 + 50ad27e commit 5c27b0b
Show file tree
Hide file tree
Showing 12 changed files with 439 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,26 @@
</div>
</div>
</div>
<div class="form-row">
<div class="form-field">
<label>Primary Objective<span class="required">*</span></label>
<select formControlName="primaryObjective">
<option value="">select...</option>
<option *ngFor="let type of objectiveTypes" [value]="type.objectiveTypeCode">{{ type.description }}</option>
</select>
</div>
<div class="form-field">
<label>Secondary Objective</label>
<select formControlName="secondaryObjective">
<option value="">select...</option>
<option *ngFor="let type of objectiveTypes" [value]="type.objectiveTypeCode">{{ type.description }}</option>
</select>
</div>
<div class="form-field">
<label>Secondary Objective Rationale</label>
<input type="text" formControlName="secondaryObjectiveRationale" placeholder="Input..." class="project-input"/>
</div>
</div>
</div>

<div class="footer">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ describe('CreateNewProjectDialogComponent', () => {
projectLeadEmail: '',
siteUnitName: '',
closestCommunity: '',
primaryObjective : '',
secondaryObjective: '',
secondaryObjectiveRationale: '',
});
});

Expand Down Expand Up @@ -149,6 +152,7 @@ describe('CreateNewProjectDialogComponent', () => {
projectLeadEmail: '[email protected]', // Optional field
siteUnitName: 'Unit 1', // Optional field
closestCommunity: 'Community 1', // Required field
primaryObjective: 'WRR' // Required field
});

// Call the function to create a project
Expand Down Expand Up @@ -251,6 +255,7 @@ describe('CreateNewProjectDialogComponent', () => {
projectLeadEmail: '[email protected]',
siteUnitName: 'Unit 1',
closestCommunity: 'Community 1',
primaryObjective: 'WRR'
});

mockProjectService.createProject.and.returnValue(of({}));
Expand Down Expand Up @@ -278,6 +283,7 @@ describe('CreateNewProjectDialogComponent', () => {
siteUnitName: 'Unit 1',
closestCommunity: 'Community 1',
latLong: '70.123456, -123.332177', // Invalid latitude
primaryObjective: 'WRR'
});

component.onCreate();
Expand Down Expand Up @@ -305,6 +311,7 @@ describe('CreateNewProjectDialogComponent', () => {
siteUnitName: 'Unit 1',
closestCommunity: 'Community 1',
latLong: '48.3, -139', // Boundary value for BC
primaryObjective: 'WRR'
});

mockProjectService.createProject.and.returnValue(of({}));
Expand Down Expand Up @@ -335,6 +342,7 @@ describe('CreateNewProjectDialogComponent', () => {
siteUnitName: 'Unit 1',
closestCommunity: 'Community 1',
latLong: 'invalid, format', // Invalid latLong format
primaryObjective: 'WRR'
});

component.onCreate();
Expand Down Expand Up @@ -386,6 +394,7 @@ describe('CreateNewProjectDialogComponent', () => {
bcParksRegion: 3,
bcParksSection: 4,
closestCommunity: 'Community 1',
primaryObjective: 'WRR'
});

mockProjectService.createProject.and.returnValue(of({}));
Expand All @@ -406,6 +415,17 @@ describe('CreateNewProjectDialogComponent', () => {

expect(errorMessage).toBeNull();
});

it('should return null if there are no errors on the form control', () => {
// Arrange: Ensure no errors are set for the 'projectName' control
component.projectForm.get('projectName')?.setErrors(null); // Clear errors

// Act: Call the getErrorMessage method
const errorMessage = component.getErrorMessage('projectName');

// Assert: Expect the method to return null
expect(errorMessage).toBeNull();
});

it('should return required field message when "required" error exists', () => {
component.projectForm.get('projectName')?.setErrors({ required: true });
Expand Down Expand Up @@ -450,6 +470,7 @@ describe('CreateNewProjectDialogComponent', () => {
projectLeadEmail: '[email protected]',
siteUnitName: 'Unit 1',
closestCommunity: 'Community 1',
primaryObjective: 'WRR'
});

// Act: Call the method to create a project
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export class CreateNewProjectDialogComponent implements OnInit {
bcParksRegions : any[] = [];
bcParksSections: any[] = [];
allBcParksSections: any[] = []; // To hold all sections initially
objectiveTypes: any[] = [];

constructor(
private readonly fb: FormBuilder,
Expand All @@ -62,6 +63,9 @@ export class CreateNewProjectDialogComponent implements OnInit {
projectLeadEmail: ['', [Validators.email, Validators.maxLength(50)]],
siteUnitName: ['', [Validators.maxLength(50)]],
closestCommunity: ['', [Validators.required, Validators.maxLength(50)]],
primaryObjective: ['', [Validators.required]],
secondaryObjective: [''],
secondaryObjectiveRationale: ['',[Validators.maxLength(50)]],
});

// Dynamically enable/disable bcParksSection based on bcParksRegion selection
Expand Down Expand Up @@ -89,12 +93,23 @@ export class CreateNewProjectDialogComponent implements OnInit {
{ name: 'forestDistrictCodes', property: 'forestDistricts', embeddedKey: 'forestDistrictCode' },
{ name: 'bcParksRegionCodes', property: 'bcParksRegions', embeddedKey: 'bcParksRegionCode' },
{ name: 'bcParksSectionCodes', property: 'allBcParksSections', embeddedKey: 'bcParksSectionCode' },
{ name: 'objectiveTypeCodes', property: 'objectiveTypes', embeddedKey: 'objectiveTypeCode' },

];

codeTables.forEach((table) => {
this.codeTableService.fetchCodeTable(table.name).subscribe({
next: (data) => {
this[table.property] = data?._embedded?.[table.embeddedKey] || [];
if (table.name === 'objectiveTypeCodes') {
const defaultObjective = this.objectiveTypes.find(
(type) => type.objectiveTypeCode === 'WRR'
);

if (defaultObjective) {
this.projectForm.get('primaryObjective')?.setValue('WRR');
}
}
},
error: (err) => {
console.error(`Error fetching ${table.name}`, err);
Expand Down Expand Up @@ -168,6 +183,16 @@ export class CreateNewProjectDialogComponent implements OnInit {
totalPlannedCostPerHectare:
this.projectForm.get('totalPlannedCostPerHectare')?.value ?? '',
totalActualAmount: this.projectForm.get('totalActualAmount')?.value ?? 0,
primaryObjectiveTypeCode: {
objectiveTypeCode: this.projectForm.get('primaryObjective')?.value
},
...(this.projectForm.get('secondaryObjective')?.value && {
secondaryObjectiveTypeCode: {
objectiveTypeCode: this.projectForm.get('secondaryObjective')?.value
}
}),
secondaryObjectiveRationale: this.projectForm.get('secondaryObjectiveRationale')?.value,

isMultiFiscalYearProj: false,
...(validatedLatLong && {
latitude: Number(validatedLatLong.latitude),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,27 +88,27 @@

<div class="form-item">
<label>Primary Objective<span class="required">*</span></label>
<select id="fundingStream" formControlName="primaryObjective">
<option value="fundingStream1">Primary Objective1</option>
<option value="fundingStream2">Primary Objective2</option>
<option value="fundingStream3">Primary Objective3</option>
<select id="fundingStream" formControlName="primaryObjectiveTypeCode">
<option *ngFor="let item of objectiveTypeCode" [value]="item.objectiveTypeCode">
{{ item.description }}
</option>
</select>
</div>

<div class="form-item">
<label>Secondary Objective</label>
<select id="fundingStream" formControlName="secondaryObjective">
<option value="fundingStream1">Secondary Objective1</option>
<option value="fundingStream2">Secondary Objective2</option>
<option value="fundingStream3">Secondary Objective3</option>
<select id="fundingStream" formControlName="secondaryObjectiveTypeCode">
<option *ngFor="let item of objectiveTypeCode" [value]="item.objectiveTypeCode">
{{ item.description }}
</option>
</select>
</div>

<div class="form-item secondary-rational">
<label for="totalFundingRequestAmount">Secondary Objective Rationale</label>
<label for="secondaryObjectiveRationale">Secondary Objective Rationale</label>
<input
type="number"
id="totalFundingRequestAmount"
type="text"
id="secondaryObjectiveRationale"
formControlName="secondaryObjectiveRationale"
placeholder="Enter Secondary Objective Rationale"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export class ProjectDetailsComponent implements OnInit, AfterViewInit, OnDestroy
forestDistrictCode: any[] = [];
bcParksRegionCode: any[] = [];
bcParksSectionCode: any[] = [];
objectiveTypeCode: any[] = [];

constructor(
private readonly fb: FormBuilder,
Expand Down Expand Up @@ -80,8 +81,8 @@ export class ProjectDetailsComponent implements OnInit, AfterViewInit, OnDestroy
closestCommunityName: ['', [Validators.required]],
forestRegionOrgUnitId: [''],
forestDistrictOrgUnitId: [''],
primaryObjective: [''],
secondaryObjective: [''],
primaryObjectiveTypeCode: [''],
secondaryObjectiveTypeCode: [''],
secondaryObjectiveRationale: [''],
bcParksRegionOrgUnitId: [''],
bcParksSectionOrgUnitId: [''],
Expand Down Expand Up @@ -145,6 +146,8 @@ export class ProjectDetailsComponent implements OnInit, AfterViewInit, OnDestroy
{ name: 'forestDistrictCodes', embeddedKey: 'forestDistrictCode' },
{ name: 'bcParksRegionCodes', embeddedKey: 'bcParksRegionCode' },
{ name: 'bcParksSectionCodes', embeddedKey: 'bcParksSectionCode' },
{ name: 'objectiveTypeCodes', embeddedKey: 'objectiveTypeCode' },

];

codeTables.forEach((table) => {
Expand Down Expand Up @@ -179,6 +182,9 @@ export class ProjectDetailsComponent implements OnInit, AfterViewInit, OnDestroy
case 'bcParksSectionCode':
this.bcParksSectionCode = data._embedded.bcParksSectionCode || [];
break;
case 'objectiveTypeCode':
this.objectiveTypeCode = data._embedded.objectiveTypeCode || [];
break;
}
}

Expand Down Expand Up @@ -249,8 +255,8 @@ export class ProjectDetailsComponent implements OnInit, AfterViewInit, OnDestroy
closestCommunityName: data.closestCommunityName,
forestRegionOrgUnitId: data.forestRegionOrgUnitId,
forestDistrictOrgUnitId: data.forestDistrictOrgUnitId,
primaryObjective: data.primaryObjective,
secondaryObjective: data.secondaryObjective,
primaryObjectiveTypeCode: data.primaryObjectiveTypeCode?.objectiveTypeCode || '',
secondaryObjectiveTypeCode: data.secondaryObjectiveTypeCode?.objectiveTypeCode || '',
secondaryObjectiveRationale: data.secondaryObjectiveRationale,
bcParksRegionOrgUnitId: data.bcParksRegionOrgUnitId,
bcParksSectionOrgUnitId: data.bcParksSectionOrgUnitId,
Expand All @@ -273,6 +279,19 @@ export class ProjectDetailsComponent implements OnInit, AfterViewInit, OnDestroy
forestAreaCode: {
forestAreaCode: "COAST",
},
primaryObjectiveTypeCode: {
objectiveTypeCode: this.detailsForm.get('primaryObjectiveTypeCode')?.value
? this.detailsForm.get('primaryObjectiveTypeCode')?.value
: this.projectDetail.primaryObjectiveTypeCode.objectiveTypeCode
},
secondaryObjectiveTypeCode: {
objectiveTypeCode: this.detailsForm.get('secondaryObjectiveTypeCode')?.value
? this.detailsForm.get('secondaryObjectiveTypeCode')?.value
: this.projectDetail.secondaryObjectiveTypeCode.objectiveTypeCode
},
tertiaryObjectiveTypeCode: {
objectiveTypeCode: 'FOR_HEALTH'
}
};
this.projectService.updateProject(this.projectGuid, updatedProject).subscribe({
next: () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,11 @@ export interface Project {
updateUser?: string;
latitude?: number;
longitude?: number;
primaryObjectiveTypeCode?: {
objectiveTypeCode: string;
};
secondaryObjectiveTypeCode?: {
objectiveTypeCode: string;
}
secondaryObjectiveRationale? :string;
}
Loading

0 comments on commit 5c27b0b

Please sign in to comment.