119 lines
4.2 KiB
TypeScript
119 lines
4.2 KiB
TypeScript
import { ModuleWithProviders, NgModule, Optional, SkipSelf } from '@angular/core';
|
|
import { CommonModule } from '@angular/common';
|
|
import { MatIconModule } from '@angular/material/icon';
|
|
import { TranslateModule } from '@ngx-translate/core';
|
|
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
|
|
import { SortByPipe } from './sorting';
|
|
import { CommonUiOptions, IqserAppConfig, ModuleWithOptions } from './utils';
|
|
import { HiddenActionComponent, LogoComponent, ToastComponent } from './shared';
|
|
import { ConnectionStatusComponent, FullPageErrorComponent } from './error';
|
|
import { IqserListingModule } from './listing';
|
|
import { IqserFiltersModule } from './filtering';
|
|
import { IqserInputsModule } from './inputs';
|
|
import { IqserIconsModule } from './icons';
|
|
import { IqserButtonsModule } from './buttons';
|
|
import { IqserScrollbarModule } from './scrollbar';
|
|
import { IqserEmptyStatesModule } from './empty-states';
|
|
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
|
|
import { MatButtonModule } from '@angular/material/button';
|
|
import { MatDialogModule } from '@angular/material/dialog';
|
|
import { MatCheckboxModule } from '@angular/material/checkbox';
|
|
import { MatProgressBarModule } from '@angular/material/progress-bar';
|
|
import { ConfirmationDialogComponent } from './dialog';
|
|
import { MatTooltipModule } from '@angular/material/tooltip';
|
|
import { ApiPathInterceptor, IqserConfigService, IqserUserPreferenceService } from './services';
|
|
import { DefaultUserPreferenceService } from './services/default-user-preference.service';
|
|
import { HTTP_INTERCEPTORS, HttpClientModule } from '@angular/common/http';
|
|
|
|
const matModules = [
|
|
MatIconModule,
|
|
MatProgressSpinnerModule,
|
|
MatButtonModule,
|
|
MatDialogModule,
|
|
MatCheckboxModule,
|
|
MatTooltipModule,
|
|
MatProgressBarModule,
|
|
];
|
|
const modules = [
|
|
IqserIconsModule,
|
|
IqserButtonsModule,
|
|
IqserListingModule,
|
|
IqserFiltersModule,
|
|
IqserInputsModule,
|
|
IqserScrollbarModule,
|
|
IqserEmptyStatesModule,
|
|
HttpClientModule,
|
|
];
|
|
const components = [
|
|
ConnectionStatusComponent,
|
|
FullPageErrorComponent,
|
|
LogoComponent,
|
|
HiddenActionComponent,
|
|
ConfirmationDialogComponent,
|
|
ToastComponent,
|
|
];
|
|
|
|
const pipes = [SortByPipe];
|
|
|
|
@NgModule({
|
|
declarations: [...components, ...pipes],
|
|
imports: [CommonModule, ...matModules, ...modules, FormsModule, ReactiveFormsModule, TranslateModule],
|
|
exports: [...components, ...pipes, ...modules],
|
|
providers: [
|
|
{
|
|
provide: HTTP_INTERCEPTORS,
|
|
multi: true,
|
|
useClass: ApiPathInterceptor,
|
|
},
|
|
],
|
|
})
|
|
export class CommonUiModule extends ModuleWithOptions {
|
|
constructor(@Optional() @SkipSelf() parentModule?: CommonUiModule) {
|
|
super();
|
|
if (parentModule) {
|
|
throw new Error('CommonUiModule is already loaded. Import it in the AppModule only!');
|
|
}
|
|
}
|
|
|
|
static forRoot<
|
|
UserPreference extends IqserUserPreferenceService,
|
|
Config extends IqserConfigService<AppConfig>,
|
|
AppConfig extends IqserAppConfig = IqserAppConfig,
|
|
>(options: CommonUiOptions<UserPreference, Config, AppConfig>): ModuleWithProviders<CommonUiModule> {
|
|
const userPreferenceService = this._getService(
|
|
IqserUserPreferenceService,
|
|
DefaultUserPreferenceService,
|
|
options.existingUserPreferenceService,
|
|
);
|
|
|
|
const configServiceProviders = this._getConfigServiceProviders(options.configServiceFactory, options.configService);
|
|
|
|
return {
|
|
ngModule: CommonUiModule,
|
|
providers: [userPreferenceService, configServiceProviders],
|
|
};
|
|
}
|
|
|
|
private static _getConfigServiceProviders(configServiceFactory: () => unknown, configService?: unknown) {
|
|
if (configService) {
|
|
return [
|
|
{
|
|
provide: configService,
|
|
useFactory: configServiceFactory,
|
|
},
|
|
{
|
|
provide: IqserConfigService,
|
|
useExisting: configService,
|
|
},
|
|
];
|
|
}
|
|
|
|
return [
|
|
{
|
|
provide: IqserConfigService,
|
|
useFactory: configServiceFactory,
|
|
},
|
|
];
|
|
}
|
|
}
|