Add service module
All checks were successful
FarmMaps.Develop/FarmMapsLib/develop This commit looks good

This commit is contained in:
Willem Dantuma 2019-11-12 22:50:57 +01:00
parent f31e4154b2
commit deda769e8b
4 changed files with 108 additions and 92 deletions

View File

@ -0,0 +1,105 @@
// angular modules
import { NgModule, APP_INITIALIZER, ModuleWithProviders, Injector,Optional,SkipSelf } from '@angular/core';
import { CommonModule, DatePipe } from '@angular/common';
import { HttpClientModule, HttpClient, HTTP_INTERCEPTORS } from '@angular/common/http';
import { FormsModule } from '@angular/forms';
// external modules
import { OAuthModule,AuthConfig, OAuthService, OAuthStorage } from 'angular-oauth2-oidc';
// routing module
import { AppCommonRoutingModule } from './common-routing.module';
import { MODULE_NAME } from './module-name';
//components
import { ItemTypeService } from './services/itemtype.service';
import { FolderService } from './services/folder.service';
import { TimespanService} from './services/timespan.service';
import { ItemService} from './services/item.service';
import { EventService } from './services/event.service';
import { TypeaheadService } from './services/typeahead.service';
import { UserService } from './services/user.service';
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';
import { SafePipe } from './shared/safe.pipe';
import { AppComponent} from './components/app/app.component';
import { AuthCallbackComponent } from './components/auth-callback/auth-callback.component';
import { AuthCallbackGuard } from './components/auth-callback/auth-callback.guard';
import { SessionClearedComponent } from './components/session-cleared/session-cleared.component';
import { ResumableFileUploadService } from './components/resumable-file-upload/resumable-file-upload.service';
import { ResumableFileUploadComponent } from './components/resumable-file-upload/resumable-file-upload.component';
import { NotFoundComponent } from './components/not-found/not-found.component';
import { NotImplementedComponent } from './components/not-implemented/not-implemented.component';
import { SidePanelComponent } from './components/side-panel/side-panel.component';
import { TimespanComponent } from './components/timespan/timespan.component';
import { TagInputComponent } from './components/tag-input/tag-input.component';
import {IEventMessage } from './models/event.message';
import { IItem, Item } from './models/item';
import {IItemType} from './models/item.type';
import {IItemTypes} from './models/item.types';
import {IItemTask,ItemTask} from './models/itemTask';
import {IListItem} from './models/list.item';
import {ITypeaheadItem} from './models/typeahead.item';
import {IUser} from './models/user';
import * as commonActions from './actions/app-common.actions';
import * as commonReducers from './reducers/app-common.reducer';
import * as commonEffects from './effects/app-common.effects';
import {NgbDateNativeAdapter} from './services/date-adapter.service'
import { from } from 'rxjs';
export {FolderService,
ItemTypeService,
TimespanService,
ItemService,
EventService,
TypeaheadService,
UserService,
AppConfig,
AccessTokenInterceptor,
AuthGuard,
NavBarGuard,
FullScreenGuard,
AuthCallbackGuard,
ResumableFileUploadService,
NgbDateNativeAdapter
};
@NgModule({
imports: [
OAuthModule.forRoot(),
]
})
export class AppCommonServiceModule {
constructor (@Optional() @SkipSelf() parentModule: AppCommonServiceModule) {
if (parentModule) {
throw new Error(
'AppCommonServiceModule is already loaded. Import it in the AppModule only');
}
}
static forRoot(): ModuleWithProviders {
return {
ngModule: AppCommonServiceModule,
providers: [
AppConfig,
{
provide: APP_INITIALIZER,
useFactory: appConfigFactory,
deps: [Injector, AppConfig, OAuthService],
multi: true
},
{
provide: HTTP_INTERCEPTORS,
useClass: AccessTokenInterceptor,
multi: true
},
DatePipe
]
};
}
}

View File

