11import { AfterViewInit , Component , OnDestroy , OnInit , ViewChild } from '@angular/core' ;
22import { ActivatedRoute } from '@angular/router' ;
3- import { catchError , debounceTime , EMPTY , filter , firstValueFrom , skip , Subject , switchMap , takeUntil , tap } from 'rxjs' ;
3+ import {
4+ catchError ,
5+ debounceTime ,
6+ EMPTY ,
7+ filter ,
8+ firstValueFrom ,
9+ skip ,
10+ Subject ,
11+ switchMap ,
12+ takeUntil ,
13+ tap ,
14+ } from 'rxjs' ;
415import { C_E_AUTOSAVE_DEBOUNCE_MS } from '../constants' ;
516import {
617 ComplianceAndEnforcementDto ,
@@ -17,9 +28,10 @@ import { PropertyComponent, cleanPropertyUpdate } from '../property/property.com
1728import { ComplianceAndEnforcementPropertyDto } from '../../../services/compliance-and-enforcement/property/property.dto' ;
1829import { ComplianceAndEnforcementPropertyService } from '../../../services/compliance-and-enforcement/property/property.service' ;
1930import { DOCUMENT_SOURCE , DOCUMENT_TYPE } from '../../../shared/document/document.dto' ;
20- import { DocumentUploadDialogOptions } from '../../../shared/document-upload-dialog/document-upload-dialog.interface' ;
31+ import { DocumentUploadDialogData } from '../../../shared/document-upload-dialog/document-upload-dialog.interface' ;
2132import { Section } from '../../../services/compliance-and-enforcement/documents/document.service' ;
2233import { ResponsiblePartiesComponent } from '../responsible-parties/responsible-parties.component' ;
34+ import { ResponsiblePartiesService } from '../../../services/compliance-and-enforcement/responsible-parties/responsible-parties.service' ;
2335
2436@Component ( {
2537 selector : 'app-compliance-and-enforcement-draft' ,
@@ -29,7 +41,9 @@ import { ResponsiblePartiesComponent } from '../responsible-parties/responsible-
2941export class DraftComponent implements OnInit , AfterViewInit , OnDestroy {
3042 Section = Section ;
3143
32- submissionDocumentOptions : DocumentUploadDialogOptions = {
44+ submissionDocumentOptions : DocumentUploadDialogData = {
45+ // A necessary hack to make this work without rewriting lots of code
46+ fileId : '' ,
3347 allowedVisibilityFlags : [ ] ,
3448 allowsFileEdit : true ,
3549 allowedDocumentSources : [
@@ -42,6 +56,29 @@ export class DraftComponent implements OnInit, AfterViewInit, OnDestroy {
4256 allowedDocumentTypes : [ DOCUMENT_TYPE . COMPLAINT , DOCUMENT_TYPE . REFERRAL ] ,
4357 } ;
4458
59+ ownershipDocumentOptions : DocumentUploadDialogData = {
60+ // A necessary hack to make this work without rewriting lots of code
61+ fileId : '' ,
62+ parcelService : this . propertyService ,
63+ submissionService : this . responsiblePartyService ,
64+ allowedVisibilityFlags : [ ] ,
65+ allowsFileEdit : true ,
66+ allowedDocumentSources : [
67+ DOCUMENT_SOURCE . PUBLIC ,
68+ DOCUMENT_SOURCE . LFNG ,
69+ DOCUMENT_SOURCE . BC_GOVERNMENT ,
70+ DOCUMENT_SOURCE . OTHER_AGENCY ,
71+ DOCUMENT_SOURCE . ALC ,
72+ ] ,
73+ defaultDocumentSource : DOCUMENT_SOURCE . ALC ,
74+ allowedDocumentTypes : [
75+ DOCUMENT_TYPE . CERTIFICATE_OF_TITLE ,
76+ DOCUMENT_TYPE . CORPORATE_SUMMARY ,
77+ DOCUMENT_TYPE . BC_ASSESSMENT_REPORT ,
78+ DOCUMENT_TYPE . SURVEY_PLAN ,
79+ ] ,
80+ } ;
81+
4582 $destroy = new Subject < void > ( ) ;
4683
4784 fileNumber ?: string ;
@@ -64,6 +101,8 @@ export class DraftComponent implements OnInit, AfterViewInit, OnDestroy {
64101 private readonly complianceAndEnforcementPropertyService : ComplianceAndEnforcementPropertyService ,
65102 private readonly route : ActivatedRoute ,
66103 private readonly toastService : ToastService ,
104+ private readonly propertyService : ComplianceAndEnforcementPropertyService ,
105+ private readonly responsiblePartyService : ResponsiblePartiesService ,
67106 ) { }
68107
69108 ngOnInit ( ) : void {
@@ -75,7 +114,12 @@ export class DraftComponent implements OnInit, AfterViewInit, OnDestroy {
75114 }
76115
77116 ngAfterViewInit ( ) : void {
78- if ( ! this . overviewComponent || ! this . submitterComponent || ! this . propertyComponent || ! this . responsiblePartiesComponent ) {
117+ if (
118+ ! this . overviewComponent ||
119+ ! this . submitterComponent ||
120+ ! this . propertyComponent ||
121+ ! this . responsiblePartiesComponent
122+ ) {
79123 console . warn ( 'Not all form sections component not initialized' ) ;
80124 return ;
81125 }
@@ -139,18 +183,18 @@ export class DraftComponent implements OnInit, AfterViewInit, OnDestroy {
139183 switchMap ( ( property ) => {
140184 // Only auto-save if there are meaningful changes (non-empty fields)
141185 const cleanedProperty = cleanPropertyUpdate ( property ) ;
142-
186+
143187 // Check if this is a meaningful ownership type change
144188 const currentOwnership = this . property ?. ownershipTypeCode || 'SMPL' ;
145189 const newOwnership = cleanedProperty . ownershipTypeCode ;
146190 const isOwnershipChange = newOwnership !== undefined && newOwnership !== currentOwnership ;
147-
191+
148192 // For non-ownership changes, check if there are other meaningful changes
149193 const propertyForCheck = { ...cleanedProperty } ;
150194 if ( propertyForCheck . ownershipTypeCode === 'SMPL' ) {
151195 delete propertyForCheck . ownershipTypeCode ;
152196 }
153-
197+
154198 const hasOtherActualData = Object . values ( propertyForCheck ) . some (
155199 ( value ) => value !== null && value !== undefined && value !== '' && value !== 0 ,
156200 ) ;
@@ -188,23 +232,19 @@ export class DraftComponent implements OnInit, AfterViewInit, OnDestroy {
188232 } ) ;
189233
190234 // Watch for property ownership changes to update Crown status
191- this . propertyComponent . $changes
192- . pipe (
193- takeUntil ( this . $destroy ) ,
194- )
195- . subscribe ( async ( propertyUpdate ) => {
196- if ( propertyUpdate . ownershipTypeCode ) {
197- const wasCrown = this . isPropertyCrown ;
198- this . isPropertyCrown = propertyUpdate . ownershipTypeCode === 'CRWN' ;
199-
200- // If Crown status changed, update responsible parties component
201- if ( wasCrown !== this . isPropertyCrown && this . responsiblePartiesComponent ) {
202- this . responsiblePartiesComponent . isPropertyCrown = this . isPropertyCrown ;
203-
204- await this . responsiblePartiesComponent . loadResponsibleParties ( ) ;
205- }
235+ this . propertyComponent . $changes . pipe ( takeUntil ( this . $destroy ) ) . subscribe ( async ( propertyUpdate ) => {
236+ if ( propertyUpdate . ownershipTypeCode ) {
237+ const wasCrown = this . isPropertyCrown ;
238+ this . isPropertyCrown = propertyUpdate . ownershipTypeCode === 'CRWN' ;
239+
240+ // If Crown status changed, update responsible parties component
241+ if ( wasCrown !== this . isPropertyCrown && this . responsiblePartiesComponent ) {
242+ this . responsiblePartiesComponent . isPropertyCrown = this . isPropertyCrown ;
243+
244+ await this . responsiblePartiesComponent . loadResponsibleParties ( ) ;
206245 }
207- } ) ;
246+ }
247+ } ) ;
208248 }
209249
210250 async loadFile ( fileNumber : string ) {
@@ -216,18 +256,20 @@ export class DraftComponent implements OnInit, AfterViewInit, OnDestroy {
216256 // Load property data
217257 if ( this . file . uuid ) {
218258 try {
219- this . property = await this . complianceAndEnforcementPropertyService . fetchByFileUuid ( this . file . uuid ) ;
220-
259+ const properties = await this . complianceAndEnforcementPropertyService . fetchParcels ( this . file . uuid ) ;
260+ // There should only ever be one while in draft
261+ this . property = properties [ 0 ] ;
262+
221263 if ( this . propertyComponent && this . property ) {
222264 this . propertyComponent . property = this . property ;
223265 }
224266 // Check if property is Crown ownership
225267 this . isPropertyCrown = this . property ?. ownershipTypeCode === 'CRWN' ;
226-
268+
227269 // Set the Crown status on the responsible parties component and load parties
228270 if ( this . responsiblePartiesComponent ) {
229271 this . responsiblePartiesComponent . isPropertyCrown = this . isPropertyCrown ;
230- // Manually trigger loading since the component's ngOnInit ran before file was loaded up
272+ // Manually trigger loading since the component's ngOnInit ran before file was loaded up
231273 if ( this . file ?. uuid ) {
232274 this . responsiblePartiesComponent . fileUuid = this . file . uuid ;
233275 await this . responsiblePartiesComponent . loadResponsibleParties ( ) ;
0 commit comments