-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
116 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,45 @@ | ||
import { Injectable } from '@angular/core'; | ||
|
||
@Injectable({ providedIn: 'root' }) | ||
export class BarService { | ||
value = 0; | ||
progress = 0; | ||
interval!: number; | ||
|
||
start(): void { | ||
this.interval = setInterval(() => { | ||
this.value += 0.015; | ||
this.progress = | ||
Math.round((Math.atan(this.value) / (Math.PI / 2)) * 100 * 1000) / 1000; | ||
if (this.progress >= 100) { | ||
clearInterval(this.interval); | ||
} | ||
}, 150); | ||
} | ||
|
||
stop(): void { | ||
clearInterval(this.interval); | ||
} | ||
|
||
async complete(): Promise<unknown> { | ||
this.set(99); | ||
return new Promise(resolve => { | ||
setTimeout(() => { | ||
clearInterval(this.interval); | ||
this.progress = 0; | ||
this.value = 0; | ||
resolve(); | ||
}, 200); | ||
}); | ||
} | ||
|
||
set(value: number): void { | ||
this.progress = value; | ||
this.value = Math.tan((value / 100) * (Math.PI / 2)); | ||
} | ||
|
||
increment(value: number): void { | ||
this.progress += value; | ||
this.value = Math.tan((this.progress / 100) * (Math.PI / 2)); | ||
} | ||
} | ||
import { Injectable } from '@angular/core'; | ||
|
||
@Injectable({ providedIn: 'root' }) | ||
export class BarService { | ||
value = 0; | ||
progress = 0; | ||
interval!: number; | ||
|
||
start(): void { | ||
this.interval = setInterval(() => { | ||
this.value += 0.015; | ||
this.progress = | ||
Math.round((Math.atan(this.value) / (Math.PI / 2)) * 100 * 1000) / 1000; | ||
if (this.progress >= 100) { | ||
clearInterval(this.interval); | ||
} | ||
}, 150); | ||
} | ||
|
||
stop(): void { | ||
clearInterval(this.interval); | ||
} | ||
|
||
async complete(): Promise<unknown> { | ||
this.set(99); | ||
return new Promise<void>(resolve => { | ||
setTimeout(() => { | ||
clearInterval(this.interval); | ||
this.progress = 0; | ||
this.value = 0; | ||
resolve(); | ||
}, 200); | ||
}); | ||
} | ||
|
||
set(value: number): void { | ||
this.progress = value; | ||
this.value = Math.tan((value / 100) * (Math.PI / 2)); | ||
} | ||
|
||
increment(value: number): void { | ||
this.progress += value; | ||
this.value = Math.tan((this.progress / 100) * (Math.PI / 2)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,69 @@ | ||
import { | ||
HttpEvent, | ||
HttpHandler, | ||
HttpInterceptor, | ||
HttpRequest, | ||
HttpResponse, | ||
} from '@angular/common/http'; | ||
import { Inject, Injectable } from '@angular/core'; | ||
import { Observable, of } from 'rxjs'; | ||
import { catchError, map } from 'rxjs/operators'; | ||
import { NgxProgressService } from './ngx-progress.service'; | ||
import { WHITELIST } from './symbols'; | ||
|
||
@Injectable() | ||
export class NgxProgressInterceptor implements HttpInterceptor { | ||
// tslint:disable-next-line:variable-name | ||
#_regexUrl: RegExp[] = []; | ||
/** | ||
* Is done the mapping from string to regex on variable assignment | ||
* @param patterns: the whitelist | ||
*/ | ||
set regexUrl(patterns: string[]) { | ||
this.#_regexUrl = patterns.map(p => new RegExp(p)); | ||
} | ||
|
||
constructor( | ||
private readonly progressService: NgxProgressService, | ||
@Inject(WHITELIST) private readonly whitelist: string[], | ||
) { | ||
this.regexUrl = whitelist; | ||
} | ||
|
||
intercept( | ||
request: HttpRequest<any>, | ||
next: HttpHandler, | ||
): Observable<HttpEvent<any>> { | ||
for (const regexUrlItem of this.#_regexUrl) { | ||
if (regexUrlItem.test(request.url)) { | ||
return next.handle(request); | ||
} | ||
} | ||
this.progressService.start(); | ||
return next.handle(request).pipe( | ||
map(event => { | ||
if (event instanceof HttpResponse) { | ||
this.progressService.end(); | ||
} | ||
return event; | ||
}), | ||
); | ||
} | ||
} | ||
|
||
@Injectable() | ||
export class ErrorInterceptor implements HttpInterceptor { | ||
constructor(private readonly progressService: NgxProgressService) {} | ||
|
||
intercept( | ||
request: HttpRequest<any>, | ||
next: HttpHandler, | ||
): Observable<HttpEvent<any>> { | ||
return next.handle(request).pipe( | ||
catchError(err => { | ||
this.progressService.terminate(); | ||
return of(err); | ||
}), | ||
); | ||
} | ||
} | ||
import { | ||
HttpEvent, | ||
HttpHandler, | ||
HttpInterceptor, | ||
HttpRequest, | ||
HttpResponse, | ||
} from '@angular/common/http'; | ||
import { Inject, Injectable } from '@angular/core'; | ||
import { Observable, of, throwError } from "rxjs"; | ||
import { catchError, map } from 'rxjs/operators'; | ||
import { NgxProgressService } from './ngx-progress.service'; | ||
import { WHITELIST } from './symbols'; | ||
|
||
@Injectable() | ||
export class NgxProgressInterceptor implements HttpInterceptor { | ||
// tslint:disable-next-line:variable-name | ||
#_regexUrl: RegExp[] = []; | ||
/** | ||
* Is done the mapping from string to regex on variable assignment | ||
* @param patterns: the whitelist | ||
*/ | ||
set regexUrl(patterns: string[]) { | ||
this.#_regexUrl = patterns.map(p => new RegExp(p)); | ||
} | ||
|
||
constructor( | ||
private readonly progressService: NgxProgressService, | ||
@Inject(WHITELIST) private readonly whitelist: string[], | ||
) { | ||
this.regexUrl = whitelist; | ||
} | ||
|
||
intercept( | ||
request: HttpRequest<any>, | ||
next: HttpHandler, | ||
): Observable<HttpEvent<any>> { | ||
for (const regexUrlItem of this.#_regexUrl) { | ||
if (regexUrlItem.test(request.url)) { | ||
return next.handle(request); | ||
} | ||
} | ||
this.progressService.start(); | ||
return next.handle(request).pipe( | ||
map(event => { | ||
if (event instanceof HttpResponse) { | ||
this.progressService.end(); | ||
} | ||
return event; | ||
}), | ||
); | ||
} | ||
} | ||
|
||
@Injectable() | ||
export class ErrorInterceptor implements HttpInterceptor { | ||
constructor(private readonly progressService: NgxProgressService) {} | ||
|
||
intercept( | ||
request: HttpRequest<any>, | ||
next: HttpHandler, | ||
): Observable<HttpEvent<any>> { | ||
return next.handle(request).pipe( | ||
catchError(err => { | ||
this.progressService.terminate(); | ||
return throwError(err); | ||
}), | ||
); | ||
} | ||
} |