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