Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { enableProdMode } from '@angular/core';
- import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
- import { AppModule } from './app/app.module';
- import { environment } from './environments/environment';
- if (environment.production) {
- enableProdMode();
- }
- document.addEventListener('DOMContentLoaded', () => {
- platformBrowserDynamic()
- .bootstrapModule(AppModule)
- .catch(err => console.log(err));
- });
- import { Component, OnDestroy, PLATFORM_ID, Inject, AfterViewInit } from '@angular/core';
- import { ActivatedRoute } from "@angular/router";
- import { isPlatformBrowser, isPlatformServer } from '@angular/common';
- import { Config } from "../../config";
- import { ISubscription } from 'rxjs/Subscription';
- import { generate } from 'rxjs/observable/generate';
- import { Observable } from 'rxjs/Observable';
- // Services
- import { ServerService } from '../../services/server.service';
- import { GetRouteService } from '../../services/getroute.service';
- import { DownloadService } from '../../services/download.service';
- import { trigger, state, style, transition, animate, keyframes, animateChild, query } from '@angular/animations';
- @Component({
- selector: 'app-home',
- templateUrl: './home.component.html',
- providers: [GetRouteService, ServerService],
- animations: [
- trigger('infoCount', [
- transition(":enter", [
- style({
- opacity: 0,
- transform: 'translateX(50%)'
- }),
- animate('600ms', keyframes([
- style({ opacity: 0, transform: 'translateX(5%)', offset: 0 }),
- style({ opacity: 1, transform: 'translateX(-10px)', offset: 0.5 }),
- style({ opacity: 1, transform: 'translateX(0)', offset: 1.0 })
- ]))
- ])
- ]),
- trigger('logoHome', [
- transition(":enter", [
- style({
- opacity: 0,
- transform: 'translateX(50%)'
- }),
- animate('1800ms', keyframes([
- style({ opacity: 0, transform: 'translateY(-5%)', offset: 0 }),
- style({ opacity: 1, transform: 'translateY(10px)', offset: 0.5 }),
- style({ opacity: 1, transform: 'translateY(0)', offset: 1.0 })
- ])),
- query('@imgHome', [
- animateChild()
- ])
- ])
- ]),
- trigger('imgHome', [
- state('1', style({
- transform: 'translateY(0)'
- })),
- state('0', style({
- transform: 'translateY(-6px)'
- })),
- transition('0 => 1', animate('600ms ease-in')),
- transition('1 => 0', animate('600ms ease-out'))
- ])
- ]
- })
- export class HomeComponent implements OnDestroy, AfterViewInit {
- subscription: ISubscription;
- URL: string;
- langUrl: string;
- html: string;
- banner: string[];
- bannerText: Object;
- logo: boolean;
- isDone: boolean = false;
- constructor(@Inject(PLATFORM_ID) private platformId: Object, private route: ActivatedRoute, private service: ServerService, private config: Config, private dl: DownloadService, private getRouteService: GetRouteService) {
- this.URL = this.config.impressURL;
- this.langUrl = this
- .config
- .getLanguage();
- this.subscription = this
- .route
- .params
- .subscribe(params => {
- if (params.lang != this.langUrl) {
- this.langUrl = params.lang;
- if (typeof params.lang != 'undefined')
- this.config.changeLanguage(params.lang);
- }
- let index = '';
- if (typeof params.index == 'undefined')
- index = 'home'
- else
- index = params.index;
- this.getText().then(async (response: string) => {
- this.bannerText = await response;
- this.isDone = !this.isDone;
- }, (error) => {
- console.log("No internet connection");
- });
- if (isPlatformBrowser(this.platformId))
- this.getDataFromIndexedDB(params, index);
- if (isPlatformServer(this.platformId))
- this.getDataFromApi(params, index);
- });
- }
- ngOnInit(): void {
- }
- ngAfterViewInit() {
- }
- ngOnDestroy() {
- if (this.subscription)
- this.subscription.unsubscribe();
- }
- getRoute(event) {
- this
- .getRouteService
- .getRoute(event);
- }
- getBanner(index, lang) {
- return this.service.getResponse(`${this.URL}/api/banner/${index}/${lang}`).toPromise();
- }
- getText() {
- return this.service.getResponse(`${this.URL}/api/homepage`).toPromise();
- }
- getDataFromIndexedDB(params, index) {
- let tempData = this.dl.getItem(this.config.impressURL, index, this.langUrl).then((response: any) => {
- if (response) {
- this.html = response.html;
- }
- else {
- this.service.getResponse(`${this.URL}/api/htmlContent/${index}/${this.langUrl}`).subscribe(response => {
- if (response)
- this.html = response;
- }, (error) => {
- this.html = "<div>Content is currently unavaible</div>";
- });
- }
- }, (error) => {
- this.service.getResponse(`${this.URL}/api/htmlContent/${index}/${this.langUrl}`).subscribe(response => {
- if (response)
- this.html = response;
- }, (error) => {
- this.html = "<div>Content is currently unavaible</div>";
- });
- });
- }
- getDataFromApi(params, index) {
- this.service.getResponse(`${this.URL}/api/htmlContent/${index}/${this.langUrl}`).toPromise().then(async response => {
- this.html = await response;
- }, (error) => {
- this.html = "<div>Content is currently unavaible</div>";
- });
- }
- }
- // Core
- import { BrowserModule, BrowserTransferStateModule } from '@angular/platform-browser';
- import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
- import { NgModule } from '@angular/core';
- import { RouterModule, Routes, PreloadAllModules } from '@angular/router';
- import { ServiceWorkerModule } from '@angular/service-worker';
- import { TransferHttpCacheModule } from '@nguniversal/common';
- import { FormsModule, ReactiveFormsModule, NgForm } from '@angular/forms';
- import { NgForageModule, NgForageConfig, NgForageOptions } from "@ngforage/ngforage-ng5";
- // Config
- import { Config } from './config';
- // Compontents
- import { AppComponent } from './app.component';
- import { ContainerComponent } from './components/container/container.component'
- import { FooterComponent } from './footer/footer.component'
- import { MenuComponent } from './menu/menu.component';
- // Modules
- import { MenuModule } from './menu/menu.module';
- import { ContainerModule } from './components/container/container.module'
- // Environment
- import { environment } from '../environments/environment';
- const routes: Routes = [
- {
- path: '',
- pathMatch: 'full',
- component: ContainerComponent
- },
- {
- path: ':lang',
- component: ContainerComponent
- },
- {
- path: ':lang/:index',
- component: ContainerComponent,
- }
- ];
- @NgModule({
- declarations: [
- AppComponent,
- FooterComponent
- ],
- imports: [
- RouterModule.forRoot(routes, { preloadingStrategy: PreloadAllModules, initialNavigation: 'enabled' }),
- BrowserModule.withServerTransition({ appId: 'main-app' }),
- BrowserTransferStateModule,
- ServiceWorkerModule.register('/ngsw-worker.js', { enabled: environment.production }),
- BrowserAnimationsModule,
- TransferHttpCacheModule,
- MenuModule,
- ContainerModule,
- NgForageModule
- ],
- providers: [
- Config
- ],
- bootstrap: [AppComponent]
- })
- export class AppModule {
- constructor(conf: NgForageConfig) {
- conf.name = 'apiDb';
- conf.storeName = 'apiStore';
- }
- }
- import { NgModule } from '@angular/core';
- import {
- ServerModule,
- ServerTransferStateModule
- } from "@angular/platform-server";
- import { ModuleMapLoaderModule } from '@nguniversal/module-map-ngfactory-loader';
- import { AppModule } from './app.module';
- import { AppComponent } from './app.component';
- import { NoopAnimationsModule } from '@angular/platform-browser/animations';
- @NgModule({
- imports: [
- AppModule,
- ServerModule,
- ServerTransferStateModule,
- ModuleMapLoaderModule,
- NoopAnimationsModule
- ],
- providers: [],
- bootstrap: [ AppComponent ],
- })
- export class AppServerModule {}
Add Comment
Please, Sign In to add comment