From 98598f03b2a212f9ac9b8fab11f8e470a036c15d Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Fri, 30 Jun 2017 22:20:12 +0100 Subject: [PATCH] AOT compatibility enhancements (#2015) * aot compatibility updates - remove index files where needed - move material dependencies to a separete module - use aot compatible lambda functions for module export * remove unused imports * re-export Material module * core module enhancements - fix AOT issue with providers (use lambda instead of variable) - move context menu to a separate module * core module enhancements * feature modules --- ng2-components/ng2-alfresco-core/index.ts | 45 ++++++++++--------- .../collapsable/collapsable.module.ts} | 22 ++++++++- .../{index.ts => context-menu.module.ts} | 34 ++++++++------ .../ng2-alfresco-core/src/components/index.ts | 21 --------- .../src/components/material/index.ts | 33 -------------- .../view/adf-card-view.component.ts | 16 +------ .../view/{index.ts => card-view.module.ts} | 17 +++++-- .../ng2-alfresco-core/src/material.module.ts | 16 ++++--- .../ng2-alfresco-datatable/index.ts | 44 +++++++++--------- .../datatable/datatable-cell.component.ts | 2 +- .../datatable/datatable.component.ts | 10 +++-- .../src/components/index.ts | 19 -------- .../src/components/pagination/index.ts | 18 -------- .../ng2-alfresco-datatable/src/data/index.ts | 4 +- .../src/directives/index.ts | 19 -------- .../src/material.module.ts} | 22 ++++++--- 16 files changed, 135 insertions(+), 207 deletions(-) rename ng2-components/{ng2-alfresco-datatable/src/components/datatable/index.ts => ng2-alfresco-core/src/components/collapsable/collapsable.module.ts} (56%) rename ng2-components/ng2-alfresco-core/src/components/context-menu/{index.ts => context-menu.module.ts} (66%) delete mode 100644 ng2-components/ng2-alfresco-core/src/components/index.ts delete mode 100644 ng2-components/ng2-alfresco-core/src/components/material/index.ts rename ng2-components/ng2-alfresco-core/src/components/view/{index.ts => card-view.module.ts} (72%) delete mode 100644 ng2-components/ng2-alfresco-datatable/src/components/index.ts delete mode 100644 ng2-components/ng2-alfresco-datatable/src/components/pagination/index.ts delete mode 100644 ng2-components/ng2-alfresco-datatable/src/directives/index.ts rename ng2-components/{ng2-alfresco-core/src/components/collapsable/index.ts => ng2-alfresco-datatable/src/material.module.ts} (62%) diff --git a/ng2-components/ng2-alfresco-core/index.ts b/ng2-components/ng2-alfresco-core/index.ts index ca539dcc3f..619718fc31 100644 --- a/ng2-components/ng2-alfresco-core/index.ts +++ b/ng2-components/ng2-alfresco-core/index.ts @@ -21,9 +21,13 @@ import { HttpModule, Http } from '@angular/http'; import { CommonModule } from '@angular/common'; import { FormsModule, ReactiveFormsModule } from '@angular/forms'; import { TranslateModule, TranslateLoader } from '@ngx-translate/core'; + import { MaterialModule } from './src/material.module'; -import { AppConfigModule } from './src/services/app-config.service'; +import { ContextMenuModule } from './src/components/context-menu/context-menu.module'; +import { CardViewModule } from './src/components/view/card-view.module'; +import { CollapsableModule } from './src/components/collapsable/collapsable.module'; import { AdfToolbarComponent } from './src/components/toolbar/toolbar.component'; +import { AppConfigModule } from './src/services/app-config.service'; import { AlfrescoAuthenticationService, @@ -49,17 +53,18 @@ import { FileSizePipe } from './src/pipes/file-size.pipe'; import { UploadDirective } from './src/directives/upload.directive'; import { DataColumnComponent } from './src/components/data-column/data-column.component'; import { DataColumnListComponent } from './src/components/data-column/data-column-list.component'; -import { MATERIAL_DESIGN_DIRECTIVES } from './src/components/material/index'; -import { CONTEXT_MENU_PROVIDERS, CONTEXT_MENU_DIRECTIVES } from './src/components/context-menu/index'; -import { COLLAPSABLE_DIRECTIVES } from './src/components/collapsable/index'; -import { VIEW_DIRECTIVES } from './src/components/view/index'; +import { MDL } from './src/components/material/mdl-upgrade-element.directive'; +import { AlfrescoMdlButtonDirective } from './src/components/material/mdl-button.directive'; +import { AlfrescoMdlMenuDirective } from './src/components/material/mdl-menu.directive'; +import { AlfrescoMdlTextFieldDirective } from './src/components/material/mdl-textfield.directive'; + +export { ContextMenuModule } from './src/components/context-menu/context-menu.module'; +export { CardViewModule } from './src/components/view/card-view.module'; +export { CollapsableModule } from './src/components/collapsable/collapsable.module'; export * from './src/services/index'; -export * from './src/components/index'; export * from './src/components/data-column/data-column.component'; export * from './src/components/data-column/data-column-list.component'; -export * from './src/components/collapsable/index'; -export * from './src/components/view/index'; export * from './src/directives/upload.directive'; export * from './src/utils/index'; export * from './src/events/base.event'; @@ -108,22 +113,20 @@ export function createTranslateLoader(http: Http, logService: LogService) { } }), MaterialModule, - AppConfigModule + AppConfigModule, + ContextMenuModule, + CardViewModule, + CollapsableModule ], declarations: [ - ...MATERIAL_DESIGN_DIRECTIVES, - ...CONTEXT_MENU_DIRECTIVES, - ...COLLAPSABLE_DIRECTIVES, - ...VIEW_DIRECTIVES, + ...obsoleteMdlDirectives(), UploadDirective, DataColumnComponent, DataColumnListComponent, FileSizePipe, AdfToolbarComponent ], - providers: [ - ...ALFRESCO_CORE_PROVIDERS - ], + providers: providers(), exports: [ BrowserAnimationsModule, CommonModule, @@ -132,10 +135,10 @@ export function createTranslateLoader(http: Http, logService: LogService) { HttpModule, TranslateModule, MaterialModule, - ...MATERIAL_DESIGN_DIRECTIVES, - ...CONTEXT_MENU_DIRECTIVES, - ...COLLAPSABLE_DIRECTIVES, - ...VIEW_DIRECTIVES, + ContextMenuModule, + CardViewModule, + CollapsableModule, + ...obsoleteMdlDirectives(), UploadDirective, DataColumnComponent, DataColumnListComponent, @@ -151,7 +154,7 @@ export class CoreModule { return { ngModule: CoreModule, providers: [ - ...ALFRESCO_CORE_PROVIDERS, + ...providers(), AppConfigService, InitAppConfigServiceProvider(appConfigFile) ] diff --git a/ng2-components/ng2-alfresco-datatable/src/components/datatable/index.ts b/ng2-components/ng2-alfresco-core/src/components/collapsable/collapsable.module.ts similarity index 56% rename from ng2-components/ng2-alfresco-datatable/src/components/datatable/index.ts rename to ng2-components/ng2-alfresco-core/src/components/collapsable/collapsable.module.ts index 4ff4ce73c5..6f864d114a 100644 --- a/ng2-components/ng2-alfresco-datatable/src/components/datatable/index.ts +++ b/ng2-components/ng2-alfresco-core/src/components/collapsable/collapsable.module.ts @@ -15,5 +15,23 @@ * limitations under the License. */ -export * from './datatable.component'; -export * from './datatable-cell.component'; +import { NgModule } from '@angular/core'; +import { CommonModule } from '@angular/common'; + +import { AccordionComponent } from './accordion.component'; +import { AccordionGroupComponent } from './accordion-group.component'; + +@NgModule({ + imports: [ + CommonModule + ], + declarations: [ + AccordionComponent, + AccordionGroupComponent + ], + exports: [ + AccordionComponent, + AccordionGroupComponent + ] +}) +export class CollapsableModule {} diff --git a/ng2-components/ng2-alfresco-core/src/components/context-menu/index.ts b/ng2-components/ng2-alfresco-core/src/components/context-menu/context-menu.module.ts similarity index 66% rename from ng2-components/ng2-alfresco-core/src/components/context-menu/index.ts rename to ng2-components/ng2-alfresco-core/src/components/context-menu/context-menu.module.ts index a6b21baf9d..7e8a3dc6b0 100644 --- a/ng2-components/ng2-alfresco-core/src/components/context-menu/index.ts +++ b/ng2-components/ng2-alfresco-core/src/components/context-menu/context-menu.module.ts @@ -15,19 +15,27 @@ * limitations under the License. */ -import { ContextMenuService } from './context-menu.service'; +import { NgModule } from '@angular/core'; +import { CommonModule } from '@angular/common'; + import { ContextMenuHolderComponent } from './context-menu-holder.component'; import { ContextMenuDirective } from './context-menu.directive'; +import { ContextMenuService } from './context-menu.service'; -export * from './context-menu.service'; -export * from './context-menu-holder.component'; -export * from './context-menu.directive'; - -export const CONTEXT_MENU_PROVIDERS: [any] = [ - ContextMenuService -]; - -export const CONTEXT_MENU_DIRECTIVES: [any] = [ - ContextMenuHolderComponent, - ContextMenuDirective -]; +@NgModule({ + imports: [ + CommonModule + ], + declarations: [ + ContextMenuHolderComponent, + ContextMenuDirective + ], + exports: [ + ContextMenuHolderComponent, + ContextMenuDirective + ], + providers: [ + ContextMenuService + ] +}) +export class ContextMenuModule {} diff --git a/ng2-components/ng2-alfresco-core/src/components/index.ts b/ng2-components/ng2-alfresco-core/src/components/index.ts deleted file mode 100644 index f8b5c98d0d..0000000000 --- a/ng2-components/ng2-alfresco-core/src/components/index.ts +++ /dev/null @@ -1,21 +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. - */ - -export * from './context-menu/index'; -export * from './material/index'; -export * from './collapsable/index'; -export * from './view/index'; diff --git a/ng2-components/ng2-alfresco-core/src/components/material/index.ts b/ng2-components/ng2-alfresco-core/src/components/material/index.ts deleted file mode 100644 index 84b01337d1..0000000000 --- a/ng2-components/ng2-alfresco-core/src/components/material/index.ts +++ /dev/null @@ -1,33 +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 { MDL } from './mdl-upgrade-element.directive'; -import { AlfrescoMdlButtonDirective } from './mdl-button.directive'; -import { AlfrescoMdlMenuDirective } from './mdl-menu.directive'; -import { AlfrescoMdlTextFieldDirective } from './mdl-textfield.directive'; - -export * from './mdl-upgrade-element.directive'; -export * from './mdl-button.directive'; -export * from './mdl-menu.directive'; -export * from './mdl-textfield.directive'; - -export const MATERIAL_DESIGN_DIRECTIVES: [any] = [ - MDL, - AlfrescoMdlButtonDirective, - AlfrescoMdlMenuDirective, - AlfrescoMdlTextFieldDirective -]; diff --git a/ng2-components/ng2-alfresco-core/src/components/view/adf-card-view.component.ts b/ng2-components/ng2-alfresco-core/src/components/view/adf-card-view.component.ts index e02c5bd6d0..fe29a7c9ed 100644 --- a/ng2-components/ng2-alfresco-core/src/components/view/adf-card-view.component.ts +++ b/ng2-components/ng2-alfresco-core/src/components/view/adf-card-view.component.ts @@ -15,11 +15,7 @@ * limitations under the License. */ -import { - Component, - Input, - OnInit -} from '@angular/core'; +import { Component, Input } from '@angular/core'; import { CardViewModel } from '../../models/card-view.model'; import * as moment from 'moment'; @@ -28,19 +24,11 @@ import * as moment from 'moment'; templateUrl: './adf-card-view.component.html', styleUrls: ['./adf-card-view.component.css'] }) -export class CardView implements OnInit { +export class CardView { @Input() properties: CardViewModel []; - constructor() { - - } - - ngOnInit() { - - } - getPropertyValue(property: CardViewModel): string { if (!property.value) { return property.default; diff --git a/ng2-components/ng2-alfresco-core/src/components/view/index.ts b/ng2-components/ng2-alfresco-core/src/components/view/card-view.module.ts similarity index 72% rename from ng2-components/ng2-alfresco-core/src/components/view/index.ts rename to ng2-components/ng2-alfresco-core/src/components/view/card-view.module.ts index 3f198d8b0e..791ae0fd90 100644 --- a/ng2-components/ng2-alfresco-core/src/components/view/index.ts +++ b/ng2-components/ng2-alfresco-core/src/components/view/card-view.module.ts @@ -15,8 +15,19 @@ * limitations under the License. */ +import { NgModule } from '@angular/core'; +import { CommonModule } from '@angular/common'; import { CardView } from './adf-card-view.component'; -export const VIEW_DIRECTIVES: [any] = [ - CardView -]; +@NgModule({ + imports: [ + CommonModule + ], + declarations: [ + CardView + ], + exports: [ + CardView + ] +}) +export class CardViewModule {} diff --git a/ng2-components/ng2-alfresco-core/src/material.module.ts b/ng2-components/ng2-alfresco-core/src/material.module.ts index af4caf1cf4..46a3addd93 100644 --- a/ng2-components/ng2-alfresco-core/src/material.module.ts +++ b/ng2-components/ng2-alfresco-core/src/material.module.ts @@ -18,14 +18,16 @@ import { NgModule } from '@angular/core'; import { MdSnackBarModule, MdToolbarModule, MdButtonModule } from '@angular/material'; -const MATERIAL_MODULES = [ - MdSnackBarModule, - MdToolbarModule, - MdButtonModule -]; +export function modules() { + return [ + MdSnackBarModule, + MdToolbarModule, + MdButtonModule + ]; +} @NgModule({ - imports: MATERIAL_MODULES, - exports: MATERIAL_MODULES + imports: modules(), + exports: modules() }) export class MaterialModule {} diff --git a/ng2-components/ng2-alfresco-datatable/index.ts b/ng2-components/ng2-alfresco-datatable/index.ts index bba922f795..4afb42c5b6 100644 --- a/ng2-components/ng2-alfresco-datatable/index.ts +++ b/ng2-components/ng2-alfresco-datatable/index.ts @@ -16,14 +16,16 @@ */ import { NgModule, ModuleWithProviders } from '@angular/core'; -import { MdCheckboxModule, MdMenuModule, MdIconModule, MdButtonModule } from '@angular/material'; import { CoreModule } from 'ng2-alfresco-core'; +import { MaterialModule } from './src/material.module'; export * from './src/data/index'; -export * from './src/components/index'; -export * from './src/components/pagination/index'; -export * from './src/components/datatable/data-cell.event'; -export * from './src/components/datatable/data-row-action.event'; + +export { DataTableCellComponent } from './src/components/datatable/datatable-cell.component'; +export { DataTableComponent } from './src/components/datatable/datatable.component'; +export { PaginationComponent } from './src/components/pagination/pagination.component'; +export { DataCellEvent, DataCellEventModel } from './src/components/datatable/data-cell.event'; +export { DataRowActionEvent, DataRowActionModel } from './src/components/datatable/data-row-action.event'; import { DataTableComponent } from './src/components/datatable/datatable.component'; import { NoContentTemplateComponent } from './src/directives/no-content-template.component'; @@ -31,31 +33,25 @@ import { LoadingContentTemplateComponent } from './src/directives/loading-templa import { PaginationComponent } from './src/components/pagination/pagination.component'; import { DataTableCellComponent } from './src/components/datatable/datatable-cell.component'; -export const ALFRESCO_DATATABLE_DIRECTIVES: [any] = [ - DataTableComponent, - DataTableCellComponent, - NoContentTemplateComponent, - LoadingContentTemplateComponent, - PaginationComponent -]; +export function directives() { + return [ + DataTableComponent, + DataTableCellComponent, + NoContentTemplateComponent, + LoadingContentTemplateComponent, + PaginationComponent + ]; +} @NgModule({ imports: [ CoreModule, - MdCheckboxModule, - MdMenuModule, - MdIconModule, - MdButtonModule - ], - declarations: [ - ...ALFRESCO_DATATABLE_DIRECTIVES + MaterialModule ], + declarations: directives(), exports: [ - ...ALFRESCO_DATATABLE_DIRECTIVES, - MdCheckboxModule, - MdMenuModule, - MdIconModule, - MdButtonModule + ...directives(), + MaterialModule ] }) export class DataTableModule { diff --git a/ng2-components/ng2-alfresco-datatable/src/components/datatable/datatable-cell.component.ts b/ng2-components/ng2-alfresco-datatable/src/components/datatable/datatable-cell.component.ts index d03020274c..eb5b892042 100644 --- a/ng2-components/ng2-alfresco-datatable/src/components/datatable/datatable-cell.component.ts +++ b/ng2-components/ng2-alfresco-datatable/src/components/datatable/datatable-cell.component.ts @@ -16,7 +16,7 @@ */ import { Component, Input, ChangeDetectionStrategy } from '@angular/core'; -import { DataTableAdapter, DataColumn, DataRow } from '../../data/index'; +import { DataTableAdapter, DataColumn, DataRow } from '../../data/datatable-adapter'; @Component({ selector: 'alfresco-datatable-cell', diff --git a/ng2-components/ng2-alfresco-datatable/src/components/datatable/datatable.component.ts b/ng2-components/ng2-alfresco-datatable/src/components/datatable/datatable.component.ts index cfe3d39ddd..9512daeb4b 100644 --- a/ng2-components/ng2-alfresco-datatable/src/components/datatable/datatable.component.ts +++ b/ng2-components/ng2-alfresco-datatable/src/components/datatable/datatable.component.ts @@ -16,12 +16,14 @@ */ import { Component, OnChanges, SimpleChange, SimpleChanges, Input, Output, EventEmitter, ElementRef, TemplateRef, AfterContentInit, ContentChild, Optional } from '@angular/core'; -import { DataTableAdapter, DataRow, DataColumn, DataSorting, DataRowEvent, ObjectDataTableAdapter, ObjectDataRow } from '../../data/index'; -import { DataCellEvent } from './data-cell.event'; -import { DataRowActionEvent } from './data-row-action.event'; -import { DataColumnListComponent } from 'ng2-alfresco-core'; import { MdCheckboxChange } from '@angular/material'; import { Observable, Observer } from 'rxjs/Rx'; +import { DataColumnListComponent } from 'ng2-alfresco-core'; + +import { DataTableAdapter, DataRow, DataColumn, DataSorting, DataRowEvent } from '../../data/datatable-adapter'; +import { ObjectDataTableAdapter, ObjectDataRow } from '../../data/object-datatable-adapter'; +import { DataCellEvent } from './data-cell.event'; +import { DataRowActionEvent } from './data-row-action.event'; declare var componentHandler; diff --git a/ng2-components/ng2-alfresco-datatable/src/components/index.ts b/ng2-components/ng2-alfresco-datatable/src/components/index.ts deleted file mode 100644 index 6139cb70a5..0000000000 --- a/ng2-components/ng2-alfresco-datatable/src/components/index.ts +++ /dev/null @@ -1,19 +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. - */ - -export * from './datatable/index'; -export * from './pagination/index'; diff --git a/ng2-components/ng2-alfresco-datatable/src/components/pagination/index.ts b/ng2-components/ng2-alfresco-datatable/src/components/pagination/index.ts deleted file mode 100644 index 4f9699a18c..0000000000 --- a/ng2-components/ng2-alfresco-datatable/src/components/pagination/index.ts +++ /dev/null @@ -1,18 +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. - */ - -export * from './pagination.component'; diff --git a/ng2-components/ng2-alfresco-datatable/src/data/index.ts b/ng2-components/ng2-alfresco-datatable/src/data/index.ts index 47d38e2aa2..8cb961eb76 100644 --- a/ng2-components/ng2-alfresco-datatable/src/data/index.ts +++ b/ng2-components/ng2-alfresco-datatable/src/data/index.ts @@ -15,5 +15,5 @@ * limitations under the License. */ -export * from './datatable-adapter'; -export * from './object-datatable-adapter'; +export { DataColumn, DataRow, DataRowEvent, DataSorting, DataTableAdapter } from './datatable-adapter'; +export { ObjectDataColumn, ObjectDataRow, ObjectDataTableAdapter } from './object-datatable-adapter'; diff --git a/ng2-components/ng2-alfresco-datatable/src/directives/index.ts b/ng2-components/ng2-alfresco-datatable/src/directives/index.ts deleted file mode 100644 index d6cee74613..0000000000 --- a/ng2-components/ng2-alfresco-datatable/src/directives/index.ts +++ /dev/null @@ -1,19 +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. - */ - -export * from './no-content-template.component'; -export * from './loading-template.component'; diff --git a/ng2-components/ng2-alfresco-core/src/components/collapsable/index.ts b/ng2-components/ng2-alfresco-datatable/src/material.module.ts similarity index 62% rename from ng2-components/ng2-alfresco-core/src/components/collapsable/index.ts rename to ng2-components/ng2-alfresco-datatable/src/material.module.ts index 90ded41f70..b4c2f06dbc 100644 --- a/ng2-components/ng2-alfresco-core/src/components/collapsable/index.ts +++ b/ng2-components/ng2-alfresco-datatable/src/material.module.ts @@ -15,10 +15,20 @@ * limitations under the License. */ -import {AccordionComponent} from './accordion.component'; -import {AccordionGroupComponent} from './accordion-group.component'; +import { NgModule } from '@angular/core'; +import { MdCheckboxModule, MdMenuModule, MdIconModule, MdButtonModule } from '@angular/material'; -export const COLLAPSABLE_DIRECTIVES: [any] = [ - AccordionComponent, - AccordionGroupComponent -]; +export function modules() { + return [ + MdCheckboxModule, + MdMenuModule, + MdIconModule, + MdButtonModule + ]; +} + +@NgModule({ + imports: modules(), + exports: modules() +}) +export class MaterialModule {}