From 4d93b6acef52e637a98dd9889f997e60d1760734 Mon Sep 17 00:00:00 2001 From: Sercan Yemen Date: Sun, 1 Jul 2018 14:02:14 +0300 Subject: [PATCH] Added a service for the Loading Bar Added FuseLoadingBarService docs Renamed service docs files --- src/@fuse/fuse.module.ts | 2 + src/@fuse/services/loading-bar.service.ts | 89 +++++++++++++++++++ .../components/toolbar/toolbar.component.ts | 29 ++---- .../services/config/config.component.ts | 17 ---- .../fuse-config.component.html} | 4 +- .../fuse-config.component.scss} | 0 .../fuse-config/fuse-config.component.ts | 17 ++++ .../fuse-loading-bar.component.html | 66 ++++++++++++++ .../fuse-loading-bar.component.scss} | 0 .../fuse-loading-bar.component.ts | 17 ++++ .../fuse-splash-screen.component.html} | 6 +- .../fuse-splash-screen.component.scss | 3 + .../fuse-splash-screen.component.ts | 17 ++++ .../documentation/services/services.module.ts | 24 +++-- .../splash-screen/splash-screen.component.ts | 17 ---- src/app/navigation/navigation.ts | 18 ++-- 16 files changed, 252 insertions(+), 74 deletions(-) create mode 100644 src/@fuse/services/loading-bar.service.ts delete mode 100644 src/app/main/documentation/services/config/config.component.ts rename src/app/main/documentation/services/{config/config.component.html => fuse-config/fuse-config.component.html} (96%) rename src/app/main/documentation/services/{config/config.component.scss => fuse-config/fuse-config.component.scss} (100%) create mode 100644 src/app/main/documentation/services/fuse-config/fuse-config.component.ts create mode 100644 src/app/main/documentation/services/fuse-loading-bar/fuse-loading-bar.component.html rename src/app/main/documentation/services/{splash-screen/splash-screen.component.scss => fuse-loading-bar/fuse-loading-bar.component.scss} (100%) create mode 100644 src/app/main/documentation/services/fuse-loading-bar/fuse-loading-bar.component.ts rename src/app/main/documentation/services/{splash-screen/splash-screen.component.html => fuse-splash-screen/fuse-splash-screen.component.html} (91%) create mode 100644 src/app/main/documentation/services/fuse-splash-screen/fuse-splash-screen.component.scss create mode 100644 src/app/main/documentation/services/fuse-splash-screen/fuse-splash-screen.component.ts delete mode 100644 src/app/main/documentation/services/splash-screen/splash-screen.component.ts diff --git a/src/@fuse/fuse.module.ts b/src/@fuse/fuse.module.ts index 7571fbe0..c25a483e 100644 --- a/src/@fuse/fuse.module.ts +++ b/src/@fuse/fuse.module.ts @@ -2,6 +2,7 @@ import { ModuleWithProviders, NgModule, Optional, SkipSelf } from '@angular/core import { FUSE_CONFIG, FuseConfigService } from '@fuse/services/config.service'; import { FuseCopierService } from '@fuse/services/copier.service'; +import { FuseLoadingBarService } from '@fuse/services/loading-bar.service'; import { FuseMatchMediaService } from '@fuse/services/match-media.service'; import { FuseMatSidenavHelperService } from '@fuse/directives/fuse-mat-sidenav/fuse-mat-sidenav.service'; import { FuseNavigationService } from '@fuse/components/navigation/navigation.service'; @@ -14,6 +15,7 @@ import { FuseTranslationLoaderService } from '@fuse/services/translation-loader. providers : [ FuseConfigService, FuseCopierService, + FuseLoadingBarService, FuseMatchMediaService, FuseMatSidenavHelperService, FuseNavigationService, diff --git a/src/@fuse/services/loading-bar.service.ts b/src/@fuse/services/loading-bar.service.ts new file mode 100644 index 00000000..81de5ced --- /dev/null +++ b/src/@fuse/services/loading-bar.service.ts @@ -0,0 +1,89 @@ +import { Injectable } from '@angular/core'; +import { NavigationEnd, NavigationStart, Router } from '@angular/router'; +import { BehaviorSubject, Observable } from 'rxjs'; +import { filter, takeUntil } from 'rxjs/operators'; + +@Injectable() +export class FuseLoadingBarService +{ + // Private + private _visible: BehaviorSubject; + + /** + * Constructor + * + * @param {Router} _router + */ + constructor( + private _router: Router + ) + { + // Initialize the service + this._init(); + } + + // ----------------------------------------------------------------------------------------------------- + // @ Accessors + // ----------------------------------------------------------------------------------------------------- + + get visible(): Observable + { + // Return the _visible as observable + return this._visible.asObservable(); + } + + // ----------------------------------------------------------------------------------------------------- + // @ Private methods + // ----------------------------------------------------------------------------------------------------- + + /** + * Initialize + * + * @private + */ + private _init(): void + { + // Initialize the behavior subject + this._visible = new BehaviorSubject(false); + + // Subscribe to the router events to show/hide the loading bar + this._router.events + .pipe( + filter((event) => event instanceof NavigationStart) + ) + .subscribe(() => { + this.showLoadingBar(); + }); + + this._router.events + .pipe( + filter((event) => event instanceof NavigationEnd) + ) + .subscribe(() => { + this.hideLoadingBar(); + }); + } + + // ----------------------------------------------------------------------------------------------------- + // @ Public methods + // ----------------------------------------------------------------------------------------------------- + + /** + * Show the loading bar + */ + showLoadingBar(): void + { + // Show + this._visible.next(true); + } + + /** + * Hide the loading bar + */ + hideLoadingBar(): void + { + // Hide + this._visible.next(false); + } +} + diff --git a/src/app/layout/components/toolbar/toolbar.component.ts b/src/app/layout/components/toolbar/toolbar.component.ts index 3783d894..20c5a5a2 100644 --- a/src/app/layout/components/toolbar/toolbar.component.ts +++ b/src/app/layout/components/toolbar/toolbar.component.ts @@ -1,7 +1,6 @@ import { Component, OnDestroy, OnInit } from '@angular/core'; -import { NavigationEnd, NavigationStart, Router } from '@angular/router'; import { Subject } from 'rxjs'; -import { filter, takeUntil } from 'rxjs/operators'; +import { takeUntil } from 'rxjs/operators'; import { TranslateService } from '@ngx-translate/core'; import * as _ from 'lodash'; @@ -9,6 +8,7 @@ import { FuseConfigService } from '@fuse/services/config.service'; import { FuseSidebarService } from '@fuse/components/sidebar/sidebar.service'; import { navigation } from 'app/navigation/navigation'; +import { FuseLoadingBarService } from '@fuse/services/loading-bar.service'; @Component({ selector : 'toolbar', @@ -34,14 +34,14 @@ export class ToolbarComponent implements OnInit, OnDestroy * Constructor * * @param {FuseConfigService} _fuseConfigService + * @param {FuseLoadingBarService} _fuseLoadingBarService * @param {FuseSidebarService} _fuseSidebarService - * @param {Router} _router * @param {TranslateService} _translateService */ constructor( private _fuseConfigService: FuseConfigService, + private _fuseLoadingBarService: FuseLoadingBarService, private _fuseSidebarService: FuseSidebarService, - private _router: Router, private _translateService: TranslateService ) { @@ -102,22 +102,11 @@ export class ToolbarComponent implements OnInit, OnDestroy */ ngOnInit(): void { - // Subscribe to the router events to show/hide the loading bar - this._router.events - .pipe( - filter((event) => event instanceof NavigationStart), - takeUntil(this._unsubscribeAll) - ) - .subscribe((event) => { - this.showLoadingBar = true; - }); - - this._router.events - .pipe( - filter((event) => event instanceof NavigationEnd) - ) - .subscribe((event) => { - this.showLoadingBar = false; + // Subscribe to the Fuse loading bar service + this._fuseLoadingBarService.visible + .pipe(takeUntil(this._unsubscribeAll)) + .subscribe((visible) => { + this.showLoadingBar = visible; }); // Subscribe to the config changes diff --git a/src/app/main/documentation/services/config/config.component.ts b/src/app/main/documentation/services/config/config.component.ts deleted file mode 100644 index d2fe116a..00000000 --- a/src/app/main/documentation/services/config/config.component.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { Component } from '@angular/core'; - -@Component({ - selector : 'config-service-docs', - templateUrl: './config.component.html', - styleUrls : ['./config.component.scss'] -}) -export class ConfigServiceDocsComponent -{ - /** - * Constructor - */ - constructor() - { - - } -} diff --git a/src/app/main/documentation/services/config/config.component.html b/src/app/main/documentation/services/fuse-config/fuse-config.component.html similarity index 96% rename from src/app/main/documentation/services/config/config.component.html rename to src/app/main/documentation/services/fuse-config/fuse-config.component.html index ed9f752d..92d69195 100644 --- a/src/app/main/documentation/services/config/config.component.html +++ b/src/app/main/documentation/services/fuse-config/fuse-config.component.html @@ -1,4 +1,4 @@ -
+
@@ -10,7 +10,7 @@ chevron_right Services
-
Config
+
Fuse Config
diff --git a/src/app/main/documentation/services/config/config.component.scss b/src/app/main/documentation/services/fuse-config/fuse-config.component.scss similarity index 100% rename from src/app/main/documentation/services/config/config.component.scss rename to src/app/main/documentation/services/fuse-config/fuse-config.component.scss diff --git a/src/app/main/documentation/services/fuse-config/fuse-config.component.ts b/src/app/main/documentation/services/fuse-config/fuse-config.component.ts new file mode 100644 index 00000000..6682ea91 --- /dev/null +++ b/src/app/main/documentation/services/fuse-config/fuse-config.component.ts @@ -0,0 +1,17 @@ +import { Component } from '@angular/core'; + +@Component({ + selector : 'fuse-config-service-docs', + templateUrl: './fuse-config.component.html', + styleUrls : ['./fuse-config.component.scss'] +}) +export class FuseConfigServiceDocsComponent +{ + /** + * Constructor + */ + constructor() + { + + } +} diff --git a/src/app/main/documentation/services/fuse-loading-bar/fuse-loading-bar.component.html b/src/app/main/documentation/services/fuse-loading-bar/fuse-loading-bar.component.html new file mode 100644 index 00000000..ee110003 --- /dev/null +++ b/src/app/main/documentation/services/fuse-loading-bar/fuse-loading-bar.component.html @@ -0,0 +1,66 @@ +
+ + +
+
+
+ home + chevron_right + Documentation + chevron_right + Services +
+
Fuse Loading Bar
+
+
+ + + +
+ +

+ Loading bar is a custom Fuse service that allows to have a control on the loading bar that is + placed in the Toolbar by default. +

+ +
Usage
+

+ + + + + +

+ +
+ +
+ diff --git a/src/app/main/documentation/services/splash-screen/splash-screen.component.scss b/src/app/main/documentation/services/fuse-loading-bar/fuse-loading-bar.component.scss similarity index 100% rename from src/app/main/documentation/services/splash-screen/splash-screen.component.scss rename to src/app/main/documentation/services/fuse-loading-bar/fuse-loading-bar.component.scss diff --git a/src/app/main/documentation/services/fuse-loading-bar/fuse-loading-bar.component.ts b/src/app/main/documentation/services/fuse-loading-bar/fuse-loading-bar.component.ts new file mode 100644 index 00000000..aaa838b5 --- /dev/null +++ b/src/app/main/documentation/services/fuse-loading-bar/fuse-loading-bar.component.ts @@ -0,0 +1,17 @@ +import { Component } from '@angular/core'; + +@Component({ + selector : 'fuse-loading-bar-service-docs', + templateUrl: './fuse-loading-bar.component.html', + styleUrls : ['./fuse-loading-bar.component.scss'] +}) +export class FuseLoadingBarServiceDocsComponent +{ + /** + * Constructor + */ + constructor() + { + + } +} diff --git a/src/app/main/documentation/services/splash-screen/splash-screen.component.html b/src/app/main/documentation/services/fuse-splash-screen/fuse-splash-screen.component.html similarity index 91% rename from src/app/main/documentation/services/splash-screen/splash-screen.component.html rename to src/app/main/documentation/services/fuse-splash-screen/fuse-splash-screen.component.html index f35a2e70..7c268f16 100644 --- a/src/app/main/documentation/services/splash-screen/splash-screen.component.html +++ b/src/app/main/documentation/services/fuse-splash-screen/fuse-splash-screen.component.html @@ -10,7 +10,7 @@ chevron_right Services -
Splash Screen
+
Fuse Splash Screen
@@ -28,13 +28,13 @@