refractor: shell (#287)
* Refractor components. * Shift theme picker component to shared module. * Shift progress bar service into its own folder. * Add footer to app shell. * Replace mat-icon by font-awesome icons. * Fix sidenav visibility bug for handsets. * Add comments. Closes #286, Fixes #285
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
import { TestBed, inject } from '@angular/core/testing';
|
||||
|
||||
import { ProgressBarService } from './progress-bar.service';
|
||||
|
||||
describe('ProgressBarService', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [ProgressBarService]
|
||||
});
|
||||
});
|
||||
|
||||
it('should be created', inject([ProgressBarService], (service: ProgressBarService) => {
|
||||
expect(service).toBeTruthy();
|
||||
}));
|
||||
});
|
||||
@@ -0,0 +1,35 @@
|
||||
import { Injectable, EventEmitter } from '@angular/core';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class ProgressBarService {
|
||||
|
||||
public updateProgressBar: EventEmitter<any>;
|
||||
private requestsRunning = 0;
|
||||
|
||||
constructor() {
|
||||
this.updateProgressBar = new EventEmitter();
|
||||
}
|
||||
|
||||
public getRequestsRunning(): number {
|
||||
return this.requestsRunning;
|
||||
}
|
||||
|
||||
public increase(): void {
|
||||
this.requestsRunning++;
|
||||
if (this.requestsRunning === 1) {
|
||||
this.updateProgressBar.emit('indeterminate');
|
||||
}
|
||||
}
|
||||
|
||||
public decrease(): void {
|
||||
if (this.requestsRunning > 0) {
|
||||
this.requestsRunning--;
|
||||
if (this.requestsRunning === 0) {
|
||||
this.updateProgressBar.emit('none');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import {HttpEvent, HttpHandler, HttpInterceptor, HttpRequest, HttpResponse} from '@angular/common/http';
|
||||
|
||||
import { Observable } from 'rxjs';
|
||||
import { tap, catchError } from 'rxjs/operators';
|
||||
|
||||
import { ProgressBarService } from './progress-bar.service';
|
||||
|
||||
@Injectable()
|
||||
export class ProgressInterceptor implements HttpInterceptor {
|
||||
|
||||
constructor(private progressBarService: ProgressBarService) { }
|
||||
|
||||
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
|
||||
this.progressBarService.increase();
|
||||
return next.handle(request)
|
||||
.pipe(
|
||||
tap(event => {
|
||||
if (event instanceof HttpResponse) {
|
||||
this.progressBarService.decrease();
|
||||
}
|
||||
})
|
||||
)
|
||||
.pipe(
|
||||
catchError(error => {
|
||||
this.progressBarService.decrease();
|
||||
throw error;
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user