Skip to content

Commit b753126

Browse files
committed
refresh metadata fxnal
1 parent 94299b7 commit b753126

File tree

6 files changed

+140
-6
lines changed

6 files changed

+140
-6
lines changed

src/@seed/api/inventory/inventory.service.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,4 +371,30 @@ export class InventoryService {
371371
}),
372372
)
373373
}
374+
375+
startRefreshMetadata(orgId: number): Observable<ProgressResponse> {
376+
const url = `/api/v3/tax_lot_properties/start_set_update_to_now/?organization_id=${orgId}`
377+
return this._httpClient.get<ProgressResponse>(url).pipe(
378+
take(1),
379+
catchError((error: HttpErrorResponse) => {
380+
return this._errorService.handleError(error, 'Error starting metadata refresh')
381+
}),
382+
)
383+
}
384+
385+
refreshMetadata(orgId: number, propertyViews: number[], taxlotViews: number[], progressKey: string): Observable<ProgressResponse> {
386+
const url = '/api/v3/tax_lot_properties/set_update_to_now/'
387+
const data = {
388+
organization_id: orgId,
389+
property_views: propertyViews,
390+
taxlot_views: taxlotViews,
391+
progress_key: progressKey,
392+
}
393+
return this._httpClient.post<ProgressResponse>(url, data).pipe(
394+
take(1),
395+
catchError((error: HttpErrorResponse) => {
396+
return this._errorService.handleError(error, 'Error refreshing metadata')
397+
}),
398+
)
399+
}
374400
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
export * from './update-derived-data.component'
1+
export * from './refresh-metadata-modal.component'
2+
export * from './update-derived-data.component'
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<seed-modal-header
2+
title="Refresh Inventory"
3+
titleIcon="fa-solid:clock"
4+
[close]="close.bind(this)"
5+
>
6+
</seed-modal-header>
7+
8+
@if (!inProgress) {
9+
<div class="text-secondary">
10+
This will set the selected inventory's 'Updated' timestamp to {{ currentTime }}.
11+
</div>
12+
}
13+
14+
@else {
15+
<seed-progress-bar
16+
[progress]="progressBarObj.progress"
17+
[title]="progressBarObj.statusMessage || 'Refreshing inventory metadata...'"
18+
[total]="progressBarObj.total"
19+
></seed-progress-bar>
20+
}
21+
22+
<div class="mt-4 flex justify-end gap-2">
23+
<button (click)="refresh()" mat-raised-button color="primary">Refresh</button>
24+
</div>
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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 { InventoryService } from '@seed/api'
5+
import { ModalHeaderComponent, ProgressBarComponent } from '@seed/components'
6+
import { MaterialImports } from '@seed/materials'
7+
import { UploaderService } from '@seed/services'
8+
import { SnackBarService } from 'app/core/snack-bar/snack-bar.service'
9+
import type { InventoryType } from 'app/modules/inventory/inventory.types'
10+
import { combineLatest, filter, finalize, Subject, switchMap, takeUntil, tap } from 'rxjs'
11+
12+
@Component({
13+
selector: 'seed-refresh-metadata-modal',
14+
templateUrl: './refresh-metadata-modal.component.html',
15+
imports: [MaterialImports, ModalHeaderComponent, ProgressBarComponent],
16+
})
17+
export class RefreshMetadataModalComponent implements OnInit, OnDestroy {
18+
private _dialogRef = inject(MatDialogRef<RefreshMetadataModalComponent>)
19+
private _inventoryService = inject(InventoryService)
20+
private _snackBar = inject(SnackBarService)
21+
private _uploaderService = inject(UploaderService)
22+
private _unsubscribeAll$ = new Subject<void>()
23+
currentTime: string
24+
inProgress = false
25+
progressBarObj = this._uploaderService.defaultProgressBarObj
26+
progressKey: string
27+
28+
data = inject(MAT_DIALOG_DATA) as {
29+
orgId: number;
30+
viewIds: number[];
31+
type: InventoryType;
32+
}
33+
34+
ngOnInit() {
35+
setInterval(() => {
36+
this.currentTime = new Date().toLocaleTimeString()
37+
}, 1000)
38+
}
39+
40+
refresh() {
41+
this.inProgress = true
42+
this._inventoryService.startRefreshMetadata(this.data.orgId)
43+
.pipe(
44+
switchMap(({ progress_key }) => this.pollRefresh(progress_key)),
45+
filter(([_, progressResponse]) => progressResponse.progress >= 100),
46+
tap(() => {
47+
this._snackBar.success('Success')
48+
this.close(true)
49+
}),
50+
takeUntil(this._unsubscribeAll$),
51+
finalize(() => { this.inProgress = false }),
52+
)
53+
.subscribe()
54+
}
55+
56+
pollRefresh(progress_key: string) {
57+
const { orgId, type, viewIds } = this.data
58+
const [propertyViews, taxlotViews] = type == 'taxlots' ? [[], viewIds] : [viewIds, []]
59+
60+
return combineLatest([
61+
this._inventoryService.refreshMetadata(orgId, propertyViews, taxlotViews, progress_key),
62+
this._uploaderService.checkProgressLoop({
63+
progressKey: progress_key,
64+
progressBarObj: this.progressBarObj,
65+
}),
66+
])
67+
}
68+
69+
close(success = false): void {
70+
this._dialogRef.close(success)
71+
}
72+
73+
ngOnDestroy(): void {
74+
this._unsubscribeAll$.next()
75+
this._unsubscribeAll$.complete()
76+
}
77+
}

