mirror of https://github.com/ghostfolio/ghostfolio
committed by
GitHub
8 changed files with 131 additions and 28 deletions
@ -0,0 +1,15 @@ |
|||
@if (status$ | async; as status) { |
|||
@if (status.isHealthy) { |
|||
<span class="text-success" i18n>Online</span> |
|||
} @else { |
|||
<span class="text-danger" i18n>Offline</span> |
|||
} |
|||
} @else { |
|||
<ngx-skeleton-loader |
|||
animation="pulse" |
|||
[theme]="{ |
|||
height: '1.5rem', |
|||
width: '100%' |
|||
}" |
|||
/> |
|||
} |
@ -0,0 +1,51 @@ |
|||
import { DataService } from '@ghostfolio/client/services/data.service'; |
|||
|
|||
import { CommonModule } from '@angular/common'; |
|||
import { |
|||
ChangeDetectionStrategy, |
|||
Component, |
|||
Input, |
|||
OnDestroy, |
|||
OnInit |
|||
} from '@angular/core'; |
|||
import type { DataSource } from '@prisma/client'; |
|||
import { NgxSkeletonLoaderModule } from 'ngx-skeleton-loader'; |
|||
import { catchError, map, type Observable, of, Subject, takeUntil } from 'rxjs'; |
|||
|
|||
import { DataProviderStatus } from './interfaces/interfaces'; |
|||
|
|||
@Component({ |
|||
changeDetection: ChangeDetectionStrategy.OnPush, |
|||
imports: [CommonModule, NgxSkeletonLoaderModule], |
|||
selector: 'gf-data-provider-status', |
|||
standalone: true, |
|||
templateUrl: './data-provider-status.component.html' |
|||
}) |
|||
export class GfDataProviderStatusComponent implements OnDestroy, OnInit { |
|||
@Input() dataSource: DataSource; |
|||
|
|||
public status$: Observable<DataProviderStatus>; |
|||
|
|||
private unsubscribeSubject = new Subject<void>(); |
|||
|
|||
public constructor(private dataService: DataService) {} |
|||
|
|||
public ngOnInit() { |
|||
this.status$ = this.dataService |
|||
.fetchDataProviderHealth(this.dataSource) |
|||
.pipe( |
|||
catchError(() => { |
|||
return of({ isHealthy: false }); |
|||
}), |
|||
map(() => { |
|||
return { isHealthy: true }; |
|||
}), |
|||
takeUntil(this.unsubscribeSubject) |
|||
); |
|||
} |
|||
|
|||
public ngOnDestroy() { |
|||
this.unsubscribeSubject.next(); |
|||
this.unsubscribeSubject.complete(); |
|||
} |
|||
} |
@ -0,0 +1,3 @@ |
|||
export interface DataProviderStatus { |
|||
isHealthy: boolean; |
|||
} |
Loading…
Reference in new issue