ngx-admin/src/app/@core/core.module.ts

107 lines
2.2 KiB
TypeScript
Raw Normal View History

import { ModuleWithProviders, NgModule, Optional, SkipSelf } from '@angular/core';
2017-04-13 14:24:23 +03:00
import { CommonModule } from '@angular/common';
2018-06-20 18:46:49 +03:00
import { NbAuthModule, NbDummyAuthStrategy } from '@nebular/auth';
import { NbSecurityModule, NbRoleProvider } from '@nebular/security';
2018-05-10 23:48:39 +03:00
import { of as observableOf } from 'rxjs';
2017-04-13 14:24:23 +03:00
import { throwIfAlreadyLoaded } from './module-import-guard';
2023-04-20 13:29:06 +02:00
import { AnalyticsService, SeoService } from './utils';
import { UserData } from './data/users';
import { UserService } from './mock/users.service';
import { MockDataModule } from './mock/mock-data.module';
const socialLinks = [
{
url: 'https://github.com/akveo/nebular',
target: '_blank',
icon: 'github',
},
{
url: 'https://www.facebook.com/akveo/',
target: '_blank',
icon: 'facebook',
},
{
url: 'https://twitter.com/akveo_inc',
target: '_blank',
icon: 'twitter',
},
];
const DATA_SERVICES = [
{ provide: UserData, useClass: UserService },
];
2018-05-10 23:48:39 +03:00
export class NbSimpleRoleProvider extends NbRoleProvider {
getRole() {
// here you could provide any role based on any auth flow
return observableOf('guest');
}
}
export const NB_CORE_PROVIDERS = [
...MockDataModule.forRoot().providers,
...DATA_SERVICES,
...NbAuthModule.forRoot({
2018-06-20 18:46:49 +03:00
strategies: [
NbDummyAuthStrategy.setup({
name: 'email',
delay: 3000,
}),
],
forms: {
login: {
socialLinks: socialLinks,
},
register: {
socialLinks: socialLinks,
},
},
}).providers,
2018-06-20 18:46:49 +03:00
NbSecurityModule.forRoot({
accessControl: {
guest: {
view: '*',
},
user: {
parent: 'guest',
create: '*',
edit: '*',
remove: '*',
},
},
}).providers,
2018-06-20 18:46:49 +03:00
{
2018-05-10 23:48:39 +03:00
provide: NbRoleProvider, useClass: NbSimpleRoleProvider,
},
2017-09-20 13:55:34 +03:00
AnalyticsService,
2019-12-20 11:09:37 +03:00
SeoService,
];
2017-04-13 14:24:23 +03:00
@NgModule({
imports: [
2017-05-06 15:35:15 +03:00
CommonModule,
2017-04-13 14:24:23 +03:00
],
exports: [
NbAuthModule,
],
2017-05-06 15:35:15 +03:00
declarations: [],
2017-04-13 14:24:23 +03:00
})
export class CoreModule {
constructor(@Optional() @SkipSelf() parentModule: CoreModule) {
throwIfAlreadyLoaded(parentModule, 'CoreModule');
}
static forRoot(): ModuleWithProviders<CoreModule> {
return {
ngModule: CoreModule,
providers: [
...NB_CORE_PROVIDERS,
],
};
}
2017-04-13 14:24:23 +03:00
}