diff --git a/angular/projects/admin-nrpti/src/app/agencies/agencies.component.html b/angular/projects/admin-nrpti/src/app/agencies/agencies.component.html new file mode 100644 index 000000000..67d7605e1 --- /dev/null +++ b/angular/projects/admin-nrpti/src/app/agencies/agencies.component.html @@ -0,0 +1,38 @@ +
+

Update Agencies

+ + + + + +
+ + +
+ + + + + + + + +
diff --git a/angular/projects/admin-nrpti/src/app/agencies/agencies.component.scss b/angular/projects/admin-nrpti/src/app/agencies/agencies.component.scss new file mode 100644 index 000000000..b5ec26e80 --- /dev/null +++ b/angular/projects/admin-nrpti/src/app/agencies/agencies.component.scss @@ -0,0 +1,2 @@ +@import "assets/styles/base/base.scss"; +@import "assets/styles/components/add-edit.scss"; diff --git a/angular/projects/admin-nrpti/src/app/agencies/agencies.component.ts b/angular/projects/admin-nrpti/src/app/agencies/agencies.component.ts new file mode 100644 index 000000000..e37c3a823 --- /dev/null +++ b/angular/projects/admin-nrpti/src/app/agencies/agencies.component.ts @@ -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; + } +} diff --git a/angular/projects/admin-nrpti/src/app/agencies/agencies.module.ts b/angular/projects/admin-nrpti/src/app/agencies/agencies.module.ts new file mode 100644 index 000000000..e7fe1d8d8 --- /dev/null +++ b/angular/projects/admin-nrpti/src/app/agencies/agencies.module.ts @@ -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 {} diff --git a/angular/projects/admin-nrpti/src/app/agencies/agencies.resolver.ts b/angular/projects/admin-nrpti/src/app/agencies/agencies.resolver.ts new file mode 100644 index 000000000..c2bfd86e8 --- /dev/null +++ b/angular/projects/admin-nrpti/src/app/agencies/agencies.resolver.ts @@ -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> { + resolve(route: ActivatedRouteSnapshot): Observable { + return null; + } +} diff --git a/angular/projects/admin-nrpti/src/app/app-routing.module.ts b/angular/projects/admin-nrpti/src/app/app-routing.module.ts index fafe4cacb..78c1fdb61 100644 --- a/angular/projects/admin-nrpti/src/app/app-routing.module.ts +++ b/angular/projects/admin-nrpti/src/app/app-routing.module.ts @@ -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 = [ { @@ -60,6 +62,17 @@ const routes: Routes = [ } ] }, + { + path: 'agencies', + pathMatch: 'full', + component: AgenciesComponent, + resolve: { + records: AgenciesResolver + }, + data: { + breadcrumb: 'Agencies' + } + }, { // wildcard default route path: '**', diff --git a/angular/projects/admin-nrpti/src/app/app.module.ts b/angular/projects/admin-nrpti/src/app/app.module.ts index 017b2327e..ed57b295b 100644 --- a/angular/projects/admin-nrpti/src/app/app.module.ts +++ b/angular/projects/admin-nrpti/src/app/app.module.ts @@ -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 @@ -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'; @@ -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(); }; } @@ -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, @@ -108,7 +115,7 @@ export function overlayScrollFactory(overlay: Overlay): () => CloseScrollStrateg { provide: APP_INITIALIZER, useFactory: initConfig, - deps: [ConfigService, KeycloakService], + deps: [ConfigService, KeycloakService, ApplicationAgencyService], multi: true }, { @@ -129,6 +136,7 @@ export function overlayScrollFactory(overlay: Overlay): () => CloseScrollStrateg NewsService, CollectionService, KeycloakService, + ApplicationAgencyService, LoggerService, TaskService, ImportListResolver, @@ -136,7 +144,7 @@ export function overlayScrollFactory(overlay: Overlay): () => CloseScrollStrateg NewsListResolver, CanActivateGuard, CanDeactivateGuard, - RecordUtils, + RecordUtils ], entryComponents: [ConfirmComponent, HomeComponent, ImportComponent, ImportTableRowsComponent], bootstrap: [AppComponent] diff --git a/angular/projects/admin-nrpti/src/app/home/home.component.spec.ts b/angular/projects/admin-nrpti/src/app/home/home.component.spec.ts index 28102c81d..e7e1a2bcf 100644 --- a/angular/projects/admin-nrpti/src/app/home/home.component.spec.ts +++ b/angular/projects/admin-nrpti/src/app/home/home.component.spec.ts @@ -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; } diff --git a/angular/projects/admin-nrpti/src/app/mines/mines-enforcement-actions/mines-administrative-penalty-add-edit/mines-administrative-penalty-add-edit.component.ts b/angular/projects/admin-nrpti/src/app/mines/mines-enforcement-actions/mines-administrative-penalty-add-edit/mines-administrative-penalty-add-edit.component.ts index f9a6b8e3f..91ace92cd 100644 --- a/angular/projects/admin-nrpti/src/app/mines/mines-enforcement-actions/mines-administrative-penalty-add-edit/mines-administrative-penalty-add-edit.component.ts +++ b/angular/projects/admin-nrpti/src/app/mines/mines-enforcement-actions/mines-administrative-penalty-add-edit/mines-administrative-penalty-add-edit.component.ts @@ -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) { diff --git a/angular/projects/admin-nrpti/src/app/records/administrative-penalties/administrative-penalty-add-edit/administrative-penalty-add-edit.component.html b/angular/projects/admin-nrpti/src/app/records/administrative-penalties/administrative-penalty-add-edit/administrative-penalty-add-edit.component.html index efcf27000..c32acf728 100644 --- a/angular/projects/admin-nrpti/src/app/records/administrative-penalties/administrative-penalty-add-edit/administrative-penalty-add-edit.component.html +++ b/angular/projects/admin-nrpti/src/app/records/administrative-penalties/administrative-penalty-add-edit/administrative-penalty-add-edit.component.html @@ -39,8 +39,8 @@

Basic Information

[control]="myForm.controls.dateIssued" [isValidate]="true" [minDate]="datepickerMinDate" - [maxDate]="datepickerMaxDate"> - + [maxDate]="datepickerMaxDate" + >
@@ -51,7 +51,8 @@

Basic Information

id="recordType" type="text" value="Administrative Penalty" - class="form-control" /> + class="form-control" + />
@@ -79,8 +80,7 @@

Basic Information

[mines]="this.storeService.getItem('mines')" [epicProjects]="this.storeService.getItem('epicProjects')" [minesOnly]="false" - > - + >
@@ -115,7 +115,8 @@

Issued To

id="coastalGaslink" value="Coastal Gaslink" formControlName="projectName" - name="projectName" /> + name="projectName" + />
@@ -150,10 +151,12 @@

Location Details

Documents

+ (documentsToDelete)="documentsToDelete = $event" + > + (documentsChanged)="documents = $event" + >
@@ -169,7 +172,8 @@

BCMI Site Content

formControlName="publishBcmi" (change)="togglePublish($event, 'bcmi')" [checked]="myForm.controls.publishBcmi.value" - ngDefaultControl> + ngDefaultControl + > {{ myForm.controls.publishBcmi.value ? 'Published' : 'Unpublished' }} *Changes made will take effect once you click "Update Record" @@ -184,7 +188,8 @@

BCMI Site Content

type="text" formControlName="bcmiSummary" class="form-control" - rows="5"> + rows="5" + >
@@ -202,7 +207,8 @@

LNG Site Content

formControlName="publishLng" (change)="togglePublish($event, 'lng')" [checked]="myForm.controls.publishLng.value" - ngDefaultControl> + ngDefaultControl + > {{ myForm.controls.publishLng.value ? 'Published' : 'Unpublished' }} *Changes made will take effect once you click "Update Record" @@ -217,7 +223,8 @@

LNG Site Content

type="text" formControlName="lngDescription" class="form-control" - rows="5"> + rows="5" + > @@ -235,7 +242,8 @@

NRCED Site Content

formControlName="publishNrced" (change)="togglePublish($event, 'nrced')" [checked]="myForm.controls.publishNrced.value" - ngDefaultControl> + ngDefaultControl + > {{ myForm.controls.publishNrced.value ? 'Published' : 'Unpublished' }} *Changes made will take effect once you click "Update Record" @@ -250,7 +258,8 @@

NRCED Site Content

type="text" formControlName="nrcedSummary" class="form-control" - rows="5"> + rows="5" + > diff --git a/angular/projects/admin-nrpti/src/app/records/administrative-penalties/administrative-penalty-add-edit/administrative-penalty-add-edit.component.spec.ts b/angular/projects/admin-nrpti/src/app/records/administrative-penalties/administrative-penalty-add-edit/administrative-penalty-add-edit.component.spec.ts index f0fe6d698..9d1c1d6b7 100644 --- a/angular/projects/admin-nrpti/src/app/records/administrative-penalties/administrative-penalty-add-edit/administrative-penalty-add-edit.component.spec.ts +++ b/angular/projects/admin-nrpti/src/app/records/administrative-penalties/administrative-penalty-add-edit/administrative-penalty-add-edit.component.spec.ts @@ -19,7 +19,14 @@ import { EventEmitter } from '@angular/core'; describe('AdministrativePenaltyAddEditComponent', () => { const testBedHelper = new TestBedHelper(AdministrativePenaltyAddEditComponent); - const mockFactoryService = jasmine.createSpyObj('FactoryService', ['userInLngRole', 'userInBcmiRole', 'userInNrcedRole', 'userOnlyInLimitedRole', 'userInRole', 'isFlavourEditEnabled']); + const mockFactoryService = jasmine.createSpyObj('FactoryService', [ + 'userInLngRole', + 'userInBcmiRole', + 'userInNrcedRole', + 'userOnlyInLimitedRole', + 'userInRole', + 'isFlavourEditEnabled' + ]); mockFactoryService.userInLngRole.and.returnValue(true); mockFactoryService.userInBcmiRole.and.returnValue(true); mockFactoryService.userInNrcedRole.and.returnValue(true); @@ -43,7 +50,7 @@ describe('AdministrativePenaltyAddEditComponent', () => { } }; - beforeEach((() => { + beforeEach(() => { TestBed.configureTestingModule({ imports: [ RouterTestingModule, @@ -68,7 +75,7 @@ describe('AdministrativePenaltyAddEditComponent', () => { ], schemas: [CUSTOM_ELEMENTS_SCHEMA] }).compileComponents(); - })); + }); it('should create', () => { const { component } = testBedHelper.createComponent(); diff --git a/angular/projects/admin-nrpti/src/app/records/administrative-penalties/administrative-penalty-add-edit/administrative-penalty-add-edit.component.ts b/angular/projects/admin-nrpti/src/app/records/administrative-penalties/administrative-penalty-add-edit/administrative-penalty-add-edit.component.ts index 61ddbcd82..e550f2a32 100644 --- a/angular/projects/admin-nrpti/src/app/records/administrative-penalties/administrative-penalty-add-edit/administrative-penalty-add-edit.component.ts +++ b/angular/projects/admin-nrpti/src/app/records/administrative-penalties/administrative-penalty-add-edit/administrative-penalty-add-edit.component.ts @@ -10,7 +10,7 @@ import { Utils as CommonUtils } from '../../../../../../common/src/app/utils/uti import { RecordUtils } from '../../utils/record-utils'; import { LoadingScreenService, LoggerService, StoreService } from 'nrpti-angular-components'; import { Constants } from '../../../utils/constants/misc'; - +import { AgencyDataService } from '../../../../../../global/src/lib/utils/agency-data-service'; @Component({ selector: 'app-administrative-penalty-add-edit', @@ -37,7 +37,7 @@ export class AdministrativePenaltyAddEditComponent implements OnInit, OnDestroy public bcmiPublishSubtext = 'Not published'; // Pick lists - public agencies = Picklists.agencyPicklist; + public agencies = Picklists.getAgencyNames(this.factoryService); public authors = Picklists.authorPicklist; public defaultAgency = ''; @@ -59,8 +59,8 @@ export class AdministrativePenaltyAddEditComponent implements OnInit, OnDestroy protected utils: Utils, protected _changeDetectionRef: ChangeDetectorRef, // @ts-ignore used by record-association component - protected storeService: StoreService, - ) { } + protected storeService: StoreService + ) {} ngOnInit() { this.route.data.pipe(takeUntil(this.ngUnsubscribe)).subscribe((res: any) => { @@ -81,6 +81,7 @@ export class AdministrativePenaltyAddEditComponent implements OnInit, OnDestroy } this.buildForm(); + this.subscribeToFormControlChanges(); this.loading = false; @@ -158,31 +159,32 @@ export class AdministrativePenaltyAddEditComponent implements OnInit, OnDestroy // Master recordName: new FormControl({ value: (this.currentRecord && this.currentRecord.recordName) || '', - disabled: (this.currentRecord && this.currentRecord.sourceSystemRef !== 'nrpti') && - !this.factoryService.userInLngRole() + disabled: + this.currentRecord && this.currentRecord.sourceSystemRef !== 'nrpti' && !this.factoryService.userInLngRole() }), dateIssued: new FormControl({ - value: (this.currentRecord && - this.currentRecord.dateIssued && - this.utils.convertJSDateToNGBDate(new Date(this.currentRecord.dateIssued))) || + value: + (this.currentRecord && + this.currentRecord.dateIssued && + this.utils.convertJSDateToNGBDate(new Date(this.currentRecord.dateIssued))) || '', - disabled: (this.currentRecord && this.currentRecord.sourceSystemRef !== 'nrpti') + disabled: this.currentRecord && this.currentRecord.sourceSystemRef !== 'nrpti' }), issuingAgency: new FormControl({ value: (this.currentRecord && this.currentRecord.issuingAgency) || this.defaultAgency, - disabled: (this.currentRecord && this.currentRecord.sourceSystemRef !== 'nrpti') + disabled: this.currentRecord && this.currentRecord.sourceSystemRef !== 'nrpti' }), author: new FormControl({ value: (this.currentRecord && this.currentRecord.author) || '', - disabled: (this.currentRecord && this.currentRecord.sourceSystemRef !== 'nrpti') + disabled: this.currentRecord && this.currentRecord.sourceSystemRef !== 'nrpti' }), association: new FormGroup({ _epicProjectId: new FormControl({ - value: this.currentRecord && this.currentRecord._epicProjectId || null, + value: (this.currentRecord && this.currentRecord._epicProjectId) || null, disabled: this.currentRecord && this.currentRecord.sourceSystemRef !== 'nrpti' }), mineGuid: new FormControl({ - value: this.currentRecord && this.currentRecord.mineGuid || null, + value: (this.currentRecord && this.currentRecord.mineGuid) || null, disabled: this.currentRecord && this.currentRecord.sourceSystemRef !== 'nrpti' }), unlistedMine: new FormControl({ @@ -197,56 +199,57 @@ export class AdministrativePenaltyAddEditComponent implements OnInit, OnDestroy issuedTo: new FormGroup({ type: new FormControl({ value: (this.currentRecord && this.currentRecord.issuedTo && this.currentRecord.issuedTo.type) || '', - disabled: (this.currentRecord && this.currentRecord.sourceSystemRef !== 'nrpti') + disabled: this.currentRecord && this.currentRecord.sourceSystemRef !== 'nrpti' }), companyName: new FormControl({ value: (this.currentRecord && this.currentRecord.issuedTo && this.currentRecord.issuedTo.companyName) || '', - disabled: (this.currentRecord && this.currentRecord.sourceSystemRef !== 'nrpti') + disabled: this.currentRecord && this.currentRecord.sourceSystemRef !== 'nrpti' }), firstName: new FormControl({ value: (this.currentRecord && this.currentRecord.issuedTo && this.currentRecord.issuedTo.firstName) || '', - disabled: (this.currentRecord && this.currentRecord.sourceSystemRef !== 'nrpti') + disabled: this.currentRecord && this.currentRecord.sourceSystemRef !== 'nrpti' }), middleName: new FormControl({ value: (this.currentRecord && this.currentRecord.issuedTo && this.currentRecord.issuedTo.middleName) || '', - disabled: (this.currentRecord && this.currentRecord.sourceSystemRef !== 'nrpti') + disabled: this.currentRecord && this.currentRecord.sourceSystemRef !== 'nrpti' }), lastName: new FormControl({ value: (this.currentRecord && this.currentRecord.issuedTo && this.currentRecord.issuedTo.lastName) || '', - disabled: (this.currentRecord && this.currentRecord.sourceSystemRef !== 'nrpti') + disabled: this.currentRecord && this.currentRecord.sourceSystemRef !== 'nrpti' }), fullName: new FormControl({ value: (this.currentRecord && this.currentRecord.issuedTo && this.currentRecord.issuedTo.fullName) || '', - disabled: (this.currentRecord && this.currentRecord.sourceSystemRef !== 'nrpti') + disabled: this.currentRecord && this.currentRecord.sourceSystemRef !== 'nrpti' }), dateOfBirth: new FormControl({ - value: (this.currentRecord && - this.currentRecord.issuedTo && - this.currentRecord.issuedTo.dateOfBirth && - this.utils.convertJSDateToNGBDate(new Date(this.currentRecord.issuedTo.dateOfBirth))) || + value: + (this.currentRecord && + this.currentRecord.issuedTo && + this.currentRecord.issuedTo.dateOfBirth && + this.utils.convertJSDateToNGBDate(new Date(this.currentRecord.issuedTo.dateOfBirth))) || '', - disabled: (this.currentRecord && this.currentRecord.sourceSystemRef !== 'nrpti') + disabled: this.currentRecord && this.currentRecord.sourceSystemRef !== 'nrpti' }), anonymous: new FormControl({ value: (this.currentRecord && this.currentRecord.issuedTo && this.currentRecord.issuedTo.anonymous) || '', - disabled: (this.currentRecord && this.currentRecord.sourceSystemRef !== 'nrpti') + disabled: this.currentRecord && this.currentRecord.sourceSystemRef !== 'nrpti' }) }), projectName: new FormControl({ value: (this.currentRecord && this.currentRecord.projectName) || '', - disabled: (this.currentRecord && this.currentRecord.sourceSystemRef !== 'nrpti') + disabled: this.currentRecord && this.currentRecord.sourceSystemRef !== 'nrpti' }), location: new FormControl({ value: (this.currentRecord && this.currentRecord.location) || '', - disabled: (this.currentRecord && this.currentRecord.sourceSystemRef !== 'nrpti') + disabled: this.currentRecord && this.currentRecord.sourceSystemRef !== 'nrpti' }), latitude: new FormControl({ value: (this.currentRecord && this.currentRecord.centroid && this.currentRecord.centroid[1]) || '', - disabled: (this.currentRecord && this.currentRecord.sourceSystemRef !== 'nrpti') + disabled: this.currentRecord && this.currentRecord.sourceSystemRef !== 'nrpti' }), longitude: new FormControl({ value: (this.currentRecord && this.currentRecord.centroid && this.currentRecord.centroid[0]) || '', - disabled: (this.currentRecord && this.currentRecord.sourceSystemRef !== 'nrpti') + disabled: this.currentRecord && this.currentRecord.sourceSystemRef !== 'nrpti' }), legislations: new FormArray(this.getLegislationsFormGroups()), @@ -303,27 +306,27 @@ export class AdministrativePenaltyAddEditComponent implements OnInit, OnDestroy new FormGroup({ act: new FormControl({ value: leg.act || '', - disabled: (this.currentRecord && this.currentRecord.sourceSystemRef !== 'nrpti') + disabled: this.currentRecord && this.currentRecord.sourceSystemRef !== 'nrpti' }), regulation: new FormControl({ value: leg.regulation || '', - disabled: (this.currentRecord && this.currentRecord.sourceSystemRef !== 'nrpti') + disabled: this.currentRecord && this.currentRecord.sourceSystemRef !== 'nrpti' }), section: new FormControl({ value: leg.section || '', - disabled: (this.currentRecord && this.currentRecord.sourceSystemRef !== 'nrpti') + disabled: this.currentRecord && this.currentRecord.sourceSystemRef !== 'nrpti' }), subSection: new FormControl({ value: leg.subSection || '', - disabled: (this.currentRecord && this.currentRecord.sourceSystemRef !== 'nrpti') + disabled: this.currentRecord && this.currentRecord.sourceSystemRef !== 'nrpti' }), paragraph: new FormControl({ value: leg.paragraph || '', - disabled: (this.currentRecord && this.currentRecord.sourceSystemRef !== 'nrpti') + disabled: this.currentRecord && this.currentRecord.sourceSystemRef !== 'nrpti' }), offence: new FormControl({ value: leg.offence || '', - disabled: (this.currentRecord && this.currentRecord.sourceSystemRef !== 'nrpti') + disabled: this.currentRecord && this.currentRecord.sourceSystemRef !== 'nrpti' }) }) ); @@ -331,7 +334,6 @@ export class AdministrativePenaltyAddEditComponent implements OnInit, OnDestroy return legislations; } - /** * Parses an array of legislations FormGroups into objects expected by the API. * @@ -379,21 +381,21 @@ export class AdministrativePenaltyAddEditComponent implements OnInit, OnDestroy new FormGroup({ type: new FormControl({ value: penalty.type || '', - disabled: (this.currentRecord && this.currentRecord.sourceSystemRef !== 'nrpti') + disabled: this.currentRecord && this.currentRecord.sourceSystemRef !== 'nrpti' }), penalty: new FormGroup({ type: new FormControl({ value: penalty.penalty.type || '', - disabled: (this.currentRecord && this.currentRecord.sourceSystemRef !== 'nrpti') + disabled: this.currentRecord && this.currentRecord.sourceSystemRef !== 'nrpti' }), value: new FormControl({ value: penalty.penalty.value || '', - disabled: (this.currentRecord && this.currentRecord.sourceSystemRef !== 'nrpti') + disabled: this.currentRecord && this.currentRecord.sourceSystemRef !== 'nrpti' }) }), description: new FormControl({ value: penalty.description || '', - disabled: (this.currentRecord && this.currentRecord.sourceSystemRef !== 'nrpti') + disabled: this.currentRecord && this.currentRecord.sourceSystemRef !== 'nrpti' }) }) ); @@ -449,7 +451,7 @@ export class AdministrativePenaltyAddEditComponent implements OnInit, OnDestroy case 'nrced': this.myForm.controls.publishNrced.setValue(event.checked); break; - case 'bcmi': + case 'bcmi': this.myForm.controls.publishBcmi.setValue(event.checked); break; default: @@ -475,12 +477,14 @@ export class AdministrativePenaltyAddEditComponent implements OnInit, OnDestroy this.myForm.get('dateIssued').value )); (this.myForm.controls.issuingAgency.dirty || this.defaultAgency) && - (administrativePenalty['issuingAgency'] = this.myForm.controls.issuingAgency.value); + (administrativePenalty['issuingAgency'] = Picklists.getAgencyCode( + this.factoryService, + this.myForm.controls.issuingAgency.value + )); + // (administrativePenalty['issuingAgency'] = this.myForm.controls.issuingAgency.value); this.myForm.controls.author.dirty && (administrativePenalty['author'] = this.myForm.controls.author.value); - if ( - this.myForm.get('association._epicProjectId').dirty - ) { + if (this.myForm.get('association._epicProjectId').dirty) { administrativePenalty['_epicProjectId'] = this.myForm.get('association._epicProjectId').value; } @@ -536,11 +540,12 @@ export class AdministrativePenaltyAddEditComponent implements OnInit, OnDestroy this.myForm.controls.location.dirty && (administrativePenalty['location'] = this.myForm.controls.location.value); administrativePenalty['centroid'] = []; if (this.myForm.controls.latitude.value && this.myForm.controls.longitude.value) { - (administrativePenalty['centroid'] = [this.myForm.controls.longitude.value, this.myForm.controls.latitude.value]); + administrativePenalty['centroid'] = [this.myForm.controls.longitude.value, this.myForm.controls.latitude.value]; } // tslint:disable-next-line:max-line-length - this.myForm.get('legislations').dirty && (administrativePenalty['legislation'] = this.parseLegislationsFormGroups()); + this.myForm.get('legislations').dirty && + (administrativePenalty['legislation'] = this.parseLegislationsFormGroups()); this.myForm.get('penalties').dirty && (administrativePenalty['penalties'] = this.parsePenaltiesFormGroups()); @@ -572,9 +577,8 @@ export class AdministrativePenaltyAddEditComponent implements OnInit, OnDestroy if (this.myForm.controls.bcmiSummary.dirty || this.myForm.controls.publishBcmi.dirty) { administrativePenalty['AdministrativePenaltyBCMI'] = {}; } - this.myForm.controls.bcmiSummary.dirty && ( - administrativePenalty['AdministrativePenaltyBCMI']['summary'] = this.myForm.controls.bcmiSummary.value - ); + this.myForm.controls.bcmiSummary.dirty && + (administrativePenalty['AdministrativePenaltyBCMI']['summary'] = this.myForm.controls.bcmiSummary.value); if (this.myForm.controls.publishBcmi.dirty && this.myForm.controls.publishBcmi.value) { administrativePenalty['AdministrativePenaltyBCMI']['addRole'] = 'public'; } else if (this.myForm.controls.publishBcmi.dirty && !this.myForm.controls.publishBcmi.value) { @@ -661,7 +665,8 @@ export class AdministrativePenaltyAddEditComponent implements OnInit, OnDestroy } displayName(agency) { - return Utils.displayNameFull(agency); + const agencyDataService = new AgencyDataService(this.factoryService); + return agencyDataService.displayNameFull(agency); } cancel() { diff --git a/angular/projects/admin-nrpti/src/app/records/administrative-penalties/administrative-penalty-bcmi-detail/administrative-penalty-bcmi-detail.component.spec.ts b/angular/projects/admin-nrpti/src/app/records/administrative-penalties/administrative-penalty-bcmi-detail/administrative-penalty-bcmi-detail.component.spec.ts index 7cfa09432..da8ef1ebb 100644 --- a/angular/projects/admin-nrpti/src/app/records/administrative-penalties/administrative-penalty-bcmi-detail/administrative-penalty-bcmi-detail.component.spec.ts +++ b/angular/projects/admin-nrpti/src/app/records/administrative-penalties/administrative-penalty-bcmi-detail/administrative-penalty-bcmi-detail.component.spec.ts @@ -17,17 +17,23 @@ describe('AdministrativePenaltyBCMIDetailComponent', () => { const mockRouter = jasmine.createSpyObj('Router', ['navigate']); const mockActivatedRoute = new ActivatedRouteStub(); - const mockFactoryService = jasmine.createSpyObj('FactoryService', ['userInLngRole', 'userInBcmiRole', 'userInNrcedRole', 'userOnlyInLimitedRole', 'userInRole']); + const mockFactoryService = jasmine.createSpyObj('FactoryService', [ + 'userInLngRole', + 'userInBcmiRole', + 'userInNrcedRole', + 'userOnlyInLimitedRole', + 'userInRole' + ]); mockFactoryService.userInLngRole.and.returnValue(true); mockFactoryService.userInBcmiRole.and.returnValue(true); mockFactoryService.userInNrcedRole.and.returnValue(true); const mockStoreService = { - getItem: () => { }, + getItem: () => {}, stateChange: new EventEmitter() }; - beforeEach((() => { + beforeEach(() => { TestBed.configureTestingModule({ imports: [RouterTestingModule, GlobalModule], declarations: [AdministrativePenaltyBCMIDetailComponent], @@ -39,7 +45,7 @@ describe('AdministrativePenaltyBCMIDetailComponent', () => { { provide: FactoryService, useValue: mockFactoryService } ] }).compileComponents(); - })); + }); it('should create', () => { const { component } = testBedHelper.createComponent(); diff --git a/angular/projects/admin-nrpti/src/app/records/administrative-penalties/administrative-penalty-bcmi-detail/administrative-penalty-bcmi-detail.component.ts b/angular/projects/admin-nrpti/src/app/records/administrative-penalties/administrative-penalty-bcmi-detail/administrative-penalty-bcmi-detail.component.ts index 5a3612894..130c77822 100644 --- a/angular/projects/admin-nrpti/src/app/records/administrative-penalties/administrative-penalty-bcmi-detail/administrative-penalty-bcmi-detail.component.ts +++ b/angular/projects/admin-nrpti/src/app/records/administrative-penalties/administrative-penalty-bcmi-detail/administrative-penalty-bcmi-detail.component.ts @@ -25,7 +25,7 @@ export class AdministrativePenaltyBCMIDetailComponent extends RecordComponent im public factoryService: FactoryService, private logger: LoggerService, public changeDetectionRef: ChangeDetectorRef, - public datePipe: DatePipe, + public datePipe: DatePipe ) { super(); } @@ -54,7 +54,9 @@ export class AdministrativePenaltyBCMIDetailComponent extends RecordComponent im const requiredRoles = Constants.FlavourEditRequiredRoles.ADMINISTRATIVE_PENALTY.BCMI; for (const role of requiredRoles) { - if (this.factoryService.userInRole(role) && this.data.write && this.data.write.includes(role)) { return true; } + if (this.factoryService.userInRole(role) && this.data.write && this.data.write.includes(role)) { + return true; + } } return false; diff --git a/angular/projects/admin-nrpti/src/app/records/administrative-penalties/administrative-penalty-detail/administrative-penalty-detail.component.html b/angular/projects/admin-nrpti/src/app/records/administrative-penalties/administrative-penalty-detail/administrative-penalty-detail.component.html index 0994e0655..fb718d000 100644 --- a/angular/projects/admin-nrpti/src/app/records/administrative-penalties/administrative-penalty-detail/administrative-penalty-detail.component.html +++ b/angular/projects/admin-nrpti/src/app/records/administrative-penalties/administrative-penalty-detail/administrative-penalty-detail.component.html @@ -87,7 +87,9 @@

Shared Data [Master]

- {{ data && data._master.centroid ? data._master.centroid[1] + '/' + data._master.centroid[0]: '-' }} + + {{ data && data._master.centroid ? data._master.centroid[1] + '/' + data._master.centroid[0] : '-' }} +
diff --git a/angular/projects/admin-nrpti/src/app/records/administrative-penalties/administrative-penalty-detail/administrative-penalty-detail.component.ts b/angular/projects/admin-nrpti/src/app/records/administrative-penalties/administrative-penalty-detail/administrative-penalty-detail.component.ts index f5c4bfc24..b1c1ffa13 100644 --- a/angular/projects/admin-nrpti/src/app/records/administrative-penalties/administrative-penalty-detail/administrative-penalty-detail.component.ts +++ b/angular/projects/admin-nrpti/src/app/records/administrative-penalties/administrative-penalty-detail/administrative-penalty-detail.component.ts @@ -7,7 +7,7 @@ import { RecordDetailComponent } from '../../utils/record-component'; import { RecordUtils } from '../../utils/record-utils'; import { Utils as CommonUtils } from '../../../../../../common/src/app/utils/utils'; import { FactoryService } from '../../../services/factory.service'; -import { Utils } from 'nrpti-angular-components'; +import { AgencyDataService } from '../../../../../../global/src/lib/utils/agency-data-service'; @Component({ selector: 'app-administrative-penalty-detail', @@ -60,7 +60,8 @@ export class AdministrativePenaltyDetailComponent extends RecordDetailComponent } displayName(agency) { - return Utils.displayNameFull(agency); + const agencyDataService = new AgencyDataService(this.factoryService); + return agencyDataService.displayNameFull(agency); } navigateToEditPage() { diff --git a/angular/projects/admin-nrpti/src/app/records/administrative-sanctions/administrative-sanction-add-edit/administrative-sanction-add-edit.component.ts b/angular/projects/admin-nrpti/src/app/records/administrative-sanctions/administrative-sanction-add-edit/administrative-sanction-add-edit.component.ts index c6cc1b37a..f6b1b280e 100644 --- a/angular/projects/admin-nrpti/src/app/records/administrative-sanctions/administrative-sanction-add-edit/administrative-sanction-add-edit.component.ts +++ b/angular/projects/admin-nrpti/src/app/records/administrative-sanctions/administrative-sanction-add-edit/administrative-sanction-add-edit.component.ts @@ -10,6 +10,7 @@ import { Utils as CommonUtils } from '../../../../../../common/src/app/utils/uti import { RecordUtils } from '../../utils/record-utils'; import { LoadingScreenService, LoggerService } from 'nrpti-angular-components'; import { Constants } from '../../../utils/constants/misc'; +import { AgencyDataService } from '../../../../../../../projects/global/src/lib/utils/agency-data-service'; @Component({ selector: 'app-administrative-sanction-add-edit', @@ -32,7 +33,7 @@ export class AdministrativeSanctionAddEditComponent implements OnInit, OnDestroy public nrcedPublishSubtext = 'Not published'; // Pick lists - public agencies = Picklists.agencyPicklist; + public agencies = Picklists.agencyCodePicklist; public authors = Picklists.authorPicklist; private defaultAgency = ''; @@ -546,7 +547,8 @@ export class AdministrativeSanctionAddEditComponent implements OnInit, OnDestroy } displayName(agency) { - return Utils.displayNameFull(agency); + const agencyDataService = new AgencyDataService(this.factoryService); + return agencyDataService.displayNameFull(agency); } cancel() { diff --git a/angular/projects/admin-nrpti/src/app/records/administrative-sanctions/administrative-sanction-detail/administrative-sanction-detail.component.ts b/angular/projects/admin-nrpti/src/app/records/administrative-sanctions/administrative-sanction-detail/administrative-sanction-detail.component.ts index c51923589..e65052557 100644 --- a/angular/projects/admin-nrpti/src/app/records/administrative-sanctions/administrative-sanction-detail/administrative-sanction-detail.component.ts +++ b/angular/projects/admin-nrpti/src/app/records/administrative-sanctions/administrative-sanction-detail/administrative-sanction-detail.component.ts @@ -7,7 +7,7 @@ import { RecordDetailComponent } from '../../utils/record-component'; import { RecordUtils } from '../../utils/record-utils'; import { Utils as CommonUtils } from '../../../../../../common/src/app/utils/utils'; import { FactoryService } from '../../../services/factory.service'; -import { Utils } from 'nrpti-angular-components'; +import { AgencyDataService } from '../../../../../../../projects/global/src/lib/utils/agency-data-service'; @Component({ selector: 'app-administrative-sanction-detail', @@ -60,7 +60,8 @@ export class AdministrativeSanctionDetailComponent extends RecordDetailComponent } displayName(agency) { - return Utils.displayNameFull(agency); + const agencyDataService = new AgencyDataService(this.factoryService); + return agencyDataService.displayNameFull(agency); } navigateToEditPage() { diff --git a/angular/projects/admin-nrpti/src/app/records/annual-reports/annual-report-add-edit/annual-report-add-edit.component.ts b/angular/projects/admin-nrpti/src/app/records/annual-reports/annual-report-add-edit/annual-report-add-edit.component.ts index ddac22488..0bf7fd1b9 100644 --- a/angular/projects/admin-nrpti/src/app/records/annual-reports/annual-report-add-edit/annual-report-add-edit.component.ts +++ b/angular/projects/admin-nrpti/src/app/records/annual-reports/annual-report-add-edit/annual-report-add-edit.component.ts @@ -10,6 +10,7 @@ import { Utils as CommonUtils } from '../../../../../../common/src/app/utils/uti import { RecordUtils } from '../../utils/record-utils'; import { LoadingScreenService, StoreService } from 'nrpti-angular-components'; import { Constants } from '../../../utils/constants/misc'; +import { AgencyDataService } from '../../../../../../../projects/global/src/lib/utils/agency-data-service'; @Component({ selector: 'app-annual-report-add-edit', @@ -30,7 +31,7 @@ export class AnnualReportAddEditComponent implements OnInit, OnDestroy { public bcmiPublishSubtext = 'Not published'; // Pick lists - public agencies = Picklists.agencyPicklist; + public agencies = Picklists.agencyCodePicklist; public datepickerMinDate = Constants.DatepickerMinDate; public datepickerMaxDate = Constants.DatepickerMaxDate; @@ -414,7 +415,8 @@ export class AnnualReportAddEditComponent implements OnInit, OnDestroy { } displayName(agency) { - return Utils.displayNameFull(agency); + const agencyDataService = new AgencyDataService(this.factoryService); + return agencyDataService.displayNameFull(agency); } cancel() { diff --git a/angular/projects/admin-nrpti/src/app/records/annual-reports/annual-report-detail/annual-report-detail.component.ts b/angular/projects/admin-nrpti/src/app/records/annual-reports/annual-report-detail/annual-report-detail.component.ts index ac040825c..c85df69c0 100644 --- a/angular/projects/admin-nrpti/src/app/records/annual-reports/annual-report-detail/annual-report-detail.component.ts +++ b/angular/projects/admin-nrpti/src/app/records/annual-reports/annual-report-detail/annual-report-detail.component.ts @@ -7,7 +7,7 @@ import { RecordDetailComponent } from '../../utils/record-component'; import { RecordUtils } from '../../utils/record-utils'; import { Utils as CommonUtils } from '../../../../../../common/src/app/utils/utils'; import { FactoryService } from '../../../services/factory.service'; -import { Utils } from 'nrpti-angular-components'; +import { AgencyDataService } from '../../../../../../../projects/global/src/lib/utils/agency-data-service'; @Component({ selector: 'app-annual-report-detail', @@ -64,7 +64,8 @@ export class AnnualReportDetailComponent extends RecordDetailComponent implement } displayName(agency) { - return Utils.displayNameFull(agency); + const agencyDataService = new AgencyDataService(this.factoryService); + return agencyDataService.displayNameFull(agency); } ngOnDestroy() { diff --git a/angular/projects/admin-nrpti/src/app/records/certificate-amendments/certificate-amendments-add-edit/certificate-amendments-add-edit.component.ts b/angular/projects/admin-nrpti/src/app/records/certificate-amendments/certificate-amendments-add-edit/certificate-amendments-add-edit.component.ts index 7e97e1672..7ca86b85f 100644 --- a/angular/projects/admin-nrpti/src/app/records/certificate-amendments/certificate-amendments-add-edit/certificate-amendments-add-edit.component.ts +++ b/angular/projects/admin-nrpti/src/app/records/certificate-amendments/certificate-amendments-add-edit/certificate-amendments-add-edit.component.ts @@ -10,6 +10,7 @@ import { Utils as CommonUtils } from '../../../../../../common/src/app/utils/uti import { RecordUtils } from '../../utils/record-utils'; import { LoadingScreenService, StoreService } from 'nrpti-angular-components'; import { Constants } from '../../../utils/constants/misc'; +import { AgencyDataService } from '../../../../../../../projects/global/src/lib/utils/agency-data-service'; @Component({ selector: 'app-certificate-amendment-add-edit', @@ -33,7 +34,7 @@ export class CertificateAmendmentAddEditComponent implements OnInit, OnDestroy { // Pick lists public certificateSubtypes = Picklists.certificateSubtypePicklist; - public agencies = Picklists.agencyPicklist; + public agencies = Picklists.agencyCodePicklist; public datepickerMinDate = Constants.DatepickerMinDate; public datepickerMaxDate = Constants.DatepickerMaxDate; @@ -482,7 +483,8 @@ export class CertificateAmendmentAddEditComponent implements OnInit, OnDestroy { } displayName(agency) { - return Utils.displayNameFull(agency); + const agencyDataService = new AgencyDataService(this.factoryService); + return agencyDataService.displayNameFull(agency); } cancel() { diff --git a/angular/projects/admin-nrpti/src/app/records/certificate-amendments/certificate-amendments-detail/certificate-amendments-detail.component.ts b/angular/projects/admin-nrpti/src/app/records/certificate-amendments/certificate-amendments-detail/certificate-amendments-detail.component.ts index eaa68c522..ac4478584 100644 --- a/angular/projects/admin-nrpti/src/app/records/certificate-amendments/certificate-amendments-detail/certificate-amendments-detail.component.ts +++ b/angular/projects/admin-nrpti/src/app/records/certificate-amendments/certificate-amendments-detail/certificate-amendments-detail.component.ts @@ -7,7 +7,7 @@ import { RecordDetailComponent } from '../../utils/record-component'; import { RecordUtils } from '../../utils/record-utils'; import { Utils as CommonUtils } from '../../../../../../common/src/app/utils/utils'; import { FactoryService } from '../../../services/factory.service'; -import { Utils } from 'nrpti-angular-components'; +import { AgencyDataService } from '../../../../../../../projects/global/src/lib/utils/agency-data-service'; @Component({ selector: 'app-certificate-amendment-detail', @@ -64,7 +64,8 @@ export class CertificateAmendmentDetailComponent extends RecordDetailComponent i } displayName(agency) { - return Utils.displayNameFull(agency); + const agencyDataService = new AgencyDataService(this.factoryService); + return agencyDataService.displayNameFull(agency); } ngOnDestroy() { diff --git a/angular/projects/admin-nrpti/src/app/records/certificates/certificate-add-edit/certificate-add-edit.component.ts b/angular/projects/admin-nrpti/src/app/records/certificates/certificate-add-edit/certificate-add-edit.component.ts index 5950c2b68..70ea1dc4d 100644 --- a/angular/projects/admin-nrpti/src/app/records/certificates/certificate-add-edit/certificate-add-edit.component.ts +++ b/angular/projects/admin-nrpti/src/app/records/certificates/certificate-add-edit/certificate-add-edit.component.ts @@ -10,6 +10,7 @@ import { Utils as CommonUtils } from '../../../../../../common/src/app/utils/uti import { RecordUtils } from '../../utils/record-utils'; import { LoadingScreenService, StoreService, LoggerService } from 'nrpti-angular-components'; import { Constants } from '../../../utils/constants/misc'; +import { AgencyDataService } from '../../../../../../../projects/global/src/lib/utils/agency-data-service'; @Component({ selector: 'app-certificate-add-edit', @@ -31,7 +32,7 @@ export class CertificateAddEditComponent implements OnInit, OnDestroy { // Pick lists public certificateSubtypes = Picklists.certificateSubtypePicklist; - public agencies = Picklists.agencyPicklist; + public agencies = Picklists.agencyCodePicklist; public datepickerMinDate = Constants.DatepickerMinDate; public datepickerMaxDate = Constants.DatepickerMaxDate; @@ -390,7 +391,8 @@ export class CertificateAddEditComponent implements OnInit, OnDestroy { } displayName(agency) { - return Utils.displayNameFull(agency); + const agencyDataService = new AgencyDataService(this.factoryService); + return agencyDataService.displayNameFull(agency); } ngOnDestroy(): void { diff --git a/angular/projects/admin-nrpti/src/app/records/certificates/certificate-detail/certificate-detail.component.ts b/angular/projects/admin-nrpti/src/app/records/certificates/certificate-detail/certificate-detail.component.ts index 298668b27..9e3d02ffb 100644 --- a/angular/projects/admin-nrpti/src/app/records/certificates/certificate-detail/certificate-detail.component.ts +++ b/angular/projects/admin-nrpti/src/app/records/certificates/certificate-detail/certificate-detail.component.ts @@ -7,7 +7,7 @@ import { RecordDetailComponent } from '../../utils/record-component'; import { RecordUtils } from '../../utils/record-utils'; import { Utils as CommonUtils } from '../../../../../../common/src/app/utils/utils'; import { FactoryService } from '../../../services/factory.service'; -import { Utils } from 'nrpti-angular-components'; +import { AgencyDataService } from '../../../../../../../projects/global/src/lib/utils/agency-data-service'; @Component({ selector: 'app-certificate-detail', @@ -64,7 +64,8 @@ export class CertificateDetailComponent extends RecordDetailComponent implements } displayName(agency) { - return Utils.displayNameFull(agency); + const agencyDataService = new AgencyDataService(this.factoryService); + return agencyDataService.displayNameFull(agency); } ngOnDestroy() { diff --git a/angular/projects/admin-nrpti/src/app/records/construction-plans/construction-plan-add-edit/construction-plan-add-edit.component.ts b/angular/projects/admin-nrpti/src/app/records/construction-plans/construction-plan-add-edit/construction-plan-add-edit.component.ts index 39ad0bcb7..23b1814ef 100644 --- a/angular/projects/admin-nrpti/src/app/records/construction-plans/construction-plan-add-edit/construction-plan-add-edit.component.ts +++ b/angular/projects/admin-nrpti/src/app/records/construction-plans/construction-plan-add-edit/construction-plan-add-edit.component.ts @@ -10,6 +10,7 @@ import { Utils as CommonUtils } from '../../../../../../common/src/app/utils/uti import { RecordUtils } from '../../utils/record-utils'; import { LoadingScreenService, StoreService, LoggerService } from 'nrpti-angular-components'; import { Constants } from '../../../utils/constants/misc'; +import { AgencyDataService } from '../../../../../../../projects/global/src/lib/utils/agency-data-service'; @Component({ selector: 'app-construction-plan-add-edit', @@ -30,7 +31,7 @@ export class ConstructionPlanAddEditComponent implements OnInit, OnDestroy { public lngPublishSubtext = 'Not published'; // Pick lists - public agencies = Picklists.agencyPicklist; + public agencies = Picklists.agencyCodePicklist; // Documents public documents = []; @@ -305,7 +306,8 @@ export class ConstructionPlanAddEditComponent implements OnInit, OnDestroy { } displayName(agency) { - return Utils.displayNameFull(agency); + const agencyDataService = new AgencyDataService(this.factoryService); + return agencyDataService.displayNameFull(agency); } cancel() { diff --git a/angular/projects/admin-nrpti/src/app/records/construction-plans/construction-plan-detail/construction-plan-detail.component.ts b/angular/projects/admin-nrpti/src/app/records/construction-plans/construction-plan-detail/construction-plan-detail.component.ts index 4781517cf..9d232f766 100644 --- a/angular/projects/admin-nrpti/src/app/records/construction-plans/construction-plan-detail/construction-plan-detail.component.ts +++ b/angular/projects/admin-nrpti/src/app/records/construction-plans/construction-plan-detail/construction-plan-detail.component.ts @@ -6,7 +6,7 @@ import { ActivatedRoute, Router } from '@angular/router'; import { RecordDetailComponent } from '../../utils/record-component'; import { RecordUtils } from '../../utils/record-utils'; import { FactoryService } from '../../../services/factory.service'; -import { Utils } from 'nrpti-angular-components'; +import { AgencyDataService } from '../../../../../../../projects/global/src/lib/utils/agency-data-service'; @Component({ selector: 'app-construction-plan-detail', @@ -54,7 +54,8 @@ export class ConstructionPlanDetailComponent extends RecordDetailComponent imple } displayName(agency) { - return Utils.displayNameFull(agency); + const agencyDataService = new AgencyDataService(this.factoryService); + return agencyDataService.displayNameFull(agency); } ngOnDestroy() { diff --git a/angular/projects/admin-nrpti/src/app/records/correspondences/correspondence-add-edit/correspondence-add-edit.component.ts b/angular/projects/admin-nrpti/src/app/records/correspondences/correspondence-add-edit/correspondence-add-edit.component.ts index 293090893..3de9d0edc 100644 --- a/angular/projects/admin-nrpti/src/app/records/correspondences/correspondence-add-edit/correspondence-add-edit.component.ts +++ b/angular/projects/admin-nrpti/src/app/records/correspondences/correspondence-add-edit/correspondence-add-edit.component.ts @@ -10,6 +10,7 @@ import { Utils as CommonUtils } from '../../../../../../common/src/app/utils/uti import { RecordUtils } from '../../utils/record-utils'; import { LoadingScreenService, StoreService } from 'nrpti-angular-components'; import { Constants } from '../../../utils/constants/misc'; +import { AgencyDataService } from '../../../../../../../projects/global/src/lib/utils/agency-data-service'; @Component({ selector: 'app-correspondence-add-edit', @@ -32,7 +33,7 @@ export class CorrespondenceAddEditComponent implements OnInit, OnDestroy { public bcmiPublishSubtext = 'Not published'; // Pick lists - public agencies = Picklists.agencyPicklist; + public agencies = Picklists.agencyCodePicklist; // Documents public documents = []; @@ -477,7 +478,8 @@ export class CorrespondenceAddEditComponent implements OnInit, OnDestroy { } displayName(agency) { - return Utils.displayNameFull(agency); + const agencyDataService = new AgencyDataService(this.factoryService); + return agencyDataService.displayNameFull(agency); } cancel() { diff --git a/angular/projects/admin-nrpti/src/app/records/correspondences/correspondence-detail/correspondence-detail.component.ts b/angular/projects/admin-nrpti/src/app/records/correspondences/correspondence-detail/correspondence-detail.component.ts index aea343150..e810532cb 100644 --- a/angular/projects/admin-nrpti/src/app/records/correspondences/correspondence-detail/correspondence-detail.component.ts +++ b/angular/projects/admin-nrpti/src/app/records/correspondences/correspondence-detail/correspondence-detail.component.ts @@ -7,7 +7,7 @@ import { RecordDetailComponent } from '../../utils/record-component'; import { RecordUtils } from '../../utils/record-utils'; import { Utils as CommonUtils } from '../../../../../../common/src/app/utils/utils'; import { FactoryService } from '../../../services/factory.service'; -import { Utils } from 'nrpti-angular-components'; +import { AgencyDataService } from '../../../../../../../projects/global/src/lib/utils/agency-data-service'; @Component({ selector: 'app-correspondence-detail', @@ -64,7 +64,8 @@ export class CorrespondenceDetailComponent extends RecordDetailComponent impleme } displayName(agency) { - return Utils.displayNameFull(agency); + const agencyDataService = new AgencyDataService(this.factoryService); + return agencyDataService.displayNameFull(agency); } ngOnDestroy() { diff --git a/angular/projects/admin-nrpti/src/app/records/court-convictions/court-conviction-add-edit/court-conviction-add-edit.component.ts b/angular/projects/admin-nrpti/src/app/records/court-convictions/court-conviction-add-edit/court-conviction-add-edit.component.ts index 6034f690d..72b417415 100644 --- a/angular/projects/admin-nrpti/src/app/records/court-convictions/court-conviction-add-edit/court-conviction-add-edit.component.ts +++ b/angular/projects/admin-nrpti/src/app/records/court-convictions/court-conviction-add-edit/court-conviction-add-edit.component.ts @@ -9,6 +9,7 @@ import { Utils, LoadingScreenService, LoggerService, StoreService } from 'nrpti- import { Utils as CommonUtils } from '../../../../../../common/src/app/utils/utils'; import { RecordUtils } from '../../utils/record-utils'; import { Constants } from '../../../utils/constants/misc'; +import { AgencyDataService } from '../../../../../../../projects/global/src/lib/utils/agency-data-service'; @Component({ selector: 'app-court-conviction-add-edit', @@ -33,7 +34,7 @@ export class CourtConvictionAddEditComponent implements OnInit, OnDestroy { public bcmiPublishSubtext = 'Not published'; // Pick lists - public agencies = Picklists.agencyPicklist; + public agencies = Picklists.agencyCodePicklist; public authors = Picklists.authorPicklist; public courtConvictionSubtypes = Picklists.courtConvictionSubtypePicklist; protected defaultAgency = ''; @@ -636,7 +637,8 @@ export class CourtConvictionAddEditComponent implements OnInit, OnDestroy { } displayName(agency) { - return Utils.displayNameFull(agency); + const agencyDataService = new AgencyDataService(this.factoryService); + return agencyDataService.displayNameFull(agency); } cancel() { diff --git a/angular/projects/admin-nrpti/src/app/records/court-convictions/court-conviction-detail/court-conviction-detail.component.ts b/angular/projects/admin-nrpti/src/app/records/court-convictions/court-conviction-detail/court-conviction-detail.component.ts index bfb373cef..e2f64fb5f 100644 --- a/angular/projects/admin-nrpti/src/app/records/court-convictions/court-conviction-detail/court-conviction-detail.component.ts +++ b/angular/projects/admin-nrpti/src/app/records/court-convictions/court-conviction-detail/court-conviction-detail.component.ts @@ -7,7 +7,7 @@ import { RecordDetailComponent } from '../../utils/record-component'; import { RecordUtils } from '../../utils/record-utils'; import { Utils as CommonUtils } from '../../../../../../common/src/app/utils/utils'; import { FactoryService } from '../../../services/factory.service'; -import { Utils } from 'nrpti-angular-components'; +import { AgencyDataService } from '../../../../../../../projects/global/src/lib/utils/agency-data-service'; @Component({ selector: 'app-court-conviction-detail', @@ -64,7 +64,8 @@ export class CourtConvictionDetailComponent extends RecordDetailComponent implem } displayName(agency) { - return Utils.displayNameFull(agency); + const agencyDataService = new AgencyDataService(this.factoryService); + return agencyDataService.displayNameFull(agency); } ngOnDestroy() { diff --git a/angular/projects/admin-nrpti/src/app/records/dam-safety-inspections/dam-safety-inspection-add-edit/dam-safety-inspection-add-edit.component.ts b/angular/projects/admin-nrpti/src/app/records/dam-safety-inspections/dam-safety-inspection-add-edit/dam-safety-inspection-add-edit.component.ts index bb760afe2..5ebee5cd2 100644 --- a/angular/projects/admin-nrpti/src/app/records/dam-safety-inspections/dam-safety-inspection-add-edit/dam-safety-inspection-add-edit.component.ts +++ b/angular/projects/admin-nrpti/src/app/records/dam-safety-inspections/dam-safety-inspection-add-edit/dam-safety-inspection-add-edit.component.ts @@ -10,6 +10,7 @@ import { Utils as CommonUtils } from '../../../../../../common/src/app/utils/uti import { RecordUtils } from '../../utils/record-utils'; import { LoadingScreenService, StoreService } from 'nrpti-angular-components'; import { Constants } from '../../../utils/constants/misc'; +import { AgencyDataService } from '../../../../../../../projects/global/src/lib/utils/agency-data-service'; @Component({ selector: 'app-dam-safety-inspection-add-edit', @@ -32,7 +33,7 @@ export class DamSafetyInspectionAddEditComponent implements OnInit, OnDestroy { public bcmiPublishSubtext = 'Not published'; // Pick lists - public agencies = Picklists.agencyPicklist; + public agencies = Picklists.agencyCodePicklist; // Documents public documents = []; @@ -492,7 +493,8 @@ export class DamSafetyInspectionAddEditComponent implements OnInit, OnDestroy { } displayName(agency) { - return Utils.displayNameFull(agency); + const agencyDataService = new AgencyDataService(this.factoryService); + return agencyDataService.displayNameFull(agency); } ngOnDestroy(): void { diff --git a/angular/projects/admin-nrpti/src/app/records/dam-safety-inspections/dam-safety-inspection-detail/dam-safety-inspection-detail.component.ts b/angular/projects/admin-nrpti/src/app/records/dam-safety-inspections/dam-safety-inspection-detail/dam-safety-inspection-detail.component.ts index 03505382a..58297c1e5 100644 --- a/angular/projects/admin-nrpti/src/app/records/dam-safety-inspections/dam-safety-inspection-detail/dam-safety-inspection-detail.component.ts +++ b/angular/projects/admin-nrpti/src/app/records/dam-safety-inspections/dam-safety-inspection-detail/dam-safety-inspection-detail.component.ts @@ -7,7 +7,7 @@ import { RecordDetailComponent } from '../../utils/record-component'; import { RecordUtils } from '../../utils/record-utils'; import { Utils as CommonUtils } from '../../../../../../common/src/app/utils/utils'; import { FactoryService } from '../../../services/factory.service'; -import { Utils } from 'nrpti-angular-components'; +import { AgencyDataService } from '../../../../../../../projects/global/src/lib/utils/agency-data-service'; @Component({ selector: 'app-dam-safety-inspection-detail', @@ -64,7 +64,8 @@ export class DamSafetyInspectionDetailComponent extends RecordDetailComponent im } displayName(agency) { - return Utils.displayNameFull(agency); + const agencyDataService = new AgencyDataService(this.factoryService); + return agencyDataService.displayNameFull(agency); } ngOnDestroy() { diff --git a/angular/projects/admin-nrpti/src/app/records/inspections/inspection-add-edit/inspection-add-edit.component.ts b/angular/projects/admin-nrpti/src/app/records/inspections/inspection-add-edit/inspection-add-edit.component.ts index 4b6a46a62..07a6cfd0f 100644 --- a/angular/projects/admin-nrpti/src/app/records/inspections/inspection-add-edit/inspection-add-edit.component.ts +++ b/angular/projects/admin-nrpti/src/app/records/inspections/inspection-add-edit/inspection-add-edit.component.ts @@ -10,6 +10,7 @@ import { Utils as CommonUtils } from '../../../../../../common/src/app/utils/uti import { RecordUtils } from '../../utils/record-utils'; import { LoadingScreenService, StoreService, LoggerService } from 'nrpti-angular-components'; import { Constants } from '../../../utils/constants/misc'; +import { AgencyDataService } from '../../../../../../../projects/global/src/lib/utils/agency-data-service'; @Component({ selector: 'app-inspection-add-edit', @@ -32,7 +33,7 @@ export class InspectionAddEditComponent implements OnInit, OnDestroy { public nrcedPublishSubtext = 'Not published'; // Pick lists - public agencies = Picklists.agencyPicklist; + public agencies = Picklists.agencyCodePicklist; public authors = Picklists.authorPicklist; public outcomeStatuses = Picklists.outcomeStatusPicklist; private defaultAgency = ''; @@ -515,7 +516,8 @@ export class InspectionAddEditComponent implements OnInit, OnDestroy { } displayName(agency) { - return Utils.displayNameFull(agency); + const agencyDataService = new AgencyDataService(this.factoryService); + return agencyDataService.displayNameFull(agency); } cancel() { diff --git a/angular/projects/admin-nrpti/src/app/records/inspections/inspection-detail/inspection-detail.component.ts b/angular/projects/admin-nrpti/src/app/records/inspections/inspection-detail/inspection-detail.component.ts index 5903a178a..feb86b3ac 100644 --- a/angular/projects/admin-nrpti/src/app/records/inspections/inspection-detail/inspection-detail.component.ts +++ b/angular/projects/admin-nrpti/src/app/records/inspections/inspection-detail/inspection-detail.component.ts @@ -7,7 +7,7 @@ import { RecordDetailComponent } from '../../utils/record-component'; import { RecordUtils } from '../../utils/record-utils'; import { Utils as CommonUtils } from '../../../../../../common/src/app/utils/utils'; import { FactoryService } from '../../../services/factory.service'; -import { Utils } from 'nrpti-angular-components'; +import { AgencyDataService } from '../../../../../../../projects/global/src/lib/utils/agency-data-service'; @Component({ selector: 'app-inspection-detail', @@ -23,7 +23,7 @@ export class InspectionDetailComponent extends RecordDetailComponent implements public route: ActivatedRoute, public router: Router, public changeDetectionRef: ChangeDetectorRef, - public factoryService: FactoryService + public factoryService: FactoryService, ) { super(factoryService); } @@ -64,7 +64,8 @@ export class InspectionDetailComponent extends RecordDetailComponent implements } displayName(agency) { - return Utils.displayNameFull(agency); + const agencyDataService = new AgencyDataService(this.factoryService); + return agencyDataService.displayNameFull(agency); } ngOnDestroy() { diff --git a/angular/projects/admin-nrpti/src/app/records/management-plans/management-plan-add-edit/management-plan-add-edit.component.ts b/angular/projects/admin-nrpti/src/app/records/management-plans/management-plan-add-edit/management-plan-add-edit.component.ts index 2c74fd446..1ccb362fb 100644 --- a/angular/projects/admin-nrpti/src/app/records/management-plans/management-plan-add-edit/management-plan-add-edit.component.ts +++ b/angular/projects/admin-nrpti/src/app/records/management-plans/management-plan-add-edit/management-plan-add-edit.component.ts @@ -10,6 +10,7 @@ import { Utils as CommonUtils } from '../../../../../../common/src/app/utils/uti import { RecordUtils } from '../../utils/record-utils'; import { LoadingScreenService, StoreService, LoggerService } from 'nrpti-angular-components'; import { Constants } from '../../../utils/constants/misc'; +import { AgencyDataService } from '../../../../../../../projects/global/src/lib/utils/agency-data-service'; @Component({ selector: 'app-management-plan-add-edit', @@ -30,7 +31,7 @@ export class ManagementPlanAddEditComponent implements OnInit, OnDestroy { public lngPublishSubtext = 'Not published'; // Pick lists - public agencies = Picklists.agencyPicklist; + public agencies = Picklists.agencyCodePicklist; // Documents public documents = []; @@ -306,7 +307,8 @@ export class ManagementPlanAddEditComponent implements OnInit, OnDestroy { } displayName(agency) { - return Utils.displayNameFull(agency); + const agencyDataService = new AgencyDataService(this.factoryService); + return agencyDataService.displayNameFull(agency); } cancel() { diff --git a/angular/projects/admin-nrpti/src/app/records/management-plans/management-plan-detail/management-plan-detail.component.ts b/angular/projects/admin-nrpti/src/app/records/management-plans/management-plan-detail/management-plan-detail.component.ts index 895ac2ba6..8d40a3875 100644 --- a/angular/projects/admin-nrpti/src/app/records/management-plans/management-plan-detail/management-plan-detail.component.ts +++ b/angular/projects/admin-nrpti/src/app/records/management-plans/management-plan-detail/management-plan-detail.component.ts @@ -5,7 +5,8 @@ import { Subject } from 'rxjs'; import { ActivatedRoute, Router } from '@angular/router'; import { RecordComponent } from '../../utils/record-component'; import { RecordUtils } from '../../utils/record-utils'; -import { Utils } from 'nrpti-angular-components'; +import { AgencyDataService } from '../../../../../../../projects/global/src/lib/utils/agency-data-service'; +import { FactoryService } from '../../../services/factory.service'; @Component({ selector: 'app-management-plan-detail', @@ -15,7 +16,8 @@ import { Utils } from 'nrpti-angular-components'; export class ManagementPlanDetailComponent extends RecordComponent implements OnInit, OnDestroy { private ngUnsubscribe: Subject = new Subject(); - constructor(public route: ActivatedRoute, public router: Router, public changeDetectionRef: ChangeDetectorRef) { + constructor(public route: ActivatedRoute, public router: Router, public changeDetectionRef: ChangeDetectorRef + , public factoryService: FactoryService) { super(); } @@ -46,7 +48,8 @@ export class ManagementPlanDetailComponent extends RecordComponent implements On } displayName(agency) { - return Utils.displayNameFull(agency); + const agencyDataService = new AgencyDataService(this.factoryService); + return agencyDataService.displayNameFull(agency); } ngOnDestroy() { @@ -54,3 +57,4 @@ export class ManagementPlanDetailComponent extends RecordComponent implements On this.ngUnsubscribe.complete(); } } + diff --git a/angular/projects/admin-nrpti/src/app/records/orders/order-add-edit/order-add-edit.component.ts b/angular/projects/admin-nrpti/src/app/records/orders/order-add-edit/order-add-edit.component.ts index 68877ef24..c0d4511a9 100644 --- a/angular/projects/admin-nrpti/src/app/records/orders/order-add-edit/order-add-edit.component.ts +++ b/angular/projects/admin-nrpti/src/app/records/orders/order-add-edit/order-add-edit.component.ts @@ -10,6 +10,7 @@ import { Utils as CommonUtils } from '../../../../../../common/src/app/utils/uti import { RecordUtils } from '../../utils/record-utils'; import { LoadingScreenService, StoreService, LoggerService } from 'nrpti-angular-components'; import { Constants } from '../../../utils/constants/misc'; +import { AgencyDataService } from '../../../../../../../projects/global/src/lib/utils/agency-data-service'; @Component({ selector: 'app-order-add-edit', @@ -33,7 +34,7 @@ export class OrderAddEditComponent implements OnInit, OnDestroy { // Pick lists public orderSubtypePicklist = Picklists.orderSubtypePicklist; - public agencies = Picklists.agencyPicklist; + public agencies = Picklists.agencyCodePicklist; public authors = Picklists.authorPicklist; public outcomeStatuses = Picklists.outcomeStatusPicklist; private defaultAgency = ''; @@ -55,7 +56,7 @@ export class OrderAddEditComponent implements OnInit, OnDestroy { private logger: LoggerService, private loadingScreenService: LoadingScreenService, private utils: Utils, - private _changeDetectionRef: ChangeDetectorRef + private _changeDetectionRef: ChangeDetectorRef, ) { } ngOnInit() { @@ -522,7 +523,8 @@ export class OrderAddEditComponent implements OnInit, OnDestroy { } displayName(agency) { - return Utils.displayNameFull(agency); + const agencyDataService = new AgencyDataService(this.factoryService); + return agencyDataService.displayNameFull(agency); } cancel() { diff --git a/angular/projects/admin-nrpti/src/app/records/orders/order-detail/order-detail.component.ts b/angular/projects/admin-nrpti/src/app/records/orders/order-detail/order-detail.component.ts index 3abeeece7..f5412d01d 100644 --- a/angular/projects/admin-nrpti/src/app/records/orders/order-detail/order-detail.component.ts +++ b/angular/projects/admin-nrpti/src/app/records/orders/order-detail/order-detail.component.ts @@ -7,7 +7,7 @@ import { RecordDetailComponent } from '../../utils/record-component'; import { RecordUtils } from '../../utils/record-utils'; import { Utils as CommonUtils } from '../../../../../../common/src/app/utils/utils'; import { FactoryService } from '../../../services/factory.service'; -import { Utils } from 'nrpti-angular-components'; +import { AgencyDataService } from '../../../../../../../projects/global/src/lib/utils/agency-data-service'; @Component({ selector: 'app-order-detail', @@ -64,7 +64,8 @@ export class OrderDetailComponent extends RecordDetailComponent implements OnIni } displayName(agency) { - return Utils.displayNameFull(agency); + const agencyDataService = new AgencyDataService(this.factoryService); + return agencyDataService.displayNameFull(agency); } ngOnDestroy() { diff --git a/angular/projects/admin-nrpti/src/app/records/permits/permit-add-edit/permit-add-edit.component.ts b/angular/projects/admin-nrpti/src/app/records/permits/permit-add-edit/permit-add-edit.component.ts index b94839cae..924a48bf6 100644 --- a/angular/projects/admin-nrpti/src/app/records/permits/permit-add-edit/permit-add-edit.component.ts +++ b/angular/projects/admin-nrpti/src/app/records/permits/permit-add-edit/permit-add-edit.component.ts @@ -10,6 +10,7 @@ import { Utils as CommonUtils } from '../../../../../../common/src/app/utils/uti import { RecordUtils } from '../../utils/record-utils'; import { LoadingScreenService, StoreService } from 'nrpti-angular-components'; import { Constants } from '../../../utils/constants/misc'; +import { AgencyDataService } from '../../../../../../../projects/global/src/lib/utils/agency-data-service'; @Component({ selector: 'app-permit-add-edit', @@ -31,7 +32,7 @@ export class PermitAddEditComponent implements OnInit, OnDestroy { // Pick lists public permitSubtypes = Picklists.permitSubtypePicklist; - public agencies = Picklists.agencyPicklist; + public agencies = Picklists.agencyCodePicklist; private defaultAgency = ''; // Documents @@ -376,7 +377,8 @@ export class PermitAddEditComponent implements OnInit, OnDestroy { } displayName(agency) { - return Utils.displayNameFull(agency); + const agencyDataService = new AgencyDataService(this.factoryService); + return agencyDataService.displayNameFull(agency); } cancel() { diff --git a/angular/projects/admin-nrpti/src/app/records/permits/permit-detail/permit-detail.component.ts b/angular/projects/admin-nrpti/src/app/records/permits/permit-detail/permit-detail.component.ts index f8162642a..682e1beb0 100644 --- a/angular/projects/admin-nrpti/src/app/records/permits/permit-detail/permit-detail.component.ts +++ b/angular/projects/admin-nrpti/src/app/records/permits/permit-detail/permit-detail.component.ts @@ -8,7 +8,7 @@ import { RecordUtils } from '../../utils/record-utils'; import { Utils as CommonUtils } from '../../../../../../common/src/app/utils/utils'; import { FactoryService } from '../../../services/factory.service'; import { StoreService } from 'nrpti-angular-components'; -import { Utils } from 'nrpti-angular-components'; +import { AgencyDataService } from '../../../../../../../projects/global/src/lib/utils/agency-data-service'; @Component({ selector: 'app-permit-detail', @@ -68,7 +68,8 @@ export class PermitDetailComponent extends RecordDetailComponent implements OnIn } displayName(agency) { - return Utils.displayNameFull(agency); + const agencyDataService = new AgencyDataService(this.factoryService); + return agencyDataService.displayNameFull(agency); } ngOnDestroy() { diff --git a/angular/projects/admin-nrpti/src/app/records/reports/report-add-edit/report-add-edit.component.ts b/angular/projects/admin-nrpti/src/app/records/reports/report-add-edit/report-add-edit.component.ts index 8ec105758..2921e8483 100644 --- a/angular/projects/admin-nrpti/src/app/records/reports/report-add-edit/report-add-edit.component.ts +++ b/angular/projects/admin-nrpti/src/app/records/reports/report-add-edit/report-add-edit.component.ts @@ -10,6 +10,7 @@ import { Utils as CommonUtils } from '../../../../../../common/src/app/utils/uti import { RecordUtils } from '../../utils/record-utils'; import { LoadingScreenService, StoreService } from 'nrpti-angular-components'; import { Constants } from '../../../utils/constants/misc'; +import { AgencyDataService } from '../../../../../../../projects/global/src/lib/utils/agency-data-service'; @Component({ selector: 'app-report-add-edit', @@ -32,7 +33,7 @@ export class ReportAddEditComponent implements OnInit, OnDestroy { public bcmiPublishSubtext = 'Not published'; // Pick lists - public agencies = Picklists.agencyPicklist; + public agencies = Picklists.agencyCodePicklist; // Documents public documents = []; @@ -479,7 +480,8 @@ export class ReportAddEditComponent implements OnInit, OnDestroy { } displayName(agency) { - return Utils.displayNameFull(agency); + const agencyDataService = new AgencyDataService(this.factoryService); + return agencyDataService.displayNameFull(agency); } cancel() { diff --git a/angular/projects/admin-nrpti/src/app/records/reports/report-detail/report-detail.component.ts b/angular/projects/admin-nrpti/src/app/records/reports/report-detail/report-detail.component.ts index 78c8033da..76beee24b 100644 --- a/angular/projects/admin-nrpti/src/app/records/reports/report-detail/report-detail.component.ts +++ b/angular/projects/admin-nrpti/src/app/records/reports/report-detail/report-detail.component.ts @@ -7,7 +7,7 @@ import { RecordDetailComponent } from '../../utils/record-component'; import { RecordUtils } from '../../utils/record-utils'; import { Utils as CommonUtils } from '../../../../../../common/src/app/utils/utils'; import { FactoryService } from '../../../services/factory.service'; -import { Utils } from 'nrpti-angular-components'; +import { AgencyDataService } from '../../../../../../../projects/global/src/lib/utils/agency-data-service'; @Component({ selector: 'app-report-detail', @@ -64,7 +64,8 @@ export class ReportDetailComponent extends RecordDetailComponent implements OnIn } displayName(agency) { - return Utils.displayNameFull(agency); + const agencyDataService = new AgencyDataService(this.factoryService); + return agencyDataService.displayNameFull(agency); } ngOnDestroy() { diff --git a/angular/projects/admin-nrpti/src/app/records/restorative-justices/restorative-justice-add-edit/restorative-justice-add-edit.component.ts b/angular/projects/admin-nrpti/src/app/records/restorative-justices/restorative-justice-add-edit/restorative-justice-add-edit.component.ts index e014b2048..efb52c90e 100644 --- a/angular/projects/admin-nrpti/src/app/records/restorative-justices/restorative-justice-add-edit/restorative-justice-add-edit.component.ts +++ b/angular/projects/admin-nrpti/src/app/records/restorative-justices/restorative-justice-add-edit/restorative-justice-add-edit.component.ts @@ -10,6 +10,7 @@ import { Utils as CommonUtils } from '../../../../../../common/src/app/utils/uti import { RecordUtils } from '../../utils/record-utils'; import { LoadingScreenService, LoggerService } from 'nrpti-angular-components'; import { Constants } from '../../../utils/constants/misc'; +import { AgencyDataService } from '../../../../../../../projects/global/src/lib/utils/agency-data-service'; @Component({ selector: 'app-restorative-justice-add-edit', @@ -32,7 +33,7 @@ export class RestorativeJusticeAddEditComponent implements OnInit, OnDestroy { public nrcedPublishSubtext = 'Not published'; // Pick lists - public agencies = Picklists.agencyPicklist; + public agencies = Picklists.agencyCodePicklist; public authors = Picklists.authorPicklist; private defaultAgency = ''; @@ -543,7 +544,8 @@ export class RestorativeJusticeAddEditComponent implements OnInit, OnDestroy { } displayName(agency) { - return Utils.displayNameFull(agency); + const agencyDataService = new AgencyDataService(this.factoryService); + return agencyDataService.displayNameFull(agency); } cancel() { diff --git a/angular/projects/admin-nrpti/src/app/records/restorative-justices/restorative-justice-detail/restorative-justice-detail.component.ts b/angular/projects/admin-nrpti/src/app/records/restorative-justices/restorative-justice-detail/restorative-justice-detail.component.ts index ed8b7b143..5469f9a69 100644 --- a/angular/projects/admin-nrpti/src/app/records/restorative-justices/restorative-justice-detail/restorative-justice-detail.component.ts +++ b/angular/projects/admin-nrpti/src/app/records/restorative-justices/restorative-justice-detail/restorative-justice-detail.component.ts @@ -7,7 +7,7 @@ import { RecordDetailComponent } from '../../utils/record-component'; import { RecordUtils } from '../../utils/record-utils'; import { Utils as CommonUtils } from '../../../../../../common/src/app/utils/utils'; import { FactoryService } from '../../../services/factory.service'; -import { Utils } from 'nrpti-angular-components'; +import { AgencyDataService } from '../../../../../../../projects/global/src/lib/utils/agency-data-service'; @Component({ selector: 'app-restorative-justice-detail', @@ -64,7 +64,8 @@ export class RestorativeJusticeDetailComponent extends RecordDetailComponent imp } displayName(agency) { - return Utils.displayNameFull(agency); + const agencyDataService = new AgencyDataService(this.factoryService); + return agencyDataService.displayNameFull(agency); } ngOnDestroy() { diff --git a/angular/projects/admin-nrpti/src/app/records/self-reports/self-report-add-edit/self-report-add-edit.component.ts b/angular/projects/admin-nrpti/src/app/records/self-reports/self-report-add-edit/self-report-add-edit.component.ts index bae2505b7..dbd2c7449 100644 --- a/angular/projects/admin-nrpti/src/app/records/self-reports/self-report-add-edit/self-report-add-edit.component.ts +++ b/angular/projects/admin-nrpti/src/app/records/self-reports/self-report-add-edit/self-report-add-edit.component.ts @@ -10,6 +10,7 @@ import { Utils as CommonUtils } from '../../../../../../common/src/app/utils/uti import { RecordUtils } from '../../utils/record-utils'; import { LoadingScreenService, LoggerService } from 'nrpti-angular-components'; import { Constants } from '../../../utils/constants/misc'; +import { AgencyDataService } from '../../../../../../../projects/global/src/lib/utils/agency-data-service'; @Component({ selector: 'app-self-report-add-edit', @@ -30,7 +31,7 @@ export class SelfReportAddEditComponent implements OnInit, OnDestroy { public lngPublishSubtext = 'Not published'; // Pick lists - public agencies = Picklists.agencyPicklist; + public agencies = Picklists.agencyCodePicklist; public authors = Picklists.authorPicklist; // Documents @@ -358,7 +359,8 @@ export class SelfReportAddEditComponent implements OnInit, OnDestroy { } displayName(agency) { - return Utils.displayNameFull(agency); + const agencyDataService = new AgencyDataService(this.factoryService); + return agencyDataService.displayNameFull(agency); } cancel() { diff --git a/angular/projects/admin-nrpti/src/app/records/self-reports/self-report-detail/self-report-detail.component.ts b/angular/projects/admin-nrpti/src/app/records/self-reports/self-report-detail/self-report-detail.component.ts index 0fab58896..c56a64f44 100644 --- a/angular/projects/admin-nrpti/src/app/records/self-reports/self-report-detail/self-report-detail.component.ts +++ b/angular/projects/admin-nrpti/src/app/records/self-reports/self-report-detail/self-report-detail.component.ts @@ -7,7 +7,7 @@ import { RecordDetailComponent } from '../../utils/record-component'; import { RecordUtils } from '../../utils/record-utils'; import { Utils as CommonUtils } from '../../../../../../common/src/app/utils/utils'; import { FactoryService } from '../../../services/factory.service'; -import { Utils } from 'nrpti-angular-components'; +import { AgencyDataService } from '../../../../../../../projects/global/src/lib/utils/agency-data-service'; @Component({ selector: 'app-self-report-detail', @@ -64,7 +64,8 @@ export class SelfReportDetailComponent extends RecordDetailComponent implements } displayName(agency) { - return Utils.displayNameFull(agency); + const agencyDataService = new AgencyDataService(this.factoryService); + return agencyDataService.displayNameFull(agency); } ngOnDestroy() { diff --git a/angular/projects/admin-nrpti/src/app/records/tickets/ticket-add-edit/ticket-add-edit.component.ts b/angular/projects/admin-nrpti/src/app/records/tickets/ticket-add-edit/ticket-add-edit.component.ts index 9086782c9..a8cbfd0af 100644 --- a/angular/projects/admin-nrpti/src/app/records/tickets/ticket-add-edit/ticket-add-edit.component.ts +++ b/angular/projects/admin-nrpti/src/app/records/tickets/ticket-add-edit/ticket-add-edit.component.ts @@ -10,6 +10,7 @@ import { Utils as CommonUtils } from '../../../../../../common/src/app/utils/uti import { RecordUtils } from '../../utils/record-utils'; import { LoadingScreenService, LoggerService } from 'nrpti-angular-components'; import { Constants } from '../../../utils/constants/misc'; +import { AgencyDataService } from '../../../../../../../projects/global/src/lib/utils/agency-data-service'; @Component({ selector: 'app-ticket-add-edit', @@ -32,7 +33,7 @@ export class TicketAddEditComponent implements OnInit, OnDestroy { public nrcedPublishSubtext = 'Not published'; // Pick lists - public agencies = Picklists.agencyPicklist; + public agencies = Picklists.agencyCodePicklist; public authors = Picklists.authorPicklist; private defaultAgency = ''; @@ -541,7 +542,8 @@ export class TicketAddEditComponent implements OnInit, OnDestroy { } displayName(agency) { - return Utils.displayNameFull(agency); + const agencyDataService = new AgencyDataService(this.factoryService); + return agencyDataService.displayNameFull(agency); } cancel() { diff --git a/angular/projects/admin-nrpti/src/app/records/tickets/ticket-detail/ticket-detail.component.ts b/angular/projects/admin-nrpti/src/app/records/tickets/ticket-detail/ticket-detail.component.ts index e3d38de6a..502f6dd11 100644 --- a/angular/projects/admin-nrpti/src/app/records/tickets/ticket-detail/ticket-detail.component.ts +++ b/angular/projects/admin-nrpti/src/app/records/tickets/ticket-detail/ticket-detail.component.ts @@ -7,7 +7,7 @@ import { RecordDetailComponent } from '../../utils/record-component'; import { RecordUtils } from '../../utils/record-utils'; import { Utils as CommonUtils } from '../../../../../../common/src/app/utils/utils'; import { FactoryService } from '../../../services/factory.service'; -import { Utils } from 'nrpti-angular-components'; +import { AgencyDataService } from '../../../../../../../projects/global/src/lib/utils/agency-data-service'; @Component({ selector: 'app-ticket-detail', @@ -64,7 +64,8 @@ export class TicketDetailComponent extends RecordDetailComponent implements OnIn } displayName(agency) { - return Utils.displayNameFull(agency); + const agencyDataService = new AgencyDataService(this.factoryService); + return agencyDataService.displayNameFull(agency); } ngOnDestroy() { diff --git a/angular/projects/admin-nrpti/src/app/records/warnings/warning-add-edit/warning-add-edit.component.ts b/angular/projects/admin-nrpti/src/app/records/warnings/warning-add-edit/warning-add-edit.component.ts index 1509bdc6e..ed6a1ea2a 100644 --- a/angular/projects/admin-nrpti/src/app/records/warnings/warning-add-edit/warning-add-edit.component.ts +++ b/angular/projects/admin-nrpti/src/app/records/warnings/warning-add-edit/warning-add-edit.component.ts @@ -10,6 +10,7 @@ import { Utils as CommonUtils } from '../../../../../../common/src/app/utils/uti import { RecordUtils } from '../../utils/record-utils'; import { LoadingScreenService, LoggerService } from 'nrpti-angular-components'; import { Constants } from '../../../utils/constants/misc'; +import { AgencyDataService } from '../../../../../../../projects/global/src/lib/utils/agency-data-service'; @Component({ selector: 'app-warning-add-edit', @@ -32,7 +33,7 @@ export class WarningAddEditComponent implements OnInit, OnDestroy { public nrcedPublishSubtext = 'Not published'; // Pick lists - public agencies = Picklists.agencyPicklist; + public agencies = Picklists.agencyCodePicklist; public authors = Picklists.authorPicklist; public outcomeStatuses = Picklists.outcomeStatusPicklist; private defaultAgency = ''; @@ -474,7 +475,8 @@ export class WarningAddEditComponent implements OnInit, OnDestroy { } displayName(agency) { - return Utils.displayNameFull(agency); + const agencyDataService = new AgencyDataService(this.factoryService); + return agencyDataService.displayNameFull(agency); } cancel() { diff --git a/angular/projects/admin-nrpti/src/app/records/warnings/warning-detail/warning-detail.component.ts b/angular/projects/admin-nrpti/src/app/records/warnings/warning-detail/warning-detail.component.ts index 17de72a6d..35b52b0d3 100644 --- a/angular/projects/admin-nrpti/src/app/records/warnings/warning-detail/warning-detail.component.ts +++ b/angular/projects/admin-nrpti/src/app/records/warnings/warning-detail/warning-detail.component.ts @@ -7,7 +7,7 @@ import { RecordDetailComponent } from '../../utils/record-component'; import { RecordUtils } from '../../utils/record-utils'; import { Utils as CommonUtils } from '../../../../../../common/src/app/utils/utils'; import { FactoryService } from '../../../services/factory.service'; -import { Utils } from 'nrpti-angular-components'; +import { AgencyDataService } from '../../../../../../../projects/global/src/lib/utils/agency-data-service'; @Component({ selector: 'app-warning-detail', @@ -64,7 +64,8 @@ export class WarningDetailComponent extends RecordDetailComponent implements OnI } displayName(agency) { - return Utils.displayNameFull(agency); + const agencyDataService = new AgencyDataService(this.factoryService); + return agencyDataService.displayNameFull(agency); } ngOnDestroy() { diff --git a/angular/projects/admin-nrpti/src/app/services/application-agency.service.ts b/angular/projects/admin-nrpti/src/app/services/application-agency.service.ts new file mode 100644 index 000000000..b172cd75d --- /dev/null +++ b/angular/projects/admin-nrpti/src/app/services/application-agency.service.ts @@ -0,0 +1,51 @@ +import { Injectable } from '@angular/core'; +import { ConfigService } from 'nrpti-angular-components'; +import { Observable } from 'rxjs'; +import { HttpClient } from '@angular/common/http'; + +/* +Service Layer for fetching issuing agencies and storing them in app_initializer +*/ + +@Injectable() +export class ApplicationAgencyService { + private api: string; + private agencies: { [key: string]: string } = {}; + + constructor(private configService: ConfigService, public http: HttpClient) {} + + async init() { + this.api = `${this.configService.config['API_LOCATION']}${this.configService.config['API_PATH']}`; + await this.refreshAgencies().toPromise(); + } + + refreshAgencies(): Observable { + return new Observable(observer => { + const apiEndpoint = `${this.api}/list-agencies`; + const getAgencies = this.http.get<{ [key: string]: string }>(apiEndpoint); + + getAgencies.subscribe( + response => { + // Data transformation to make the data easier to work with + const agencyList = {}; + for (const record in response) { + if (response.hasOwnProperty(record)) { + agencyList[response[record]['agencyCode']] = response[record]['agencyName']; + } + } + this.agencies = agencyList; + observer.next(); + observer.complete(); + }, + error => { + console.error('HTTP Request Error: ', error); + observer.error(error); + } + ); + }); + } + + getAgencies(): { [key: string]: string } { + return this.agencies; + } +} diff --git a/angular/projects/admin-nrpti/src/app/services/factory.service.ts b/angular/projects/admin-nrpti/src/app/services/factory.service.ts index 2f136d1b0..1c87a3759 100644 --- a/angular/projects/admin-nrpti/src/app/services/factory.service.ts +++ b/angular/projects/admin-nrpti/src/app/services/factory.service.ts @@ -13,6 +13,7 @@ import { NewsService } from './news.service'; import { CollectionService } from './collection.service'; import { MineService } from './mine.service'; import { MapLayerInfoService } from './map-layer-info.service'; +import { ApplicationAgencyService } from './application-agency.service'; /** * Facade service for all admin-nrpti services. @@ -35,6 +36,7 @@ export class FactoryService { private _documentService: DocumentService; private _configService: ConfigService; private _mapLayerInfoService: MapLayerInfoService; + private _applicationAgencyService: ApplicationAgencyService; constructor(private injector: Injector) { // The following items are loaded by a file that is only present on cluster builds. @@ -88,6 +90,20 @@ export class FactoryService { return this._apiService; } + /** + * Inject agency service if it hasn't already been injected. + * + * @readonly + * @type {ApiService} + * @memberof FactoryService + */ + public get applicationAgencyService(): ApplicationAgencyService { + if (!this._applicationAgencyService) { + this._applicationAgencyService = this.injector.get(ApplicationAgencyService); + } + return this._applicationAgencyService; + } + /** * Inject record service if it hasn't already been injected. * @@ -240,7 +256,6 @@ export class FactoryService { } isFlavourEditEnabled(requiredRoles: string[]) { - for (const role of requiredRoles) { if (this.userInRole(role)) { return true; @@ -602,13 +617,13 @@ export class FactoryService { return isInsert ? this.recordService - .createRecord(dataPackage) - .pipe(catchError(error => this.apiService.handleError(error))) - .toPromise() + .createRecord(dataPackage) + .pipe(catchError(error => this.apiService.handleError(error))) + .toPromise() : this.recordService - .editRecord(dataPackage) - .pipe(catchError(error => this.apiService.handleError(error))) - .toPromise(); + .editRecord(dataPackage) + .pipe(catchError(error => this.apiService.handleError(error))) + .toPromise(); } public createConfigData(configData, application): Promise { @@ -625,4 +640,20 @@ export class FactoryService { public updateMapLayerInfo(mapLayerInfo): Promise { return this.mapLayerInfoService.updateMapLayerInfo(mapLayerInfo); } + + /** + * Get agency data. If data is not cached, fetch it from the ApplicationAgencyService. + * + * @readonly + * @type {{ [key: string]: string }} + * @memberof FactoryService + */ + public getApplicationAgencyService(): Observable { + if (Object.keys(this.applicationAgencyService.getAgencies).length === 0) { + this.applicationAgencyService.refreshAgencies().subscribe(() => { + this.applicationAgencyService.getAgencies(); + }); + } + return this.applicationAgencyService.refreshAgencies(); + } } diff --git a/angular/projects/admin-nrpti/src/app/services/import.service.ts b/angular/projects/admin-nrpti/src/app/services/import.service.ts index bd9dd34aa..513b8a709 100644 --- a/angular/projects/admin-nrpti/src/app/services/import.service.ts +++ b/angular/projects/admin-nrpti/src/app/services/import.service.ts @@ -16,7 +16,7 @@ export class ImportService { private configService: ConfigService, private eventService: EventService ) { - this.data = new BehaviorSubject(new SearchResult); + this.data = new BehaviorSubject(new SearchResult()); this.fetchDataConfig = this.configService.config['DEFAULT_IMPORT_TABLE_QUERY_PARAMS']; } @@ -49,7 +49,6 @@ export class ImportService { pageSize: number = 20, sortBy: string = null ) { - // Caching for later this.fetchDataConfig = { pathAPI: pathAPI, @@ -63,26 +62,13 @@ export class ImportService { let res = null; try { - res = await this.factoryService.searchService.getSearchResults( - pathAPI, - keys, - dataset, - fields, - pageNum, - pageSize, - sortBy - ).toPromise(); + res = await this.factoryService.searchService + .getSearchResults(pathAPI, keys, dataset, fields, pageNum, pageSize, sortBy) + .toPromise(); } catch (error) { - this.eventService.setError( - new EventObject( - EventKeywords.ERROR, - error, - 'Import Service' - ) - ); + this.eventService.setError(new EventObject(EventKeywords.ERROR, error, 'Import Service')); } - // tslint:disable-next-line: prefer-const let searchResult = new SearchResult(); @@ -91,31 +77,19 @@ export class ImportService { searchResult.data = res[0].data.searchResults; } else { this.eventService.setError( - new EventObject( - EventKeywords.ERROR, - 'Search results were empty.', - 'Import Service' - ) + new EventObject(EventKeywords.ERROR, 'Search results were empty.', 'Import Service') ); } if (res[0].data.meta[0] && res[0].data.meta[0].searchResultsTotal) { searchResult.totalSearchCount = res[0].data.meta[0].searchResultsTotal; } else { this.eventService.setError( - new EventObject( - EventKeywords.ERROR, - 'Total search results count was not returned.', - 'Import Service' - ) + new EventObject(EventKeywords.ERROR, 'Total search results count was not returned.', 'Import Service') ); } } else { this.eventService.setError( - new EventObject( - EventKeywords.ERROR, - 'No data was returned from the server.', - 'Import Service' - ) + new EventObject(EventKeywords.ERROR, 'No data was returned from the server.', 'Import Service') ); } this.setValue(searchResult); diff --git a/angular/projects/admin-nrpti/src/app/services/issuingagency.service.ts b/angular/projects/admin-nrpti/src/app/services/issuingagency.service.ts new file mode 100644 index 000000000..f2d810894 --- /dev/null +++ b/angular/projects/admin-nrpti/src/app/services/issuingagency.service.ts @@ -0,0 +1,34 @@ +import { Injectable } from '@angular/core'; +import { HttpClient } from '@angular/common/http'; + +import { ApiService } from './api.service'; +/* +Service Layer for agencies component. Used for fetching issuing agencies and storing them in database +*/ +@Injectable({ providedIn: 'root' }) +export class IssuingAgencyService { + constructor(public apiService: ApiService, public http: HttpClient) {} + + public getIssuingAgencies(): Promise { + return this.http + .get(`${this.apiService.pathAPI}/list-agencies`) + .toPromise() + .catch(error => { + console.error('API call error:', error); + throw error; // Rethrow the error to propagate it further + }); + } + + public updateAgency(agencyCode: string, agencyName: any): Promise { + const apiUrl = `${this.apiService.pathAPI}/update-agencies`; + const updatedAgency = { agencies: [{ agencyCode: agencyCode, agencyName: agencyName }] }; // Wrap the array in an object + console.log(JSON.stringify(updatedAgency)); + return this.http + .put(apiUrl, updatedAgency) + .toPromise() + .catch(error => { + console.error('API call error:', error); + throw error; // Rethrow the error to propagate it further + }); + } +} diff --git a/angular/projects/admin-nrpti/src/app/services/keycloak.service.ts b/angular/projects/admin-nrpti/src/app/services/keycloak.service.ts index 9c401d2c0..b241a3880 100644 --- a/angular/projects/admin-nrpti/src/app/services/keycloak.service.ts +++ b/angular/projects/admin-nrpti/src/app/services/keycloak.service.ts @@ -161,6 +161,9 @@ export class KeycloakService { roles.includes(Constants.ApplicationRoles.ADMIN_LNG) || roles.includes(Constants.ApplicationRoles.ADMIN_NRCED) || roles.includes(Constants.ApplicationRoles.ADMIN_BCMI); + + this.menus[Constants.Menus.AGENCIES] = + roles.includes(Constants.ApplicationRoles.ADMIN); } buildAddRecordDropdownCache(roles) { diff --git a/angular/projects/admin-nrpti/src/app/sidebar/sidebar.component.html b/angular/projects/admin-nrpti/src/app/sidebar/sidebar.component.html index 167ee20d4..50864f03b 100644 --- a/angular/projects/admin-nrpti/src/app/sidebar/sidebar.component.html +++ b/angular/projects/admin-nrpti/src/app/sidebar/sidebar.component.html @@ -1,106 +1,136 @@ \ No newline at end of file + diff --git a/angular/projects/admin-nrpti/src/app/sidebar/sidebar.component.spec.ts b/angular/projects/admin-nrpti/src/app/sidebar/sidebar.component.spec.ts index 2bd67d897..a0810ab8c 100644 --- a/angular/projects/admin-nrpti/src/app/sidebar/sidebar.component.spec.ts +++ b/angular/projects/admin-nrpti/src/app/sidebar/sidebar.component.spec.ts @@ -16,7 +16,7 @@ describe('SidebarComponent', () => { const mockStoreService = { change: of(), - toggleSideNave: () => { } + toggleSideNave: () => {} }; const mockLoadingScreenService = { @@ -27,23 +27,42 @@ describe('SidebarComponent', () => { }; const mockKeyCloakService = { - isMenuEnabled: (menuName) => { + isMenuEnabled: menuName => { let retVal = false; switch (menuName) { - case Constants.Menus.ALL_MINES: retVal = true; break; - case Constants.Menus.ALL_RECORDS: retVal = true; break; - case Constants.Menus.NEWS_LIST: retVal = true; break; - case Constants.Menus.ANALYTICS: retVal = false; break; - case Constants.Menus.MAP: retVal = false; break; - case Constants.Menus.ENTITIES: retVal = false; break; - case Constants.Menus.IMPORTS: retVal = true; break; - case Constants.Menus.COMMUNICATIONS: retVal = true; break; + case Constants.Menus.ALL_MINES: + retVal = true; + break; + case Constants.Menus.ALL_RECORDS: + retVal = true; + break; + case Constants.Menus.NEWS_LIST: + retVal = true; + break; + case Constants.Menus.ANALYTICS: + retVal = false; + break; + case Constants.Menus.MAP: + retVal = false; + break; + 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; } }; - beforeEach((() => { + beforeEach(() => { TestBed.configureTestingModule({ imports: [RouterTestingModule], declarations: [SidebarComponent], @@ -54,7 +73,7 @@ describe('SidebarComponent', () => { { provide: KeycloakService, useValue: mockKeyCloakService } ] }).compileComponents(); - })); + }); it('sidebar menu should render properly', () => { const routerMock = TestBed.get(Router); @@ -70,6 +89,7 @@ describe('SidebarComponent', () => { expect(component.keycloakService.isMenuEnabled(Constants.Menus.ENTITIES)).toEqual(false); expect(component.keycloakService.isMenuEnabled(Constants.Menus.IMPORTS)).toEqual(true); expect(component.keycloakService.isMenuEnabled(Constants.Menus.COMMUNICATIONS)).toEqual(true); + expect(component.keycloakService.isMenuEnabled(Constants.Menus.AGENCIES)).toEqual(true); expect(component.keycloakService.isMenuEnabled('Something Not Here')).toEqual(false); expect(component).toBeTruthy(); diff --git a/angular/projects/admin-nrpti/src/app/utils/constants/ams-csv-constants.ts b/angular/projects/admin-nrpti/src/app/utils/constants/ams-csv-constants.ts index e5ee5b936..d632a5d25 100644 --- a/angular/projects/admin-nrpti/src/app/utils/constants/ams-csv-constants.ts +++ b/angular/projects/admin-nrpti/src/app/utils/constants/ams-csv-constants.ts @@ -20,12 +20,7 @@ export const amsOrdersCsvRequiredHeaders = [ * Required fields for AMS Order csv. * */ -export const amsOrdersCsvRequiredFields = [ - 'AuthNumber', - 'ClientName', - 'IssueDate', - 'AuthorizationType', -]; +export const amsOrdersCsvRequiredFields = ['AuthNumber', 'ClientName', 'IssueDate', 'AuthorizationType']; /** * Fields for AMS Order csv that have a required format. diff --git a/angular/projects/admin-nrpti/src/app/utils/constants/misc.ts b/angular/projects/admin-nrpti/src/app/utils/constants/misc.ts index 598862fb6..8c0be0fc5 100644 --- a/angular/projects/admin-nrpti/src/app/utils/constants/misc.ts +++ b/angular/projects/admin-nrpti/src/app/utils/constants/misc.ts @@ -48,7 +48,8 @@ export class Constants { MAP: 'Map', ENTITIES: 'Entities', IMPORTS: 'Imports', - COMMUNICATIONS: 'Communications' + COMMUNICATIONS: 'Communications', + AGENCIES: 'Agencies' }; public static readonly RecordTypes: any = { @@ -320,9 +321,7 @@ export class Constants { public static readonly RoleAgencyPickList: any = { [Constants.ApplicationRoles.ADMIN_WF]: ['BC Wildfire Service'], - [Constants.ApplicationRoles.ADMIN_FLNRO]: [ - 'Ministry of Environment and Climate Change Strategy' - ], + [Constants.ApplicationRoles.ADMIN_FLNRO]: ['Ministry of Environment and Climate Change Strategy'], [Constants.ApplicationRoles.ADMIN_FLNR_NRO]: ['Natural Resource Officers'], [Constants.ApplicationRoles.ADMIN_AGRI]: ['Ministry of Agriculture and Food'], [Constants.ApplicationRoles.ADMIN_ENV_EPD]: ['Ministry of Environment and Climate Change Strategy'], @@ -332,6 +331,18 @@ export class Constants { [Constants.ApplicationRoles.ADMIN_WLRS]: ['Ministry of Water, Land and Resource Stewardship'] }; + public static readonly RoleAgencyCodePickList: any = { + [Constants.ApplicationRoles.ADMIN_WF]: ['AGENCY_WF'], + [Constants.ApplicationRoles.ADMIN_FLNRO]: ['AGENCY_ENV'], + [Constants.ApplicationRoles.ADMIN_FLNR_NRO]: ['AGENCY_FLNR_NRO'], + [Constants.ApplicationRoles.ADMIN_AGRI]: ['AGENCY_AGRI'], + [Constants.ApplicationRoles.ADMIN_ENV_EPD]: ['AGENCY_ENV_EPD'], + [Constants.ApplicationRoles.ADMIN_ENV_COS]: ['AGENCY_ENV_COS'], + [Constants.ApplicationRoles.ADMIN_ENV_BCPARKS]: ['AGENCY_ENV_BCPARKS'], + [Constants.ApplicationRoles.ADMIN_ALC]: ['AGENCY_ALC'], + [Constants.ApplicationRoles.ADMIN_WLRS]: ['AGENCY_WLRS'] + }; + public static readonly LngSectionPickList: string[] = [ 'Section 1', 'Section 2', diff --git a/angular/projects/common/src/app/utils/record-constants.ts b/angular/projects/common/src/app/utils/record-constants.ts index ecaaf8e1c..35c791f68 100644 --- a/angular/projects/common/src/app/utils/record-constants.ts +++ b/angular/projects/common/src/app/utils/record-constants.ts @@ -1,5 +1,7 @@ import { Utils } from './utils'; import { Legislation } from '../models/master/common-models/legislation'; +import { AgencyDataService } from '../../../../../projects/global/src/lib/utils/agency-data-service'; +import { FactoryService } from '../../../../../projects/admin-nrpti/src/app/services/factory.service'; export class EpicProjectIds { public static readonly lngCanadaId = '588511d0aaecd9001b826192'; @@ -21,11 +23,9 @@ export class SearchSubsets { } export class Constants { - // Datepicker is off by one so add one to the desired year. public static readonly DatepickerMinDate = new Date('1901'); public static readonly DatepickerMaxDate = new Date(); - } /** * Schema lists for search. @@ -162,20 +162,47 @@ export class Picklists { public static readonly penaltyTypePicklist = ['Years', 'Days', 'Dollars', 'Hours', 'Other']; public static readonly agencyPicklist = [ - 'Agricultural Land Commission', - 'BC Energy Regulator', - 'BC Parks', - 'BC Wildfire Service', - 'Climate Action Secretariat', - 'Conservation Officer Service', - 'Environmental Assessment Office', - 'LNG Secretariat', - 'Ministry of Agriculture and Food', - 'Ministry of Energy Mines and Low Carbon Innovation', - 'Ministry of Environment and Climate Change Strategy', - 'Ministry of Forests', - 'Ministry of Water, Land and Resource Stewardship', - 'Natural Resource Officers', + 'Agricultural Land Commission 1', + 'BC Energy Regulator 1', + 'BC Parks 1', + 'BC Wildfire Service 1', + 'Climate Action Secretariat 1', + 'Conservation Officer Service 1', + 'Environmental Assessment Office 1', + 'LNG Secretariat 1', + 'Ministry of Agriculture and Food 1', + 'Ministry of Energy Mines and Low Carbon Innovation 1', + 'Ministry of Environment and Climate Change Strategy 1', + 'Ministry of Forests 1', + 'Ministry of Water, Land and Resource Stewardship 1', + 'Natural Resource Officers 1' + ]; + + public static getAgencyNames(factoryService: FactoryService) { + const agencyDataService = new AgencyDataService(factoryService); + return agencyDataService.getAgencyNames(); + } + + public static getAgencyCode(factoryService: FactoryService, agencyName) { + const agencyDataService = new AgencyDataService(factoryService); + return agencyDataService.getAgencyCode(agencyName); + } + + public static readonly agencyCodePicklist = [ + 'AGENCY_ALC', + 'AGENCY_OGC', + 'AGENCY_ENV_BCPARKS', + 'AGENCY_WF', + 'AGENCY_CAS', + 'AGENCY_ENV_COS', + 'AGENCY_EAO', + 'AGENCY_LNG', + 'AGENCY_AGRI', + 'AGENCY_EMLI', + 'AGENCY_ENV', + 'AGENCY_FLNRO', + 'AGENCY_WLRS', + 'AGENCY_FLNR_NRO' ]; public static readonly entityTypePicklist = ['Company', 'Individual']; @@ -267,7 +294,11 @@ export class Picklists { 'Report' ]; - public static readonly collectionAgencyPicklist = ['Environmental Assessment Office', 'Ministry of Energy Mines and Low Carbon Innovation', 'Ministry of Environment and Climate Change Strategy']; + public static readonly collectionAgencyPicklist = [ + 'Environmental Assessment Office', + 'Ministry of Energy Mines and Low Carbon Innovation', + 'Ministry of Environment and Climate Change Strategy' + ]; /** * Contains a mapping of acts to regulations. @@ -800,7 +831,7 @@ export class Picklists { * @memberof Picklists * @returns {string[]} sorted array of acts */ - public static getAllActs = function (): string[] { + public static getAllActs = function(): string[] { return Object.keys(this.legislationActsMappedToRegulations).sort((a, b) => a.localeCompare(b)); }; @@ -811,7 +842,7 @@ export class Picklists { * @memberof Picklists * @returns {string[]} sorted array of regulations */ - public static getAllRegulations = function (): string[] { + public static getAllRegulations = function(): string[] { const regulations = []; Object.keys(this.legislationActsMappedToRegulations).forEach(act => @@ -835,7 +866,7 @@ export class Picklists { * @memberof Picklists * @returns {{ [key: string]: string[] }} */ - public static getLegislationRegulationsMappedToActs = function (): { [key: string]: string[] } { + public static getLegislationRegulationsMappedToActs = function(): { [key: string]: string[] } { const regulations = {}; Object.keys(this.legislationActsMappedToRegulations).forEach(act => @@ -1242,8 +1273,7 @@ export class Picklists { 'Park Act': { '9': { '1': { - description: - 'For use of natural resource without valid park permit' + description: 'For use of natural resource without valid park permit' } }, '16': { @@ -1920,12 +1950,12 @@ export class Picklists { 'Park Act': { '17': { description: 'Park Act Order' - }, // nrpti-1085: Add new legislation description for orders - 'Park, Conservancy and Recreation Area Regulation' : { - '9': { - description: 'Order to leave a park, conservancy or recreation area' + }, // nrpti-1085: Add new legislation description for orders + 'Park, Conservancy and Recreation Area Regulation': { + '9': { + description: 'Order to leave a park, conservancy or recreation area' + } } - } }, 'Wildfire Act': { '7': { @@ -2508,7 +2538,7 @@ export class Picklists { }, '3': { description: 'Fail to submit separate fee' - }, + } }, '32': { '1': { @@ -2523,7 +2553,7 @@ export class Picklists { }, d: { description: 'Fail to ensure facility is of sound construction' - }, + } }, '2': { a: { @@ -2531,7 +2561,7 @@ export class Picklists { }, b: { description: 'Fail to have adequate ventilation' - }, + } }, '3': { description: 'Fail to have appropriate waste disposal system' @@ -2577,7 +2607,7 @@ export class Picklists { }, f: { description: 'Fail to review food safety plan annually or if required' - }, + } }, '3': { description: 'Fail to have a food safety plan in writing', @@ -2598,7 +2628,7 @@ export class Picklists { }, f: { description: 'Fail to keep appropriate records' - }, + } }, '4': { description: 'Fail to change food safety plan as directed' @@ -2625,7 +2655,7 @@ export class Picklists { }, d: { description: 'Fail to make sanitation plan/records available' - }, + } }, '2': { description: 'Fail to have sanitation plan in writing', @@ -2634,7 +2664,7 @@ export class Picklists { }, b: { description: 'Fail to identify cleaning/sanitizing agents and pesticides used' - }, + } } }, '42': { @@ -2644,7 +2674,7 @@ export class Picklists { }, b: { description: 'Fail to have pest proof containers' - }, + } }, '43': { '1': { @@ -2656,14 +2686,14 @@ export class Picklists { }, c: { description: 'Conduct activities that lead to unsafe food' - }, + } }, '2': { description: 'Fail to ensure handwashing' }, '3': { description: 'Fail to ensure tobacco/vapour products not used in facility' - }, + } }, '44': { description: 'Permit food contact by ill persons' @@ -2674,7 +2704,7 @@ export class Picklists { }, b: { description: 'Fail to keep fish as permitted by inspector' - }, + } }, '46': { a: { @@ -2682,7 +2712,7 @@ export class Picklists { }, b: { description: 'Fail to label chemicals/cleaners' - }, + } }, '47': { description: 'Fail to properly store/label' @@ -2699,7 +2729,7 @@ export class Picklists { }, '2': { description: 'Receive marine cultured fish from unacceptable source' - }, + } }, '51': { description: 'Process dead lobster/crab' @@ -2731,7 +2761,7 @@ export class Picklists { }, '3': { description: 'Fail to properly label carton of sport caught fish' - }, + } }, '55': { '1': { @@ -2746,7 +2776,7 @@ export class Picklists { }, c: { description: 'Fail to have system that verifies fish returned to sport fisher' - }, + } } }, '56': { @@ -2817,7 +2847,7 @@ export class Picklists { description: 'Fail to submit report' } } - }, + } }, 'Fisheries Act (Canada)': { 'Fishing (General) Regulations': { @@ -5125,8 +5155,7 @@ export class Picklists { * @static * @returns {string} legislation description or null */ - public static getLegislationDescription = function (recordType: string, legislation: Legislation): string { - + public static getLegislationDescription = function(recordType: string, legislation: Legislation): string { if (!recordType || (!legislation && !legislation.act && !legislation.section)) { return null; } @@ -5181,7 +5210,7 @@ export class Picklists { * @param {string[]} paths properties to descend, in order, through the object. * @returns the value found at the end of the path, or null */ - public static traverseObject = function (obj: object, paths: string[]) { + public static traverseObject = function(obj: object, paths: string[]) { if (!obj || !paths || !paths.length) { return null; } diff --git a/angular/projects/global/src/lib/utils/agency-data-service.ts b/angular/projects/global/src/lib/utils/agency-data-service.ts new file mode 100644 index 000000000..777690e9d --- /dev/null +++ b/angular/projects/global/src/lib/utils/agency-data-service.ts @@ -0,0 +1,45 @@ +import { FactoryService } from '../../../../admin-nrpti/src/app/services/factory.service'; + +export class AgencyDataService { + constructor( + private factoryService: FactoryService, + ) {} + + displayNameFull(agencyCode): string { + // Access cached agency data from FactoryService + const agencyService = this.factoryService.applicationAgencyService; + const agencyList = agencyService ? agencyService.getAgencies() : null; + + return agencyList && agencyList[agencyCode] ? agencyList[agencyCode] : agencyCode; + } + + getAgencyCodes(): string[] { + const agencyService = this.factoryService.applicationAgencyService; + const agencyList = agencyService ? agencyService.getAgencies() : null; + + return agencyList ? Object.keys(agencyList) : []; + } + + getAgencyNames(): string[] { + const agencyService = this.factoryService.applicationAgencyService; + const agencyList = agencyService ? agencyService.getAgencies() : null; + + return agencyList ? Object.values(agencyList) : []; + } + + getAgencyCode(agencyName: string): string { + const agencyService = this.factoryService.applicationAgencyService; + const agencyList = agencyService ? agencyService.getAgencies() : null; + + if (agencyList) { + for (const key in agencyList) { + if (agencyList.hasOwnProperty(key) && agencyList[key] === agencyName) { + return key; // Return the key if the value matches + } + } + } + // Return a default value or handle the case where agencyList is undefined or empty + return ''; + } + +} diff --git a/angular/projects/global/src/lib/utils/utils.ts b/angular/projects/global/src/lib/utils/utils.ts index c70929750..bc6bc7a0f 100644 --- a/angular/projects/global/src/lib/utils/utils.ts +++ b/angular/projects/global/src/lib/utils/utils.ts @@ -1,4 +1,4 @@ -const ApplicationAgencies = { +const ApplicationAgencies: any = { AGENCY_ALC: 'Agricultural Land Commission', AGENCY_WF: 'BC Wildfire Service', AGENCY_ENV_COS: 'Conservation Officer Service', @@ -15,6 +15,22 @@ const ApplicationAgencies = { AGENCY_WLRS: 'Ministry of Water, Land and Resource Stewardship', }; +export const ApplicationAgencyList = { + AGENCY_ALC: 'Agricultural Land Commission', + AGENCY_WF: 'BC Wildfire Service', + AGENCY_ENV_COS: 'Conservation Officer Service', + AGENCY_EAO: 'Environmental Assessment Office', + AGENCY_EMLI: 'Ministry of Energy Mines and Low Carbon Innovation', + AGENCY_ENV: 'Ministry of Environment and Climate Change Strategy', + AGENCY_ENV_BCPARKS: 'BC Parks', + AGENCY_OGC: 'BC Energy Regulator', + AGENCY_ENV_EPD: 'Ministry of Environment and Climate Change Strategy', + AGENCY_LNG: 'LNG Secretariat', + AGENCY_AGRI: 'Ministry of Agriculture and Food', + AGENCY_FLNRO: 'Ministry of Forests', + AGENCY_FLNR_NRO: 'Natural Resource Officers', + AGENCY_WLRS: 'Ministry of Water, Land and Resource Stewardship', +}; /** * General purpose utils. * @@ -134,17 +150,9 @@ export class Utils { } - static displayNameFull(agency): string { - switch (agency) { - case ApplicationAgencies.AGENCY_AGRI: - return 'Ministry of Agriculture and Food'; - case ApplicationAgencies.AGENCY_EMLI: - return 'Ministry of Energy, Mines, and Low Carbon Innovation'; - case ApplicationAgencies.AGENCY_FLNRO: - return 'Ministry of Forests'; - default: - return agency; - } + static displayNameFull(agencyCode): string { + const agencyList = ApplicationAgencyList; + return agencyList[agencyCode] || agencyCode; } static displayNameAcronym(agency): string { diff --git a/angular/projects/public-nrpti/src/app/services/api.service.ts b/angular/projects/public-nrpti/src/app/services/api.service.ts index 45625f980..623525c85 100644 --- a/angular/projects/public-nrpti/src/app/services/api.service.ts +++ b/angular/projects/public-nrpti/src/app/services/api.service.ts @@ -3,7 +3,7 @@ import { HttpClient } from '@angular/common/http'; import { Observable, throwError } from 'rxjs'; import { Document } from '../../../../common/src/app/models/document'; -import { Utils, ConfigService , LoggerService} from 'nrpti-angular-components'; +import { Utils, ConfigService, LoggerService } from 'nrpti-angular-components'; /** * TODO: populate this documentation @@ -19,17 +19,12 @@ export class ApiService { pathAPI: string; env: 'local' | 'dev' | 'test' | 'prod'; - constructor( - public http: HttpClient, - private configService: ConfigService, - private logger: LoggerService - ) { - this.isMS = window.navigator.msSaveOrOpenBlob ? true : false; + constructor(public http: HttpClient, private configService: ConfigService, private logger: LoggerService) { + this.isMS = window.navigator.msSaveOrOpenBlob ? true : false; - this.env = this.configService.config['ENVIRONMENT']; + this.env = this.configService.config['ENVIRONMENT']; - this.pathAPI = this.configService.config['API_LOCATION'] - + this.configService.config['API_PUBLIC_PATH']; + this.pathAPI = this.configService.config['API_LOCATION'] + this.configService.config['API_PUBLIC_PATH']; } /** diff --git a/api/migrations/20230911220312-addApplicationAgenciesModel.js b/api/migrations/20230911220312-addApplicationAgenciesModel.js new file mode 100644 index 000000000..b0d048a25 --- /dev/null +++ b/api/migrations/20230911220312-addApplicationAgenciesModel.js @@ -0,0 +1,88 @@ +'use strict'; +const ApplicationAgency = require('../src/models/master/applicationAgency'); +const mongoose = require('mongoose'); + +var dbm; +var type; +var seed; + +/* +Migration file for adding agency codes and agency values to the nrpti collection +*/ + +exports.setup = function(options, seedLink) { + dbm = options.dbmigrate; + type = dbm.dataType; + seed = seedLink; +}; + +exports.up = async function (db) { + console.log('**** Adding ApplicationAgencies constants to nrpti collection ****'); + + // Connect to the database + const mClient = await db.connection.connect(db.connectionString, { + native_parser: true, + }); + + const agencies = [ + { agencyCode: "AGENCY_ALC", agencyName: 'Agricultural Land Commission' }, + { agencyCode: "AGENCY_WF", agencyName: 'BC Wildfire Service' }, + { agencyCode: "AGENCY_ENV_COS", agencyName: 'Conservation Officer Service' }, + { agencyCode: "AGENCY_EAO", agencyName: 'Environmental Assessment Office' }, + { agencyCode: "AGENCY_EMLI", agencyName: 'Ministry of Energy Mines and Low Carbon Innovation' }, + { agencyCode: "AGENCY_ENV", agencyName: 'Ministry of Environment and Climate Change Strategy' }, + { agencyCode: "AGENCY_ENV_BCPARKS", agencyName: 'BC Parks' }, + { agencyCode: "AGENCY_OGC", agencyName: 'BC Energy Regulator' }, + { agencyCode: "AGENCY_ENV_EPD", agencyName: 'Ministry of Environment and Climate Change Strategy' }, + { agencyCode: "AGENCY_LNG", agencyName: 'LNG Secretariat' }, + { agencyCode: "AGENCY_AGRI", agencyName: 'Ministry of Agriculture and Food' }, + { agencyCode: "AGENCY_FLNRO", agencyName: 'Ministry of Forests' }, + { agencyCode: "AGENCY_FLNR_NRO", agencyName: 'Natural Resource Officers' }, + { agencyCode: "AGENCY_WLRS", agencyName: 'Ministry of Water, Land and Resource Stewardship' }, + { agencyCode: "AGENCY_CAS", agencyName: 'Climate Action Secretariat' }, + ] + + try { + let currentCollection = await mClient.collection('nrpti'); + + for (const agency of agencies) { + const existingAgency = await currentCollection.findOne({ _schemaName: 'ApplicationAgency', agencyCode: agency['agencyCode'] }); + + if (!existingAgency) { + await currentCollection.insertOne( + { + _schemaName: 'ApplicationAgency', + agencyCode: agency['agencyCode'], + agencyName: agency['agencyName'], + read: ['sysadmin'], + write: ['sysadmin'], + dateAdded: new Date(), + dateUpdated: null, + addedBy: '', + updatedBy: '', + } + ); + console.log(` **** Add the ApplicationAgency code ${agency['agencyCode']} into nrpti collection ****`); + } else { + console.log(' **** ApplicationAgency code already exists in nrpti collection ****') + } + } + } catch (err) { + console.log(` **** Error updating nrpti collection for agency: ${agency['agencyName']} ****`, err); + } finally { + if (mClient) { + console.log(' **** Closing connection to nrpti collection ****') + await mClient.close(); + } + } + + return null; +}; + +exports.down = function(db) { + return null; +}; + +exports._meta = { + "version": 1 +}; diff --git a/api/migrations/20230912181649-updateIssuingAgencyToCode.js b/api/migrations/20230912181649-updateIssuingAgencyToCode.js new file mode 100644 index 000000000..b2a35065a --- /dev/null +++ b/api/migrations/20230912181649-updateIssuingAgencyToCode.js @@ -0,0 +1,121 @@ +'use strict'; + +var dbm; +var seed; + +/** + * Migration file for updating all existing records to use agency code instead of agency value + */ +exports.setup = function (options, seedLink) { + dbm = options.dbmigrate; + seed = seedLink; +}; + +exports.up = async function (db) { + const mClient = await db.connection.connect(db.connectionString, { + native_parser: true, + }); + + const LegislationActs = { + ACT_Env_Management: 'Environmental Management Act', + ACT_Int_Pest_Management: 'Integrated Pest Management Act', + }; + + const agencies = [ + { agencyCode: 'AGENCY_ALC', agencyName: 'Agricultural Land Commission' }, + { agencyCode: 'AGENCY_WF', agencyName: 'BC Wildfire Service' }, + { agencyCode: "AGENCY_ENV_COS", agencyName: 'Conservation Officer Service' }, + { agencyCode: "AGENCY_EAO", agencyName: 'Environmental Assessment Office' }, + { agencyCode: "AGENCY_EMLI", agencyName: 'Ministry of Energy Mines and Low Carbon Innovation' }, + { agencyCode: "AGENCY_ENV", agencyName: 'Ministry of Environment and Climate Change Strategy' }, + { agencyCode: "AGENCY_ENV_BCPARKS", agencyName: 'BC Parks' }, + { agencyCode: "AGENCY_OGC", agencyName: 'BC Energy Regulator' }, + { agencyCode: "AGENCY_ENV_EPD", agencyName: 'Ministry of Environment and Climate Change Strategy' }, + { agencyCode: "AGENCY_LNG", agencyName: 'LNG Secretariat' }, + { agencyCode: "AGENCY_AGRI", agencyName: 'Ministry of Agriculture and Food' }, + { agencyCode: "AGENCY_FLNRO", agencyName: 'Ministry of Forests' }, + { agencyCode: "AGENCY_FLNR_NRO", agencyName: 'Natural Resource Officers' }, + { agencyCode: "AGENCY_WLRS", agencyName: 'Ministry of Water, Land and Resource Stewardship' }, + { agencyCode: "AGENCY_CAS", agencyName: 'Climate Action Secretariat' } + ]; + + const collections = ['nrpti', 'redacted_record_subset']; + + try { + for (let collection of collections) { + console.log(`***** Collection: ${collection} *****`); + console.log(`***** Updating ocers-csv records *****`); + + try { + let currentCollection = await mClient.collection(collection); + + // Update issuingAgency to 'AGENCY_ENV_EPD' for specific records + await currentCollection.updateMany( + { + $and: [ + { issuingAgency: 'Ministry of Environment and Climate Change Strategy' }, + { author: 'Ministry of Environment and Climate Change Strategy' }, + { 'legislation.act': { $in: [LegislationActs.ACT_Env_Management, LegislationActs.ACT_Int_Pest_Management] } } + ] + }, + { $set: { issuingAgency: 'AGENCY_ENV_EPD', author: 'AGENCY_ENV_EPD' } } + ); + + console.log(` ***** Updated records in collection: ${collection} *****`); + } catch (err) { + console.error(` ***** Error updating collection: ${collection} *****`, err); + } + + console.log(`***** Updating all other records records *****`); + try { + let currentCollection = await mClient.collection(collection); + + for (const agency of agencies) { + // Update issuingAgency and author fields for the agency + await currentCollection.updateMany( + { + $and: [ + { issuingAgency: agency['agencyName'] }, + { author: agency['agencyName'] } + ] + }, + { $set: { issuingAgency: agency['agencyCode'], author: agency['agencyCode'] } } + ); + + console.log(` ***** Updated collection: ${collection} for agency: ${agency['agencyName']} *****`); + } + } catch (err) { + console.error(` ***** Error updating collection: ${collection} for agency: ${agency['agencyName']} *****`, err); + } + } + } catch (err) { + console.error('Error connecting to the database:', err); + } finally { + if (mClient) { + await mClient.close(); + } + } + + return null; +}; + +exports.down = function (db) { + return null; +}; + +exports._meta = { + version: 1 +}; + +/** + * Update a record in the collection with a new agency code. + * @param {Collection} collection - MongoDB collection. + * @param {string} recordId - The ID of the record to update. + * @param {string} newAgencyCode - The new agency code. + */ +async function updateRecord(collection, recordId, newAgencyCode) { + await collection.updateOne( + { _id: recordId }, + { $set: { 'legislation.act': newAgencyCode } } + ); +} diff --git a/api/src/controllers/agencies.js b/api/src/controllers/agencies.js new file mode 100644 index 000000000..dc224cfbe --- /dev/null +++ b/api/src/controllers/agencies.js @@ -0,0 +1,83 @@ +const queryActions = require('../utils/query-actions'); +const mongodb = require('../utils/mongodb'); +const RECORD_TYPE = require('../utils/constants/record-type-enum'); +const defaultLog = require('../utils/logger')('record'); + +/* +APIs for Update Issuing Agency page +Includes Get and Put apis to load and update agency names from the database +*/ + +exports.publicGet = async function(args, res, next) { + const db = mongodb.connection.db(process.env.MONGODB_DATABASE || 'nrpti-dev'); + const collectionDB = db.collection('nrpti'); + + let agencyList; + + try { + //Obtain documents with Application Agency Schema + let agencyDocuments = await collectionDB.find({ _schemaName: RECORD_TYPE.ApplicationAgency._schemaName }).toArray(); + //Using map function to iterate through the original array and creates a new array with objects containing only the _id, agencyCode, and agencyName properties. + agencyList = agencyDocuments.map(item => ({ + _id: item._id, + agencyCode: item.agencyCode, + agencyName: item.agencyName + })); + } catch (error) { + defaultLog.log(error); + throw error; + } + + queryActions.sendResponse(res, 200, agencyList); +}; +/** +* @param {*} args +* @param {*} res +* @param {*} next +* @param {*} incomingObj see example +* @returns edited lng order record +* Example of args.swagger.params.data.value + { + "agencies": + [ + { + "agencyCode": "AGENCY_ALC", + "agencyName": "Agricultural Land Commission_1" + } + ] + } +*/ + +exports.protectedPut = async function(args, res, next) { + const db = mongodb.connection.db(process.env.MONGODB_DATABASE || 'nrpti-dev'); + let promises = []; + let result = null; + let incomingObj = args.swagger.params.data.value; + const agencies = incomingObj['agencies']; + if (agencies && agencies.length > 0) { + const agencyCode = agencies[0]['agencyCode']; + const agencyName = agencies[0]['agencyName']; + const collectionDB = db.collection('nrpti'); + promises.push( + collectionDB.findOneAndUpdate( + { agencyCode: agencyCode }, + { + $set: { + agencyName: agencyName + } + } + ) + ); + } + try { + await Promise.all(promises); + result = 'Success'; + } catch (error) { + defaultLog.info(`protectedPut - agencies controller - error updating record: ${incomingObj}`); + defaultLog.debug(error); + result = 'Error'; + return queryActions.sendResponse(res, 400, {}); + } + queryActions.sendResponse(res, 200, result); + next(); +}; diff --git a/api/src/models/master/applicationAgency.js b/api/src/models/master/applicationAgency.js new file mode 100644 index 000000000..b5bebba03 --- /dev/null +++ b/api/src/models/master/applicationAgency.js @@ -0,0 +1,15 @@ +module.exports = require('../../utils/model-schema-generator')( + 'ApplicationAgencies', + { + _schemaName: { type: String, default: 'ApplicationAgency', index: true }, + agencyCode: { type: String, default: null, unique: true }, + agencyName: { type: String, default: null, required: true }, + read: [{ type: String, trim: true, default: 'sysadmin' }], + write: [{ type: String, trim: true, default: 'sysadmin' }], + dateAdded: { type: Date, default: Date.now() }, + dateUpdated: { type: Date, default: null }, + addedBy: { type: String, default: '' }, + updatedBy: { type: String, default: '' }, + }, + 'nrpti' + ); diff --git a/api/src/swagger/swagger.yaml b/api/src/swagger/swagger.yaml index e2a463954..4dcf6156b 100644 --- a/api/src/swagger/swagger.yaml +++ b/api/src/swagger/swagger.yaml @@ -238,6 +238,9 @@ definitions: message: type: string + UpdateAgencyObject: + type: object + paths: /config: x-swagger-router-controller: config @@ -2053,4 +2056,68 @@ paths: '403': description: 'Access Denied' schema: - $ref: '#/definitions/Error' \ No newline at end of file + $ref: '#/definitions/Error' + /list-agencies: + x-swagger-router-controller: agencies + options: + tags: + - agencies-list + summary: 'list agencies' + operationId: publicGet + responses: + '200': + description: "Success" + '403': + description: 'Access Denied' + get: + tags: + - agencies-list + summary: 'list agencies' + operationId: publicGet + responses: + '200': + description: "Success" + '403': + description: 'Access Denied' + /update-agencies: + x-swagger-router-controller: agencies + options: + tags: + - agencies-update + summary: 'update agencies' + operationId: protectedPut + parameters: + - in: body + name: data + description: 'Agency info to be updated' + required: true + schema: + $ref: '#/definitions/UpdateAgencyObject' + responses: + '200': + description: "Success" + '403': + description: 'Access Denied' + put: + tags: + - agencies-update + summary: 'update agencies' + security: + - Bearer: [] + x-security-scopes: + - sysadmin + - admin:lng + - admin:wlrs + operationId: protectedPut + parameters: + - in: body + name: data + description: 'Agency info to be updated' + required: true + schema: + $ref: '#/definitions/UpdateAgencyObject' + responses: + '200': + description: "Success" + '403': + description: 'Access Denied' diff --git a/api/src/utils/constants/record-type-enum.js b/api/src/utils/constants/record-type-enum.js index 58b976107..f1a4629bb 100644 --- a/api/src/utils/constants/record-type-enum.js +++ b/api/src/utils/constants/record-type-enum.js @@ -142,6 +142,12 @@ const RECORD_TYPE = Object.freeze({ displayName: 'Warning', recordControllerName: 'warnings', flavours: { lng: { _schemaName: 'WarningLNG' }, nrced: { _schemaName: 'WarningNRCED' } } + }, + ApplicationAgency: { + _schemaName: 'ApplicationAgency', + displayName: 'ApplicationAgency', + recordControllerName: 'agencies', + flavours: {} } }); module.exports = RECORD_TYPE;