]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/app.module.ts
Client: move video watch modals in their own component
[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
10 import { DropdownModule } from 'ng2-bootstrap/components/dropdown';
11 import { ProgressbarModule } from 'ng2-bootstrap/components/progressbar';
12 import { PaginationModule } from 'ng2-bootstrap/components/pagination';
13 import { ModalModule } from 'ng2-bootstrap/components/modal';
14
15 import { FileUploadModule } from 'ng2-file-upload/ng2-file-upload';
16
17 import { MetaConfig, MetaModule } from 'ng2-meta';
18
19 /*
20 * Platform and Environment providers/directives/pipes
21 */
22 import { ENV_PROVIDERS } from './environment';
23 import { routes } from './app.routes';
24 // App is our top level component
25 import { AppComponent } from './app.component';
26 import { AppState } from './app.service';
27
28 import {
29 AdminComponent,
30 FriendsComponent,
31 FriendAddComponent,
32 FriendListComponent,
33 FriendService,
34 MenuAdminComponent,
35 RequestsComponent,
36 RequestStatsComponent,
37 RequestService,
38 UsersComponent,
39 UserAddComponent,
40 UserListComponent,
41 UserService
42 } from './admin';
43 import { AccountComponent, AccountService } from './account';
44 import { LoginComponent } from './login';
45 import { MenuComponent } from './menu.component';
46 import { AuthService, AuthHttp, RestExtractor, RestService, SearchComponent, SearchService } from './shared';
47 import {
48 LoaderComponent,
49 VideosComponent,
50 VideoAddComponent,
51 VideoListComponent,
52 VideoMiniatureComponent,
53 VideoSortComponent,
54 VideoWatchComponent,
55 VideoShareComponent,
56 VideoMagnetComponent,
57 VideoService,
58 WebTorrentService
59 } from './videos';
60
61 const metaConfig: MetaConfig = {
62 //Append a title suffix such as a site name to all titles
63 //Defaults to false
64 useTitleSuffix: true,
65 defaults: {
66 title: 'PeerTube'
67 }
68 };
69
70 // Application wide providers
71 const APP_PROVIDERS = [
72 AppState,
73
74 {
75 provide: AuthHttp,
76 useFactory: (backend: XHRBackend, defaultOptions: RequestOptions, authService: AuthService) => {
77 return new AuthHttp(backend, defaultOptions, authService);
78 },
79 deps: [ XHRBackend, RequestOptions, AuthService ]
80 },
81
82 AuthService,
83 RestExtractor,
84 RestService,
85
86 VideoService,
87 SearchService,
88 FriendService,
89 RequestService,
90 UserService,
91 AccountService,
92 WebTorrentService
93 ];
94 /**
95 * `AppModule` is the main entry point into Angular2's bootstraping process
96 */
97 @NgModule({
98 bootstrap: [ AppComponent ],
99 declarations: [
100 AccountComponent,
101 AdminComponent,
102 AppComponent,
103 BytesPipe,
104 FriendAddComponent,
105 FriendListComponent,
106 FriendsComponent,
107 LoaderComponent,
108 LoginComponent,
109 MenuAdminComponent,
110 MenuComponent,
111 RequestsComponent,
112 RequestStatsComponent,
113 SearchComponent,
114 UserAddComponent,
115 UserListComponent,
116 UsersComponent,
117 VideoAddComponent,
118 VideoListComponent,
119 VideoMiniatureComponent,
120 VideosComponent,
121 VideoSortComponent,
122 VideoWatchComponent,
123 VideoShareComponent,
124 VideoMagnetComponent
125 ],
126 imports: [ // import Angular's modules
127 BrowserModule,
128 FormsModule,
129 ReactiveFormsModule,
130 HttpModule,
131 RouterModule.forRoot(routes),
132
133 DropdownModule,
134 ProgressbarModule,
135 PaginationModule,
136 ModalModule,
137
138 FileUploadModule,
139
140 MetaModule.forRoot(metaConfig)
141 ],
142 providers: [ // expose our Services and Providers into Angular's dependency injection
143 ENV_PROVIDERS,
144 APP_PROVIDERS
145 ]
146 })
147 export class AppModule {
148 constructor(public appRef: ApplicationRef, public appState: AppState) {}
149 hmrOnInit(store) {
150 if (!store || !store.state) return;
151 console.log('HMR store', store);
152 this.appState._state = store.state;
153 this.appRef.tick();
154 delete store.state;
155 }
156 hmrOnDestroy(store) {
157 const cmpLocation = this.appRef.components.map(cmp => cmp.location.nativeElement);
158 // recreate elements
159 const state = this.appState._state;
160 store.state = state;
161 store.disposeOldHosts = createNewHosts(cmpLocation);
162 // remove styles
163 removeNgStyles();
164 }
165 hmrAfterDestroy(store) {
166 // display new elements
167 store.disposeOldHosts();
168 delete store.disposeOldHosts;
169 }
170 }