mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-07-24 17:31:52 +00:00
[ACA-4497] allow user to extend the search configuration (#2204)
* * support search extension * * unit test added * * fix lints * Update application-features.md
This commit is contained in:
@@ -873,4 +873,59 @@ describe('AppExtensionService', () => {
|
||||
expect(actions.children[1].id).toBe('header.action.1');
|
||||
});
|
||||
});
|
||||
|
||||
describe('search', () => {
|
||||
beforeEach(() => {
|
||||
applyConfig({
|
||||
$id: 'test',
|
||||
$name: 'test',
|
||||
$version: '1.0.0',
|
||||
$license: 'MIT',
|
||||
$vendor: 'Good company',
|
||||
$runtime: '1.5.0',
|
||||
features: {
|
||||
search: [
|
||||
{
|
||||
id: 'app.search',
|
||||
order: 100,
|
||||
name: 'default',
|
||||
default: true,
|
||||
filterWithContains: true,
|
||||
'aca:fields': ['cm:name', 'cm:title', 'cm:description', 'TEXT', 'TAG'],
|
||||
include: ['path', 'allowableOperations', 'properties'],
|
||||
categories: [
|
||||
{
|
||||
id: 'size',
|
||||
name: 'SEARCH.CATEGORIES.SIZE',
|
||||
enabled: true
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
id: 'app.search-1',
|
||||
order: 200,
|
||||
name: 'default',
|
||||
default: false
|
||||
},
|
||||
{
|
||||
id: 'app.search-2',
|
||||
order: 200,
|
||||
name: 'default',
|
||||
disabled: true
|
||||
}
|
||||
]
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('should load the search extension', () => {
|
||||
expect(service.search.length).toBe(2);
|
||||
expect(service.search[0].id).toBe('app.search');
|
||||
expect(service.search[1].id).toBe('app.search-1');
|
||||
});
|
||||
|
||||
it('should not load the disabled search extension', () => {
|
||||
expect(service.search.find(({ id }) => id === 'app.search-2')).toBe(undefined, 'disabled configuration shown in the result');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -47,7 +47,8 @@ import {
|
||||
ExtensionRef,
|
||||
RuleContext,
|
||||
DocumentListPresetRef,
|
||||
IconRef
|
||||
IconRef,
|
||||
mergeArrays
|
||||
} from '@alfresco/adf-extensions';
|
||||
import { AppConfigService, AuthenticationService, LogService } from '@alfresco/adf-core';
|
||||
import { BehaviorSubject, Observable } from 'rxjs';
|
||||
@@ -73,6 +74,7 @@ export class AppExtensionService implements RuleContext {
|
||||
sidebarTabs: Array<SidebarTabRef> = [];
|
||||
sidebarActions: Array<ContentActionRef> = [];
|
||||
contentMetadata: any;
|
||||
search: any;
|
||||
viewerRules: ViewerRules = {};
|
||||
settingGroups: Array<SettingsGroupRef> = [];
|
||||
|
||||
@@ -150,6 +152,7 @@ export class AppExtensionService implements RuleContext {
|
||||
this.navbar = this.loadNavBar(config);
|
||||
this.sidebarTabs = this.loader.getElements<SidebarTabRef>(config, 'features.sidebar.tabs');
|
||||
this.contentMetadata = this.loadContentMetadata(config);
|
||||
this.search = this.loadSearchForms(config);
|
||||
|
||||
this.documentListPresets = {
|
||||
files: this.getDocumentListPreset(config, 'files'),
|
||||
@@ -286,6 +289,25 @@ export class AppExtensionService implements RuleContext {
|
||||
return { presets };
|
||||
}
|
||||
|
||||
loadSearchForms(config: ExtensionConfig): any {
|
||||
const elements = this.loader.getElements<any>(config, 'features.search');
|
||||
if (!elements.length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
let search = [];
|
||||
search = mergeArrays(search, elements)
|
||||
.filter((entry) => !entry.disabled)
|
||||
.sort(sortByOrder);
|
||||
|
||||
try {
|
||||
this.appConfig.config['search'] = search;
|
||||
} catch (error) {
|
||||
this.logger.error(error, '- could not change search from app.config -');
|
||||
}
|
||||
return search;
|
||||
}
|
||||
|
||||
filterDisabled(object: Array<{ disabled: boolean }> | { disabled: boolean }) {
|
||||
if (Array.isArray(object)) {
|
||||
return object.filter((item) => !item.disabled).map((item) => this.filterDisabled(item));
|
||||
|
Reference in New Issue
Block a user