Sprint 8: add widget manifest and data source engine

This commit is contained in:
sdarbinyan
2026-07-05 02:08:15 +04:00
parent 91d9444875
commit c3d1153f0e
20 changed files with 867 additions and 375 deletions

View File

@@ -0,0 +1,34 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable, catchError, map, of, shareReplay } from 'rxjs';
import { WidgetManifestEntry, WidgetManifestFile } from '../contracts/widget-manifest.contract';
@Injectable({ providedIn: 'root' })
export class WidgetManifestService {
private readonly manifestUrl = '/assets/mock/bootstrap/widget-manifest.json';
private manifest$?: Observable<WidgetManifestFile>;
constructor(private readonly http: HttpClient) {}
getManifest(): Observable<WidgetManifestFile> {
if (!this.manifest$) {
this.manifest$ = this.http.get<WidgetManifestFile>(this.manifestUrl).pipe(
shareReplay({ bufferSize: 1, refCount: true }),
catchError(() => {
this.manifest$ = undefined;
return of({ widgets: [] });
})
);
}
return this.manifest$;
}
getWidgets(): Observable<WidgetManifestEntry[]> {
return this.getManifest().pipe(map((manifest) => manifest.widgets ?? []));
}
getWidget(type: string): Observable<WidgetManifestEntry | undefined> {
return this.getWidgets().pipe(map((widgets) => widgets.find((widget) => widget.type === type)));
}
}