From b580efb7f61e06d366d02f8f87804fd5dfbc4853 Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Tue, 24 Apr 2018 14:28:24 +0100 Subject: [PATCH] [ADF-2786] AOT support for search filter widgets (#3224) * AOT support for search filter widgets * json schema for search settings --- demo-shell/src/app.config.json | 14 ++-- lib/content-services/content.module.ts | 4 +- lib/content-services/material.module.ts | 6 +- .../search-filter/search-filter.service.ts | 37 +++++++++ .../search-widget-container.component.ts | 24 +++--- .../search-widgets.module.ts | 58 ------------- lib/content-services/search/search.module.ts | 22 ++++- lib/core/app-config/schema.json | 82 +++++++++++++++++++ 8 files changed, 164 insertions(+), 83 deletions(-) create mode 100644 lib/content-services/search/components/search-filter/search-filter.service.ts delete mode 100644 lib/content-services/search/components/search-widget-container/search-widgets.module.ts diff --git a/demo-shell/src/app.config.json b/demo-shell/src/app.config.json index 18b2181d1a..490fe38e22 100644 --- a/demo-shell/src/app.config.json +++ b/demo-shell/src/app.config.json @@ -53,10 +53,6 @@ } ], "search": { - "limits": { - "permissionEvaluationTime": null, - "permissionEvaluationCount": null - }, "filterQueries": [ { "query": "TYPE:'cm:folder' OR TYPE:'cm:content'" }, { "query": "NOT cm:creator:System" } @@ -87,7 +83,7 @@ "enabled": false, "expanded": false, "component": { - "selector": "adf-search-text", + "selector": "text", "settings": { "field": "fieldname" } @@ -99,7 +95,7 @@ "enabled": true, "expanded": true, "component": { - "selector": "adf-search-text", + "selector": "text", "settings": { "pattern": "cm:name:'(.*?)'", "field": "cm:name", @@ -113,7 +109,7 @@ "enabled": true, "expanded": false, "component": { - "selector": "adf-search-fields", + "selector": "fields", "settings": { "field": null, "options": [ @@ -131,7 +127,7 @@ "enabled": true, "expanded": false, "component": { - "selector": "adf-search-radio", + "selector": "radio", "settings": { "field": null, "options": [ @@ -149,7 +145,7 @@ "enabled": true, "expanded": false, "component": { - "selector": "adf-search-scope-locations", + "selector": "scope-locations", "settings": { "field": null, "options": [ diff --git a/lib/content-services/content.module.ts b/lib/content-services/content.module.ts index ade530330d..6dd253dd5d 100644 --- a/lib/content-services/content.module.ts +++ b/lib/content-services/content.module.ts @@ -44,6 +44,7 @@ import { ContentMetadataConfigFactory } from './content-metadata/services/config import { BasicPropertiesService } from './content-metadata/services/basic-properties.service'; import { PropertyGroupTranslatorService } from './content-metadata/services/property-groups-translator.service'; import { SearchQueryBuilderService } from './search/search-query-builder.service'; +import { SearchFilterService } from './search/components/search-filter/search-filter.service'; @NgModule({ imports: [ @@ -83,7 +84,8 @@ import { SearchQueryBuilderService } from './search/search-query-builder.service ContentMetadataConfigFactory, BasicPropertiesService, PropertyGroupTranslatorService, - SearchQueryBuilderService + SearchQueryBuilderService, + SearchFilterService ], exports: [ CoreModule, diff --git a/lib/content-services/material.module.ts b/lib/content-services/material.module.ts index c2e576f45c..272db886c1 100644 --- a/lib/content-services/material.module.ts +++ b/lib/content-services/material.module.ts @@ -33,7 +33,8 @@ import { MatSelectModule, MatCheckboxModule, MatDatepickerModule, - MatSlideToggleModule + MatSlideToggleModule, + MatRadioModule } from '@angular/material'; export function modules() { @@ -54,7 +55,8 @@ export function modules() { MatSelectModule, MatCheckboxModule, MatDatepickerModule, - MatSlideToggleModule + MatSlideToggleModule, + MatRadioModule ]; } diff --git a/lib/content-services/search/components/search-filter/search-filter.service.ts b/lib/content-services/search/components/search-filter/search-filter.service.ts new file mode 100644 index 0000000000..d56c31b104 --- /dev/null +++ b/lib/content-services/search/components/search-filter/search-filter.service.ts @@ -0,0 +1,37 @@ +/*! + * @license + * Copyright 2016 Alfresco Software, Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { Injectable, Type } from '@angular/core'; +import { SearchTextComponent } from '../search-text/search-text.component'; +import { SearchRadioComponent } from '../search-radio/search-radio.component'; +import { SearchFieldsComponent } from '../search-fields/search-fields.component'; +import { SearchScopeLocationsComponent } from '../search-scope-locations/search-scope-locations.component'; + +@Injectable() +export class SearchFilterService { + + /** + * Contains string-to-type mappings for registered widgets. + */ + widgets: { [id: string]: Type<{}> } = { + 'text': SearchTextComponent, + 'radio': SearchRadioComponent, + 'fields': SearchFieldsComponent, + 'scope-locations': SearchScopeLocationsComponent + }; + +} diff --git a/lib/content-services/search/components/search-widget-container/search-widget-container.component.ts b/lib/content-services/search/components/search-widget-container/search-widget-container.component.ts index b337fe9783..e7cbd37596 100644 --- a/lib/content-services/search/components/search-widget-container/search-widget-container.component.ts +++ b/lib/content-services/search/components/search-widget-container/search-widget-container.component.ts @@ -15,9 +15,9 @@ * limitations under the License. */ -import { Component, Input, ViewChild, ViewContainerRef, OnInit, OnDestroy, Compiler, ModuleWithComponentFactories, ComponentRef } from '@angular/core'; -import { SearchWidgetsModule } from './search-widgets.module'; +import { Component, Input, ViewChild, ViewContainerRef, OnInit, OnDestroy, ComponentRef, ComponentFactoryResolver } from '@angular/core'; import { SearchQueryBuilderService } from '../../search-query-builder.service'; +import { SearchFilterService } from '../search-filter/search-filter.service'; @Component({ selector: 'adf-search-widget-container', @@ -40,19 +40,23 @@ export class SearchWidgetContainerComponent implements OnInit, OnDestroy { @Input() config: any; - private module: ModuleWithComponentFactories; private componentRef: ComponentRef; - constructor(compiler: Compiler, private queryBuilder: SearchQueryBuilderService) { - this.module = compiler.compileModuleAndAllComponentsSync(SearchWidgetsModule); + constructor( + private searchFilterService: SearchFilterService, + private queryBuilder: SearchQueryBuilderService, + private componentFactoryResolver: ComponentFactoryResolver) { } ngOnInit() { - const factory = this.module.componentFactories.find(f => f.selector === this.selector); - if (factory) { - this.content.clear(); - this.componentRef = this.content.createComponent(factory, 0); - this.setupWidget(this.componentRef); + const componentType = this.searchFilterService.widgets[this.selector]; + if (componentType) { + const factory = this.componentFactoryResolver.resolveComponentFactory(componentType); + if (factory) { + this.content.clear(); + this.componentRef = this.content.createComponent(factory, 0); + this.setupWidget(this.componentRef); + } } } diff --git a/lib/content-services/search/components/search-widget-container/search-widgets.module.ts b/lib/content-services/search/components/search-widget-container/search-widgets.module.ts deleted file mode 100644 index c7d322442d..0000000000 --- a/lib/content-services/search/components/search-widget-container/search-widgets.module.ts +++ /dev/null @@ -1,58 +0,0 @@ -/*! - * @license - * Copyright 2016 Alfresco Software, Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { NgModule } from '@angular/core'; -import { MatButtonModule, MatInputModule, MatRadioModule, MatCheckboxModule, MatSelectModule } from '@angular/material'; -import { FormsModule, ReactiveFormsModule } from '@angular/forms'; -import { CommonModule } from '@angular/common'; -import { SearchTextComponent } from '../search-text/search-text.component'; -import { SearchRadioComponent } from '../search-radio/search-radio.component'; -import { SearchFieldsComponent } from '../search-fields/search-fields.component'; -import { SearchScopeLocationsComponent } from '../search-scope-locations/search-scope-locations.component'; - -@NgModule({ - imports: [ - CommonModule, - FormsModule, - ReactiveFormsModule, - MatButtonModule, - MatInputModule, - MatRadioModule, - MatCheckboxModule, - MatSelectModule - ], - declarations: [ - SearchTextComponent, - SearchRadioComponent, - SearchFieldsComponent, - SearchScopeLocationsComponent - ], - exports: [ - SearchTextComponent, - SearchRadioComponent, - SearchFieldsComponent, - SearchScopeLocationsComponent - ], - entryComponents: [ - SearchTextComponent, - SearchRadioComponent, - SearchFieldsComponent, - SearchScopeLocationsComponent - ] -}) -export class SearchWidgetsModule { -} diff --git a/lib/content-services/search/search.module.ts b/lib/content-services/search/search.module.ts index a120a55157..8e0d3d846a 100644 --- a/lib/content-services/search/search.module.ts +++ b/lib/content-services/search/search.module.ts @@ -31,6 +31,10 @@ import { EmptySearchResultComponent } from './components/empty-search-result.com import { SearchWidgetContainerComponent } from './components/search-widget-container/search-widget-container.component'; import { SearchFilterComponent } from './components/search-filter/search-filter.component'; import { SearchChipListComponent } from './components/search-chip-list/search-chip-list.component'; +import { SearchTextComponent } from './components/search-text/search-text.component'; +import { SearchRadioComponent } from './components/search-radio/search-radio.component'; +import { SearchFieldsComponent } from './components/search-fields/search-fields.component'; +import { SearchScopeLocationsComponent } from './components/search-scope-locations/search-scope-locations.component'; export const ALFRESCO_SEARCH_DIRECTIVES: any[] = [ SearchComponent, @@ -52,14 +56,26 @@ export const ALFRESCO_SEARCH_DIRECTIVES: any[] = [ ], declarations: [ ...ALFRESCO_SEARCH_DIRECTIVES, - SearchWidgetContainerComponent + SearchWidgetContainerComponent, + SearchTextComponent, + SearchRadioComponent, + SearchFieldsComponent, + SearchScopeLocationsComponent ], exports: [ ...ALFRESCO_SEARCH_DIRECTIVES, - SearchWidgetContainerComponent + SearchWidgetContainerComponent, + SearchTextComponent, + SearchRadioComponent, + SearchFieldsComponent, + SearchScopeLocationsComponent ], entryComponents: [ - SearchWidgetContainerComponent + SearchWidgetContainerComponent, + SearchTextComponent, + SearchRadioComponent, + SearchFieldsComponent, + SearchScopeLocationsComponent ] }) export class SearchModule {} diff --git a/lib/core/app-config/schema.json b/lib/core/app-config/schema.json index 39c0383025..48956b2cdb 100644 --- a/lib/core/app-config/schema.json +++ b/lib/core/app-config/schema.json @@ -476,6 +476,88 @@ "allowComments": { "type": "boolean" }, "allowDownload": { "type": "boolean" } } + }, + "search": { + "description": "Search configuration parameters", + "type": "object", + "properties": { + "limits": { + "description": "The limits element limits the time and resources used for query execution. Limits applied to the query go to the database.", + "type": "object", + "properties": { + "permissionEvaluationTime": { "type": "integer" }, + "permissionEvaluationCount": { "type": "integer" } + } + }, + "filterQueries": { + "type": "array", + "items": { + "type": "object", + "required": [ "query" ], + "properties": { + "query": { "type": "string" } + } + } + }, + "facetFields": { + "type": "object", + "required": [ "facets" ], + "properties": { + "facets": { + "type": "array", + "items": { + "type": "object", + "required": [ "field", "mincount", "label" ], + "properties": { + "field": { "type": "string" }, + "mincount": { "type": "integer" }, + "label": { "type": "string" } + } + } + } + } + }, + "facetQueries": { + "type": "array", + "items": { + "type": "object", + "required": [ "query", "label" ], + "properties": { + "query": { "type": "string" }, + "label": { "type": "string" } + } + } + }, + "query": { + "type": "object", + "required": [ "categories" ], + "properties": { + "categories": { + "type": "array", + "minItems": 1, + "items": { + "type": "object", + "required": [ "id", "name" ], + "properties": { + "id": { "type": "string" }, + "name": { "type": "string" }, + "enabled": { "type": "boolean" }, + "expanded": { "type": "boolean" }, + "component": { + "type": "object", + "required": [ "selector", "settings" ], + "properties": { + "selector": { "type": "string" }, + "settings": { "type": "object" } + } + } + } + } + } + } + } + } + } } }