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