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