|
| 1 | +import type { OnDestroy, OnInit} from '@angular/core' |
| 2 | +import { Component, inject } from '@angular/core' |
| 3 | +import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog' |
| 4 | +import { GeocodeService } from '@seed/api' |
| 5 | +import type { ConfidenceSummary, GeocodingColumns } from '@seed/api/geocode/geocode.types' |
| 6 | +import { AlertComponent, ModalHeaderComponent } from '@seed/components' |
| 7 | +import { SharedImports } from '@seed/directives' |
| 8 | +import { MaterialImports } from '@seed/materials' |
| 9 | +import type { InventoryType } from 'app/modules/inventory/inventory.types' |
| 10 | +import { forkJoin, Subject, tap } from 'rxjs' |
| 11 | + |
| 12 | +@Component({ |
| 13 | + selector: 'seed-geocode-modal', |
| 14 | + templateUrl: './geocode-modal.component.html', |
| 15 | + imports: [AlertComponent, MaterialImports, ModalHeaderComponent, SharedImports], |
| 16 | +}) |
| 17 | +export class GeocodeModalComponent implements OnInit, OnDestroy { |
| 18 | + private _dialogRef = inject(MatDialogRef<GeocodeModalComponent>) |
| 19 | + private _geocodeService = inject(GeocodeService) |
| 20 | + private _unsubscribeAll$ = new Subject<void>() |
| 21 | + |
| 22 | + confidenceSummary: ConfidenceSummary |
| 23 | + geocodingEnabled = true |
| 24 | + hasApiKey = true |
| 25 | + hasEnoughGeoCols = true |
| 26 | + hasGeoColumns = true |
| 27 | + suggestVerify = true |
| 28 | + notGeocoded = false |
| 29 | + |
| 30 | + geocodeState: 'verify' | 'geocode' | 'result' | 'fail' = 'verify' |
| 31 | + |
| 32 | + data = inject(MAT_DIALOG_DATA) as { |
| 33 | + orgId: number; |
| 34 | + viewIds: number[]; |
| 35 | + type: InventoryType; |
| 36 | + } |
| 37 | + |
| 38 | + get valid() { |
| 39 | + return this.hasApiKey && this.geocodingEnabled && this.hasGeoColumns |
| 40 | + } |
| 41 | + |
| 42 | + ngOnInit(): void { |
| 43 | + this.getGeocodeConfig() |
| 44 | + } |
| 45 | + |
| 46 | + getGeocodeConfig() { |
| 47 | + forkJoin([ |
| 48 | + this._geocodeService.checkApiKey(this.data.orgId), |
| 49 | + this._geocodeService.geocodingEnabled(this.data.orgId), |
| 50 | + this._geocodeService.geocodingColumns(this.data.orgId), |
| 51 | + this._geocodeService.confidenceSummary(this.data.orgId, this.data.viewIds, this.data.type), |
| 52 | + ]).pipe( |
| 53 | + tap(([hasApiKey, geocodingEnabled, geoColumns, confidenceSummary]) => { |
| 54 | + this.hasApiKey = hasApiKey |
| 55 | + this.geocodingEnabled = geocodingEnabled |
| 56 | + this.processGeoColumns(geoColumns) |
| 57 | + this.processConfidenceSummary(confidenceSummary) |
| 58 | + this.suggestVerify = hasApiKey && this.hasGeoColumns && this.geocodeState === 'verify' |
| 59 | + }), |
| 60 | + ).subscribe() |
| 61 | + } |
| 62 | + |
| 63 | + processGeoColumns({ PropertyState, TaxLotState }: GeocodingColumns) { |
| 64 | + this.hasGeoColumns = this.data.type === 'taxlots' ? TaxLotState.length > 0 : PropertyState.length > 0 |
| 65 | + } |
| 66 | + |
| 67 | + processConfidenceSummary(confidenceSummary: ConfidenceSummary) { |
| 68 | + this.confidenceSummary = confidenceSummary |
| 69 | + // Process the confidence summary as needed |
| 70 | + } |
| 71 | + |
| 72 | + close(success = false) { |
| 73 | + this._dialogRef.close(success) |
| 74 | + } |
| 75 | + |
| 76 | + onSubmit() { |
| 77 | + console.log('submit') |
| 78 | + } |
| 79 | + |
| 80 | + ngOnDestroy(): void { |
| 81 | + this._unsubscribeAll$.next() |
| 82 | + this._unsubscribeAll$.complete() |
| 83 | + } |
| 84 | +} |
0 commit comments