[ADF-2786] AOT support for search filter widgets (#3224)

* AOT support for search filter widgets

* json schema for search settings
This commit is contained in:
Denys Vuika 2018-04-24 14:28:24 +01:00 committed by Eugenio Romano
parent 40b4fc7d66
commit b580efb7f6
8 changed files with 164 additions and 83 deletions

View File

@ -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": [

View File

@ -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,

View File

@ -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
];
}

View File

@ -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
};
}

View File

@ -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<SearchWidgetsModule>;
private componentRef: ComponentRef<any>;
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);
}
}
}

View File

@ -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 {
}

View File

@ -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 {}

View File

@ -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" }
}
}
}
}
}
}
}
}
}
}
}