]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/app.module.ts
Client: reactive forms
[github/Chocobozzz/PeerTube.git] / client / src / app / app.module.ts
CommitLineData
ab32b0fc
C
1import { NgModule, ApplicationRef } from '@angular/core';
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
8import { FileSelectDirective } from 'ng2-file-upload/ng2-file-upload';
9import { ProgressbarModule } from 'ng2-bootstrap/components/progressbar';
10import { PaginationModule } from 'ng2-bootstrap/components/pagination';
11import { BytesPipe } from 'angular-pipes/src/math/bytes.pipe';
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';
21import { AccountComponent, AccountService } from './account';
22import { LoginComponent } from './login';
23import {
24 LoaderComponent,
25 VideosComponent,
26 VideoAddComponent,
27 VideoListComponent,
28 VideoMiniatureComponent,
29 VideoSortComponent,
30 VideoWatchComponent,
4b2f33f3
C
31 VideoService,
32 WebTorrentService
ab32b0fc
C
33} from './videos';
34import {
35 FriendsComponent,
36 FriendAddComponent,
37 FriendListComponent,
38 FriendService,
39 UsersComponent,
40 UserAddComponent,
41 UserListComponent,
42 UserService,
43 AdminComponent,
44 MenuAdminComponent
45} from './admin';
46import { MenuComponent } from './menu.component';
47import { AuthService, AuthHttp, RestExtractor, RestService, SearchComponent, SearchService } from './shared';
48
49// Application wide providers
50const 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,
4b2f33f3 63 RestExtractor, RestService, VideoService, SearchService, FriendService, UserService, AccountService, WebTorrentService
ab32b0fc
C
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})
108export 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}