diff --git a/docs/content-services/services/category.service.md b/docs/content-services/services/category.service.md index 4eb14b8b9e..dd4d3af3cb 100644 --- a/docs/content-services/services/category.service.md +++ b/docs/content-services/services/category.service.md @@ -22,6 +22,9 @@ Manages categories in Content Services. - **getCategory**(categoryId: `string`): [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`CategoryEntry`](https://github.com/Alfresco/alfresco-js-api/blob/master/src/api/content-rest-api/docs/CategoryEntry.md)`>`
Gets a specific category by categoryId. - _categoryId:_ `string` - The identifier of a category + - _opts:_ `any` - Optional parameters + - _opts.fields_ `string[]` - A list of field names + - _opts.include_ `string[]` - Returns additional information about the category. The following optional fields can be requested: count, path - **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`CategoryEntry`](https://github.com/Alfresco/alfresco-js-api/blob/master/src/api/content-rest-api/docs/CategoryEntry.md)`>` - CategoryEntry object (defined in JS-API) containing information about the category. - **createSubcategories**(parentCategoryId: `string`, payload: [`CategoryBody[]`](https://github.com/Alfresco/alfresco-js-api/blob/master/src/api/content-rest-api/docs/CategoryBody.md)): [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`CategoryPaging`](https://github.com/Alfresco/alfresco-js-api/blob/master/src/api/content-rest-api/docs/CategoryPaging.md) | [`CategoryEntry`](https://github.com/Alfresco/alfresco-js-api/blob/master/src/api/content-rest-api/docs/CategoryEntry.md)`>`
Creates subcategories under category with provided categoryId. diff --git a/lib/content-services/src/lib/category/services/category.service.spec.ts b/lib/content-services/src/lib/category/services/category.service.spec.ts index f769164865..3a744b9bc5 100644 --- a/lib/content-services/src/lib/category/services/category.service.spec.ts +++ b/lib/content-services/src/lib/category/services/category.service.spec.ts @@ -67,8 +67,8 @@ describe('CategoryService', () => { it('should fetch the category with the provided categoryId', fakeAsync(() => { const getSpy = spyOn(categoryService.categoriesApi, 'getCategory').and.returnValue(Promise.resolve(fakeCategoryEntry)); - categoryService.getCategory(fakeParentCategoryId).subscribe(() => { - expect(getSpy).toHaveBeenCalledOnceWith(fakeParentCategoryId); + categoryService.getCategory(fakeParentCategoryId, {include: ['path']}).subscribe(() => { + expect(getSpy).toHaveBeenCalledOnceWith(fakeParentCategoryId, {include: ['path']}); }); })); diff --git a/lib/content-services/src/lib/category/services/category.service.ts b/lib/content-services/src/lib/category/services/category.service.ts index f5e6da5eb5..a17b44afbf 100644 --- a/lib/content-services/src/lib/category/services/category.service.ts +++ b/lib/content-services/src/lib/category/services/category.service.ts @@ -62,10 +62,15 @@ export class CategoryService { * Get a category by ID * * @param categoryId The identifier of a category. + * @param opts Optional parameters. + * @param opts.fields A list of field names. + * @param opts.include Returns additional information about the category. The following optional fields can be requested: + * count + * path * @return Observable */ - getCategory(categoryId: string): Observable { - return from(this.categoriesApi.getCategory(categoryId)); + getCategory(categoryId: string, opts?: any): Observable { + return from(this.categoriesApi.getCategory(categoryId, opts)); } /** diff --git a/lib/content-services/src/lib/search/services/search-facet-filters.service.spec.ts b/lib/content-services/src/lib/search/services/search-facet-filters.service.spec.ts index e415b8cad5..c04abefdd9 100644 --- a/lib/content-services/src/lib/search/services/search-facet-filters.service.spec.ts +++ b/lib/content-services/src/lib/search/services/search-facet-filters.service.spec.ts @@ -34,8 +34,7 @@ describe('SearchFacetFiltersService', () => { providers: [{ provide: CategoryService, useValue: { - getCategory: () => EMPTY, - searchCategories: () => EMPTY + getCategory: () => EMPTY } }] }); @@ -472,22 +471,9 @@ describe('SearchFacetFiltersService', () => { }); it('should load category names for cm:categories facet', () => { - const entry = {id: 'test-id-test', name: 'name'}; + const entry = {id: 'test-id-test', name: 'name', path: '/categories/General/Test Category/Subcategory'}; searchFacetFiltersService.responseFacets = null; spyOn(categoryService, 'getCategory').and.returnValue(of({entry})); - spyOn(categoryService, 'searchCategories').and.returnValue(of({ - list: { - entries: [{ - entry: { - ...entry, - nodeType: 'node-type', - path: { name: '/categories/General/Test Category/Subcategory'}, - isFolder: false, - isFile: false - } - }] - } - })); queryBuilder.config = { categories: [], @@ -521,8 +507,7 @@ describe('SearchFacetFiltersService', () => { searchFacetFiltersService.onDataLoaded(data); - expect(categoryService.getCategory).toHaveBeenCalledWith(entry.id); - expect(categoryService.searchCategories).toHaveBeenCalledWith(entry.name); + expect(categoryService.getCategory).toHaveBeenCalledWith(entry.id, { include: [ 'path' ]}); expect(searchFacetFiltersService.responseFacets[1].buckets.items[0].display).toBe(`Test Category/Subcategory/${entry.name}`); expect(searchFacetFiltersService.responseFacets[1].buckets.length).toEqual(1); expect(searchFacetFiltersService.responseFacets.length).toEqual(2); diff --git a/lib/content-services/src/lib/search/services/search-facet-filters.service.ts b/lib/content-services/src/lib/search/services/search-facet-filters.service.ts index 6edb9a010d..56b965f0c4 100644 --- a/lib/content-services/src/lib/search/services/search-facet-filters.service.ts +++ b/lib/content-services/src/lib/search/services/search-facet-filters.service.ts @@ -22,7 +22,7 @@ import { SEARCH_QUERY_SERVICE_TOKEN } from '../search-query-service.token'; import { SearchQueryBuilderService } from './search-query-builder.service'; import { TranslationService } from '@alfresco/adf-core'; import { SearchService } from './search.service'; -import { catchError, concatMap, takeUntil } from 'rxjs/operators'; +import { catchError, takeUntil } from 'rxjs/operators'; import { GenericBucket, GenericFacetResponse, ResultSetContext, ResultSetPaging } from '@alfresco/js-api'; import { SearchFilterList } from '../models/search-filter-list.model'; import { FacetFieldBucket } from '../models/facet-field-bucket.interface'; @@ -345,19 +345,14 @@ export class SearchFacetFiltersService implements OnDestroy { private loadCategoryNames(bucketList: FacetFieldBucket[]) { bucketList.forEach((item) => { const categoryId = item.label.split('/').pop(); - this.categoryService.getCategory(categoryId) - .pipe( - concatMap((categoryEntry) => this.categoryService.searchCategories(categoryEntry.entry.name)), - catchError(error => throwError(error)) - ) + this.categoryService.getCategory(categoryId, {include: ['path']}) + .pipe(catchError(error => throwError(error))) .subscribe( - result => { + category => { const nextAfterGeneralPathPartIndex = 3; const pathSeparator = '/'; - const currentCat = result.list.entries.filter(entry => entry.entry.id === categoryId)[0]; - const path = currentCat.entry.path.name.split(pathSeparator).slice(nextAfterGeneralPathPartIndex).join('/'); - - item.display = path ? `${path}/${currentCat.entry.name}` : currentCat.entry.name; + const path = category.entry.path.split(pathSeparator).slice(nextAfterGeneralPathPartIndex).join('/'); + item.display = path ? `${path}/${category.entry.name}` : category.entry.name; } ); });