import { HttpClient, HttpParams } from '@angular/common/http'
import { inject, Injectable } from '@angular/core'
import { Observable } from 'rxjs'
-import { map, publishReplay, refCount } from 'rxjs/operators'
+import { map, publishReplay, refCount, tap } from 'rxjs/operators'
import { ObjectWithId } from 'src/app/data/object-with-id'
import { Results } from 'src/app/data/results'
import { environment } from 'src/environments/environment'
protected http: HttpClient
protected resourceName: string
+ protected _loading: boolean = false
+ public get loading(): boolean {
+ return this._loading
+ }
+
constructor() {
this.http = inject(HttpClient)
}
sortReverse?: boolean,
extraParams?
): Observable<Results<T>> {
+ this._loading = true
let httpParams = new HttpParams()
if (page) {
httpParams = httpParams.set('page', page.toString())
httpParams = httpParams.set(extraParamKey, extraParams[extraParamKey])
}
}
- return this.http.get<Results<T>>(this.getResourceUrl(), {
- params: httpParams,
- })
+ return this.http
+ .get<Results<T>>(this.getResourceUrl(), {
+ params: httpParams,
+ })
+ .pipe(
+ tap(() => {
+ this._loading = false
+ })
+ )
}
private _listAll: Observable<Results<T>>
}
getFew(ids: number[], extraParams?): Observable<Results<T>> {
+ this._loading = true
let httpParams = new HttpParams()
httpParams = httpParams.set('id__in', ids.join(','))
httpParams = httpParams.set('ordering', '-id')
httpParams = httpParams.set(extraParamKey, extraParams[extraParamKey])
}
}
- return this.http.get<Results<T>>(this.getResourceUrl(), {
- params: httpParams,
- })
+ return this.http
+ .get<Results<T>>(this.getResourceUrl(), {
+ params: httpParams,
+ })
+ .pipe(
+ tap(() => {
+ this._loading = false
+ })
+ )
}
clearCache() {
}
get(id: number): Observable<T> {
- return this.http.get<T>(this.getResourceUrl(id))
+ this._loading = true
+ return this.http.get<T>(this.getResourceUrl(id)).pipe(
+ tap(() => {
+ this._loading = false
+ })
+ )
}
create(o: T): Observable<T> {
private settingsService = inject(SettingsService)
private documentService = inject(DocumentService)
- public loading: boolean = true
private savedViews: SavedView[] = []
private savedViewDocumentCounts: Map<number, number> = new Map()
private unsubscribeNotifier: Subject<void> = new Subject<void>()
tap({
next: (r) => {
this.savedViews = r.results
- this.loading = false
+ this._loading = false
this.settingsService.dashboardIsEmpty =
this.dashboardViews.length === 0
},
error: () => {
- this.loading = false
+ this._loading = false
this.settingsService.dashboardIsEmpty = true
},
})