@ -18,25 +18,10 @@ import { AppCommonRoutingModule } from './common-routing.module';
import { MODULE_NAME } from './module-name'; import { MODULE_NAME } from './module-name';
//components //components
import { ItemTypeService } from './services/itemtype.service';
import { FolderService } from './services/folder.service';
import { TimespanService} from './services/timespan.service';
import { ItemService} from './services/item.service';
import { EventService } from './services/event.service';
import { TypeaheadService } from './services/typeahead.service';
import { UserService } from './services/user.service';
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';
import { SafePipe } from './shared/safe.pipe'; import { SafePipe } from './shared/safe.pipe';
import { AppComponent} from './components/app/app.component'; import { AppComponent} from './components/app/app.component';
import { AuthCallbackComponent } from './components/auth-callback/auth-callback.component'; import { AuthCallbackComponent } from './components/auth-callback/auth-callback.component';
import { AuthCallbackGuard } from './components/auth-callback/auth-callback.guard';
import { SessionClearedComponent } from './components/session-cleared/session-cleared.component'; import { SessionClearedComponent } from './components/session-cleared/session-cleared.component';
import { ResumableFileUploadService } from './components/resumable-file-upload/resumable-file-upload.service';
import { ResumableFileUploadComponent } from './components/resumable-file-upload/resumable-file-upload.component'; import { ResumableFileUploadComponent } from './components/resumable-file-upload/resumable-file-upload.component';
import { NotFoundComponent } from './components/not-found/not-found.component'; import { NotFoundComponent } from './components/not-found/not-found.component';
import { NotImplementedComponent } from './components/not-implemented/not-implemented.component'; import { NotImplementedComponent } from './components/not-implemented/not-implemented.component';
@ -54,27 +39,12 @@ import {IUser} from './models/user';
import * as commonActions from './actions/app-common.actions'; import * as commonActions from './actions/app-common.actions';
import * as commonReducers from './reducers/app-common.reducer'; import * as commonReducers from './reducers/app-common.reducer';
import * as commonEffects from './effects/app-common.effects'; import * as commonEffects from './effects/app-common.effects';
import {NgbDateNativeAdapter} from './services/date-adapter.service'
import { from } from 'rxjs';
export {FolderService, export {
ItemTypeService,
TimespanService,
ItemService,
EventService,
TypeaheadService,
UserService,
AppConfig,
AccessTokenInterceptor,
AuthGuard,
NavBarGuard,
FullScreenGuard,
SafePipe, SafePipe,
AuthCallbackComponent, AuthCallbackComponent,
AuthCallbackGuard,
AppComponent, AppComponent,
SessionClearedComponent, SessionClearedComponent,
ResumableFileUploadService,
ResumableFileUploadComponent, ResumableFileUploadComponent,
NotFoundComponent, NotFoundComponent,
NotImplementedComponent, NotImplementedComponent,
@ -92,8 +62,7 @@ export {FolderService,
ITypeaheadItem, ITypeaheadItem,
IUser, IUser,
commonActions, commonActions,
commonReducers, commonReducers
NgbDateNativeAdapter
}; };
@NgModule({ @NgModule({
@ -108,9 +77,6 @@ export {FolderService,
FormsModule, FormsModule,
UploadxModule UploadxModule
], ],
providers: [
DatePipe
],
declarations: [ declarations: [
AppComponent, AppComponent,
AuthCallbackComponent, AuthCallbackComponent,
@ -141,29 +107,4 @@ export {FolderService,
] ]
}) })
export class AppCommonModule { export class AppCommonModule {
constructor (@Optional() @SkipSelf() parentModule: AppCommonModule) {
if (parentModule) {
throw new Error(
'AppCommonModule is already loaded. Import it in the AppModule only');
}
}
static forRoot(): ModuleWithProviders {
return {
ngModule: AppCommonModule,
providers: [
AppConfig,
{
provide: APP_INITIALIZER,
useFactory: appConfigFactory,
deps: [Injector, AppConfig, OAuthService],
multi: true
},
{
provide: HTTP_INTERCEPTORS,
useClass: AccessTokenInterceptor,
multi: true
}
]
};
}
} }

View File

@ -3,3 +3,4 @@
*/ */
export * from './fm/common.module'; export * from './fm/common.module';
export * from './fm/common-service.module';

View File

@ -1,31 +0,0 @@
import { TestBed, async } from '@angular/core/testing';
import { AppComponent } from './app.component';
describe('AppComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
AppComponent
],
}).compileComponents();
}));
it('should create the app', () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.debugElement.componentInstance;
expect(app).toBeTruthy();
});
it(`should have as title 'farmmaps-lib-app'`, () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.debugElement.componentInstance;
expect(app.title).toEqual('farmmaps-lib-app');
});
it('should render title in a h1 tag', () => {
const fixture = TestBed.createComponent(AppComponent);
fixture.detectChanges();
const compiled = fixture.debugElement.nativeElement;
expect(compiled.querySelector('h1').textContent).toContain('Welcome to farmmaps-lib-app!');
});
});