Client: split in angular modules

This commit is contained in:
Chocobozzz 2016-11-20 17:18:15 +01:00
parent 2c8d4697db
commit 693b1aba46
33 changed files with 371 additions and 174 deletions

View File

@ -34,7 +34,7 @@
"@types/uglify-js": "^2.0.27",
"@types/videojs": "0.0.30",
"@types/webpack": "^1.12.29",
"angular-pipes": "^4.0.0",
"angular-pipes": "^5.0.0",
"angular2-template-loader": "^0.6.0",
"assets-webpack-plugin": "^3.4.0",
"awesome-typescript-loader": "^2.2.1",
@ -53,7 +53,7 @@
"json-loader": "^0.5.4",
"ng2-bootstrap": "1.1.16",
"ng2-file-upload": "^1.1.0",
"ng2-meta": "github:chocobozzz/ng2-meta",
"ng2-meta": "^2.0.0",
"node-sass": "^3.10.0",
"normalize.css": "^5.0.0",
"raw-loader": "^0.5.1",

View File

@ -0,0 +1,22 @@
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { AccountComponent } from './account.component';
const accountRoutes: Routes = [
{
path: 'account',
component: AccountComponent,
data: {
meta: {
titleSuffix: ' - My account'
}
}
}
];
@NgModule({
imports: [ RouterModule.forChild(accountRoutes) ],
exports: [ RouterModule ]
})
export class AccountRoutingModule {}

View File

@ -0,0 +1,26 @@
import { NgModule } from '@angular/core';
import { AccountRoutingModule } from './account-routing.module';
import { AccountComponent } from './account.component';
import { AccountService } from './account.service';
import { SharedModule } from '../shared';
@NgModule({
imports: [
AccountRoutingModule,
SharedModule
],
declarations: [
AccountComponent
],
exports: [
AccountComponent
],
providers: [
AccountService
]
})
export class AccountModule { }

View File

@ -1,13 +0,0 @@
import { AccountComponent } from './account.component';
export const AccountRoutes = [
{
path: 'account',
component: AccountComponent,
data: {
meta: {
titleSuffix: ' - My account'
}
}
}
];

View File

