-
Notifications
You must be signed in to change notification settings - Fork 5
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
1 parent
17216dd
commit 55106f8
Showing
23 changed files
with
241 additions
and
37 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
3 changes: 3 additions & 0 deletions
3
src/src/app/main/components/google-map/google-map.component.css
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,3 @@ | ||
:host { | ||
display: contents; | ||
} |
3 changes: 3 additions & 0 deletions
3
src/src/app/main/components/google-map/google-map.component.html
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,3 @@ | ||
<ng-container *ngIf="loaded$ | async"> | ||
<google-map></google-map> | ||
</ng-container> |
53 changes: 53 additions & 0 deletions
53
src/src/app/main/components/google-map/google-map.component.spec.ts
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,53 @@ | ||
import { HttpClientTestingModule } from '@angular/common/http/testing'; | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { environment } from '../../../../environments/environment.sample'; | ||
import { GoogleMapConfigService } from '../../services/google-map-config.service'; | ||
import { GoogleMapScriptLoaderService } from '../../services/google-map-script-loader.service'; | ||
import { GoogleMapScriptLoaderMockService } from '../../../tests/services/google-map-script-loader-mock.service'; | ||
import { GoogleMapComponent } from './google-map.component'; | ||
|
||
let component: GoogleMapComponent; | ||
let fixture: ComponentFixture<GoogleMapComponent>; | ||
|
||
describe('GoogleMapComponent', () => { | ||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
declarations: [GoogleMapComponent], | ||
imports: [HttpClientTestingModule], | ||
providers: [ | ||
{ | ||
provide: GoogleMapConfigService, | ||
useValue: environment.googleMapApiKey, | ||
}, | ||
{ | ||
provide: GoogleMapScriptLoaderService, | ||
useClass: GoogleMapScriptLoaderMockService, | ||
}, | ||
], | ||
}).compileComponents(); | ||
}); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(GoogleMapComponent); | ||
component = fixture.componentInstance; | ||
}); | ||
|
||
tests(); | ||
}); | ||
|
||
function tests() { | ||
beforeEach(() => { | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).not.toBeNull(); | ||
}); | ||
|
||
it('should render google-map tag', () => { | ||
const compiled = <HTMLElement>fixture.debugElement.nativeElement; | ||
|
||
expect(compiled.querySelector('google-map')).not.toBeNull(); | ||
}); | ||
} |
35 changes: 35 additions & 0 deletions
35
src/src/app/main/components/google-map/google-map.component.ts
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,35 @@ | ||
import { | ||
ChangeDetectionStrategy, | ||
Component, | ||
Inject, | ||
OnInit, | ||
} from '@angular/core'; | ||
import { of } from 'rxjs'; | ||
|
||
import { GoogleMapConfig } from '../../models/google-map-config'; | ||
import { GoogleMapConfigService } from '../../services/google-map-config.service'; | ||
import { GoogleMapScriptLoaderService } from '../../services/google-map-script-loader.service'; | ||
|
||
@Component({ | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
selector: 'app-google-map', | ||
templateUrl: './google-map.component.html', | ||
styleUrls: ['./google-map.component.css'], | ||
}) | ||
export class GoogleMapComponent implements OnInit { | ||
loaded$ = of(false); | ||
|
||
constructor( | ||
@Inject(GoogleMapConfigService) | ||
private readonly _config: GoogleMapConfig, | ||
private readonly _loader: GoogleMapScriptLoaderService | ||
) {} | ||
|
||
ngOnInit() { | ||
const url = | ||
'https://maps.googleapis.com/maps/api/js' + | ||
`?key=${this._config.googleMapApiKey}`; | ||
|
||
this.loaded$ = this._loader.loadScript(url); | ||
} | ||
} |
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 +1,5 @@ | ||
<p>main works!</p> | ||
|
||
<app-google-map></app-google-map> | ||
|
||
<app-date-slider (onSliderChange)="outputSliderRange($event)"></app-date-slider> |
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,10 +1,16 @@ | ||
import { ChangeDetectionStrategy, Component } from '@angular/core'; | ||
|
||
import { ISlider } from '../date-slider/slider'; | ||
|
||
@Component({ | ||
selector: 'app-main', | ||
templateUrl: './main.component.html', | ||
styleUrls: ['./main.component.css'], | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class MainComponent { | ||
} | ||
outputSliderRange(range: ISlider): void { | ||
const datesRange = `Start: ${range.startDate.getFullYear()} End: ${range.endDate.getFullYear()}`; | ||
console.log(datesRange); | ||
} | ||
} |
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,23 @@ | ||
import { NgxSliderModule } from '@angular-slider/ngx-slider'; | ||
import { CommonModule } from '@angular/common'; | ||
import { NgModule } from '@angular/core'; | ||
import { GoogleMapsModule } from '@angular/google-maps'; | ||
import { RouterModule } from '@angular/router'; | ||
|
||
import { DateSliderComponent } from '../date-slider/date-slider.component'; | ||
import { GoogleMapComponent } from './components/google-map/google-map.component'; | ||
import { MainComponent } from './main.component'; | ||
import { routes } from './main.routes'; | ||
import { MapsModule } from './maps.module'; | ||
|
||
@NgModule({ | ||
declarations: [MainComponent, DateSliderComponent, GoogleMapComponent], | ||
imports: [ | ||
CommonModule, | ||
GoogleMapsModule, | ||
RouterModule.forChild(routes), | ||
NgxSliderModule, | ||
MapsModule, | ||
], | ||
}) | ||
export class MainLazyLoadedModule {} |
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,10 @@ | ||
import { Routes } from '@angular/router'; | ||
|
||
import { MainComponent } from './main.component'; | ||
|
||
export const routes: Routes = [ | ||
{ | ||
path: '', | ||
component: MainComponent, | ||
}, | ||
]; |
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,23 @@ | ||
import { CommonModule } from '@angular/common'; | ||
import { HttpClientJsonpModule, HttpClientModule } from '@angular/common/http'; | ||
import { ModuleWithProviders, NgModule } from '@angular/core'; | ||
|
||
import { GoogleMapConfig } from './models/google-map-config'; | ||
import { GoogleMapConfigService } from './services/google-map-config.service'; | ||
|
||
@NgModule({ | ||
imports: [CommonModule, HttpClientModule, HttpClientJsonpModule], | ||
}) | ||
export class MapsModule { | ||
static forRoot(config: GoogleMapConfig): ModuleWithProviders<MapsModule> { | ||
return { | ||
ngModule: MapsModule, | ||
providers: [ | ||
{ | ||
provide: GoogleMapConfigService, | ||
useValue: config, | ||
}, | ||
], | ||
}; | ||
} | ||
} |
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,3 @@ | ||
export interface GoogleMapConfig { | ||
googleMapApiKey: string; | ||
} |
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,7 @@ | ||
import { InjectionToken } from '@angular/core'; | ||
|
||
import { GoogleMapConfig } from '../models/google-map-config'; | ||
|
||
export const GoogleMapConfigService = new InjectionToken<GoogleMapConfig>( | ||
'GoogleMapConfig' | ||
); |
18 changes: 18 additions & 0 deletions
18
src/src/app/main/services/google-map-script-loader.service.ts
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,18 @@ | ||
import { HttpClient } from '@angular/common/http'; | ||
import { Injectable } from '@angular/core'; | ||
import { Observable, of } from 'rxjs'; | ||
import { catchError, map } from 'rxjs/operators'; | ||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class GoogleMapScriptLoaderService { | ||
constructor(private readonly _httpClient: HttpClient) {} | ||
|
||
loadScript(url: string): Observable<boolean> { | ||
return this._httpClient.jsonp(url, 'callback').pipe( | ||
map(() => true), | ||
catchError(() => of(false)) | ||
); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/src/app/tests/services/google-map-script-loader-mock.service.ts
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,11 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { Observable, of } from 'rxjs'; | ||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class GoogleMapScriptLoaderMockService { | ||
loadScript(): Observable<boolean> { | ||
return of(true); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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 @@ | ||
export const environment = { | ||
production: false, | ||
googleMapApiKey: 'google-map-api-key', // Google Map API Key | ||
}; |
This file was deleted.
Oops, something went wrong.