Skip to content

Commit

Permalink
[NRPTI-1045] - WIP - Update agency name in NRPTI (#1114)
Browse files Browse the repository at this point in the history
* 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
5 people authored Oct 3, 2023
1 parent bd47e52 commit 9bd2658
Show file tree
Hide file tree
Showing 69 changed files with 1,226 additions and 324 deletions.
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>
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 angular/projects/admin-nrpti/src/app/agencies/agencies.component.ts
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 angular/projects/admin-nrpti/src/app/agencies/agencies.module.ts
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 angular/projects/admin-nrpti/src/app/agencies/agencies.resolver.ts
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;
}
}
13 changes: 13 additions & 0 deletions angular/projects/admin-nrpti/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { NewsResolver } from './news/news-resolver';
import { NewsListComponent } from './news/news-list.component';
import { CommunicationsComponent } from './communications/communications.component';
import { LngMapInfoResolver } from './communications/lng-map-info/lng-map-info-resolver';
import { AgenciesComponent } from './agencies/agencies.component';
import { AgenciesResolver } from './agencies/agencies.resolver';

const routes: Routes = [
{
Expand Down Expand Up @@ -60,6 +62,17 @@ const routes: Routes = [
}
]
},
{
path: 'agencies',
pathMatch: 'full',
component: AgenciesComponent,
resolve: {
records: AgenciesResolver
},
data: {
breadcrumb: 'Agencies'
}
},
{
// wildcard default route
path: '**',
Expand Down
16 changes: 12 additions & 4 deletions angular/projects/admin-nrpti/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { RecordsModule } from './records/records.module';
import { NewsModule } from './news/news.module';
import { MinesModule } from './mines/mines.module';
import { CommunicationsModule } from './communications/communications.module';
import { AgenciesModule } from './agencies/agencies.module';
import { ToastrModule } from 'ngx-toastr';

// components
Expand All @@ -43,6 +44,7 @@ import { RecordService } from './services/record.service';
import { TaskService } from './services/task.service';
import { ConfigService, LoggerService } from 'nrpti-angular-components';
import { NewsService } from './services/news.service';
import { ApplicationAgencyService } from './services/application-agency.service';

// resolvers
import { ImportListResolver } from './import/import-list-resolver';
Expand All @@ -58,11 +60,15 @@ import { TokenInterceptor } from './utils/token-interceptor';
import { RecordUtils } from './records/utils/record-utils';
import { CollectionService } from './services/collection.service';


export function initConfig(configService: ConfigService, keycloakService: KeycloakService) {
export function initConfig(
configService: ConfigService,
keycloakService: KeycloakService,
applicationAgency: ApplicationAgencyService
) {
return async () => {
await configService.init();
await keycloakService.init();
await applicationAgency.init();
};
}

Expand Down Expand Up @@ -98,6 +104,7 @@ export function overlayScrollFactory(overlay: Overlay): () => CloseScrollStrateg
NewsModule,
MinesModule,
CommunicationsModule,
AgenciesModule,
AppRoutingModule, // <-- module import order matters - https://angular.io/guide/router#module-import-order-matters
NgbModule.forRoot(),
NgxPaginationModule,
Expand All @@ -108,7 +115,7 @@ export function overlayScrollFactory(overlay: Overlay): () => CloseScrollStrateg
{
provide: APP_INITIALIZER,
useFactory: initConfig,
deps: [ConfigService, KeycloakService],
deps: [ConfigService, KeycloakService, ApplicationAgencyService],
multi: true
},
{
Expand All @@ -129,14 +136,15 @@ export function overlayScrollFactory(overlay: Overlay): () => CloseScrollStrateg
NewsService,
CollectionService,
KeycloakService,
ApplicationAgencyService,
LoggerService,
TaskService,
ImportListResolver,
NewsResolver,
NewsListResolver,
CanActivateGuard,
CanDeactivateGuard,
RecordUtils,
RecordUtils
],
entryComponents: [ConfirmComponent, HomeComponent, ImportComponent, ImportTableRowsComponent],
bootstrap: [AppComponent]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ describe('HomeComponent', () => {
case Constants.Menus.ENTITIES: retVal = false; break;
case Constants.Menus.IMPORTS: retVal = true; break;
case Constants.Menus.COMMUNICATIONS: retVal = true; break;
case Constants.Menus.AGENCIES: retVal = true; break;
}
return retVal;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class MinesAdministrativePenaltyAddEditComponent extends AdministrativePe
);
}

ngOnInit() {
async ngOnInit() {
this.route.data.pipe(takeUntil(this.ngUnsubscribe)).subscribe((res: any) => {
this.isEditing = res.breadcrumb !== 'Add Administrative Penalty';
if (this.isEditing) {
Expand Down
Loading

0 comments on commit 9bd2658

Please sign in to comment.