@ -1,6 +1,7 @@
import { Injectable } from '@angular/core';
import { AuthHttp, AuthService, RestExtractor } from '../shared';
import { AuthService } from '../core';
import { AuthHttp, RestExtractor } from '../shared';
@Injectable()
export class AccountService {

View File

@ -1,3 +1,4 @@
export * from './account-routing.module';
export * from './account.component';
export * from './account.routes';
export * from './account.module';
export * from './account.service';

View File

@ -1,11 +1,12 @@
import { Routes } from '@angular/router';
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { AdminComponent } from './admin.component';
import { FriendsRoutes } from './friends';
import { RequestsRoutes } from './requests';
import { UsersRoutes } from './users';
export const AdminRoutes: Routes = [
const adminRoutes: Routes = [
{
path: 'admin',
component: AdminComponent,
@ -21,3 +22,9 @@ export const AdminRoutes: Routes = [
]
}
];
@NgModule({
imports: [ RouterModule.forChild(adminRoutes) ],
exports: [ RouterModule ]
})
export class AdminRoutingModule {}

View File

@ -0,0 +1,45 @@
import { NgModule } from '@angular/core';
import { AdminComponent } from './admin.component';
import { AdminRoutingModule } from './admin-routing.module';
import { FriendsComponent, FriendAddComponent, FriendListComponent, FriendService } from './friends';
import { RequestsComponent, RequestStatsComponent, RequestService } from './requests';
import { UsersComponent, UserAddComponent, UserListComponent, UserService } from './users';
import { MenuAdminComponent } from './menu-admin.component';
import { SharedModule } from '../shared';
@NgModule({
imports: [
AdminRoutingModule,
SharedModule
],
declarations: [
AdminComponent,
FriendsComponent,
FriendAddComponent,
FriendListComponent,
RequestsComponent,
RequestStatsComponent,
UsersComponent,
UserAddComponent,
UserListComponent,
MenuAdminComponent
],
exports: [
AdminComponent,
MenuAdminComponent
],
providers: [
FriendService,
RequestService,
UserService
]
})
export class AdminModule { }

View File

@ -1,6 +1,7 @@
export * from './friends';
export * from './requests';
export * from './users';
export * from './admin-routing.module';
export * from './admin.module';
export * from './admin.component';
export * from './admin.routes';
export * from './menu-admin.component';

View File

@ -0,0 +1,17 @@
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
const routes: Routes = [
{
path: '',
redirectTo: '/videos/list',
pathMatch: 'full'
}
];
@NgModule({
imports: [ RouterModule.forRoot(routes) ],
exports: [ RouterModule ]
})
export class AppRoutingModule {}

View File

@ -1,62 +1,22 @@
import { ApplicationRef, NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { HttpModule, RequestOptions, XHRBackend } from '@angular/http';
import { RouterModule } from '@angular/router';
import { removeNgStyles, createNewHosts } from '@angularclass/hmr';
import { BytesPipe } from 'angular-pipes/src/math/bytes.pipe';
import { MetaModule, MetaConfig } from 'ng2-meta';
import { DropdownModule } from 'ng2-bootstrap/components/dropdown';
import { ProgressbarModule } from 'ng2-bootstrap/components/progressbar';
import { PaginationModule } from 'ng2-bootstrap/components/pagination';
import { ModalModule } from 'ng2-bootstrap/components/modal';
import { FileUploadModule } from 'ng2-file-upload/ng2-file-upload';
import { MetaConfig, MetaModule } from 'ng2-meta';
/*
* Platform and Environment providers/directives/pipes
*/
import { ENV_PROVIDERS } from './environment';
import { routes } from './app.routes';
// App is our top level component
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { AppState } from './app.service';
import {
AdminComponent,
FriendsComponent,
FriendAddComponent,
FriendListComponent,
FriendService,
MenuAdminComponent,
RequestsComponent,
RequestStatsComponent,
RequestService,
UsersComponent,
UserAddComponent,
UserListComponent,
UserService
} from './admin';
import { AccountComponent, AccountService } from './account';
import { LoginComponent } from './login';
import { AccountModule } from './account';
import { AdminModule } from './admin';
import { CoreModule } from './core';
import { LoginModule } from './login';
import { SharedModule } from './shared';
import { VideosModule } from './videos';
import { MenuComponent } from './menu.component';
import { AuthService, AuthHttp, RestExtractor, RestService, SearchComponent, SearchService } from './shared';
import {
LoaderComponent,
VideosComponent,
VideoAddComponent,
VideoListComponent,
VideoMiniatureComponent,
VideoSortComponent,
VideoWatchComponent,
VideoShareComponent,
VideoMagnetComponent,
VideoService,
WebTorrentService
} from './videos';
const metaConfig: MetaConfig = {
//Append a title suffix such as a site name to all titles
@ -69,75 +29,31 @@ const metaConfig: MetaConfig = {
// Application wide providers
const APP_PROVIDERS = [
AppState,
{
provide: AuthHttp,
useFactory: (backend: XHRBackend, defaultOptions: RequestOptions, authService: AuthService) => {
return new AuthHttp(backend, defaultOptions, authService);
},
deps: [ XHRBackend, RequestOptions, AuthService ]
},
AuthService,
RestExtractor,
RestService,
VideoService,
SearchService,
FriendService,
RequestService,
UserService,
AccountService,
WebTorrentService
AppState
];
/**
* `AppModule` is the main entry point into Angular2's bootstraping process
*/
@NgModule({
bootstrap: [ AppComponent ],
declarations: [
AccountComponent,
AdminComponent,
AppComponent,
BytesPipe,
FriendAddComponent,
FriendListComponent,
FriendsComponent,
LoaderComponent,
LoginComponent,
MenuAdminComponent,
MenuComponent,
RequestsComponent,
RequestStatsComponent,
SearchComponent,
UserAddComponent,
UserListComponent,
UsersComponent,
VideoAddComponent,
VideoListComponent,
VideoMiniatureComponent,
VideosComponent,
VideoSortComponent,
VideoWatchComponent,
VideoShareComponent,
VideoMagnetComponent
MenuComponent
],
imports: [ // import Angular's modules
imports: [
BrowserModule,
FormsModule,
ReactiveFormsModule,
HttpModule,
RouterModule.forRoot(routes),
DropdownModule,
ProgressbarModule,
PaginationModule,
ModalModule,
CoreModule,
SharedModule,
FileUploadModule,
AppRoutingModule,
MetaModule.forRoot(metaConfig)
MetaModule.forRoot(metaConfig),
AccountModule,
AdminModule,
CoreModule,
LoginModule,
SharedModule,
VideosModule
],
providers: [ // expose our Services and Providers into Angular's dependency injection
ENV_PROVIDERS,

View File

@ -1,18 +0,0 @@
import { Routes } from '@angular/router';
import { AccountRoutes } from './account';
import { LoginRoutes } from './login';
import { AdminRoutes } from './admin';
import { VideosRoutes } from './videos';
export const routes: Routes = [
{
path: '',
redirectTo: '/videos/list',
pathMatch: 'full'
},
...AdminRoutes,
...AccountRoutes,
...LoginRoutes,
...VideosRoutes
];

View File

@ -4,9 +4,10 @@ import { Router } from '@angular/router';
import { Observable } from 'rxjs/Observable';
import { Subject } from 'rxjs/Subject';
import { AuthStatus } from './auth-status.model';
import { AuthUser } from './auth-user.model';
import { RestExtractor } from '../rest';
// Do not use the barrel (dependency loop)
import { AuthStatus } from '../../shared/auth/auth-status.model';
import { AuthUser } from '../../shared/auth/auth-user.model';
import { RestExtractor } from '../../shared/rest';
@Injectable()
export class AuthService {

View File

@ -0,0 +1 @@
export * from './auth.service'

View File

@ -0,0 +1,21 @@
import { NgModule, Optional, SkipSelf } from '@angular/core';
import { CommonModule } from '@angular/common';
import { HttpModule } from '@angular/http';
import { AuthService } from './auth';
import { throwIfAlreadyLoaded } from './module-import-guard';
@NgModule({
imports: [
CommonModule,
HttpModule
],
declarations: [ ],
exports: [ ],
providers: [ AuthService ]
})
export class CoreModule {
constructor( @Optional() @SkipSelf() parentModule: CoreModule) {
throwIfAlreadyLoaded(parentModule, 'CoreModule');
}
}

View File

@ -0,0 +1,2 @@
export * from './auth';
export * from './core.module'

View File

@ -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.`);
}
}

View File

@ -1,2 +1,3 @@
export * from './login-routing.module';
export * from './login.component';
export * from './login.routes';
export * from './login.module';

View File

@ -0,0 +1,22 @@
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { LoginComponent } from './login.component';
const loginRoutes: Routes = [
{
path: 'login',
component: LoginComponent,
data: {
meta: {
titleSuffix: ' - Login'
}
}
}
];
@NgModule({
imports: [ RouterModule.forChild(loginRoutes) ],
exports: [ RouterModule ]
})
export class LoginRoutingModule {}

View File

@ -2,7 +2,8 @@ import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { Router } from '@angular/router';
import { AuthService, FormReactive } from '../shared';
import { AuthService } from '../core';
import { FormReactive } from '../shared';
@Component({
selector: 'my-login',

View File

@ -0,0 +1,24 @@
import { NgModule } from '@angular/core';
import { LoginRoutingModule } from './login-routing.module';
import { LoginComponent } from './login.component';
import { SharedModule } from '../shared';
@NgModule({
imports: [
LoginRoutingModule,
SharedModule
],
declarations: [
LoginComponent
],
exports: [
LoginComponent
],
providers: [
]
})
export class LoginModule { }

View File

@ -1,13 +0,0 @@
import { LoginComponent } from './login.component';
export const LoginRoutes = [
{
path: 'login',
component: LoginComponent,
data: {
meta: {
titleSuffix: ' - Login'
}
}
}
];

View File

@ -1,7 +1,8 @@
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { AuthService, AuthStatus } from './shared';
import { AuthService } from './core';
import { AuthStatus } from './shared';
@Component({
selector: 'my-menu',

View File

@ -7,11 +7,12 @@ import {
RequestMethod,
RequestOptions,
RequestOptionsArgs,
Response
Response,
XHRBackend
} from '@angular/http';
import { Observable } from 'rxjs/Observable';
import { AuthService } from './auth.service';
import { AuthService } from '../../core';
@Injectable()
export class AuthHttp extends Http {
@ -78,3 +79,13 @@ export class AuthHttp extends Http {
headers.set('Authorization', this.authService.getRequestHeaderValue());
}
}
export const AUTH_HTTP_PROVIDERS = [
{
provide: AuthHttp,
useFactory: (backend: XHRBackend, defaultOptions: RequestOptions, authService: AuthService) => {
return new AuthHttp(backend, defaultOptions, authService);
},
deps: [ XHRBackend, RequestOptions, AuthService ]
},
];

View File

@ -1,4 +1,3 @@
export * from './auth-http.service';
export * from './auth-status.model';
export * from './auth.service';
export * from './auth-user.model';

View File

@ -3,3 +3,4 @@ export * from './forms';
export * from './rest';
export * from './search';
export * from './users';
export * from './shared.module';

View File

@ -0,0 +1,62 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { HttpModule } from '@angular/http';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { RouterModule } from '@angular/router';
import { BytesPipe } from 'angular-pipes/src/math/bytes.pipe';
import { DropdownModule } from 'ng2-bootstrap/components/dropdown';
import { ProgressbarModule } from 'ng2-bootstrap/components/progressbar';
import { PaginationModule } from 'ng2-bootstrap/components/pagination';
import { ModalModule } from 'ng2-bootstrap/components/modal';
import { FileUploadModule } from 'ng2-file-upload/ng2-file-upload';
import { AUTH_HTTP_PROVIDERS } from './auth';
import { RestExtractor, RestService } from './rest';
import { SearchComponent, SearchService } from './search';
@NgModule({
imports: [
CommonModule,
FormsModule,
ReactiveFormsModule,
HttpModule,
RouterModule,
DropdownModule,
FileUploadModule,
ModalModule,
PaginationModule,
ProgressbarModule
],
declarations: [
BytesPipe,
SearchComponent
],
exports: [
CommonModule,
FormsModule,
ReactiveFormsModule,
HttpModule,
RouterModule,
DropdownModule,
FileUploadModule,
ModalModule,
PaginationModule,
ProgressbarModule,
BytesPipe,
SearchComponent
],
providers: [
AUTH_HTTP_PROVIDERS,
RestExtractor,
RestService,
SearchService
]
})
export class SharedModule { }

View File

@ -2,5 +2,6 @@ export * from './shared';
export * from './video-add';
export * from './video-list';
export * from './video-watch';
export * from './videos-routing.module';
export * from './videos.component';
export * from './videos.routes';
export * from './videos.module';

View File

@ -4,7 +4,8 @@ import { Observable } from 'rxjs/Observable';
import { Search } from '../../shared';
import { SortField } from './sort-field.type';
import { AuthHttp, AuthService, RestExtractor, RestPagination, RestService, ResultList } from '../../shared';
import { AuthService } from '../../core';
import { AuthHttp, RestExtractor, RestPagination, RestService, ResultList } from '../../shared';
import { Video } from './video.model';
@Injectable()

View File

@ -4,7 +4,8 @@ import { Router } from '@angular/router';
import { FileUploader } from 'ng2-file-upload/ng2-file-upload';
import { AuthService, FormReactive, VIDEO_NAME, VIDEO_DESCRIPTION, VIDEO_TAGS } from '../../shared';
import { AuthService } from '../../core';
import { FormReactive, VIDEO_NAME, VIDEO_DESCRIPTION, VIDEO_TAGS } from '../../shared';
@Component({
selector: 'my-videos-add',

View File

@ -7,7 +7,8 @@ import {
Video,
VideoService
} from '../shared';
import { AuthService, AuthUser, RestPagination, Search, SearchField } from '../../shared';
import { AuthService } from '../../core';
import { AuthUser, RestPagination, Search, SearchField } from '../../shared';
import { SearchService } from '../../shared';
@Component({

View File

@ -1,11 +1,12 @@
import { Routes } from '@angular/router';
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { VideoAddComponent } from './video-add';
import { VideoListComponent } from './video-list';
import { VideosComponent } from './videos.component';
import { VideoWatchComponent } from './video-watch';
export const VideosRoutes: Routes = [
const videosRoutes: Routes = [
{
path: 'videos',
component: VideosComponent,
@ -35,3 +36,9 @@ export const VideosRoutes: Routes = [
]
}
];
@NgModule({
imports: [ RouterModule.forChild(videosRoutes) ],
exports: [ RouterModule ]
})
export class VideosRoutingModule {}

View File

@ -0,0 +1,42 @@
import { NgModule } from '@angular/core';
import { VideosRoutingModule } from './videos-routing.module';
import { VideosComponent } from './videos.component';
import { VideoAddComponent } from './video-add';
import { VideoListComponent, VideoMiniatureComponent, VideoSortComponent } from './video-list';
import { VideoWatchComponent, VideoMagnetComponent, VideoShareComponent, WebTorrentService } from './video-watch';
import { LoaderComponent, VideoService } from './shared';
import { SharedModule } from '../shared';
@NgModule({
imports: [
VideosRoutingModule,
SharedModule
],
declarations: [
VideosComponent,
VideoAddComponent,
VideoListComponent,
VideoMiniatureComponent,
VideoSortComponent,
VideoWatchComponent,
VideoMagnetComponent,
VideoShareComponent,
LoaderComponent
],
exports: [
VideosComponent
],
providers: [
VideoService,
WebTorrentService
]
})
export class VideosModule { }