]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/app.module.ts
3b7750a763757755c98b7b7315c7f9ffe582b2d8
[github/Chocobozzz/PeerTube.git] / client / src / app / app.module.ts
1 import { ApplicationRef, NgModule } from '@angular/core';
2 import { BrowserModule } from '@angular/platform-browser';
3 import { FormsModule, ReactiveFormsModule } from '@angular/forms';
4 import { HttpModule, RequestOptions, XHRBackend } from '@angular/http';
5 import { RouterModule } from '@angular/router';
6 import { removeNgStyles, createNewHosts } from '@angularclass/hmr';
7
8 import { BytesPipe } from 'angular-pipes/src/math/bytes.pipe';
9 import { ProgressbarModule } from 'ng2-bootstrap/components/progressbar';
10 import { PaginationModule } from 'ng2-bootstrap/components/pagination';
11 import { FileSelectDirective } from 'ng2-file-upload/ng2-file-upload';
12
13 /*
14 * Platform and Environment providers/directives/pipes
15 */
16 import { ENV_PROVIDERS } from './environment';
17 import { routes } from './app.routes';
18 // App is our top level component
19 import { AppComponent } from './app.component';
20 import { AppState } from './app.service';
21
22 import {
23 AdminComponent,
24 FriendsComponent,
25 FriendAddComponent,
26 FriendListComponent,
27 FriendService,
28 MenuAdminComponent,
29 UsersComponent,
30 UserAddComponent,
31 UserListComponent,
32 UserService
33 } from './admin';
34 import { AccountComponent, AccountService } from './account';
35 import { LoginComponent } from './login';
36 import { MenuComponent } from './menu.component';
37 import { AuthService, AuthHttp, RestExtractor, RestService, SearchComponent, SearchService } from './shared';
38 import {
39 LoaderComponent,
40 VideosComponent,
41 VideoAddComponent,
42 VideoListComponent,
43 VideoMiniatureComponent,
44 VideoSortComponent,
45 VideoWatchComponent,
46 VideoService,
47 WebTorrentService
48 } from './videos';
49
50 // Application wide providers
51 const APP_PROVIDERS = [
52 AppState,
53
54 {
55 provide: AuthHttp,
56 useFactory: (backend: XHRBackend, defaultOptions: RequestOptions, authService: AuthService) => {
57 return new AuthHttp(backend, defaultOptions, authService);
58 },
59 deps: [ XHRBackend, RequestOptions, AuthService ]
60 },
61
62 AuthService,
63 RestExtractor,
64 RestService,
65
66 VideoService,
67 SearchService,
68 FriendService,
69 UserService,
70 AccountService,
71 WebTorrentService
72 ];
73 /**
74 * `AppModule` is the main entry point into Angular2's bootstraping process
75 */
76 @NgModule({
77 bootstrap: [ AppComponent ],
78 declarations: [
79 AccountComponent,
80 AdminComponent,
81 AppComponent,
82 BytesPipe,
83 FileSelectDirective,
84 FriendAddComponent,
85 FriendListComponent,
86 FriendsComponent,
87 LoaderComponent,
88 LoginComponent,
89 MenuAdminComponent,
90 MenuComponent,
91 SearchComponent,
92 UserAddComponent,
93 UserListComponent,
94 UsersComponent,
95 VideoAddComponent,
96 VideoListComponent,
97 VideoMiniatureComponent,
98 VideosComponent,
99 VideoSortComponent,
100 VideoWatchComponent,
101 ],
102 imports: [ // import Angular's modules
103 BrowserModule,
104 FormsModule,
105 ReactiveFormsModule,
106 HttpModule,
107 RouterModule.forRoot(routes),
108
109 ProgressbarModule,
110 PaginationModule
111 ],
112 providers: [ // expose our Services and Providers into Angular's dependency injection
113 ENV_PROVIDERS,
114 APP_PROVIDERS
115 ]
116 })
117 export class AppModule {
118 constructor(public appRef: ApplicationRef, public appState: AppState) {}
119 hmrOnInit(store) {
120 if (!store || !store.state) return;
121 console.log('HMR store', store);
122 this.appState._state = store.state;
123 this.appRef.tick();
124 delete store.state;
125 }
126 hmrOnDestroy(store) {
127 const cmpLocation = this.appRef.components.map(cmp => cmp.location.nativeElement);
128 // recreate elements
129 const state = this.appState._state;
130 store.state = state;
131 store.disposeOldHosts = createNewHosts(cmpLocation);
132 // remove styles
133 removeNgStyles();
134 }
135 hmrAfterDestroy(store) {
136 // display new elements
137 store.disposeOldHosts();
138 delete store.disposeOldHosts;
139 }
140 }