-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NRPTI-1045] - WIP - Update agency name in NRPTI (#1114)
* add menu item and page code - wip * Updated the front end to display list of agencies from drop down and update values from that list with value from a text box. * create model and migration for agencies * fix to model and migration - wip * update agency code migration, add update issuingAgency * update model to only add to nrpti collection * sample api added - list-agencies WIP * added api to list agencies, schema type * added get api * put api added for updating agencies * New component to make request to new endpoint for issuing agencies * Options added * Fixed component to properly display the information returned from get request * Update the agencyList array with selection from drop down menu. Create the object which will be sent to the api for updating the agencyList. Also worth noting the alerts are being used here for console debugging. My local settings are preventing logging, when I find the reason I will update readme to document process * First steps of patch logic to the update agency service * Front end component updates entries in for agency issuers through new endpoint. * security token enabled, alerts removed, compile issue fixed * toast added * button style updated * Style added to dropdown * current selected agency removed * wip - add agency service to app_init, change displayName * error message added * removed logging and fixed indentation * replaced hardcoded agency names with api calls * api call moved to service layer * issuing agency in add order replaced with api calls * add climate action secretariat to migrations * wip - agencies are updated in factory, prelim update to components * wip - update picklist to allow dynamic update (admin penalty only) * wip - make buildForm for admin penalty async * wip - update to factory service, fix buildForm in admin penalty * refresh agencies after they are updated * remove async ngOnInit, no longer needed * update to more relevant terminology * update to agencies in components and modules * agency name translated to agency code on admin penalty save * update admin penalty to show agency; linting updates * linting updates * linting updates * API unit tests fix * linting fix for agency-data-service * Agencies icon changed * agency code updated * agency code updated * issuing agency replaced with api call * update migration to change 'author' name to code; separate agency_env_epd * update migration for ENV_EPD and update authors * linting: white space added * linting * Update api/src/models/master/applicationAgency.js Co-authored-by: Matthew Logan <62873746+LocalNewsTV@users.noreply.github.com> * Update api/src/swagger/swagger.yaml crlf Co-authored-by: Matthew Logan <62873746+LocalNewsTV@users.noreply.github.com> * Update api/migrations/20230911220312-addApplicationAgenciesModel.js crlf Co-authored-by: Matthew Logan <62873746+LocalNewsTV@users.noreply.github.com> * comments added, unused function removed --------- Co-authored-by: Christopher-walsh22 <106549296+Christopher-walsh22@users.noreply.github.com> Co-authored-by: Sanjay Babu <sanjaytkbabu@gmail.com> Co-authored-by: Sanjay Babu <111102886+sanjaytkbabu@users.noreply.github.com> Co-authored-by: Matthew Logan <62873746+LocalNewsTV@users.noreply.github.com>
- Loading branch information
1 parent
bd47e52
commit 9bd2658
Showing
69 changed files
with
1,226 additions
and
324 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
angular/projects/admin-nrpti/src/app/agencies/agencies.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<div class="container"> | ||
<h1>Update Agencies</h1> | ||
|
||
<!-- Dropdown for selecting an agency --> | ||
<div class="dropDownArea"> | ||
<label>Select The Agency You Would Like to Update:</label> | ||
<br /> | ||
<!-- <select (change)="onSelected($event.target.value)"> | ||
<option *ngFor="let agency of agencyList" [value]="agency">{{ agency }}</option> | ||
</select> --> | ||
|
||
<select | ||
_ngcontent-ity-c12="" | ||
class="form-control ng-pristine ng-valid ng-touched" | ||
(change)="onSelected($event.target.value)" | ||
> | ||
<option *ngFor="let agency of agencyList" [value]="agency">{{ agency }}</option> | ||
</select> | ||
</div> | ||
|
||
<!-- Text field for entering a new agency --> | ||
<div class="form-group"> | ||
<label for="newAgency">Updated Agency Name:</label> | ||
<input type="text" id="newAgency" [(ngModel)]="newAgency" class="form-control" /> | ||
</div> | ||
|
||
<!-- Submit button to update the selected agency --> | ||
<!-- <button (click)="updateSelectedAgency()">Update Selected Agency</button> --> | ||
<button _ngcontent-req-c21="" class="btn btn-primary" (click)="updateSelectedAgency()" title="Update Selected Agency"> | ||
Update Selected Agency | ||
</button> | ||
|
||
<!-- Displays current selection - Would probably remove before release --> | ||
<!-- <div *ngIf="choiceMade"> | ||
<p>Selected Agency: {{ selectedAgency }}</p> | ||
</div> --> | ||
<!-- This div is just for debugging, Trying other ways to display the agencies --> | ||
</div> |
2 changes: 2 additions & 0 deletions
2
angular/projects/admin-nrpti/src/app/agencies/agencies.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
@import "assets/styles/base/base.scss"; | ||
@import "assets/styles/components/add-edit.scss"; |
106 changes: 106 additions & 0 deletions
106
angular/projects/admin-nrpti/src/app/agencies/agencies.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
import { IssuingAgencyService } from '../services/issuingagency.service'; | ||
import { LoggerService } from 'nrpti-angular-components'; | ||
import { Constants } from '../utils/constants/misc'; | ||
import { ToastService } from '../services/toast.service'; | ||
import { FactoryService } from '../services/factory.service'; | ||
|
||
@Component({ | ||
selector: 'app-agencies', | ||
templateUrl: './agencies.component.html', | ||
styleUrls: ['./agencies.component.scss'] | ||
}) | ||
export class AgenciesComponent implements OnInit { | ||
public loading = false; | ||
selectedAgency = ''; // Initialize the selectedAgency | ||
choiceMade = false; | ||
newAgency = ''; // Initialize the new agency input field | ||
agencies: { [key: string]: string } = { 'Kyle': 'Williams' }; | ||
agencyList: string[] = ['-Select-']; // Use a string array for agencyList | ||
updatedData: any = { | ||
agencies: [] | ||
}; | ||
constructor( | ||
private issuingAgencyService: IssuingAgencyService, | ||
private logger: LoggerService, | ||
private toastService: ToastService, | ||
private factoryService: FactoryService | ||
) {} | ||
|
||
onSelected(value: string): void { | ||
this.selectedAgency = value; | ||
this.choiceMade = true; | ||
} | ||
putRecords(agencyCode: any, agencyName: any) { | ||
this.issuingAgencyService.updateAgency(agencyCode, agencyName).then(() => { | ||
// Once record is updated, refresh the agencies | ||
this.refreshAgencies(); | ||
}); | ||
} | ||
refreshAgencies() { | ||
this.factoryService.applicationAgencyService.refreshAgencies().subscribe(); | ||
} | ||
updateSelectedAgency(): void { | ||
try { | ||
if (this.newAgency.trim() !== '') { | ||
// Find the agency code that matches the selected agency name | ||
const matchingCode = Object.keys(this.agencies).find(key => this.agencies[key] === this.selectedAgency); | ||
if (matchingCode) { | ||
// Update the agencyList with the new value at the same index | ||
const index = this.agencyList.indexOf(this.selectedAgency); | ||
if (index !== -1) { | ||
this.agencyList[index] = this.newAgency; | ||
} | ||
// Update the selectedAgency with the new value | ||
this.selectedAgency = this.newAgency; | ||
// Clear the input field | ||
this.newAgency = ''; | ||
this.choiceMade = true; | ||
// Update the updatedData object to match the desired layout | ||
this.updatedData.agencies.push({ | ||
agencyCode: matchingCode, | ||
agencyName: this.selectedAgency | ||
}); | ||
this.putRecords(matchingCode, this.selectedAgency); | ||
this.updatedData.agencies = []; | ||
} | ||
this.toastService.addMessage('Agency Successfully Updated', 'Success Updated', Constants.ToastTypes.SUCCESS); | ||
} else { | ||
this.toastService.addMessage( | ||
'Updated Agency Name Cannot be Empty', | ||
'Save unsuccessful', | ||
Constants.ToastTypes.ERROR | ||
); | ||
} | ||
} catch (error) { | ||
this.toastService.addMessage( | ||
'An error has occured while saving', | ||
'Save unsuccessful', | ||
Constants.ToastTypes.ERROR | ||
); | ||
} | ||
} | ||
|
||
ngOnInit(): void { | ||
this.issuingAgencyService | ||
.getIssuingAgencies() | ||
.then(response => { | ||
const agencies = {}; | ||
if (response && Array.isArray(response)) { | ||
response.forEach(agency => { | ||
agencies[agency.agencyCode] = agency.agencyName; | ||
}); | ||
} | ||
this.agencies = agencies; // Assign the agencies object as an Observable | ||
for (const key in agencies) { | ||
if (agencies.hasOwnProperty(key)) { | ||
this.agencyList.push(agencies[key]); | ||
} | ||
} | ||
}) | ||
.catch(error => { | ||
console.error('API call error:', error); | ||
}); | ||
this.logger.level = 0; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
angular/projects/admin-nrpti/src/app/agencies/agencies.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// modules | ||
import { NgModule } from '@angular/core'; | ||
import { RouterModule } from '@angular/router'; | ||
import { FormsModule, ReactiveFormsModule } from '@angular/forms'; | ||
import { CommonModule } from '@angular/common'; | ||
import { NgbModule } from '@ng-bootstrap/ng-bootstrap'; | ||
import { BrowserModule } from '@angular/platform-browser'; | ||
import { EditorModule } from '@tinymce/tinymce-angular'; | ||
import { GlobalModule } from 'nrpti-angular-components'; | ||
|
||
import { CommonModule as NrptiCommonModule } from '../../../../common/src/app/common.module'; | ||
import { AgenciesComponent } from './agencies.component'; | ||
import { AgenciesResolver } from './agencies.resolver'; | ||
|
||
@NgModule({ | ||
imports: [ | ||
BrowserModule, | ||
EditorModule, | ||
FormsModule, | ||
ReactiveFormsModule, | ||
CommonModule, | ||
GlobalModule, | ||
NrptiCommonModule, | ||
RouterModule, | ||
NgbModule | ||
], | ||
declarations: [AgenciesComponent], | ||
providers: [AgenciesResolver], | ||
entryComponents: [AgenciesComponent], | ||
exports: [] | ||
}) | ||
export class AgenciesModule {} |
10 changes: 10 additions & 0 deletions
10
angular/projects/admin-nrpti/src/app/agencies/agencies.resolver.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { ActivatedRouteSnapshot, Resolve } from '@angular/router'; | ||
import { Observable } from 'rxjs/Observable'; | ||
|
||
@Injectable() | ||
export class AgenciesResolver implements Resolve<Observable<object>> { | ||
resolve(route: ActivatedRouteSnapshot): Observable<object> { | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.