]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/app.module.ts
Client: fix search dropdown
[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 import { DropdownModule } from 'ng2-bootstrap/components/dropdown';
10 import { ProgressbarModule } from 'ng2-bootstrap/components/progressbar';
11 import { PaginationModule } from 'ng2-bootstrap/components/pagination';
12 import { FileUploadModule } from 'ng2-file-upload/ng2-file-upload';
13
14 /*
15 * Platform and Environment providers/directives/pipes
16 */
17 import { ENV_PROVIDERS } from './environment';
18 import { routes } from './app.routes';
19 // App is our top level component
20 import { AppComponent } from './app.component';
21 import { AppState } from './app.service';
22
23 import {
24 AdminComponent,
25 FriendsComponent,
26 FriendAddComponent,
27 FriendListComponent,
28 FriendService,
29 MenuAdminComponent,
30 RequestsComponent,
31 RequestStatsComponent,
32 RequestService,
33 UsersComponent,
34 UserAddComponent,
35 UserListComponent,
36 UserService
37 } from './admin';
38 import { AccountComponent, AccountService } from './account';
39 import { LoginComponent } from './login';
40 import { MenuComponent } from './menu.component';
41 import { AuthService, AuthHttp, RestExtractor, RestService, SearchComponent, SearchService } from './shared';
42 import {
43 LoaderComponent,
44 VideosComponent,
45 VideoAddComponent,
46 VideoListComponent,
47 VideoMiniatureComponent,
48 VideoSortComponent,
49 VideoWatchComponent,
50 VideoService,
51 WebTorrentService
52 } from './videos';
53
54 // Application wide providers
55 const 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,
68 RestService,
69
70 VideoService,
71 SearchService,
72 FriendService,
73 RequestService,
74 UserService,
75 AccountService,
76 WebTorrentService
77 ];
78 /**
79 * `AppModule` is the main entry point into Angular2's bootstraping process
80 */
81 @NgModule({
82 bootstrap: [ AppComponent ],
83 declarations: [
84 AccountComponent,
85 AdminComponent,
86 AppComponent,
87 BytesPipe,
88 FriendAddComponent,
89 FriendListComponent,
90 FriendsComponent,
91 LoaderComponent,
92 LoginComponent,
93 MenuAdminComponent,
94 MenuComponent,
95 RequestsComponent,
96 RequestStatsComponent,
97 SearchComponent,
98 UserAddComponent,
99 UserListComponent,
100 UsersComponent,
101 VideoAddComponent,
102 VideoListComponent,
103 VideoMiniatureComponent,
104 VideosComponent,
105 VideoSortComponent,
106 VideoWatchComponent,
107 ],
108 imports: [ // import Angular's modules
109 BrowserModule,
110 FormsModule,
111 ReactiveFormsModule,
112 HttpModule,
113 RouterModule.forRoot(routes),
114
115 DropdownModule,
116 ProgressbarModule,
117 PaginationModule,
118 FileUploadModule
119 ],
120 providers: [ // expose our Services and Providers into Angular's dependency injection
121 ENV_PROVIDERS,
122 APP_PROVIDERS
123 ]
124 })
125 export 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 }