src/app/modules/inventory-list/list/grid/actions.component.html

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@
8080
<mat-divider class="my-0"></mat-divider>
8181
<span class="text-secondary text-sm">Other</span>
8282
<seed-menu-item class="text-secondary line-through" [disabled]="!hasSelection" (action)="tempAction()" label="Email"></seed-menu-item>
83-
<seed-menu-item class="text-secondary line-through" [disabled]="!hasSelection" (action)="tempAction()" label="Export"></seed-menu-item>
8483
<seed-menu-item
8584
class="text-secondary line-through"
8685
[disabled]="!hasSelection"
@@ -89,10 +88,9 @@
8988
></seed-menu-item>
9089
<seed-menu-item class="text-secondary line-through" [disabled]="!hasSelection" (action)="tempAction()" label="Geocode"></seed-menu-item>
9190
<seed-menu-item
92-
class="text-secondary line-through"
9391
[disabled]="!hasSelection"
94-
(action)="tempAction()"
95-
label="Set Update Time to Now"
92+
(action)="openRefreshMetadataModal()"
93+
label="Refresh Updated Timestamp"
9694
></seed-menu-item>
9795
<!-- SalesForce -->
9896
<mat-divider class="my-0"></mat-divider>

src/app/modules/inventory-list/list/grid/actions.component.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { ModalComponent } from 'app/modules/column-list-profile/modal/modal.comp
1111
import { DQCStartModalComponent } from 'app/modules/data-quality'
1212
import { AliChangeModalComponent, AnalysisRunModalComponent, ExportModalComponent, GroupsModalComponent, LabelsModalComponent } from 'app/modules/inventory/actions'
1313
import type { InventoryType, Profile } from '../../../inventory/inventory.types'
14-
import { UpdateDerivedDataComponent } from '../actions'
14+
import { RefreshMetadataModalComponent, UpdateDerivedDataComponent } from '../actions'
1515

1616
@Component({
1717
selector: 'seed-inventory-grid-actions',
@@ -178,6 +178,14 @@ export class ActionsComponent implements OnDestroy, OnChanges, OnInit {
178178
this.afterClosed(dialogRef)
179179
}
180180

181+
openRefreshMetadataModal() {
182+
const dialogRef = this._dialog.open(RefreshMetadataModalComponent, {
183+
width: '40rem',
184+
data: this.baseData(),
185+
})
186+
this.afterClosed(dialogRef)
187+
}
188+
181189
afterClosed(dialogRef: MatDialogRef<unknown>) {
182190
dialogRef.afterClosed().pipe(
183191
filter(Boolean),

0 commit comments

Comments
 (0)