[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

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