From 61269634b958c5ca78f3717bffe47ff5595517ff Mon Sep 17 00:00:00 2001 From: David <62899351+davidclaveau@users.noreply.github.com> Date: Mon, 11 Sep 2023 13:53:22 -0700 Subject: [PATCH 01/77] add menu item and page code - wip --- .../admin-nrpti/src/app/app-routing.module.ts | 13 +++++++ .../admin-nrpti/src/app/app.module.ts | 2 + .../src/app/home/home.component.spec.ts | 1 + .../src/app/services/keycloak.service.ts | 3 ++ .../src/app/sidebar/sidebar.component.html | 8 ++++ .../src/app/sidebar/sidebar.component.spec.ts | 2 + .../update-issuing-agency.component.html | 3 ++ .../update-issuing-agency.component.scss | 2 + .../update-issuing-agency.component.ts | 15 +++++++ .../update-issuing-agency.module.ts | 39 +++++++++++++++++++ .../update-issuing-agency.resolver.ts | 12 ++++++ .../src/app/utils/constants/misc.ts | 3 +- 12 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.html create mode 100644 angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.scss create mode 100644 angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.ts create mode 100644 angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.module.ts create mode 100644 angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.resolver.ts 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..d70124e06 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 { UpdateIssuingAgencyComponent } from './update-issuing-agency/update-issuing-agency.component'; +import { UpdateIssuingAgencyResolver } from './update-issuing-agency/update-issuing-agency.resolver'; const routes: Routes = [ { @@ -60,6 +62,17 @@ const routes: Routes = [ } ] }, + { + path: 'update-issuing-agency', + pathMatch: 'full', + component: UpdateIssuingAgencyComponent, + resolve: { + records: UpdateIssuingAgencyResolver + }, + data: { + breadcrumb: 'Update Issuing Agency' + } + }, { // 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..d4c6ec1f0 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 { UpdateIssuingAgencyModule } from './update-issuing-agency/update-issuing-agency.module'; import { ToastrModule } from 'ngx-toastr'; // components @@ -98,6 +99,7 @@ export function overlayScrollFactory(overlay: Overlay): () => CloseScrollStrateg NewsModule, MinesModule, CommunicationsModule, + UpdateIssuingAgencyModule, AppRoutingModule, // <-- module import order matters - https://angular.io/guide/router#module-import-order-matters NgbModule.forRoot(), NgxPaginationModule, 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..30620d708 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.UPDATE_ISSUING_AGENCY: retVal = true; break; } return retVal; } 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..e9c59c209 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.UPDATE_ISSUING_AGENCY] = + 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..7da3bd911 100644 --- a/angular/projects/admin-nrpti/src/app/sidebar/sidebar.component.html +++ b/angular/projects/admin-nrpti/src/app/sidebar/sidebar.component.html @@ -102,5 +102,13 @@ chat Communications + + notifications_active + Update Issuing Agency + \ 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..05648b88e 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 @@ -38,6 +38,7 @@ describe('SidebarComponent', () => { case Constants.Menus.ENTITIES: retVal = false; break; case Constants.Menus.IMPORTS: retVal = true; break; case Constants.Menus.COMMUNICATIONS: retVal = true; break; + case Constants.Menus.UPDATE_ISSUING_AGENCY: retVal = true; break; } return retVal; } @@ -70,6 +71,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.UPDATE_ISSUING_AGENCY)).toEqual(true); expect(component.keycloakService.isMenuEnabled('Something Not Here')).toEqual(false); expect(component).toBeTruthy(); diff --git a/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.html b/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.html new file mode 100644 index 000000000..025bd3233 --- /dev/null +++ b/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.html @@ -0,0 +1,3 @@ +
+

Hello

+
\ No newline at end of file diff --git a/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.scss b/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.scss new file mode 100644 index 000000000..b5ec26e80 --- /dev/null +++ b/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.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/update-issuing-agency/update-issuing-agency.component.ts b/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.ts new file mode 100644 index 000000000..58d311765 --- /dev/null +++ b/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.ts @@ -0,0 +1,15 @@ + +import { Component, OnInit } from '@angular/core'; + +@Component({ + selector: 'app-update-issuing-agency', + templateUrl: './update-issuing-agency.component.html', + styleUrls: ['./update-issuing-agency.component.scss'] +}) +export class UpdateIssuingAgencyComponent implements OnInit { + public loading = false; + + ngOnInit(): void { + console.log("UpdateIssuingAgencyComponent.ngOnInit()") + } +} diff --git a/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.module.ts b/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.module.ts new file mode 100644 index 000000000..21d5f6955 --- /dev/null +++ b/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.module.ts @@ -0,0 +1,39 @@ +// 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 { UpdateIssuingAgencyComponent } from './update-issuing-agency.component'; +import { UpdateIssuingAgencyResolver } from './update-issuing-agency.resolver'; + + +@NgModule({ + imports: [ + BrowserModule, + EditorModule, + FormsModule, + ReactiveFormsModule, + CommonModule, + GlobalModule, + NrptiCommonModule, + RouterModule, + NgbModule, + ], + declarations: [ + UpdateIssuingAgencyComponent + ], + providers: [ + UpdateIssuingAgencyResolver + ], + entryComponents: [ + UpdateIssuingAgencyComponent + ], + exports: [] +}) +export class UpdateIssuingAgencyModule {} diff --git a/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.resolver.ts b/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.resolver.ts new file mode 100644 index 000000000..90c2e2f7b --- /dev/null +++ b/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.resolver.ts @@ -0,0 +1,12 @@ +import { Injectable } from '@angular/core'; +import { ActivatedRouteSnapshot, Resolve } from '@angular/router'; +import { Observable } from 'rxjs/Observable'; + + +@Injectable() +export class UpdateIssuingAgencyResolver implements Resolve> { + resolve(route: ActivatedRouteSnapshot): Observable { + console.log("UpdateIssuingAgencyResolver.resolve()") + return null; + } +} 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 0a61e760b..ff73372b1 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', + UPDATE_ISSUING_AGENCY: 'Update Issuing Agency' }; public static readonly RecordTypes: any = { From 32f14a4182bc0689451904a43c87a9e124fa7bd9 Mon Sep 17 00:00:00 2001 From: Christopher-walsh22 <106549296+Christopher-walsh22@users.noreply.github.com> Date: Mon, 11 Sep 2023 16:50:37 -0700 Subject: [PATCH 02/77] Updated the front end to display list of agencies from drop down and update values from that list with value from a text box. --- .../update-issuing-agency.component.html | 28 +++++++++++++++-- .../update-issuing-agency.component.ts | 30 +++++++++++++++---- .../projects/global/src/lib/utils/utils.ts | 16 ++++++++++ 3 files changed, 66 insertions(+), 8 deletions(-) diff --git a/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.html b/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.html index 025bd3233..864439593 100644 --- a/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.html +++ b/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.html @@ -1,3 +1,25 @@ -
-

Hello

-
\ No newline at end of file +
+

Update Issuing Agency

+ + + + + +
+ + +
+ + + + + +
+

Selected Agency: {{ agencies[selectedAgency] }}

+
+
diff --git a/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.ts b/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.ts index 58d311765..70508238a 100644 --- a/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.ts +++ b/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.ts @@ -1,15 +1,35 @@ - import { Component, OnInit } from '@angular/core'; - +import utils from 'esri/widgets/smartMapping/support/utils'; +import { ApplicationAgencyList } from '../../../../global/src/lib/utils/utils'; @Component({ selector: 'app-update-issuing-agency', templateUrl: './update-issuing-agency.component.html', styleUrls: ['./update-issuing-agency.component.scss'] }) export class UpdateIssuingAgencyComponent implements OnInit { - public loading = false; + public loading = false; + selectedAgency = 'Select an Agency'; // Set the initial selected value + choiceMade = false; + newAgency = ''; // Initialize the new agency input field + + agencies: {} = ApplicationAgencyList; - ngOnInit(): void { - console.log("UpdateIssuingAgencyComponent.ngOnInit()") + onSelected(value: string): void { + this.selectedAgency = value; + this.choiceMade = true; + } + + updateSelectedAgency(): void { + if (this.newAgency.trim() !== '') { + // Only update the selected agency if the new agency input is not empty + this.agencies[this.selectedAgency] = this.newAgency; + this.selectedAgency = this.newAgency; // Update the selected value + this.newAgency = ''; // Clear the input field + this.choiceMade = true; } + } + + ngOnInit(): void { + console.log('UpdateIssuingAgencyComponent.ngOnInit()'); + } } diff --git a/angular/projects/global/src/lib/utils/utils.ts b/angular/projects/global/src/lib/utils/utils.ts index c70929750..6ba5f429a 100644 --- a/angular/projects/global/src/lib/utils/utils.ts +++ b/angular/projects/global/src/lib/utils/utils.ts @@ -15,6 +15,22 @@ const ApplicationAgencies = { AGENCY_WLRS: 'Ministry of Water, Land and Resource Stewardship', }; +export var 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. * From 346cf1b7266eeda95891fab0d6a59cf6646667a0 Mon Sep 17 00:00:00 2001 From: David <62899351+davidclaveau@users.noreply.github.com> Date: Mon, 11 Sep 2023 16:56:12 -0700 Subject: [PATCH 03/77] create model and migration for agencies --- ...30911220312-addApplicationAgenciesModel.js | 66 +++++++++++++++++++ api/src/models/master/applicationAgency.js | 15 +++++ 2 files changed, 81 insertions(+) create mode 100644 api/migrations/20230911220312-addApplicationAgenciesModel.js create mode 100644 api/src/models/master/applicationAgency.js diff --git a/api/migrations/20230911220312-addApplicationAgenciesModel.js b/api/migrations/20230911220312-addApplicationAgenciesModel.js new file mode 100644 index 000000000..1fe7ef743 --- /dev/null +++ b/api/migrations/20230911220312-addApplicationAgenciesModel.js @@ -0,0 +1,66 @@ +'use strict'; +const ApplicationAgency = require('../src/models/master/applicationAgency'); +const mongoose = require('mongoose'); + +var dbm; +var type; +var seed; + +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 + mongoose.connect(db.connectionString, { useNewUrlParser: true, useUnifiedTopology: true }); + const dbConnection = mongoose.connection; + + dbConnection.on('error', console.error.bind(console, 'MongoDB connection error:')); + dbConnection.once('open', async function () { + const agencies = { + 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', + }; + + // Create and insert documents for each agency + const agencyInsertPromises = Object.entries(agencies).map(([code, name]) => + ApplicationAgency.create({ agencyCode: code, agencyName: name }) + .catch(error => { + console.error(`Error inserting agency ${code}:`, error); + }) + ); + + try { + // await Promise.all(agencyInsertPromises); + console.log('Migration completed successfully'); + } catch (error) { + console.error('Migration failed:', error); + } + }); + + mongoose.connection.close(); +}; + +exports.down = function(db) { + return null; +}; + +exports._meta = { + "version": 1 +}; \ No newline at end of file diff --git a/api/src/models/master/applicationAgency.js b/api/src/models/master/applicationAgency.js new file mode 100644 index 000000000..2c0b66759 --- /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 }, + agencyName: { type: String, default: null }, + 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' + ); \ No newline at end of file From f424e3979aacfb0ddae5e9b182708dee7b86aaee Mon Sep 17 00:00:00 2001 From: David <62899351+davidclaveau@users.noreply.github.com> Date: Mon, 11 Sep 2023 17:00:32 -0700 Subject: [PATCH 04/77] fix to model and migration - wip --- api/migrations/20230911220312-addApplicationAgenciesModel.js | 2 +- api/src/models/master/applicationAgency.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/api/migrations/20230911220312-addApplicationAgenciesModel.js b/api/migrations/20230911220312-addApplicationAgenciesModel.js index 1fe7ef743..30298b4f8 100644 --- a/api/migrations/20230911220312-addApplicationAgenciesModel.js +++ b/api/migrations/20230911220312-addApplicationAgenciesModel.js @@ -47,7 +47,7 @@ exports.up = async function (db) { ); try { - // await Promise.all(agencyInsertPromises); + await Promise.all(agencyInsertPromises); console.log('Migration completed successfully'); } catch (error) { console.error('Migration failed:', error); diff --git a/api/src/models/master/applicationAgency.js b/api/src/models/master/applicationAgency.js index 2c0b66759..ae292ce90 100644 --- a/api/src/models/master/applicationAgency.js +++ b/api/src/models/master/applicationAgency.js @@ -2,8 +2,8 @@ module.exports = require('../../utils/model-schema-generator')( 'ApplicationAgencies', { _schemaName: { type: String, default: 'ApplicationAgency', index: true }, - agencyCode: { type: String, default: null }, - agencyName: { type: String, default: null }, + 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() }, From 1d99fe53a0d6941e8c06b4fd167c5506aa857b80 Mon Sep 17 00:00:00 2001 From: David <62899351+davidclaveau@users.noreply.github.com> Date: Tue, 12 Sep 2023 11:40:40 -0700 Subject: [PATCH 05/77] update agency code migration, add update issuingAgency --- ...30911220312-addApplicationAgenciesModel.js | 19 ++++- ...0230912181649-updateIssuingAgencyToCode.js | 78 +++++++++++++++++++ 2 files changed, 94 insertions(+), 3 deletions(-) create mode 100644 api/migrations/20230912181649-updateIssuingAgencyToCode.js diff --git a/api/migrations/20230911220312-addApplicationAgenciesModel.js b/api/migrations/20230911220312-addApplicationAgenciesModel.js index 30298b4f8..ccebabcb1 100644 --- a/api/migrations/20230911220312-addApplicationAgenciesModel.js +++ b/api/migrations/20230911220312-addApplicationAgenciesModel.js @@ -40,7 +40,14 @@ exports.up = async function (db) { // Create and insert documents for each agency const agencyInsertPromises = Object.entries(agencies).map(([code, name]) => - ApplicationAgency.create({ agencyCode: code, agencyName: name }) + ApplicationAgency.create( + { + agencyCode: code, + agencyName: name, + read: ['sysadmin'], + write: ['sysadmin'], + } + ) .catch(error => { console.error(`Error inserting agency ${code}:`, error); }) @@ -51,10 +58,16 @@ exports.up = async function (db) { console.log('Migration completed successfully'); } catch (error) { console.error('Migration failed:', error); + } finally { + mongoose.connection.close(() => { + mongoose.connection.close(); + console.log('Database connection closed'); + process.exit(0); + }); + + return null } }); - - mongoose.connection.close(); }; exports.down = function(db) { diff --git a/api/migrations/20230912181649-updateIssuingAgencyToCode.js b/api/migrations/20230912181649-updateIssuingAgencyToCode.js new file mode 100644 index 000000000..f87ac1a49 --- /dev/null +++ b/api/migrations/20230912181649-updateIssuingAgencyToCode.js @@ -0,0 +1,78 @@ +'use strict'; + +var dbm; +var type; +var seed; + +/** + * We receive the dbmigrate dependency from dbmigrate initially. + * This enables us to not have to rely on NODE_PATH. + */ +exports.setup = function(options, seedLink) { + dbm = options.dbmigrate; + type = dbm.dataType; + seed = seedLink; +}; + + +exports.up = async function (db) { + 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' }, + ] + + const collections = ['nrpti', 'redacted_record_subset']; + + try { + for (let collection of collections) { + console.log(`***** Collection: ${collection} *****`); + + for (const agency of agencies) { + try { + let currentCollection = await mClient.collection(collection); + + await currentCollection.updateMany( + { issuingAgency: agency['agencyName'] }, + { $set: { issuingAgency: agency['agencyCode'] } } + ); + + console.log(` ***** Updated collection: ${collection} for agency: ${agency['agencyName']} *****`); + } catch (err) { + console.log(` ***** 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 +}; From 7e356ceb1cd408150c1d3f3872363aaf0aa89ca5 Mon Sep 17 00:00:00 2001 From: David <62899351+davidclaveau@users.noreply.github.com> Date: Tue, 12 Sep 2023 12:22:38 -0700 Subject: [PATCH 06/77] update model to only add to nrpti collection --- ...30911220312-addApplicationAgenciesModel.js | 102 +++++++++--------- 1 file changed, 53 insertions(+), 49 deletions(-) diff --git a/api/migrations/20230911220312-addApplicationAgenciesModel.js b/api/migrations/20230911220312-addApplicationAgenciesModel.js index ccebabcb1..609fab420 100644 --- a/api/migrations/20230911220312-addApplicationAgenciesModel.js +++ b/api/migrations/20230911220312-addApplicationAgenciesModel.js @@ -16,58 +16,62 @@ exports.up = async function (db) { console.log('**** Adding ApplicationAgencies constants to nrpti collection ****'); // Connect to the database - mongoose.connect(db.connectionString, { useNewUrlParser: true, useUnifiedTopology: true }); - const dbConnection = mongoose.connection; - - dbConnection.on('error', console.error.bind(console, 'MongoDB connection error:')); - dbConnection.once('open', async function () { - const agencies = { - 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', - }; - - // Create and insert documents for each agency - const agencyInsertPromises = Object.entries(agencies).map(([code, name]) => - ApplicationAgency.create( - { - agencyCode: code, - agencyName: name, - read: ['sysadmin'], - write: ['sysadmin'], - } - ) - .catch(error => { - console.error(`Error inserting agency ${code}:`, error); - }) - ); + const mClient = await db.connection.connect(db.connectionString, { + native_parser: true, + }); - try { - await Promise.all(agencyInsertPromises); - console.log('Migration completed successfully'); - } catch (error) { - console.error('Migration failed:', error); - } finally { - mongoose.connection.close(() => { - mongoose.connection.close(); - console.log('Database connection closed'); - process.exit(0); - }); + 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' }, + ] + + try { + let currentCollection = await mClient.collection('nrpti'); + + for (const agency of agencies) { + const existingAgency = await currentCollection.findOne({ _schemaName: 'ApplicationAgency', agencyCode: agency['agencyCode'] }); - return null + 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) { From 8cf29f91cfae76061fcaedfa3c7242ffcf95263d Mon Sep 17 00:00:00 2001 From: Sanjay Babu Date: Tue, 12 Sep 2023 16:28:30 -0700 Subject: [PATCH 07/77] sample api added - list-agencies WIP --- api/src/controllers/agencies.js | 66 +++++++++++++++++++++++++++++++++ api/src/swagger/swagger.yaml | 14 ++++++- 2 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 api/src/controllers/agencies.js diff --git a/api/src/controllers/agencies.js b/api/src/controllers/agencies.js new file mode 100644 index 000000000..be3ec5df1 --- /dev/null +++ b/api/src/controllers/agencies.js @@ -0,0 +1,66 @@ +const QueryActions = require('../utils/query-actions'); +const { metric: Metric } = require('../models/index'); + +exports.protectedOptions = function (args, res, next) { + res.status(200).send(); +}; + +exports.publicGetConfig = async function (args, res, next) { + // protected by swagger route by the scope +// const agg = [ +// { +// $match: { +// _schemaName: "Metric" +// } +// }, +// { +// $project: { +// code: 1 +// } +// } +// ]; + +// const metrics = await Metric.aggregate(agg); +let metrics = 'hello from publicGet' + + QueryActions.sendResponse(res, 200, metrics); +}; + +exports.protectedGet = async function (args, res, next) { +// if (!args.swagger.params.code) { +// return QueryActions.sendResponse(res, 400, {}); +// } + +// const query = { +// _schemaName: "Metric", +// code: args.swagger.params.code.value +// }; + +// const metric = await Metric.find(query); + + QueryActions.sendResponse(res, 200, 'hello from protectedGet'); +}; + +exports.protectedGetData = async function (args, res, next) { + const query = { + _schemaName: "Metric", + code: args.swagger.params.code.value + }; + + // Future: Set read/write roles on metric, guard against execution at this point. + const metric = await Metric.findOne(query); + + if (!metric.operation) { + return QueryActions.sendResponse(res, 400, {}); + } + + try { + const aggregateOperation = JSON.parse(metric.operation); + + const data = await Metric.aggregate(aggregateOperation); + + QueryActions.sendResponse(res, 200, data); + } catch (e) { + QueryActions.sendResponse(res, 400, e); + } +}; diff --git a/api/src/swagger/swagger.yaml b/api/src/swagger/swagger.yaml index e2a463954..868743adc 100644 --- a/api/src/swagger/swagger.yaml +++ b/api/src/swagger/swagger.yaml @@ -2053,4 +2053,16 @@ paths: '403': description: 'Access Denied' schema: - $ref: '#/definitions/Error' \ No newline at end of file + $ref: '#/definitions/Error' + /list-agencies: + get: + x-swagger-router-controller: agencies + tags: + - agencies-list + summary: 'list agencies' + operationId: publicGetConfig + responses: + '200': + description: "Success" + '403': + description: 'Access Denied' \ No newline at end of file From 5d55424798e695fc2b7cddf7dd17df592ee33672 Mon Sep 17 00:00:00 2001 From: Sanjay Babu Date: Wed, 13 Sep 2023 09:26:26 -0700 Subject: [PATCH 08/77] added api to list agencies, schema type --- .../update-issuing-agency.component.ts | 2 +- api/src/controllers/agencies.js | 75 +++++-------------- api/src/utils/constants/record-type-enum.js | 6 ++ 3 files changed, 25 insertions(+), 58 deletions(-) diff --git a/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.ts b/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.ts index 70508238a..dbd05e6c5 100644 --- a/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.ts +++ b/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.ts @@ -1,5 +1,5 @@ import { Component, OnInit } from '@angular/core'; -import utils from 'esri/widgets/smartMapping/support/utils'; +//import utils from 'esri/widgets/smartMapping/support/utils'; import { ApplicationAgencyList } from '../../../../global/src/lib/utils/utils'; @Component({ selector: 'app-update-issuing-agency', diff --git a/api/src/controllers/agencies.js b/api/src/controllers/agencies.js index be3ec5df1..43952a7a8 100644 --- a/api/src/controllers/agencies.js +++ b/api/src/controllers/agencies.js @@ -1,66 +1,27 @@ const QueryActions = require('../utils/query-actions'); -const { metric: Metric } = require('../models/index'); - -exports.protectedOptions = function (args, res, next) { - res.status(200).send(); -}; +const mongodb = require('../utils/mongodb'); +const RECORD_TYPE = require('../utils/constants/record-type-enum'); exports.publicGetConfig = async function (args, res, next) { - // protected by swagger route by the scope -// const agg = [ -// { -// $match: { -// _schemaName: "Metric" -// } -// }, -// { -// $project: { -// code: 1 -// } -// } -// ]; - -// const metrics = await Metric.aggregate(agg); -let metrics = 'hello from publicGet' - - QueryActions.sendResponse(res, 200, metrics); -}; - -exports.protectedGet = async function (args, res, next) { -// if (!args.swagger.params.code) { -// return QueryActions.sendResponse(res, 400, {}); -// } -// const query = { -// _schemaName: "Metric", -// code: args.swagger.params.code.value -// }; +const db = mongodb.connection.db(process.env.MONGODB_DATABASE || 'nrpti-dev'); +const collectionDB = db.collection('nrpti'); -// const metric = await Metric.find(query); - - QueryActions.sendResponse(res, 200, 'hello from protectedGet'); -}; - -exports.protectedGetData = async function (args, res, next) { - const query = { - _schemaName: "Metric", - code: args.swagger.params.code.value - }; - - // Future: Set read/write roles on metric, guard against execution at this point. - const metric = await Metric.findOne(query); - - if (!metric.operation) { - return QueryActions.sendResponse(res, 400, {}); - } + let agencyList; try { - const aggregateOperation = JSON.parse(metric.operation); - - const data = await Metric.aggregate(aggregateOperation); - - QueryActions.sendResponse(res, 200, data); - } catch (e) { - QueryActions.sendResponse(res, 400, e); + //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) { + console.log(error) + throw error; } + + QueryActions.sendResponse(res, 200, agencyList); }; 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; From 23044bbcf46ae482261cc7f63a8b9e74ed2b2866 Mon Sep 17 00:00:00 2001 From: Sanjay Babu Date: Wed, 13 Sep 2023 10:22:15 -0700 Subject: [PATCH 09/77] added get api --- api/src/controllers/agencies.js | 57 ++++++++++++++++++++++++++++++++- api/src/swagger/swagger.yaml | 2 +- 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/api/src/controllers/agencies.js b/api/src/controllers/agencies.js index 43952a7a8..47c3eaa5e 100644 --- a/api/src/controllers/agencies.js +++ b/api/src/controllers/agencies.js @@ -2,7 +2,7 @@ const QueryActions = require('../utils/query-actions'); const mongodb = require('../utils/mongodb'); const RECORD_TYPE = require('../utils/constants/record-type-enum'); -exports.publicGetConfig = async function (args, res, next) { +exports.publicGet = async function (args, res, next) { const db = mongodb.connection.db(process.env.MONGODB_DATABASE || 'nrpti-dev'); const collectionDB = db.collection('nrpti'); @@ -18,6 +18,7 @@ const collectionDB = db.collection('nrpti'); agencyCode: item.agencyCode, agencyName: item.agencyName })); + console.log('hello from publicGet') } catch (error) { console.log(error) throw error; @@ -25,3 +26,57 @@ const collectionDB = db.collection('nrpti'); QueryActions.sendResponse(res, 200, agencyList); }; + +// exports.protectedPost = async function (args, res, next) { +// // Confirm user has correct role for this type of record. +// // if (!userHasValidRoles([utils.ApplicationRoles.ADMIN, utils.ApplicationRoles.ADMIN_BCMI], args.swagger.params.auth_payload.client_roles)) { +// // throw new Error('Missing valid user role.'); +// // } + +// // let incomingObj = {}; +// // if (args.swagger.params.collection && args.swagger.params.collection.value) { +// // incomingObj = args.swagger.params.collection.value +// // } else { +// // defaultLog.info(`protectedPost - you must provide an id to post`); +// // queryActions.sendResponse(res, 400, {}); +// // next(); +// // } + +// // let obj = null; +// // try { +// // // Need to determine the published state of the mine and make the new collection match. +// // const minePublished = await isMinePublished(incomingObj); +// // if (minePublished) { +// // incomingObj.addRole = 'public'; +// // } + +// // obj = await createCollection(incomingObj, args.swagger.params.auth_payload.displayName); +// // } catch (error) { +// // defaultLog.info(`protectedPost - error inserting collection: ${incomingObj}`); +// // defaultLog.debug(error); +// // return queryActions.sendResponse(res, 400, {}); +// // } +// let promises = []; +// const collectionDB = db.collection('nrpti'); +// promises.push(collectionDB.findOneAndUpdate( +// { agencyCode: args.agencyCode }, +// { +// $set: { +// agencyName: args.agencyName +// }, +// $pull: { read: 'public' } +// } +// )); + + +// try { +// await Promise.all(promises); +// } catch (error) { +// defaultLog.info(`protectedPut - collection controller - error updating records with: ${collectionId}`); +// defaultLog.debug(error); +// throw error; +// } + +// queryActions.sendResponse(res, 200, obj.ops[0]); +// next(); +// } \ No newline at end of file diff --git a/api/src/swagger/swagger.yaml b/api/src/swagger/swagger.yaml index 868743adc..2a71f30cc 100644 --- a/api/src/swagger/swagger.yaml +++ b/api/src/swagger/swagger.yaml @@ -2060,7 +2060,7 @@ paths: tags: - agencies-list summary: 'list agencies' - operationId: publicGetConfig + operationId: publicGet responses: '200': description: "Success" From 8fe57851f02d2b61854a9ef0ae6832446a504c41 Mon Sep 17 00:00:00 2001 From: Sanjay Babu Date: Wed, 13 Sep 2023 14:02:21 -0700 Subject: [PATCH 10/77] put api added for updating agencies --- api/src/controllers/agencies.js | 121 +++++++++++++++----------------- api/src/swagger/swagger.yaml | 28 ++++++++ 2 files changed, 85 insertions(+), 64 deletions(-) diff --git a/api/src/controllers/agencies.js b/api/src/controllers/agencies.js index 47c3eaa5e..8d867efc9 100644 --- a/api/src/controllers/agencies.js +++ b/api/src/controllers/agencies.js @@ -1,82 +1,75 @@ -const QueryActions = require('../utils/query-actions'); +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'); -exports.publicGet = async function (args, res, next) { - -const db = mongodb.connection.db(process.env.MONGODB_DATABASE || 'nrpti-dev'); -const collectionDB = db.collection('nrpti'); +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 => ({ + 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 })); - console.log('hello from publicGet') } catch (error) { - console.log(error) + defaultLog.log(error); throw error; } - QueryActions.sendResponse(res, 200, agencyList); + 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.protectedPost = async function (args, res, next) { -// // Confirm user has correct role for this type of record. -// // if (!userHasValidRoles([utils.ApplicationRoles.ADMIN, utils.ApplicationRoles.ADMIN_BCMI], args.swagger.params.auth_payload.client_roles)) { -// // throw new Error('Missing valid user role.'); -// // } - -// // let incomingObj = {}; -// // if (args.swagger.params.collection && args.swagger.params.collection.value) { -// // incomingObj = args.swagger.params.collection.value -// // } else { -// // defaultLog.info(`protectedPost - you must provide an id to post`); -// // queryActions.sendResponse(res, 400, {}); -// // next(); -// // } - -// // let obj = null; -// // try { -// // // Need to determine the published state of the mine and make the new collection match. -// // const minePublished = await isMinePublished(incomingObj); -// // if (minePublished) { -// // incomingObj.addRole = 'public'; -// // } - -// // obj = await createCollection(incomingObj, args.swagger.params.auth_payload.displayName); -// // } catch (error) { -// // defaultLog.info(`protectedPost - error inserting collection: ${incomingObj}`); -// // defaultLog.debug(error); -// // return queryActions.sendResponse(res, 400, {}); -// // } -// let promises = []; -// const collectionDB = db.collection('nrpti'); -// promises.push(collectionDB.findOneAndUpdate( -// { agencyCode: args.agencyCode }, -// { -// $set: { -// agencyName: args.agencyName -// }, -// $pull: { read: 'public' } -// } -// )); - - -// try { -// await Promise.all(promises); -// } catch (error) { -// defaultLog.info(`protectedPut - collection controller - error updating records with: ${collectionId}`); -// defaultLog.debug(error); -// throw error; -// } - -// queryActions.sendResponse(res, 200, obj.ops[0]); -// next(); -// } \ No newline at end of file +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 collectionDB = db.collection('nrpti'); + for (let agency of incomingObj['agencies']) { + promises.push( + collectionDB.findOneAndUpdate( + { agencyCode: agency['agencyCode'] }, + { + $set: { + agencyName: agency['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/swagger/swagger.yaml b/api/src/swagger/swagger.yaml index 2a71f30cc..46f0441bf 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 @@ -2061,6 +2064,31 @@ paths: - agencies-list summary: 'list agencies' operationId: publicGet + responses: + '200': + description: "Success" + '403': + description: 'Access Denied' + /update-agencies: + put: + x-swagger-router-controller: agencies + 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" From 8711ada2545ec0de464c460b3c9124e3738cf117 Mon Sep 17 00:00:00 2001 From: Christopher-walsh22 <106549296+Christopher-walsh22@users.noreply.github.com> Date: Thu, 14 Sep 2023 09:04:53 -0700 Subject: [PATCH 11/77] New component to make request to new endpoint for issuing agencies --- .../src/app/services/issuingagency.service.ts | 19 ++++++++ .../update-issuing-agency.component.html | 9 +++- .../update-issuing-agency.component.ts | 43 ++++++++++++++----- 3 files changed, 60 insertions(+), 11 deletions(-) create mode 100644 angular/projects/admin-nrpti/src/app/services/issuingagency.service.ts 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..298bbcd4a --- /dev/null +++ b/angular/projects/admin-nrpti/src/app/services/issuingagency.service.ts @@ -0,0 +1,19 @@ +import { Injectable } from '@angular/core'; +import { HttpClient } from '@angular/common/http'; + +import { ApiService } from './api.service'; + +@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 + }); + } +} diff --git a/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.html b/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.html index 864439593..c21a78817 100644 --- a/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.html +++ b/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.html @@ -5,7 +5,7 @@

Update Issuing Agency

@@ -22,4 +22,11 @@

Update Issuing Agency

Selected Agency: {{ agencies[selectedAgency] }}

+ +
+

Agencies

+

+ {{ key }}: {{ agencies[key] }} +

+
diff --git a/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.ts b/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.ts index dbd05e6c5..722664ccf 100644 --- a/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.ts +++ b/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.ts @@ -1,6 +1,8 @@ import { Component, OnInit } from '@angular/core'; -//import utils from 'esri/widgets/smartMapping/support/utils'; -import { ApplicationAgencyList } from '../../../../global/src/lib/utils/utils'; +import { IssuingAgencyService } from '../services/issuingagency.service'; +import { LoggerService } from 'nrpti-angular-components'; +import { Observable, of } from 'rxjs'; + @Component({ selector: 'app-update-issuing-agency', templateUrl: './update-issuing-agency.component.html', @@ -8,11 +10,15 @@ import { ApplicationAgencyList } from '../../../../global/src/lib/utils/utils'; }) export class UpdateIssuingAgencyComponent implements OnInit { public loading = false; - selectedAgency = 'Select an Agency'; // Set the initial selected value + selectedAgency: string = ''; // Initialize the selectedAgency choiceMade = false; - newAgency = ''; // Initialize the new agency input field + newAgency: string = ''; // Initialize the new agency input field + agencies$: Observable<{ [key: string]: string }> = of({"Kyle": "Williams"}); // Initialize agencies as an Observable - agencies: {} = ApplicationAgencyList; + constructor( + private issuingAgencyService: IssuingAgencyService, + private logger: LoggerService + ) {} onSelected(value: string): void { this.selectedAgency = value; @@ -22,14 +28,31 @@ export class UpdateIssuingAgencyComponent implements OnInit { updateSelectedAgency(): void { if (this.newAgency.trim() !== '') { // Only update the selected agency if the new agency input is not empty - this.agencies[this.selectedAgency] = this.newAgency; - this.selectedAgency = this.newAgency; // Update the selected value - this.newAgency = ''; // Clear the input field - this.choiceMade = true; + this.agencies$.subscribe(agencies => { + agencies[this.selectedAgency] = this.newAgency; + this.selectedAgency = this.newAgency; // Update the selected value + this.newAgency = ''; // Clear the input field + this.choiceMade = true; + }); } } ngOnInit(): void { - console.log('UpdateIssuingAgencyComponent.ngOnInit()'); + this.issuingAgencyService.getIssuingAgencies() + .then(response => { + const agencies = {}; + if (response && Array.isArray(response)) { + response.forEach(agency => { + agencies[agency._id] = agency.agencyName; + }); + } + this.agencies$ = of(agencies); // Assign the agencies object as an Observable + console.log("IS IT IN THE CONSOLE?") + alert(JSON.stringify(this.agencies$)) + }) + .catch(error => { + console.error('API call error:', error); + }); + this.logger.level = 0; } } From de0f22c6033f97330e1977410e2520f00292ca31 Mon Sep 17 00:00:00 2001 From: Sanjay Babu Date: Thu, 14 Sep 2023 09:38:04 -0700 Subject: [PATCH 12/77] Options added --- api/src/swagger/swagger.yaml | 37 ++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/api/src/swagger/swagger.yaml b/api/src/swagger/swagger.yaml index 46f0441bf..8707c3abf 100644 --- a/api/src/swagger/swagger.yaml +++ b/api/src/swagger/swagger.yaml @@ -2058,8 +2058,18 @@ paths: schema: $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: - x-swagger-router-controller: agencies tags: - agencies-list summary: 'list agencies' @@ -2070,8 +2080,31 @@ paths: '403': description: 'Access Denied' /update-agencies: + x-swagger-router-controller: agencies + options: + 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' put: - x-swagger-router-controller: agencies tags: - agencies-update summary: 'update agencies' From 1b8b7b0246c06f12bf08254ebbba80d90f519fb6 Mon Sep 17 00:00:00 2001 From: Christopher-walsh22 <106549296+Christopher-walsh22@users.noreply.github.com> Date: Thu, 14 Sep 2023 09:58:24 -0700 Subject: [PATCH 13/77] Fixed component to properly display the information returned from get request --- .../update-issuing-agency.component.html | 15 ++++------- .../update-issuing-agency.component.ts | 25 +++++++++++++------ 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.html b/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.html index c21a78817..bb87f599a 100644 --- a/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.html +++ b/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.html @@ -4,8 +4,8 @@

Update Issuing Agency

@@ -20,13 +20,8 @@

Update Issuing Agency

-

Selected Agency: {{ agencies[selectedAgency] }}

-
- -
-

Agencies

-

- {{ key }}: {{ agencies[key] }} -

+

Selected Agency: {{ selectedAgency }}

+ + diff --git a/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.ts b/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.ts index 722664ccf..d2756efe4 100644 --- a/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.ts +++ b/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.ts @@ -13,7 +13,8 @@ export class UpdateIssuingAgencyComponent implements OnInit { selectedAgency: string = ''; // Initialize the selectedAgency choiceMade = false; newAgency: string = ''; // Initialize the new agency input field - agencies$: Observable<{ [key: string]: string }> = of({"Kyle": "Williams"}); // Initialize agencies as an Observable + agencies: { [key: string]: string } = {"Kyle": "Williams"}; + agencyList = [] constructor( private issuingAgencyService: IssuingAgencyService, @@ -27,15 +28,15 @@ export class UpdateIssuingAgencyComponent implements OnInit { updateSelectedAgency(): void { if (this.newAgency.trim() !== '') { - // Only update the selected agency if the new agency input is not empty - this.agencies$.subscribe(agencies => { - agencies[this.selectedAgency] = this.newAgency; + + this.agencies[this.selectedAgency] = this.newAgency; this.selectedAgency = this.newAgency; // Update the selected value this.newAgency = ''; // Clear the input field this.choiceMade = true; - }); + }; + alert(this.agencies) } - } + ngOnInit(): void { this.issuingAgencyService.getIssuingAgencies() @@ -46,9 +47,17 @@ export class UpdateIssuingAgencyComponent implements OnInit { agencies[agency._id] = agency.agencyName; }); } - this.agencies$ = of(agencies); // Assign the agencies object as an Observable + this.agencies = agencies; // Assign the agencies object as an Observable console.log("IS IT IN THE CONSOLE?") - alert(JSON.stringify(this.agencies$)) + alert(JSON.stringify(this.agencies)) + + for (const key in agencies) { + if (agencies.hasOwnProperty(key)) { + this.agencyList.push(agencies[key]); + } + } + alert(this.agencyList) + }) .catch(error => { console.error('API call error:', error); From 30be5315687ae5ef177c708c080fafb214c47e76 Mon Sep 17 00:00:00 2001 From: Christopher-walsh22 <106549296+Christopher-walsh22@users.noreply.github.com> Date: Thu, 14 Sep 2023 12:19:08 -0700 Subject: [PATCH 14/77] Update the agencyList array with selection from drop down menu. Create the object which will be sent to the api for updating the agencyList. Also worth noting the alerts are being used here for console debugging. My local settings are preventing logging, when I find the reason I will update readme to document process --- .../update-issuing-agency.component.html | 2 +- .../update-issuing-agency.component.ts | 44 ++++++++++++++----- 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.html b/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.html index bb87f599a..7aaeaf0d4 100644 --- a/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.html +++ b/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.html @@ -18,7 +18,7 @@

Update Issuing Agency

- +

Selected Agency: {{ selectedAgency }}

diff --git a/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.ts b/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.ts index d2756efe4..2b05dd513 100644 --- a/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.ts +++ b/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.ts @@ -14,8 +14,10 @@ export class UpdateIssuingAgencyComponent implements OnInit { choiceMade = false; newAgency: string = ''; // Initialize the new agency input field agencies: { [key: string]: string } = {"Kyle": "Williams"}; - agencyList = [] - + agencyList: string[] = ["-Select-"]; // Use a string array for agencyList + updatedData: any = { + "agencies": [] + }; constructor( private issuingAgencyService: IssuingAgencyService, private logger: LoggerService @@ -28,15 +30,34 @@ export class UpdateIssuingAgencyComponent implements OnInit { updateSelectedAgency(): void { 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; - this.agencies[this.selectedAgency] = this.newAgency; - this.selectedAgency = this.newAgency; // Update the selected value - this.newAgency = ''; // Clear the input field + // Clear the input field + this.newAgency = ''; this.choiceMade = true; - }; - alert(this.agencies) - } + // Update the updatedData object to match the desired layout + this.updatedData.agencies.push({ + "agencyCode": matchingCode, + "agencyName": this.selectedAgency + }); + } + } + alert(JSON.stringify(this.updatedData)) + } ngOnInit(): void { this.issuingAgencyService.getIssuingAgencies() @@ -44,19 +65,18 @@ export class UpdateIssuingAgencyComponent implements OnInit { const agencies = {}; if (response && Array.isArray(response)) { response.forEach(agency => { - agencies[agency._id] = agency.agencyName; + agencies[agency.agencyCode] = agency.agencyName; }); } this.agencies = agencies; // Assign the agencies object as an Observable - console.log("IS IT IN THE CONSOLE?") - alert(JSON.stringify(this.agencies)) + alert(JSON.stringify(this.agencies)); for (const key in agencies) { if (agencies.hasOwnProperty(key)) { this.agencyList.push(agencies[key]); } } - alert(this.agencyList) + alert(this.agencyList); }) .catch(error => { From 8e41013503ffed1841f64814121a4feda1a80073 Mon Sep 17 00:00:00 2001 From: Christopher-walsh22 <106549296+Christopher-walsh22@users.noreply.github.com> Date: Thu, 14 Sep 2023 14:36:06 -0700 Subject: [PATCH 15/77] First steps of patch logic to the update agency service --- .../src/app/services/issuingagency.service.ts | 13 +++++++++++++ .../update-issuing-agency.component.ts | 8 ++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/angular/projects/admin-nrpti/src/app/services/issuingagency.service.ts b/angular/projects/admin-nrpti/src/app/services/issuingagency.service.ts index 298bbcd4a..892610b38 100644 --- a/angular/projects/admin-nrpti/src/app/services/issuingagency.service.ts +++ b/angular/projects/admin-nrpti/src/app/services/issuingagency.service.ts @@ -16,4 +16,17 @@ export class IssuingAgencyService { throw error; // Rethrow the error to propagate it further }); } + + public updateAgency(agencyCode: string, agencyName: any): Promise { + const apiUrl = `${this.apiService.pathAPI}/update-agencies`; + let updatedAgency = { "agencies": [{"agencyCode": agencyCode, "agencyName": agencyName}]} + console.log(updatedAgency) + alert(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/update-issuing-agency/update-issuing-agency.component.ts b/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.ts index 2b05dd513..8dcf921cc 100644 --- a/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.ts +++ b/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.ts @@ -27,7 +27,9 @@ export class UpdateIssuingAgencyComponent implements OnInit { this.selectedAgency = value; this.choiceMade = true; } - + putRecords(agencyCode: any, agencyName: any){ + this.issuingAgencyService.updateAgency(agencyCode, agencyName) + } updateSelectedAgency(): void { if (this.newAgency.trim() !== '') { // Find the agency code that matches the selected agency name @@ -54,9 +56,11 @@ export class UpdateIssuingAgencyComponent implements OnInit { "agencyCode": matchingCode, "agencyName": this.selectedAgency }); + this.putRecords(this.updatedData.agencies["agencyCode"], this.updatedData.agencies["agencyName"]) + alert(JSON.stringify(this.updatedData)) + this.updatedData.agencies = [] } } - alert(JSON.stringify(this.updatedData)) } ngOnInit(): void { From 58a0f7d091a999a7642086db8bb9c8a3363b1bde Mon Sep 17 00:00:00 2001 From: Christopher-walsh22 <106549296+Christopher-walsh22@users.noreply.github.com> Date: Thu, 14 Sep 2023 16:36:32 -0700 Subject: [PATCH 16/77] Front end component updates entries in for agency issuers through new endpoint. --- .../src/app/services/issuingagency.service.ts | 9 +++--- .../update-issuing-agency.component.ts | 11 +------ api/src/controllers/agencies.js | 32 ++++++++++++------- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/angular/projects/admin-nrpti/src/app/services/issuingagency.service.ts b/angular/projects/admin-nrpti/src/app/services/issuingagency.service.ts index 892610b38..ee77310de 100644 --- a/angular/projects/admin-nrpti/src/app/services/issuingagency.service.ts +++ b/angular/projects/admin-nrpti/src/app/services/issuingagency.service.ts @@ -19,14 +19,15 @@ export class IssuingAgencyService { public updateAgency(agencyCode: string, agencyName: any): Promise { const apiUrl = `${this.apiService.pathAPI}/update-agencies`; - let updatedAgency = { "agencies": [{"agencyCode": agencyCode, "agencyName": agencyName}]} - console.log(updatedAgency) - alert(updatedAgency) + let updatedAgency = { "agencies": [{"agencyCode": agencyCode, "agencyName": agencyName}]}; // Wrap the array in an object + console.log(JSON.stringify(updatedAgency)); + alert(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/update-issuing-agency/update-issuing-agency.component.ts b/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.ts index 8dcf921cc..171fd0d0e 100644 --- a/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.ts +++ b/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.ts @@ -36,28 +36,23 @@ export class UpdateIssuingAgencyComponent implements OnInit { 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(this.updatedData.agencies["agencyCode"], this.updatedData.agencies["agencyName"]) - alert(JSON.stringify(this.updatedData)) + this.putRecords(matchingCode, this.selectedAgency); this.updatedData.agencies = [] } } @@ -73,15 +68,11 @@ export class UpdateIssuingAgencyComponent implements OnInit { }); } this.agencies = agencies; // Assign the agencies object as an Observable - alert(JSON.stringify(this.agencies)); - for (const key in agencies) { if (agencies.hasOwnProperty(key)) { this.agencyList.push(agencies[key]); } } - alert(this.agencyList); - }) .catch(error => { console.error('API call error:', error); diff --git a/api/src/controllers/agencies.js b/api/src/controllers/agencies.js index 8d867efc9..4159d36f1 100644 --- a/api/src/controllers/agencies.js +++ b/api/src/controllers/agencies.js @@ -44,23 +44,31 @@ exports.publicGet = async function(args, res, next) { */ 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 collectionDB = db.collection('nrpti'); - for (let agency of incomingObj['agencies']) { - promises.push( - collectionDB.findOneAndUpdate( - { agencyCode: agency['agencyCode'] }, - { - $set: { - agencyName: agency['agencyName'] - } + console.log("iiiiiiiiiiiiiiiiiiiii ---->" + JSON.stringify(incomingObj)) + + 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'; From 70c61224e0d84763be651d03ab818691e0cda3ee Mon Sep 17 00:00:00 2001 From: Sanjay Babu Date: Fri, 15 Sep 2023 08:51:21 -0700 Subject: [PATCH 17/77] security token enabled, alerts removed, compile issue fixed --- .../src/app/services/issuingagency.service.ts | 1 - .../update-issuing-agency.component.ts | 2 +- api/src/swagger/swagger.yaml | 18 ++++++------------ 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/angular/projects/admin-nrpti/src/app/services/issuingagency.service.ts b/angular/projects/admin-nrpti/src/app/services/issuingagency.service.ts index ee77310de..b24e05ee8 100644 --- a/angular/projects/admin-nrpti/src/app/services/issuingagency.service.ts +++ b/angular/projects/admin-nrpti/src/app/services/issuingagency.service.ts @@ -21,7 +21,6 @@ export class IssuingAgencyService { const apiUrl = `${this.apiService.pathAPI}/update-agencies`; let updatedAgency = { "agencies": [{"agencyCode": agencyCode, "agencyName": agencyName}]}; // Wrap the array in an object console.log(JSON.stringify(updatedAgency)); - alert(updatedAgency); return this.http.put(apiUrl, updatedAgency) .toPromise() .catch((error) => { diff --git a/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.ts b/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.ts index 171fd0d0e..4a1d101a4 100644 --- a/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.ts +++ b/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.ts @@ -1,7 +1,7 @@ import { Component, OnInit } from '@angular/core'; import { IssuingAgencyService } from '../services/issuingagency.service'; import { LoggerService } from 'nrpti-angular-components'; -import { Observable, of } from 'rxjs'; +// import { Observable, of } from 'rxjs'; @Component({ selector: 'app-update-issuing-agency', diff --git a/api/src/swagger/swagger.yaml b/api/src/swagger/swagger.yaml index 8707c3abf..865bdb07d 100644 --- a/api/src/swagger/swagger.yaml +++ b/api/src/swagger/swagger.yaml @@ -2085,12 +2085,6 @@ paths: tags: - agencies-update summary: 'update agencies' - # security: - # - Bearer: [] - # x-security-scopes: - # - sysadmin - # - admin:lng - # - admin:wlrs operationId: protectedPut parameters: - in: body @@ -2108,12 +2102,12 @@ paths: tags: - agencies-update summary: 'update agencies' - # security: - # - Bearer: [] - # x-security-scopes: - # - sysadmin - # - admin:lng - # - admin:wlrs + security: + - Bearer: [] + x-security-scopes: + - sysadmin + - admin:lng + - admin:wlrs operationId: protectedPut parameters: - in: body From c118d7fc222b28fdfa809131b104ce2fb2940342 Mon Sep 17 00:00:00 2001 From: Sanjay Babu Date: Fri, 15 Sep 2023 09:52:57 -0700 Subject: [PATCH 18/77] toast added --- .../update-issuing-agency.component.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.ts b/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.ts index 4a1d101a4..1ac5a20f6 100644 --- a/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.ts +++ b/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.ts @@ -1,6 +1,8 @@ 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 { Observable, of } from 'rxjs'; @Component({ @@ -20,7 +22,8 @@ export class UpdateIssuingAgencyComponent implements OnInit { }; constructor( private issuingAgencyService: IssuingAgencyService, - private logger: LoggerService + private logger: LoggerService, + private toastService: ToastService ) {} onSelected(value: string): void { @@ -31,6 +34,7 @@ export class UpdateIssuingAgencyComponent implements OnInit { this.issuingAgencyService.updateAgency(agencyCode, agencyName) } updateSelectedAgency(): void { + try{ if (this.newAgency.trim() !== '') { // Find the agency code that matches the selected agency name const matchingCode = Object.keys(this.agencies).find( @@ -55,8 +59,17 @@ export class UpdateIssuingAgencyComponent implements OnInit { this.putRecords(matchingCode, this.selectedAgency); this.updatedData.agencies = [] } + this.toastService.addMessage('Agency Successfully Updated', 'Success Updated', Constants.ToastTypes.SUCCESS); } } +catch (error) { + this.toastService.addMessage( + 'An error has occured while saving', + 'Save unsuccessful', + Constants.ToastTypes.ERROR + ); +} + } ngOnInit(): void { this.issuingAgencyService.getIssuingAgencies() From 5688d7264d94d4c6db30caea86412df499482ee5 Mon Sep 17 00:00:00 2001 From: Sanjay Babu Date: Fri, 15 Sep 2023 09:55:51 -0700 Subject: [PATCH 19/77] button style updated --- .../update-issuing-agency/update-issuing-agency.component.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.html b/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.html index 7aaeaf0d4..6ff80c8f2 100644 --- a/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.html +++ b/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.html @@ -16,7 +16,8 @@

Update Issuing Agency

- + +
From edca104c720902854c11302493f0605ee78f3543 Mon Sep 17 00:00:00 2001 From: Sanjay Babu Date: Fri, 15 Sep 2023 10:27:56 -0700 Subject: [PATCH 20/77] Style added to dropdown --- .../update-issuing-agency.component.html | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.html b/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.html index 6ff80c8f2..211b51234 100644 --- a/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.html +++ b/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.html @@ -4,9 +4,14 @@

Update Issuing Agency

From 8c5876676162cc672e230770bf4766756bef67dc Mon Sep 17 00:00:00 2001 From: Sanjay Babu Date: Fri, 15 Sep 2023 10:29:23 -0700 Subject: [PATCH 21/77] current selected agency removed --- .../update-issuing-agency.component.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.html b/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.html index 211b51234..6b242a720 100644 --- a/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.html +++ b/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.html @@ -25,9 +25,9 @@

Update Issuing Agency

-
+
From d6982c3a9d1e5eb34f8e9a0e07c387d820a28b56 Mon Sep 17 00:00:00 2001 From: David <62899351+davidclaveau@users.noreply.github.com> Date: Fri, 15 Sep 2023 11:52:07 -0700 Subject: [PATCH 22/77] wip - add agency service to app_init, change displayName --- .../admin-nrpti/src/app/app.module.ts | 11 ++-- .../inspection-add-edit.component.ts | 4 +- .../app/services/applicationAgency.service.ts | 55 +++++++++++++++++++ .../src/app/services/factory.service.ts | 17 ++++++ .../projects/global/src/lib/utils/utils.ts | 16 ++---- 5 files changed, 85 insertions(+), 18 deletions(-) create mode 100644 angular/projects/admin-nrpti/src/app/services/applicationAgency.service.ts diff --git a/angular/projects/admin-nrpti/src/app/app.module.ts b/angular/projects/admin-nrpti/src/app/app.module.ts index d4c6ec1f0..659ac1ee5 100644 --- a/angular/projects/admin-nrpti/src/app/app.module.ts +++ b/angular/projects/admin-nrpti/src/app/app.module.ts @@ -44,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/applicationAgency.service'; // resolvers import { ImportListResolver } from './import/import-list-resolver'; @@ -60,12 +61,13 @@ 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(); + } +}; export function overlayScrollFactory(overlay: Overlay): () => CloseScrollStrategy { return () => overlay.scrollStrategies.close(); @@ -110,7 +112,7 @@ export function overlayScrollFactory(overlay: Overlay): () => CloseScrollStrateg { provide: APP_INITIALIZER, useFactory: initConfig, - deps: [ConfigService, KeycloakService], + deps: [ConfigService, KeycloakService, ApplicationAgencyService], multi: true }, { @@ -131,6 +133,7 @@ export function overlayScrollFactory(overlay: Overlay): () => CloseScrollStrateg NewsService, CollectionService, KeycloakService, + ApplicationAgencyService, LoggerService, TaskService, ImportListResolver, 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..adb64a0c3 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 @@ -514,8 +514,8 @@ export class InspectionAddEditComponent implements OnInit, OnDestroy { return Utils.convertAcronyms(acronym); } - displayName(agency) { - return Utils.displayNameFull(agency); + displayName(agencyCode) { + return Utils.displayNameFull(agencyCode); } cancel() { diff --git a/angular/projects/admin-nrpti/src/app/services/applicationAgency.service.ts b/angular/projects/admin-nrpti/src/app/services/applicationAgency.service.ts new file mode 100644 index 000000000..08cd91eff --- /dev/null +++ b/angular/projects/admin-nrpti/src/app/services/applicationAgency.service.ts @@ -0,0 +1,55 @@ +import { Injectable } from '@angular/core'; +import { ConfigService } from 'nrpti-angular-components'; +import { Observable } from 'rxjs'; +import { HttpClient } from '@angular/common/http'; +// import { Utils } from '../../../../global/src/lib/utils/utils'; + +@Injectable() +export class ApplicationAgencyService { + private api: string; + + constructor( + private configService: ConfigService, + public http: HttpClient + ) {} + + async init() { + this.api = `${this.configService.config['API_LOCATION']}${this.configService.config['API_PATH']}`; + + // Start the initial agencies retrieval. + await this.refreshAgencies().toPromise(); + } + + // ... Other methods ... + refreshAgencies(): Observable { + return new Observable(observer => { + console.log("refreshAgencies here"); + + // Construct the full API endpoint URL + const apiEndpoint = `${this.api}/list-agencies`; + + // Make the HTTP GET request + const getAgencies = this.http.get(apiEndpoint); + + // Subscribe to the HTTP request and handle the response + getAgencies.subscribe( + (response) => { + // Update the agency list by calling the updateAgencyList function + // Utils.setAgencyList(response); + + observer.next(); + observer.complete(); + }, + (error) => { + console.error("HTTP Request Error: ", error); + + // You can handle errors here if needed + // ... + + // Notify the observer about the error + observer.error(error); + } + ); + }); + } +} 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..823e88b28 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 './applicationAgency.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. @@ -625,4 +627,19 @@ export class FactoryService { public updateMapLayerInfo(mapLayerInfo): Promise { return this.mapLayerInfoService.updateMapLayerInfo(mapLayerInfo); } + + /** + * Inject agencies service if it hasn't already been injected. + * + * @readonly + * @type {ApplicationAgencyService} + * @memberof FactoryService + */ + public get applicationAgencyService(): ApplicationAgencyService { + if (!this._applicationAgencyService) { + this._applicationAgencyService = this.injector.get(ApplicationAgencyService); + } + + return this._applicationAgencyService; + } } diff --git a/angular/projects/global/src/lib/utils/utils.ts b/angular/projects/global/src/lib/utils/utils.ts index 6ba5f429a..7f00f9b26 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', @@ -150,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 { From bf4856d3ca450a34b0c826405cdff528b85c09f6 Mon Sep 17 00:00:00 2001 From: Sanjay Babu Date: Fri, 15 Sep 2023 15:13:33 -0700 Subject: [PATCH 23/77] error message added --- .../update-issuing-agency.component.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.ts b/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.ts index 1ac5a20f6..4a874d546 100644 --- a/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.ts +++ b/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.ts @@ -60,6 +60,12 @@ export class UpdateIssuingAgencyComponent implements OnInit { 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) { From d8ec256beb83ccfa6c3ce81b9db16b774289ccb1 Mon Sep 17 00:00:00 2001 From: Sanjay Babu Date: Mon, 18 Sep 2023 11:48:33 -0700 Subject: [PATCH 24/77] removed logging and fixed indentation --- api/src/controllers/agencies.js | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/api/src/controllers/agencies.js b/api/src/controllers/agencies.js index 4159d36f1..cd631b4d7 100644 --- a/api/src/controllers/agencies.js +++ b/api/src/controllers/agencies.js @@ -44,31 +44,26 @@ exports.publicGet = async function(args, res, next) { */ 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; - console.log("iiiiiiiiiiiiiiiiiiiii ---->" + JSON.stringify(incomingObj)) - 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 + promises.push( + collectionDB.findOneAndUpdate( + { agencyCode: agencyCode }, + { + $set: { + agencyName: agencyName + } } - } - ) - );} + ) + ); + } try { await Promise.all(promises); result = 'Success'; From b5a1fc3ad08bec6dec2166f101ea9fad30503052 Mon Sep 17 00:00:00 2001 From: Sanjay Babu Date: Mon, 18 Sep 2023 12:08:12 -0700 Subject: [PATCH 25/77] replaced hardcoded agency names with api calls --- .../inspection-detail.component.ts | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) 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..26d7b2b9b 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 { IssuingAgencyService } from '../../../services/issuingagency.service'; @Component({ selector: 'app-inspection-detail', @@ -19,11 +19,14 @@ export class InspectionDetailComponent extends RecordDetailComponent implements public legislationString = ''; + public issuingAgencyMap = {}; + constructor( public route: ActivatedRoute, public router: Router, public changeDetectionRef: ChangeDetectorRef, - public factoryService: FactoryService + public factoryService: FactoryService, + private issuingAgencyService: IssuingAgencyService ) { super(factoryService); } @@ -50,6 +53,7 @@ export class InspectionDetailComponent extends RecordDetailComponent implements this.disableEdit(); this.changeDetectionRef.detectChanges(); + this.getIssuingAgencyList(); }); } @@ -64,11 +68,27 @@ export class InspectionDetailComponent extends RecordDetailComponent implements } displayName(agency) { - return Utils.displayNameFull(agency); + return this.issuingAgencyMap[agency]; } ngOnDestroy() { this.ngUnsubscribe.next(); this.ngUnsubscribe.complete(); } + + getIssuingAgencyList = () => { + this.issuingAgencyService + .getIssuingAgencies() + .then(response => { + if (response && Array.isArray(response)) { + this.issuingAgencyMap = response.reduce((result, item) => { + result[item.agencyCode] = item.agencyName; + return result; + }, {}); + } + }) + .catch(error => { + console.error('API call error:', error); + }); + }; } From 99674dff8bc178ebd4a29d16f362dc2bf2fc826d Mon Sep 17 00:00:00 2001 From: Sanjay Babu Date: Mon, 18 Sep 2023 15:44:49 -0700 Subject: [PATCH 26/77] api call moved to service layer --- .../inspection-detail.component.ts | 23 ++++------- .../src/app/services/issuingagency.service.ts | 40 +++++++++++++------ 2 files changed, 35 insertions(+), 28 deletions(-) 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 26d7b2b9b..cfd6860da 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 @@ -53,8 +53,8 @@ export class InspectionDetailComponent extends RecordDetailComponent implements this.disableEdit(); this.changeDetectionRef.detectChanges(); - this.getIssuingAgencyList(); }); + this.getIssuingAgencyMap(); } populateTextFields() { @@ -75,20 +75,11 @@ export class InspectionDetailComponent extends RecordDetailComponent implements this.ngUnsubscribe.next(); this.ngUnsubscribe.complete(); } - - getIssuingAgencyList = () => { - this.issuingAgencyService - .getIssuingAgencies() - .then(response => { - if (response && Array.isArray(response)) { - this.issuingAgencyMap = response.reduce((result, item) => { - result[item.agencyCode] = item.agencyName; - return result; - }, {}); - } - }) - .catch(error => { - console.error('API call error:', error); - }); + getIssuingAgencyMap = async () => { + try { + this.issuingAgencyMap = await this.issuingAgencyService.getIssuingAgencyMap(); + } catch (error) { + console.error(' getIssuingAgencyMap() API call error'); + } }; } diff --git a/angular/projects/admin-nrpti/src/app/services/issuingagency.service.ts b/angular/projects/admin-nrpti/src/app/services/issuingagency.service.ts index b24e05ee8..19c10f30b 100644 --- a/angular/projects/admin-nrpti/src/app/services/issuingagency.service.ts +++ b/angular/projects/admin-nrpti/src/app/services/issuingagency.service.ts @@ -5,28 +5,44 @@ import { ApiService } from './api.service'; @Injectable({ providedIn: 'root' }) export class IssuingAgencyService { - constructor(public apiService: ApiService, public http: HttpClient) { } + 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 - }); + 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`; - let updatedAgency = { "agencies": [{"agencyCode": agencyCode, "agencyName": agencyName}]}; // Wrap the array in an object + let updatedAgency = { agencies: [{ agencyCode: agencyCode, agencyName: agencyName }] }; // Wrap the array in an object console.log(JSON.stringify(updatedAgency)); - return this.http.put(apiUrl, updatedAgency) + return this.http + .put(apiUrl, updatedAgency) .toPromise() - .catch((error) => { + .catch(error => { console.error('API call error:', error); throw error; // Rethrow the error to propagate it further }); } -} + public async getIssuingAgencyMap() { + try { + const response = await this.getIssuingAgencies(); + const issuingAgencyMap: { [key: string]: string } = {}; + if (response && Array.isArray(response)) { + response.forEach(agency => { + issuingAgencyMap[agency.agencyCode] = agency.agencyName; + }); + } + return issuingAgencyMap; + } catch (error) { + console.error('getIssuingAgencyMap() API call error:', error); + throw error; + } + } +} From 6c93abd50a80646f3b36b9e6420a4a120b01da04 Mon Sep 17 00:00:00 2001 From: Sanjay Babu Date: Tue, 19 Sep 2023 08:56:12 -0700 Subject: [PATCH 27/77] issuing agency in add order replaced with api calls --- .../order-add-edit.component.ts | 18 +++++++++++++++--- .../src/app/utils/constants/misc.ts | 14 ++++++++++++++ .../common/src/app/utils/record-constants.ts | 19 +++++++++++++++++++ 3 files changed, 48 insertions(+), 3 deletions(-) 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..c2e78b7d3 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 { IssuingAgencyService } from '../../../services/issuingagency.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 = ''; @@ -45,6 +46,7 @@ export class OrderAddEditComponent implements OnInit, OnDestroy { public datepickerMinDate = Constants.DatepickerMinDate; public datepickerMaxDate = Constants.DatepickerMaxDate; + public issuingAgencyMap = {}; constructor( public route: ActivatedRoute, @@ -55,7 +57,8 @@ export class OrderAddEditComponent implements OnInit, OnDestroy { private logger: LoggerService, private loadingScreenService: LoadingScreenService, private utils: Utils, - private _changeDetectionRef: ChangeDetectorRef + private _changeDetectionRef: ChangeDetectorRef, + private issuingAgencyService: IssuingAgencyService ) { } ngOnInit() { @@ -81,6 +84,7 @@ export class OrderAddEditComponent implements OnInit, OnDestroy { this.loading = false; this._changeDetectionRef.detectChanges(); }); + this.getIssuingAgencyMap(); } private populateTextFields() { @@ -522,9 +526,17 @@ export class OrderAddEditComponent implements OnInit, OnDestroy { } displayName(agency) { - return Utils.displayNameFull(agency); + return this.issuingAgencyMap[agency] || agency; } + getIssuingAgencyMap = async () => { + try { + this.issuingAgencyMap = await this.issuingAgencyService.getIssuingAgencyMap(); + } catch (error) { + console.error(' getIssuingAgencyMap() API call error'); + } + }; + cancel() { const shouldCancel = confirm( 'Leaving this page will discard unsaved changes. Are you sure you would like to continue?' 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 ff73372b1..4687d0e78 100644 --- a/angular/projects/admin-nrpti/src/app/utils/constants/misc.ts +++ b/angular/projects/admin-nrpti/src/app/utils/constants/misc.ts @@ -333,6 +333,20 @@ 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..c135db175 100644 --- a/angular/projects/common/src/app/utils/record-constants.ts +++ b/angular/projects/common/src/app/utils/record-constants.ts @@ -178,6 +178,25 @@ export class Picklists { 'Natural Resource Officers', ]; + public static readonly agencyCodePicklist = [ + 'AGENCY_ALC', + 'AGENCY_OGC', + 'AGENCY_ENV_BCPARKS', + 'AGENCY_WF', + 'Climate Action Secretariat', + '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']; public static readonly authorPicklist = ['BC Government', 'Proponent', 'Other']; From 95608e655eb627bf09d83b8e90c76a42c7933853 Mon Sep 17 00:00:00 2001 From: David <62899351+davidclaveau@users.noreply.github.com> Date: Thu, 21 Sep 2023 11:42:57 -0700 Subject: [PATCH 28/77] add climate action secretariat to migrations --- api/migrations/20230911220312-addApplicationAgenciesModel.js | 1 + api/migrations/20230912181649-updateIssuingAgencyToCode.js | 1 + 2 files changed, 2 insertions(+) diff --git a/api/migrations/20230911220312-addApplicationAgenciesModel.js b/api/migrations/20230911220312-addApplicationAgenciesModel.js index 609fab420..9a450b2f3 100644 --- a/api/migrations/20230911220312-addApplicationAgenciesModel.js +++ b/api/migrations/20230911220312-addApplicationAgenciesModel.js @@ -35,6 +35,7 @@ exports.up = async function (db) { { 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 { diff --git a/api/migrations/20230912181649-updateIssuingAgencyToCode.js b/api/migrations/20230912181649-updateIssuingAgencyToCode.js index f87ac1a49..5036cc5c6 100644 --- a/api/migrations/20230912181649-updateIssuingAgencyToCode.js +++ b/api/migrations/20230912181649-updateIssuingAgencyToCode.js @@ -35,6 +35,7 @@ exports.up = async function (db) { { 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']; From 9376f16edf682537f352c276a3efc2df84bf31a9 Mon Sep 17 00:00:00 2001 From: David <62899351+davidclaveau@users.noreply.github.com> Date: Fri, 22 Sep 2023 16:32:52 -0700 Subject: [PATCH 29/77] wip - agencies are updated in factory, prelim update to components --- .../inspection-detail.component.ts | 16 ++-------- .../order-add-edit.component.ts | 16 ++-------- .../permit-detail/permit-detail.component.ts | 5 ++-- .../app/services/applicationAgency.service.ts | 30 ++++++++----------- .../src/app/services/factory.service.ts | 22 ++++++++------ .../src/lib/utils/agency-data-service.ts | 13 ++++++++ 6 files changed, 47 insertions(+), 55 deletions(-) create mode 100644 angular/projects/global/src/lib/utils/agency-data-service.ts 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 cfd6860da..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 { IssuingAgencyService } from '../../../services/issuingagency.service'; +import { AgencyDataService } from '../../../../../../../projects/global/src/lib/utils/agency-data-service'; @Component({ selector: 'app-inspection-detail', @@ -19,14 +19,11 @@ export class InspectionDetailComponent extends RecordDetailComponent implements public legislationString = ''; - public issuingAgencyMap = {}; - constructor( public route: ActivatedRoute, public router: Router, public changeDetectionRef: ChangeDetectorRef, public factoryService: FactoryService, - private issuingAgencyService: IssuingAgencyService ) { super(factoryService); } @@ -54,7 +51,6 @@ export class InspectionDetailComponent extends RecordDetailComponent implements this.changeDetectionRef.detectChanges(); }); - this.getIssuingAgencyMap(); } populateTextFields() { @@ -68,18 +64,12 @@ export class InspectionDetailComponent extends RecordDetailComponent implements } displayName(agency) { - return this.issuingAgencyMap[agency]; + const agencyDataService = new AgencyDataService(this.factoryService); + return agencyDataService.displayNameFull(agency); } ngOnDestroy() { this.ngUnsubscribe.next(); this.ngUnsubscribe.complete(); } - getIssuingAgencyMap = async () => { - try { - this.issuingAgencyMap = await this.issuingAgencyService.getIssuingAgencyMap(); - } catch (error) { - console.error(' getIssuingAgencyMap() API call error'); - } - }; } 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 c2e78b7d3..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,7 +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 { IssuingAgencyService } from '../../../services/issuingagency.service'; +import { AgencyDataService } from '../../../../../../../projects/global/src/lib/utils/agency-data-service'; @Component({ selector: 'app-order-add-edit', @@ -46,7 +46,6 @@ export class OrderAddEditComponent implements OnInit, OnDestroy { public datepickerMinDate = Constants.DatepickerMinDate; public datepickerMaxDate = Constants.DatepickerMaxDate; - public issuingAgencyMap = {}; constructor( public route: ActivatedRoute, @@ -58,7 +57,6 @@ export class OrderAddEditComponent implements OnInit, OnDestroy { private loadingScreenService: LoadingScreenService, private utils: Utils, private _changeDetectionRef: ChangeDetectorRef, - private issuingAgencyService: IssuingAgencyService ) { } ngOnInit() { @@ -84,7 +82,6 @@ export class OrderAddEditComponent implements OnInit, OnDestroy { this.loading = false; this._changeDetectionRef.detectChanges(); }); - this.getIssuingAgencyMap(); } private populateTextFields() { @@ -526,17 +523,10 @@ export class OrderAddEditComponent implements OnInit, OnDestroy { } displayName(agency) { - return this.issuingAgencyMap[agency] || agency; + const agencyDataService = new AgencyDataService(this.factoryService); + return agencyDataService.displayNameFull(agency); } - getIssuingAgencyMap = async () => { - try { - this.issuingAgencyMap = await this.issuingAgencyService.getIssuingAgencyMap(); - } catch (error) { - console.error(' getIssuingAgencyMap() API call error'); - } - }; - cancel() { const shouldCancel = confirm( 'Leaving this page will discard unsaved changes. Are you sure you would like to continue?' 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/services/applicationAgency.service.ts b/angular/projects/admin-nrpti/src/app/services/applicationAgency.service.ts index 08cd91eff..634a3191f 100644 --- a/angular/projects/admin-nrpti/src/app/services/applicationAgency.service.ts +++ b/angular/projects/admin-nrpti/src/app/services/applicationAgency.service.ts @@ -2,11 +2,11 @@ import { Injectable } from '@angular/core'; import { ConfigService } from 'nrpti-angular-components'; import { Observable } from 'rxjs'; import { HttpClient } from '@angular/common/http'; -// import { Utils } from '../../../../global/src/lib/utils/utils'; @Injectable() export class ApplicationAgencyService { private api: string; + private agencies: { [key: string]: string } = {}; constructor( private configService: ConfigService, @@ -15,41 +15,35 @@ export class ApplicationAgencyService { async init() { this.api = `${this.configService.config['API_LOCATION']}${this.configService.config['API_PATH']}`; - - // Start the initial agencies retrieval. await this.refreshAgencies().toPromise(); } - // ... Other methods ... refreshAgencies(): Observable { return new Observable(observer => { - console.log("refreshAgencies here"); - - // Construct the full API endpoint URL const apiEndpoint = `${this.api}/list-agencies`; + const getAgencies = this.http.get<{ [key: string]: string }>(apiEndpoint); - // Make the HTTP GET request - const getAgencies = this.http.get(apiEndpoint); - - // Subscribe to the HTTP request and handle the response getAgencies.subscribe( (response) => { - // Update the agency list by calling the updateAgencyList function - // Utils.setAgencyList(response); + // Data transformation to make the data easier to work with + const agencyList = {} + for (const record in response) { + agencyList[response[record]["agencyCode"]] = response[record]["agencyName"] + } + this.agencies = agencyList; observer.next(); observer.complete(); }, (error) => { console.error("HTTP Request Error: ", error); - - // You can handle errors here if needed - // ... - - // Notify the observer about the 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 823e88b28..34f88f0fd 100644 --- a/angular/projects/admin-nrpti/src/app/services/factory.service.ts +++ b/angular/projects/admin-nrpti/src/app/services/factory.service.ts @@ -36,7 +36,7 @@ export class FactoryService { private _documentService: DocumentService; private _configService: ConfigService; private _mapLayerInfoService: MapLayerInfoService; - private _applicationAgencyService: ApplicationAgencyService; + private agencies: { [key: string]: string } = {}; constructor(private injector: Injector) { // The following items are loaded by a file that is only present on cluster builds. @@ -629,17 +629,21 @@ export class FactoryService { } /** - * Inject agencies service if it hasn't already been injected. + * Get agency data. If data is not cached, fetch it from the ApplicationAgencyService. * * @readonly - * @type {ApplicationAgencyService} + * @type {{ [key: string]: string }} * @memberof FactoryService */ - public get applicationAgencyService(): ApplicationAgencyService { - if (!this._applicationAgencyService) { - this._applicationAgencyService = this.injector.get(ApplicationAgencyService); - } - - return this._applicationAgencyService; + public get agencyData(): { [key: string]: string } { + if (Object.keys(this.agencies).length === 0) { + // Data is not in the cache, fetch it from the ApplicationAgencyService. + const applicationAgencyService = this.injector.get(ApplicationAgencyService); + applicationAgencyService.refreshAgencies().subscribe(() => { + // Once data is fetched and updated in the service, retrieve it and store it in the cache. + this.agencies = applicationAgencyService.getAgencies(); + }); } + return this.agencies; + } } 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..f8df2fe14 --- /dev/null +++ b/angular/projects/global/src/lib/utils/agency-data-service.ts @@ -0,0 +1,13 @@ +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 agencyList = this.factoryService.agencyData; + return agencyList[agencyCode] || agencyCode; + } +} From d4d0ccd521355dc300dc4e9782ea0f852fd2d0f4 Mon Sep 17 00:00:00 2001 From: David <62899351+davidclaveau@users.noreply.github.com> Date: Sun, 24 Sep 2023 22:21:35 -0700 Subject: [PATCH 30/77] wip - update picklist to allow dynamic update (admin penalty only) --- ...ministrative-penalty-add-edit.component.ts | 3 +- .../common/src/app/utils/record-constants.ts | 38 +++++++++++-------- .../src/lib/utils/agency-data-service.ts | 10 +++++ 3 files changed, 34 insertions(+), 17 deletions(-) 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..1cca2f97b 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 @@ -11,7 +11,6 @@ import { RecordUtils } from '../../utils/record-utils'; import { LoadingScreenService, LoggerService, StoreService } from 'nrpti-angular-components'; import { Constants } from '../../../utils/constants/misc'; - @Component({ selector: 'app-administrative-penalty-add-edit', templateUrl: './administrative-penalty-add-edit.component.html', @@ -37,7 +36,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 = ''; diff --git a/angular/projects/common/src/app/utils/record-constants.ts b/angular/projects/common/src/app/utils/record-constants.ts index c135db175..716d220a8 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'; @@ -136,6 +138,7 @@ export enum StateStatus { * @class Picklists */ export class Picklists { + public static readonly orderSubtypePicklist = ['None', 'Cease', 'Remedy', 'Stop Work', 'Other']; public static readonly permitSubtypePicklist = ['Ancillary Site', 'General', 'Investigative Use', 'Road', 'Water']; public static readonly certificateSubtypePicklist = [ @@ -162,28 +165,33 @@ 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 Wate 1r, Land and Resource Stewardship 1', + 'Natural Resource Officers 1', ]; + public static getAgencyNames(factoryService: FactoryService) { + const agencyDataService = new AgencyDataService(factoryService); + return agencyDataService.getAgencyNames(); + } + public static readonly agencyCodePicklist = [ 'AGENCY_ALC', 'AGENCY_OGC', 'AGENCY_ENV_BCPARKS', 'AGENCY_WF', - 'Climate Action Secretariat', + 'AGENCY_CAS', 'AGENCY_ENV_COS', 'AGENCY_EAO', 'AGENCY_LNG', diff --git a/angular/projects/global/src/lib/utils/agency-data-service.ts b/angular/projects/global/src/lib/utils/agency-data-service.ts index f8df2fe14..5c812ec37 100644 --- a/angular/projects/global/src/lib/utils/agency-data-service.ts +++ b/angular/projects/global/src/lib/utils/agency-data-service.ts @@ -10,4 +10,14 @@ export class AgencyDataService { const agencyList = this.factoryService.agencyData; return agencyList[agencyCode] || agencyCode; } + + getAgencyCodes(): string[] { + const agencyList = this.factoryService.agencyData; + return Object.keys(agencyList); + } + + getAgencyNames(): string[] { + const agencyList = this.factoryService.agencyData; + return Object.values(agencyList); + } } From c63f17b34af2b904cd50ebc5744ceeb728104247 Mon Sep 17 00:00:00 2001 From: David <62899351+davidclaveau@users.noreply.github.com> Date: Mon, 25 Sep 2023 10:36:29 -0700 Subject: [PATCH 31/77] wip - make buildForm for admin penalty async --- ...administrative-penalty-add-edit.component.ts | 2 +- ...administrative-penalty-add-edit.component.ts | 17 +++++++++++++++-- .../common/src/app/utils/record-constants.ts | 2 +- 3 files changed, 17 insertions(+), 4 deletions(-) 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.ts b/angular/projects/admin-nrpti/src/app/records/administrative-penalties/administrative-penalty-add-edit/administrative-penalty-add-edit.component.ts index 1cca2f97b..524c3028d 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 @@ -61,7 +61,7 @@ export class AdministrativePenaltyAddEditComponent implements OnInit, OnDestroy protected storeService: StoreService, ) { } - ngOnInit() { + async ngOnInit() { this.route.data.pipe(takeUntil(this.ngUnsubscribe)).subscribe((res: any) => { this.isEditing = res.breadcrumb !== 'Add Administrative Penalty'; if (this.isEditing) { @@ -79,11 +79,24 @@ export class AdministrativePenaltyAddEditComponent implements OnInit, OnDestroy }; } - this.buildForm(); this.subscribeToFormControlChanges(); this.loading = false; this._changeDetectionRef.detectChanges(); + + this.route.data.pipe(takeUntil(this.ngUnsubscribe)).subscribe(async (res: any) => { + this.agencies = await this.fetchAgencies(); + this.buildForm(); + }); + }); + } + + private async fetchAgencies(): Promise { + return new Promise((resolve) => { + setTimeout(() => { + const agenciesData = Picklists.getAgencyNames(this.factoryService); + resolve(agenciesData); + }, 1000); }); } diff --git a/angular/projects/common/src/app/utils/record-constants.ts b/angular/projects/common/src/app/utils/record-constants.ts index 716d220a8..497b07ef3 100644 --- a/angular/projects/common/src/app/utils/record-constants.ts +++ b/angular/projects/common/src/app/utils/record-constants.ts @@ -177,7 +177,7 @@ export class Picklists { 'Ministry of Energy Mines and Low Carbon Innovation 1', 'Ministry of Environment and Climate Change Strategy 1', 'Ministry of Forests 1', - 'Ministry of Wate 1r, Land and Resource Stewardship 1', + 'Ministry of Water, Land and Resource Stewardship 1', 'Natural Resource Officers 1', ]; From 318a46967a9506724be7581423dec8473354f0d1 Mon Sep 17 00:00:00 2001 From: David <62899351+davidclaveau@users.noreply.github.com> Date: Mon, 25 Sep 2023 10:59:13 -0700 Subject: [PATCH 32/77] wip - update to factory service, fix buildForm in admin penalty --- ...ministrative-penalty-add-edit.component.ts | 2 ++ .../src/app/services/factory.service.ts | 33 ++++++++++++------- .../src/lib/utils/agency-data-service.ts | 6 ++-- 3 files changed, 27 insertions(+), 14 deletions(-) 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 524c3028d..99cc2cb93 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 @@ -79,6 +79,8 @@ export class AdministrativePenaltyAddEditComponent implements OnInit, OnDestroy }; } + this.buildForm(); + this.subscribeToFormControlChanges(); this.loading = false; 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 34f88f0fd..e725dd190 100644 --- a/angular/projects/admin-nrpti/src/app/services/factory.service.ts +++ b/angular/projects/admin-nrpti/src/app/services/factory.service.ts @@ -36,7 +36,7 @@ export class FactoryService { private _documentService: DocumentService; private _configService: ConfigService; private _mapLayerInfoService: MapLayerInfoService; - private agencies: { [key: string]: string } = {}; + private _applicationAgencyService: ApplicationAgencyService constructor(private injector: Injector) { // The following items are loaded by a file that is only present on cluster builds. @@ -90,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. * @@ -635,15 +649,12 @@ export class FactoryService { * @type {{ [key: string]: string }} * @memberof FactoryService */ - public get agencyData(): { [key: string]: string } { - if (Object.keys(this.agencies).length === 0) { - // Data is not in the cache, fetch it from the ApplicationAgencyService. - const applicationAgencyService = this.injector.get(ApplicationAgencyService); - applicationAgencyService.refreshAgencies().subscribe(() => { - // Once data is fetched and updated in the service, retrieve it and store it in the cache. - this.agencies = applicationAgencyService.getAgencies(); - }); - } - return this.agencies; + 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/global/src/lib/utils/agency-data-service.ts b/angular/projects/global/src/lib/utils/agency-data-service.ts index 5c812ec37..664df6832 100644 --- a/angular/projects/global/src/lib/utils/agency-data-service.ts +++ b/angular/projects/global/src/lib/utils/agency-data-service.ts @@ -7,17 +7,17 @@ export class AgencyDataService { displayNameFull(agencyCode): string { // Access cached agency data from FactoryService - const agencyList = this.factoryService.agencyData; + const agencyList = this.factoryService.applicationAgencyService.getAgencies(); return agencyList[agencyCode] || agencyCode; } getAgencyCodes(): string[] { - const agencyList = this.factoryService.agencyData; + const agencyList = this.factoryService.applicationAgencyService.getAgencies(); return Object.keys(agencyList); } getAgencyNames(): string[] { - const agencyList = this.factoryService.agencyData; + const agencyList = this.factoryService.applicationAgencyService.getAgencies(); return Object.values(agencyList); } } From f564dfa36d1c47ff2e1ac8636147731e49f0c83c Mon Sep 17 00:00:00 2001 From: David <62899351+davidclaveau@users.noreply.github.com> Date: Mon, 25 Sep 2023 14:13:58 -0700 Subject: [PATCH 33/77] refresh agencies after they are updated --- .../src/app/services/applicationAgency.service.ts | 1 - .../update-issuing-agency.component.ts | 14 +++++++++++--- .../update-issuing-agency.resolver.ts | 1 - 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/angular/projects/admin-nrpti/src/app/services/applicationAgency.service.ts b/angular/projects/admin-nrpti/src/app/services/applicationAgency.service.ts index 634a3191f..81fd692df 100644 --- a/angular/projects/admin-nrpti/src/app/services/applicationAgency.service.ts +++ b/angular/projects/admin-nrpti/src/app/services/applicationAgency.service.ts @@ -31,7 +31,6 @@ export class ApplicationAgencyService { agencyList[response[record]["agencyCode"]] = response[record]["agencyName"] } this.agencies = agencyList; - observer.next(); observer.complete(); }, diff --git a/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.ts b/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.ts index 4a874d546..f1a649b72 100644 --- a/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.ts +++ b/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.ts @@ -3,7 +3,7 @@ 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 { Observable, of } from 'rxjs'; +import { FactoryService } from '../../../../admin-nrpti/src/app/services/factory.service'; @Component({ selector: 'app-update-issuing-agency', @@ -23,15 +23,23 @@ export class UpdateIssuingAgencyComponent implements OnInit { constructor( private issuingAgencyService: IssuingAgencyService, private logger: LoggerService, - private toastService: ToastService + private toastService: ToastService, + private factoryService: FactoryService, ) {} onSelected(value: string): void { this.selectedAgency = value; this.choiceMade = true; } - putRecords(agencyCode: any, agencyName: any){ + 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{ diff --git a/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.resolver.ts b/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.resolver.ts index 90c2e2f7b..d86e79004 100644 --- a/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.resolver.ts +++ b/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.resolver.ts @@ -6,7 +6,6 @@ import { Observable } from 'rxjs/Observable'; @Injectable() export class UpdateIssuingAgencyResolver implements Resolve> { resolve(route: ActivatedRouteSnapshot): Observable { - console.log("UpdateIssuingAgencyResolver.resolve()") return null; } } From 370fcee2afb1ac5008d7d5b31805e3c351023be9 Mon Sep 17 00:00:00 2001 From: David <62899351+davidclaveau@users.noreply.github.com> Date: Mon, 25 Sep 2023 14:23:50 -0700 Subject: [PATCH 34/77] remove async ngOnInit, no longer needed --- .../administrative-penalty-add-edit.component.ts | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) 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 99cc2cb93..2c80fc2ce 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 @@ -61,7 +61,7 @@ export class AdministrativePenaltyAddEditComponent implements OnInit, OnDestroy protected storeService: StoreService, ) { } - async ngOnInit() { + ngOnInit() { this.route.data.pipe(takeUntil(this.ngUnsubscribe)).subscribe((res: any) => { this.isEditing = res.breadcrumb !== 'Add Administrative Penalty'; if (this.isEditing) { @@ -85,20 +85,6 @@ export class AdministrativePenaltyAddEditComponent implements OnInit, OnDestroy this.loading = false; this._changeDetectionRef.detectChanges(); - - this.route.data.pipe(takeUntil(this.ngUnsubscribe)).subscribe(async (res: any) => { - this.agencies = await this.fetchAgencies(); - this.buildForm(); - }); - }); - } - - private async fetchAgencies(): Promise { - return new Promise((resolve) => { - setTimeout(() => { - const agenciesData = Picklists.getAgencyNames(this.factoryService); - resolve(agenciesData); - }, 1000); }); } From 9ab27bb5042004b2c31e12376f0e5fd6d2644c7f Mon Sep 17 00:00:00 2001 From: David <62899351+davidclaveau@users.noreply.github.com> Date: Mon, 25 Sep 2023 14:45:59 -0700 Subject: [PATCH 35/77] update to more relevant terminology --- angular/projects/admin-nrpti/src/app/app-routing.module.ts | 2 +- .../admin-nrpti/src/app/home/home.component.spec.ts | 2 +- .../admin-nrpti/src/app/services/keycloak.service.ts | 2 +- .../admin-nrpti/src/app/sidebar/sidebar.component.html | 6 +++--- .../admin-nrpti/src/app/sidebar/sidebar.component.spec.ts | 4 ++-- .../update-issuing-agency.component.html | 2 +- .../projects/admin-nrpti/src/app/utils/constants/misc.ts | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) 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 d70124e06..8e3f33b4e 100644 --- a/angular/projects/admin-nrpti/src/app/app-routing.module.ts +++ b/angular/projects/admin-nrpti/src/app/app-routing.module.ts @@ -70,7 +70,7 @@ const routes: Routes = [ records: UpdateIssuingAgencyResolver }, data: { - breadcrumb: 'Update Issuing Agency' + breadcrumb: 'Agencies' } }, { 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 30620d708..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,7 +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.UPDATE_ISSUING_AGENCY: retVal = true; break; + case Constants.Menus.AGENCIES: retVal = true; break; } return retVal; } 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 e9c59c209..2d5f672fe 100644 --- a/angular/projects/admin-nrpti/src/app/services/keycloak.service.ts +++ b/angular/projects/admin-nrpti/src/app/services/keycloak.service.ts @@ -162,7 +162,7 @@ export class KeycloakService { roles.includes(Constants.ApplicationRoles.ADMIN_NRCED) || roles.includes(Constants.ApplicationRoles.ADMIN_BCMI); - this.menus[Constants.Menus.UPDATE_ISSUING_AGENCY] = + this.menus[Constants.Menus.AGENCIES] = roles.includes(Constants.ApplicationRoles.ADMIN) } 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 7da3bd911..d8f432e57 100644 --- a/angular/projects/admin-nrpti/src/app/sidebar/sidebar.component.html +++ b/angular/projects/admin-nrpti/src/app/sidebar/sidebar.component.html @@ -103,12 +103,12 @@ Communications - notifications_active - Update Issuing Agency + edit + Agencies \ 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 05648b88e..d18c43403 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 @@ -38,7 +38,7 @@ describe('SidebarComponent', () => { case Constants.Menus.ENTITIES: retVal = false; break; case Constants.Menus.IMPORTS: retVal = true; break; case Constants.Menus.COMMUNICATIONS: retVal = true; break; - case Constants.Menus.UPDATE_ISSUING_AGENCY: retVal = true; break; + case Constants.Menus.AGENCIES: retVal = true; break; } return retVal; } @@ -71,7 +71,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.UPDATE_ISSUING_AGENCY)).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/update-issuing-agency/update-issuing-agency.component.html b/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.html index 6b242a720..90c138878 100644 --- a/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.html +++ b/angular/projects/admin-nrpti/src/app/update-issuing-agency/update-issuing-agency.component.html @@ -1,5 +1,5 @@
-

Update Issuing Agency

+

Update Agencies