-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Request service and spinner): Request service that tracks the on… (
#119) * feat(Request service and spinner): Request service that tracks the ongoing requests and a spinner component that displays itself when more than 0 requests are ongoing
- Loading branch information
Showing
20 changed files
with
222 additions
and
51 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
<main> | ||
<igo-spinner></igo-spinner> | ||
<router-outlet></router-outlet> | ||
</main> |
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
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* tslint:disable:no-unused-variable */ | ||
|
||
import { TestBed, async, inject } from '@angular/core/testing'; | ||
import { RequestService } from './request.service'; | ||
|
||
describe('RequestService', () => { | ||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
providers: [RequestService] | ||
}); | ||
}); | ||
|
||
it('should ...', inject([RequestService], (service: RequestService) => { | ||
expect(service).toBeTruthy(); | ||
})); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { Observable } from 'rxjs/Observable'; | ||
import { Subject } from 'rxjs/Subject'; | ||
|
||
@Injectable() | ||
export class RequestService { | ||
|
||
private count = 0; | ||
requests = new Subject<number>(); | ||
|
||
constructor() { } | ||
|
||
register(request: Observable<any>) { | ||
this.count += 1; | ||
this.requests.next(this.count); | ||
|
||
return request.finally(this.unregister.call(this)); | ||
} | ||
|
||
private unregister() { | ||
this.count -= 1; | ||
this.requests.next(this.count); | ||
} | ||
|
||
} |
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
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<div class="igo-spinner" [ngClass]="{'igo-spinner-shown': shown}"> | ||
<div class="igo-spinner-background"></div> | ||
<md-progress-circle mode="indeterminate"></md-progress-circle> | ||
</div> |
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { TestModule } from '../../test.module'; | ||
|
||
import { RequestService } from '../request.service'; | ||
import { SpinnerComponent } from './spinner.component'; | ||
|
||
describe('SpinnerComponent', () => { | ||
let component: SpinnerComponent; | ||
let fixture: ComponentFixture<SpinnerComponent>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [ | ||
TestModule | ||
], | ||
declarations: [ SpinnerComponent ], | ||
providers: [ RequestService ] | ||
}) | ||
.compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(SpinnerComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
@require '../../../css/theme.styl'; | ||
|
||
$igo-spinner-size = 40px; | ||
$igo-spinner-border-width = 4px; | ||
$igo-spinner-top-left = 2px; | ||
|
||
.igo-spinner { | ||
display: none; | ||
} | ||
|
||
.igo-spinner-shown { | ||
display: block; | ||
} | ||
|
||
md-progress-circle { | ||
height: $igo-spinner-size; | ||
width: $igo-spinner-size; | ||
border-radius: 50%; | ||
} | ||
|
||
:host >>> md-progress-circle path { | ||
stroke: $igo-primary-color; | ||
} | ||
|
||
.igo-spinner-background { | ||
height: $igo-spinner-size - $igo-spinner-border-width; | ||
width: $igo-spinner-size - $igo-spinner-border-width; | ||
border-radius: 50%; | ||
border: $igo-spinner-border-width solid $igo-tertiary-color; | ||
position: absolute; | ||
top: $igo-spinner-top-left; | ||
left: $igo-spinner-top-left; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
|
||
import { RequestService } from '../request.service'; | ||
|
||
@Component({ | ||
selector: 'igo-spinner', | ||
templateUrl: './spinner.component.html', | ||
styleUrls: ['./spinner.component.styl'], | ||
}) | ||
export class SpinnerComponent implements OnInit { | ||
|
||
shown: boolean = false; | ||
|
||
constructor(private requestService: RequestService) { } | ||
|
||
ngOnInit() { | ||
this.requestService.requests.subscribe((count: number) => { | ||
this.shown = count > 0; | ||
}); | ||
} | ||
|
||
} |
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
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,17 +1,6 @@ | ||
@require '../../../css/theme.styl'; | ||
@require '../../../css/media.styl'; | ||
|
||
.igo-zoom-container { | ||
position: absolute; | ||
top: $igo-margin; | ||
right: $igo-margin; | ||
width: $igo-icon-button-width; | ||
|
||
+media(mobile) { | ||
display: none; | ||
} | ||
} | ||
|
||
.igo-zoom-container button:first-child { | ||
margin-bottom: 2px; | ||
} |
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
Oops, something went wrong.