mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-2128] facet container component (#3094)
* (wip) facet container * shaping out the API * code lint fixes * radiobox facet example * fields selector facet * search limits support * scope locations facet example * move custom search to 'search.query' config * use facet fields and queries from the config file * use facet filters * use facet buckets in query * preserve expanded/checked states * code cleanup and binding fixes * fix apis after rebase * extract query builder into separate class * code improvements * full chip list (merge facet fields with queries) * placeholder for range requests * move search infrastructure to ADF core * cleanup code * auto-search on init * move search components to the content services * selected facets chip list * split into separate components at ADF level * move the rest of the implementation to ADF * facet builder fixes and tests * translation support for category names * docs placeholders * update language level * unit tests and packaging updates * fix after rebase * remove fdescribe * some docs on search settings * rename components as per review * simplify chip list as per review * turn query builder into service * improve search service, integrate old search results * fix node selector integration * move service to the top module * update tests * remove fdescribe * update tests * test fixes * test fixes * test updates * fix tests * code and test fixes * remove fit * fix tests * fix tests * remove obsolete test * increase bundle threshold * update docs to reflect PR changes * fix docs
This commit is contained in:
committed by
Eugenio Romano
parent
d6f51c22aa
commit
ed48994e67
@@ -4,6 +4,7 @@
|
||||
"src": "./core/",
|
||||
"dest": "../dist/core/",
|
||||
"lib": {
|
||||
"languageLevel": [ "dom", "es2016" ],
|
||||
"licensePath": "../config/assets/license_header_add.txt",
|
||||
"comments" : "none",
|
||||
"entryFile": "./public-api.ts",
|
||||
|
@@ -19,7 +19,7 @@ import { Injectable } from '@angular/core';
|
||||
import {
|
||||
AlfrescoApi, ContentApi, FavoritesApi, NodesApi,
|
||||
PeopleApi, RenditionsApi, SharedlinksApi, SitesApi,
|
||||
VersionsApi, ClassesApi
|
||||
VersionsApi, ClassesApi, SearchApi
|
||||
} from 'alfresco-js-api';
|
||||
import * as alfrescoApi from 'alfresco-js-api';
|
||||
import { AppConfigService } from '../app-config/app-config.service';
|
||||
@@ -62,7 +62,7 @@ export class AlfrescoApiService {
|
||||
return this.getInstance().core.peopleApi;
|
||||
}
|
||||
|
||||
get searchApi() {
|
||||
get searchApi(): SearchApi {
|
||||
return this.getInstance().search.searchApi;
|
||||
}
|
||||
|
||||
|
@@ -57,7 +57,7 @@ describe('SearchService', () => {
|
||||
it('should call search API with no additional options', (done) => {
|
||||
let searchTerm = 'searchTerm63688';
|
||||
spyOn(searchMockApi.core.queriesApi, 'findNodes').and.returnValue(Promise.resolve(fakeSearch));
|
||||
service.getNodeQueryResults(searchTerm).subscribe(
|
||||
service.getNodeQueryResults(searchTerm).then(
|
||||
() => {
|
||||
expect(searchMockApi.core.queriesApi.findNodes).toHaveBeenCalledWith(searchTerm, undefined);
|
||||
done();
|
||||
@@ -72,7 +72,7 @@ describe('SearchService', () => {
|
||||
nodeType: 'cm:content'
|
||||
};
|
||||
spyOn(searchMockApi.core.queriesApi, 'findNodes').and.returnValue(Promise.resolve(fakeSearch));
|
||||
service.getNodeQueryResults(searchTerm, options).subscribe(
|
||||
service.getNodeQueryResults(searchTerm, options).then(
|
||||
() => {
|
||||
expect(searchMockApi.core.queriesApi.findNodes).toHaveBeenCalledWith(searchTerm, options);
|
||||
done();
|
||||
@@ -81,7 +81,7 @@ describe('SearchService', () => {
|
||||
});
|
||||
|
||||
it('should return search results returned from the API', (done) => {
|
||||
service.getNodeQueryResults('').subscribe(
|
||||
service.getNodeQueryResults('').then(
|
||||
(res: any) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res).toEqual(fakeSearch);
|
||||
@@ -92,7 +92,7 @@ describe('SearchService', () => {
|
||||
|
||||
it('should notify errors returned from the API', (done) => {
|
||||
spyOn(searchMockApi.core.queriesApi, 'findNodes').and.returnValue(Promise.reject(mockError));
|
||||
service.getNodeQueryResults('').subscribe(
|
||||
service.getNodeQueryResults('').then(
|
||||
() => {},
|
||||
(res: any) => {
|
||||
expect(res).toBeDefined();
|
||||
@@ -101,17 +101,4 @@ describe('SearchService', () => {
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('should notify a general error if the API does not return a specific error', (done) => {
|
||||
spyOn(searchMockApi.core.queriesApi, 'findNodes').and.returnValue(Promise.reject(null));
|
||||
service.getNodeQueryResults('').subscribe(
|
||||
() => {},
|
||||
(res: any) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res).toEqual('Server error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
});
|
||||
|
@@ -17,45 +17,41 @@
|
||||
|
||||
import { Injectable } from '@angular/core';
|
||||
import { NodePaging, QueryBody } from 'alfresco-js-api';
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import { AlfrescoApiService } from './alfresco-api.service';
|
||||
import { AuthenticationService } from './authentication.service';
|
||||
import 'rxjs/add/observable/throw';
|
||||
import { Subject } from 'rxjs/Subject';
|
||||
|
||||
import { AlfrescoApiService } from './alfresco-api.service';
|
||||
import { SearchConfigurationService } from './search-configuration.service';
|
||||
|
||||
@Injectable()
|
||||
export class SearchService {
|
||||
|
||||
constructor(public authService: AuthenticationService,
|
||||
private apiService: AlfrescoApiService,
|
||||
dataLoaded: Subject<NodePaging> = new Subject();
|
||||
|
||||
constructor(private apiService: AlfrescoApiService,
|
||||
private searchConfigurationService: SearchConfigurationService) {
|
||||
}
|
||||
|
||||
getNodeQueryResults(term: string, options?: SearchOptions): Observable<NodePaging> {
|
||||
return Observable.fromPromise(this.apiService.getInstance().core.queriesApi.findNodes(term, options))
|
||||
.map(res => <NodePaging> res)
|
||||
.catch(err => this.handleError(err));
|
||||
async getNodeQueryResults(term: string, options?: SearchOptions): Promise<NodePaging> {
|
||||
const data = await this.apiService.getInstance().core.queriesApi.findNodes(term, options);
|
||||
|
||||
this.dataLoaded.next(data);
|
||||
return data;
|
||||
}
|
||||
|
||||
search(searchTerm: string, maxResults: number, skipCount: number): Observable<NodePaging> {
|
||||
const searchQuery = Object.assign(this.searchConfigurationService.generateQueryBody(searchTerm, maxResults, skipCount));
|
||||
const promise = this.apiService.getInstance().search.searchApi.search(searchQuery);
|
||||
async search(searchTerm: string, maxResults: number, skipCount: number): Promise<NodePaging> {
|
||||
const searchQuery = this.searchConfigurationService.generateQueryBody(searchTerm, maxResults, skipCount);
|
||||
const data = await this.apiService.searchApi.search(searchQuery);
|
||||
|
||||
return Observable
|
||||
.fromPromise(promise)
|
||||
.catch(err => this.handleError(err));
|
||||
this.dataLoaded.next(data);
|
||||
return data;
|
||||
}
|
||||
|
||||
searchByQueryBody(queryBody: QueryBody): Observable<NodePaging> {
|
||||
const promise = this.apiService.getInstance().search.searchApi.search(queryBody);
|
||||
async searchByQueryBody(queryBody: QueryBody): Promise<NodePaging> {
|
||||
const data = await this.apiService.searchApi.search(queryBody);
|
||||
|
||||
return Observable
|
||||
.fromPromise(promise)
|
||||
.catch(err => this.handleError(err));
|
||||
}
|
||||
|
||||
private handleError(error: any): Observable<any> {
|
||||
return Observable.throw(error || 'Server error');
|
||||
this.dataLoaded.next(data);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -16,10 +16,8 @@
|
||||
*/
|
||||
|
||||
import { async, TestBed } from '@angular/core/testing';
|
||||
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
|
||||
import { SettingsService } from './settings.service';
|
||||
import { AppConfigModule } from '../app-config/app-config.module';
|
||||
import { TranslateLoaderService } from './translate-loader.service';
|
||||
|
||||
describe('SettingsService', () => {
|
||||
|
||||
@@ -28,13 +26,7 @@ describe('SettingsService', () => {
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
AppConfigModule,
|
||||
TranslateModule.forRoot({
|
||||
loader: {
|
||||
provide: TranslateLoader,
|
||||
useClass: TranslateLoaderService
|
||||
}
|
||||
})
|
||||
AppConfigModule
|
||||
],
|
||||
providers: [
|
||||
SettingsService
|
||||
|
Reference in New Issue
Block a user