AAE-30901 Allow to use different saveSearch service (#10623)

This commit is contained in:
Bartosz Sekula 2025-02-05 17:27:34 +01:00 committed by GitHub
parent 8e3bd154ed
commit 72a889241e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -15,28 +15,41 @@
* limitations under the License. * limitations under the License.
*/ */
import { NodesApi, NodeEntry, PreferencesApi } from '@alfresco/js-api'; import { NodesApi, NodeEntry, PreferencesApi, ContentFieldsQuery, PreferenceEntry } from '@alfresco/js-api';
import { Injectable } from '@angular/core'; import { inject, Injectable, InjectionToken } from '@angular/core';
import { Observable, of, from, ReplaySubject, throwError } from 'rxjs'; import { Observable, of, from, ReplaySubject, throwError } from 'rxjs';
import { catchError, concatMap, first, map, switchMap, take, tap } from 'rxjs/operators'; import { catchError, concatMap, first, map, switchMap, take, tap } from 'rxjs/operators';
import { AlfrescoApiService } from '../../services/alfresco-api.service'; import { AlfrescoApiService } from '../../services/alfresco-api.service';
import { SavedSearch } from '../interfaces/saved-search.interface'; import { SavedSearch } from '../interfaces/saved-search.interface';
import { AuthenticationService } from '@alfresco/adf-core'; import { AuthenticationService } from '@alfresco/adf-core';
export interface SavedSearchesPreferencesApiService {
getPreference: (personId: string, preferenceName: string, opts?: ContentFieldsQuery) => Promise<PreferenceEntry> | Observable<PreferenceEntry>;
updatePreference: (personId: string, preferenceName: string, preferenceValue: string) => Promise<PreferenceEntry> | Observable<PreferenceEntry>;
}
export const SAVED_SEARCHES_SERVICE_PREFERENCES = new InjectionToken<SavedSearchesPreferencesApiService>('SAVED_SEARCHES_SERVICE_PREFERENCES');
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
}) })
export class SavedSearchesService { export class SavedSearchesService {
private savedSearchFileNodeId: string; private savedSearchFileNodeId: string;
private _nodesApi: NodesApi; private _nodesApi: NodesApi;
private _preferencesApi: PreferencesApi; private _preferencesApi: SavedSearchesPreferencesApiService;
private preferencesService = inject(SAVED_SEARCHES_SERVICE_PREFERENCES, { optional: true });
get nodesApi(): NodesApi { get nodesApi(): NodesApi {
this._nodesApi = this._nodesApi ?? new NodesApi(this.apiService.getInstance()); this._nodesApi = this._nodesApi ?? new NodesApi(this.apiService.getInstance());
return this._nodesApi; return this._nodesApi;
} }
get preferencesApi(): PreferencesApi { get preferencesApi(): SavedSearchesPreferencesApiService {
if (this.preferencesService) {
this._preferencesApi = this.preferencesService;
return this._preferencesApi;
}
this._preferencesApi = this._preferencesApi ?? new PreferencesApi(this.apiService.getInstance()); this._preferencesApi = this._preferencesApi ?? new PreferencesApi(this.apiService.getInstance());
return this._preferencesApi; return this._preferencesApi;
} }