Guest User

Untitled

a guest
Mar 19th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.03 KB | None | 0 0
  1. import { enableProdMode } from '@angular/core';
  2. import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
  3. import { AppModule } from './app/app.module';
  4. import { environment } from './environments/environment';
  5.  
  6. if (environment.production) {
  7. enableProdMode();
  8. }
  9.  
  10. document.addEventListener('DOMContentLoaded', () => {
  11. platformBrowserDynamic()
  12. .bootstrapModule(AppModule)
  13. .catch(err => console.log(err));
  14. });
  15.  
  16. import { Component, OnDestroy, PLATFORM_ID, Inject, AfterViewInit } from '@angular/core';
  17. import { ActivatedRoute } from "@angular/router";
  18. import { isPlatformBrowser, isPlatformServer } from '@angular/common';
  19. import { Config } from "../../config";
  20. import { ISubscription } from 'rxjs/Subscription';
  21. import { generate } from 'rxjs/observable/generate';
  22. import { Observable } from 'rxjs/Observable';
  23. // Services
  24.  
  25. import { ServerService } from '../../services/server.service';
  26. import { GetRouteService } from '../../services/getroute.service';
  27. import { DownloadService } from '../../services/download.service';
  28.  
  29. import { trigger, state, style, transition, animate, keyframes, animateChild, query } from '@angular/animations';
  30.  
  31.  
  32.  
  33. @Component({
  34. selector: 'app-home',
  35. templateUrl: './home.component.html',
  36. providers: [GetRouteService, ServerService],
  37. animations: [
  38. trigger('infoCount', [
  39. transition(":enter", [
  40. style({
  41. opacity: 0,
  42. transform: 'translateX(50%)'
  43. }),
  44. animate('600ms', keyframes([
  45. style({ opacity: 0, transform: 'translateX(5%)', offset: 0 }),
  46. style({ opacity: 1, transform: 'translateX(-10px)', offset: 0.5 }),
  47. style({ opacity: 1, transform: 'translateX(0)', offset: 1.0 })
  48. ]))
  49. ])
  50. ]),
  51. trigger('logoHome', [
  52. transition(":enter", [
  53. style({
  54. opacity: 0,
  55. transform: 'translateX(50%)'
  56. }),
  57. animate('1800ms', keyframes([
  58. style({ opacity: 0, transform: 'translateY(-5%)', offset: 0 }),
  59. style({ opacity: 1, transform: 'translateY(10px)', offset: 0.5 }),
  60. style({ opacity: 1, transform: 'translateY(0)', offset: 1.0 })
  61. ])),
  62. query('@imgHome', [
  63. animateChild()
  64. ])
  65. ])
  66. ]),
  67. trigger('imgHome', [
  68. state('1', style({
  69. transform: 'translateY(0)'
  70. })),
  71. state('0', style({
  72. transform: 'translateY(-6px)'
  73. })),
  74. transition('0 => 1', animate('600ms ease-in')),
  75. transition('1 => 0', animate('600ms ease-out'))
  76.  
  77. ])
  78. ]
  79. })
  80.  
  81. export class HomeComponent implements OnDestroy, AfterViewInit {
  82. subscription: ISubscription;
  83. URL: string;
  84. langUrl: string;
  85. html: string;
  86. banner: string[];
  87. bannerText: Object;
  88. logo: boolean;
  89. isDone: boolean = false;
  90.  
  91. constructor(@Inject(PLATFORM_ID) private platformId: Object, private route: ActivatedRoute, private service: ServerService, private config: Config, private dl: DownloadService, private getRouteService: GetRouteService) {
  92. this.URL = this.config.impressURL;
  93. this.langUrl = this
  94. .config
  95. .getLanguage();
  96.  
  97. this.subscription = this
  98. .route
  99. .params
  100. .subscribe(params => {
  101.  
  102. if (params.lang != this.langUrl) {
  103. this.langUrl = params.lang;
  104. if (typeof params.lang != 'undefined')
  105. this.config.changeLanguage(params.lang);
  106. }
  107.  
  108. let index = '';
  109. if (typeof params.index == 'undefined')
  110. index = 'home'
  111. else
  112. index = params.index;
  113.  
  114.  
  115.  
  116. this.getText().then(async (response: string) => {
  117. this.bannerText = await response;
  118. this.isDone = !this.isDone;
  119. }, (error) => {
  120. console.log("No internet connection");
  121. });
  122.  
  123. if (isPlatformBrowser(this.platformId))
  124. this.getDataFromIndexedDB(params, index);
  125.  
  126.  
  127. if (isPlatformServer(this.platformId))
  128. this.getDataFromApi(params, index);
  129.  
  130.  
  131. });
  132. }
  133.  
  134. ngOnInit(): void {
  135. }
  136.  
  137. ngAfterViewInit() {
  138.  
  139. }
  140.  
  141. ngOnDestroy() {
  142. if (this.subscription)
  143. this.subscription.unsubscribe();
  144. }
  145.  
  146. getRoute(event) {
  147. this
  148. .getRouteService
  149. .getRoute(event);
  150. }
  151.  
  152. getBanner(index, lang) {
  153. return this.service.getResponse(`${this.URL}/api/banner/${index}/${lang}`).toPromise();
  154. }
  155.  
  156. getText() {
  157. return this.service.getResponse(`${this.URL}/api/homepage`).toPromise();
  158. }
  159.  
  160. getDataFromIndexedDB(params, index) {
  161.  
  162. let tempData = this.dl.getItem(this.config.impressURL, index, this.langUrl).then((response: any) => {
  163. if (response) {
  164. this.html = response.html;
  165. }
  166. else {
  167.  
  168. this.service.getResponse(`${this.URL}/api/htmlContent/${index}/${this.langUrl}`).subscribe(response => {
  169. if (response)
  170. this.html = response;
  171. }, (error) => {
  172. this.html = "<div>Content is currently unavaible</div>";
  173. });
  174. }
  175. }, (error) => {
  176. this.service.getResponse(`${this.URL}/api/htmlContent/${index}/${this.langUrl}`).subscribe(response => {
  177. if (response)
  178. this.html = response;
  179. }, (error) => {
  180. this.html = "<div>Content is currently unavaible</div>";
  181. });
  182. });
  183. }
  184.  
  185. getDataFromApi(params, index) {
  186. this.service.getResponse(`${this.URL}/api/htmlContent/${index}/${this.langUrl}`).toPromise().then(async response => {
  187. this.html = await response;
  188. }, (error) => {
  189. this.html = "<div>Content is currently unavaible</div>";
  190. });
  191. }
  192.  
  193. }
  194.  
  195. // Core
  196. import { BrowserModule, BrowserTransferStateModule } from '@angular/platform-browser';
  197. import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
  198. import { NgModule } from '@angular/core';
  199. import { RouterModule, Routes, PreloadAllModules } from '@angular/router';
  200. import { ServiceWorkerModule } from '@angular/service-worker';
  201. import { TransferHttpCacheModule } from '@nguniversal/common';
  202. import { FormsModule, ReactiveFormsModule, NgForm } from '@angular/forms';
  203. import { NgForageModule, NgForageConfig, NgForageOptions } from "@ngforage/ngforage-ng5";
  204.  
  205. // Config
  206. import { Config } from './config';
  207.  
  208.  
  209. // Compontents
  210. import { AppComponent } from './app.component';
  211. import { ContainerComponent } from './components/container/container.component'
  212. import { FooterComponent } from './footer/footer.component'
  213. import { MenuComponent } from './menu/menu.component';
  214.  
  215.  
  216. // Modules
  217. import { MenuModule } from './menu/menu.module';
  218. import { ContainerModule } from './components/container/container.module'
  219.  
  220.  
  221. // Environment
  222. import { environment } from '../environments/environment';
  223.  
  224.  
  225.  
  226.  
  227. const routes: Routes = [
  228. {
  229. path: '',
  230. pathMatch: 'full',
  231. component: ContainerComponent
  232. },
  233. {
  234. path: ':lang',
  235. component: ContainerComponent
  236. },
  237. {
  238. path: ':lang/:index',
  239. component: ContainerComponent,
  240. }
  241. ];
  242.  
  243.  
  244. @NgModule({
  245. declarations: [
  246. AppComponent,
  247. FooterComponent
  248. ],
  249. imports: [
  250. RouterModule.forRoot(routes, { preloadingStrategy: PreloadAllModules, initialNavigation: 'enabled' }),
  251. BrowserModule.withServerTransition({ appId: 'main-app' }),
  252. BrowserTransferStateModule,
  253. ServiceWorkerModule.register('/ngsw-worker.js', { enabled: environment.production }),
  254. BrowserAnimationsModule,
  255. TransferHttpCacheModule,
  256. MenuModule,
  257. ContainerModule,
  258. NgForageModule
  259.  
  260. ],
  261. providers: [
  262. Config
  263. ],
  264. bootstrap: [AppComponent]
  265. })
  266.  
  267.  
  268.  
  269. export class AppModule {
  270.  
  271. constructor(conf: NgForageConfig) {
  272. conf.name = 'apiDb';
  273. conf.storeName = 'apiStore';
  274. }
  275. }
  276.  
  277. import { NgModule } from '@angular/core';
  278. import {
  279. ServerModule,
  280. ServerTransferStateModule
  281. } from "@angular/platform-server";
  282. import { ModuleMapLoaderModule } from '@nguniversal/module-map-ngfactory-loader';
  283. import { AppModule } from './app.module';
  284. import { AppComponent } from './app.component';
  285. import { NoopAnimationsModule } from '@angular/platform-browser/animations';
  286.  
  287. @NgModule({
  288. imports: [
  289. AppModule,
  290. ServerModule,
  291. ServerTransferStateModule,
  292. ModuleMapLoaderModule,
  293. NoopAnimationsModule
  294. ],
  295. providers: [],
  296. bootstrap: [ AppComponent ],
  297. })
  298. export class AppServerModule {}
Add Comment
Please, Sign In to add comment