-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add ngx-admi to Angular app, add swagger to NestJS
- Loading branch information
Showing
68 changed files
with
7,652 additions
and
8,538 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import { ModuleWithProviders, NgModule, Optional, SkipSelf } from '@angular/core'; | ||
import { CommonModule } from '@angular/common'; | ||
import { NbAuthModule, NbDummyAuthStrategy } from '@nebular/auth'; | ||
import { NbSecurityModule, NbRoleProvider } from '@nebular/security'; | ||
import { of as observableOf } from 'rxjs'; | ||
|
||
import { throwIfAlreadyLoaded } from './module-import-guard'; | ||
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 }, | ||
]; | ||
|
||
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({ | ||
|
||
strategies: [ | ||
NbDummyAuthStrategy.setup({ | ||
name: 'email', | ||
delay: 3000, | ||
}), | ||
], | ||
forms: { | ||
login: { | ||
socialLinks: socialLinks, | ||
}, | ||
register: { | ||
socialLinks: socialLinks, | ||
}, | ||
}, | ||
}).providers, | ||
|
||
NbSecurityModule.forRoot({ | ||
accessControl: { | ||
guest: { | ||
view: '*', | ||
}, | ||
user: { | ||
parent: 'guest', | ||
create: '*', | ||
edit: '*', | ||
remove: '*', | ||
}, | ||
}, | ||
}).providers, | ||
|
||
{ | ||
provide: NbRoleProvider, useClass: NbSimpleRoleProvider, | ||
}, | ||
AnalyticsService, | ||
SeoService, | ||
]; | ||
|
||
@NgModule({ | ||
imports: [ | ||
CommonModule, | ||
], | ||
exports: [ | ||
NbAuthModule, | ||
], | ||
declarations: [], | ||
}) | ||
export class CoreModule { | ||
constructor(@Optional() @SkipSelf() parentModule: CoreModule) { | ||
throwIfAlreadyLoaded(parentModule, 'CoreModule'); | ||
} | ||
|
||
static forRoot(): ModuleWithProviders<CoreModule> { | ||
return { | ||
ngModule: CoreModule, | ||
providers: [ | ||
...NB_CORE_PROVIDERS, | ||
], | ||
}; | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Application-wise data providers. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Observable } from 'rxjs'; | ||
|
||
export interface User { | ||
name: string; | ||
picture: string; | ||
} | ||
|
||
export interface Contacts { | ||
user: User; | ||
type: string; | ||
} | ||
|
||
export interface RecentUsers extends Contacts { | ||
time: number; | ||
} | ||
|
||
export abstract class UserData { | ||
abstract getUsers(): Observable<User[]>; | ||
abstract getContacts(): Observable<Contacts[]>; | ||
abstract getRecentUsers(): Observable<RecentUsers[]>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Application-wise data providers. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { NgModule, ModuleWithProviders } from '@angular/core'; | ||
import { CommonModule } from '@angular/common'; | ||
|
||
import { UserService } from './users.service'; | ||
|
||
const SERVICES = [ | ||
UserService, | ||
]; | ||
|
||
@NgModule({ | ||
imports: [ | ||
CommonModule, | ||
], | ||
providers: [ | ||
...SERVICES, | ||
], | ||
}) | ||
export class MockDataModule { | ||
static forRoot(): ModuleWithProviders<MockDataModule> { | ||
return { | ||
ngModule: MockDataModule, | ||
providers: [ | ||
...SERVICES, | ||
], | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { of as observableOf, Observable } from 'rxjs'; | ||
import { Injectable } from '@angular/core'; | ||
import { Contacts, RecentUsers, UserData } from '../data/users'; | ||
|
||
@Injectable() | ||
export class UserService extends UserData { | ||
|
||
private time: Date = new Date; | ||
|
||
private users = { | ||
nick: { name: 'Nick Jones', picture: 'assets/images/nick.png' }, | ||
eva: { name: 'Eva Moor', picture: 'assets/images/eva.png' }, | ||
jack: { name: 'Jack Williams', picture: 'assets/images/jack.png' }, | ||
lee: { name: 'Lee Wong', picture: 'assets/images/lee.png' }, | ||
alan: { name: 'Alan Thompson', picture: 'assets/images/alan.png' }, | ||
kate: { name: 'Kate Martinez', picture: 'assets/images/kate.png' }, | ||
}; | ||
private types = { | ||
mobile: 'mobile', | ||
home: 'home', | ||
work: 'work', | ||
}; | ||
private contacts: Contacts[] = [ | ||
{ user: this.users.nick, type: this.types.mobile }, | ||
{ user: this.users.eva, type: this.types.home }, | ||
{ user: this.users.jack, type: this.types.mobile }, | ||
{ user: this.users.lee, type: this.types.mobile }, | ||
{ user: this.users.alan, type: this.types.home }, | ||
{ user: this.users.kate, type: this.types.work }, | ||
]; | ||
private recentUsers: RecentUsers[] = [ | ||
{ user: this.users.alan, type: this.types.home, time: this.time.setHours(21, 12)}, | ||
{ user: this.users.eva, type: this.types.home, time: this.time.setHours(17, 45)}, | ||
{ user: this.users.nick, type: this.types.mobile, time: this.time.setHours(5, 29)}, | ||
{ user: this.users.lee, type: this.types.mobile, time: this.time.setHours(11, 24)}, | ||
{ user: this.users.jack, type: this.types.mobile, time: this.time.setHours(10, 45)}, | ||
{ user: this.users.kate, type: this.types.work, time: this.time.setHours(9, 42)}, | ||
{ user: this.users.kate, type: this.types.work, time: this.time.setHours(9, 31)}, | ||
{ user: this.users.jack, type: this.types.mobile, time: this.time.setHours(8, 0)}, | ||
]; | ||
|
||
getUsers(): Observable<any> { | ||
return observableOf(this.users); | ||
} | ||
|
||
getContacts(): Observable<Contacts[]> { | ||
return observableOf(this.contacts); | ||
} | ||
|
||
getRecentUsers(): Observable<RecentUsers[]> { | ||
return observableOf(this.recentUsers); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export function throwIfAlreadyLoaded(parentModule: any, moduleName: string) { | ||
if (parentModule) { | ||
throw new Error(`${moduleName} has already been loaded. Import Core modules in the AppModule only.`); | ||
} | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { NavigationEnd, Router } from '@angular/router'; | ||
import { Location } from '@angular/common'; | ||
import { filter } from 'rxjs/operators'; | ||
|
||
declare const ga: any; | ||
|
||
@Injectable() | ||
export class AnalyticsService { | ||
private enabled: boolean; | ||
|
||
constructor(private location: Location, private router: Router) { | ||
this.enabled = false; | ||
} | ||
|
||
trackPageViews() { | ||
if (this.enabled) { | ||
this.router.events.pipe( | ||
filter((event) => event instanceof NavigationEnd), | ||
) | ||
.subscribe(() => { | ||
ga('send', {hitType: 'pageview', page: this.location.path()}); | ||
}); | ||
} | ||
} | ||
|
||
trackEvent(eventName: string) { | ||
if (this.enabled) { | ||
ga('send', 'event', eventName); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { AnalyticsService } from './analytics.service'; | ||
export { SeoService } from './seo.service'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { Injectable, Inject, PLATFORM_ID, OnDestroy } from '@angular/core'; | ||
import { isPlatformBrowser } from '@angular/common'; | ||
import { NavigationEnd, Router } from '@angular/router'; | ||
import { NB_DOCUMENT } from '@nebular/theme'; | ||
import { filter, takeUntil } from 'rxjs/operators'; | ||
import { Subject } from 'rxjs'; | ||
|
||
@Injectable() | ||
export class SeoService implements OnDestroy { | ||
|
||
private readonly destroy$ = new Subject<void>(); | ||
private readonly dom: Document; | ||
private readonly isBrowser: boolean; | ||
private linkCanonical: HTMLLinkElement; | ||
|
||
constructor( | ||
private router: Router, | ||
@Inject(NB_DOCUMENT) document, | ||
@Inject(PLATFORM_ID) platformId, | ||
) { | ||
this.isBrowser = isPlatformBrowser(platformId); | ||
this.dom = document; | ||
|
||
if (this.isBrowser) { | ||
this.createCanonicalTag(); | ||
} | ||
} | ||
|
||
ngOnDestroy() { | ||
this.destroy$.next(); | ||
this.destroy$.complete(); | ||
} | ||
|
||
createCanonicalTag() { | ||
this.linkCanonical = this.dom.createElement('link'); | ||
this.linkCanonical.setAttribute('rel', 'canonical'); | ||
this.dom.head.appendChild(this.linkCanonical); | ||
this.linkCanonical.setAttribute('href', this.getCanonicalUrl()); | ||
} | ||
|
||
trackCanonicalChanges() { | ||
if (!this.isBrowser) { | ||
return; | ||
} | ||
|
||
this.router.events.pipe( | ||
filter((event) => event instanceof NavigationEnd), | ||
takeUntil(this.destroy$), | ||
) | ||
.subscribe(() => { | ||
this.linkCanonical.setAttribute('href', this.getCanonicalUrl()); | ||
}); | ||
} | ||
|
||
private getCanonicalUrl(): string { | ||
return this.dom.location.origin + this.dom.location.pathname; | ||
} | ||
} |
Oops, something went wrong.