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