]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/app.module.ts
Client: add more informations to watch video view
[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';
2ac6c525 9import { DropdownModule } from 'ng2-bootstrap/components/dropdown';
ab32b0fc
C
10import { ProgressbarModule } from 'ng2-bootstrap/components/progressbar';
11import { PaginationModule } from 'ng2-bootstrap/components/pagination';
c53d2a4e 12import { FileUploadModule } from 'ng2-file-upload/ng2-file-upload';
ab32b0fc
C
13
14/*
15 * Platform and Environment providers/directives/pipes
16 */
17import { ENV_PROVIDERS } from './environment';
18import { routes } from './app.routes';
19// App is our top level component
20import { AppComponent } from './app.component';
21import { AppState } from './app.service';
23bcf666
C
22
23import {
24 AdminComponent,
25 FriendsComponent,
26 FriendAddComponent,
27 FriendListComponent,
28 FriendService,
29 MenuAdminComponent,
eb4f957e
C
30 RequestsComponent,
31 RequestStatsComponent,
32 RequestService,
23bcf666
C
33 UsersComponent,
34 UserAddComponent,
35 UserListComponent,
36 UserService
37} from './admin';
ab32b0fc
C
38import { AccountComponent, AccountService } from './account';
39import { LoginComponent } from './login';
23bcf666
C
40import { MenuComponent } from './menu.component';
41import { AuthService, AuthHttp, RestExtractor, RestService, SearchComponent, SearchService } from './shared';
ab32b0fc
C
42import {
43 LoaderComponent,
44 VideosComponent,
45 VideoAddComponent,
46 VideoListComponent,
47 VideoMiniatureComponent,
48 VideoSortComponent,
49 VideoWatchComponent,
4b2f33f3
C
50 VideoService,
51 WebTorrentService
ab32b0fc 52} from './videos';
ab32b0fc
C
53
54// Application wide providers
55const APP_PROVIDERS = [
56 AppState,
57
58 {
59 provide: AuthHttp,
60 useFactory: (backend: XHRBackend, defaultOptions: RequestOptions, authService: AuthService) => {
61 return new AuthHttp(backend, defaultOptions, authService);
62 },
63 deps: [ XHRBackend, RequestOptions, AuthService ]
64 },
65
66 AuthService,
67 RestExtractor,
23bcf666
C
68 RestService,
69
70 VideoService,
71 SearchService,
72 FriendService,
eb4f957e 73 RequestService,
23bcf666
C
74 UserService,
75 AccountService,
76 WebTorrentService
ab32b0fc
C
77];
78/**
79 * `AppModule` is the main entry point into Angular2's bootstraping process
80 */
81@NgModule({
82 bootstrap: [ AppComponent ],
83 declarations: [
23bcf666
C
84 AccountComponent,
85 AdminComponent,
ab32b0fc
C
86 AppComponent,
87 BytesPipe,
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
2ac6c525 115 DropdownModule,
ab32b0fc 116 ProgressbarModule,
c53d2a4e
C
117 PaginationModule,
118 FileUploadModule
ab32b0fc
C
119 ],
120 providers: [ // expose our Services and Providers into Angular's dependency injection
121 ENV_PROVIDERS,
122 APP_PROVIDERS
123 ]
124})
125export class AppModule {
126 constructor(public appRef: ApplicationRef, public appState: AppState) {}
127 hmrOnInit(store) {
128 if (!store || !store.state) return;
129 console.log('HMR store', store);
130 this.appState._state = store.state;
131 this.appRef.tick();
132 delete store.state;
133 }
134 hmrOnDestroy(store) {
135 const cmpLocation = this.appRef.components.map(cmp => cmp.location.nativeElement);
136 // recreate elements
137 const state = this.appState._state;
138 store.state = state;
139 store.disposeOldHosts = createNewHosts(cmpLocation);
140 // remove styles
141 removeNgStyles();
142 }
143 hmrAfterDestroy(store) {
144 // display new elements
145 store.disposeOldHosts();
146 delete store.disposeOldHosts;
147 }
148}