FarmMapsLib/projects/common/src/fm/common-service.module.ts

93 lines
3.2 KiB
TypeScript
Raw Normal View History

2019-12-19 12:32:51 +00:00
// angular modules
2020-01-22 13:12:57 +00:00
import { NgModule, APP_INITIALIZER, ModuleWithProviders, Injector, Optional, SkipSelf } from '@angular/core';
import { DatePipe } from '@angular/common';
import { HTTP_INTERCEPTORS } from '@angular/common/http';
2019-12-19 12:32:51 +00:00
// external modules
2020-01-22 13:12:57 +00:00
import { OAuthModule, OAuthService, OAuthStorage } from 'angular-oauth2-oidc';
2019-12-19 12:32:51 +00:00
//components
import { ItemTypeService } from './services/itemtype.service';
2020-06-22 11:12:02 +00:00
import { SchemaService } from './services/schema.service';
2019-12-19 12:32:51 +00:00
import { FolderService } from './services/folder.service';
2020-01-22 13:12:57 +00:00
import { TimespanService } from './services/timespan.service';
import { ItemService } from './services/item.service';
2019-12-19 12:32:51 +00:00
import { EventService } from './services/event.service';
import { TypeaheadService } from './services/typeahead.service';
import { UserService } from './services/user.service';
import { WeatherService} from './services/weather.service';
2019-12-19 12:32:51 +00:00
import { AppConfig } from './shared/app.config';
import { AccessTokenInterceptor } from "./shared/accesstoken.interceptor";
import { appConfigFactory } from "./shared/app.config.factory";
import { AuthGuard } from './services/auth-guard.service';
import { NavBarGuard } from './services/nav-bar-guard.service';
import { FullScreenGuard } from './services/full-screen-guard.service';
2020-01-22 13:12:57 +00:00
import { CodeListItemService } from './services/codelistitem.service';
2019-12-19 12:32:51 +00:00
import { AuthCallbackGuard } from './components/auth-callback/auth-callback.guard';
import { ResumableFileUploadService } from './components/resumable-file-upload/resumable-file-upload.service';
2020-01-22 13:12:57 +00:00
import { NgbDateNativeAdapter } from './services/date-adapter.service'
import { AuthConfigFactory } from './shared/authconfigFactory';
import { StateSerializerService } from './services/state-serializer.service';
2020-06-24 05:56:28 +00:00
import { PackageService } from './services/package.service';
2020-06-29 13:44:23 +00:00
import { SenmlService } from './services/senml-service';
2019-12-19 12:32:51 +00:00
2020-01-22 13:12:57 +00:00
export {
FolderService,
2019-12-19 12:32:51 +00:00
ItemTypeService,
TimespanService,
ItemService,
EventService,
TypeaheadService,
UserService,
WeatherService,
2020-01-22 13:12:57 +00:00
CodeListItemService,
2019-12-19 12:32:51 +00:00
AppConfig,
AccessTokenInterceptor,
AuthGuard,
NavBarGuard,
FullScreenGuard,
AuthCallbackGuard,
ResumableFileUploadService,
NgbDateNativeAdapter,
2020-06-22 11:12:02 +00:00
StateSerializerService,
2020-06-24 05:56:28 +00:00
SchemaService,
2020-06-29 13:44:23 +00:00
PackageService,
SenmlService
2019-12-19 12:32:51 +00:00
};
@NgModule({
imports: [
OAuthModule.forRoot(),
]
})
export class AppCommonServiceModule {
2020-01-22 13:12:57 +00:00
constructor(@Optional() @SkipSelf() parentModule: AppCommonServiceModule) {
2019-12-19 12:32:51 +00:00
if (parentModule) {
throw new Error(
'AppCommonServiceModule is already loaded. Import it in the AppModule only');
}
}
2020-04-01 07:06:11 +00:00
static forRoot(): ModuleWithProviders<AppCommonServiceModule> {
2019-12-19 12:32:51 +00:00
return {
ngModule: AppCommonServiceModule,
providers: [
AppConfig,
2020-02-11 17:55:43 +00:00
ItemTypeService,
2019-12-19 12:32:51 +00:00
{
provide: APP_INITIALIZER,
useFactory: appConfigFactory,
2020-06-22 11:12:02 +00:00
deps: [Injector, AppConfig, OAuthService, AuthConfigFactory, OAuthStorage, ItemTypeService],
2019-12-19 12:32:51 +00:00
multi: true
2020-01-22 13:12:57 +00:00
},
2019-12-19 12:32:51 +00:00
{
provide: HTTP_INTERCEPTORS,
useClass: AccessTokenInterceptor,
multi: true
},
DatePipe
]
};
}
}