Skip to content

Commit

Permalink
feat(user): add user button on map
Browse files Browse the repository at this point in the history
  • Loading branch information
mbarbeau committed Sep 1, 2017
1 parent 1cbd693 commit 379b757
Show file tree
Hide file tree
Showing 40 changed files with 606 additions and 59 deletions.
23 changes: 22 additions & 1 deletion src/lib/auth/shared/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Injectable } from '@angular/core';
import { Http, Headers } from '@angular/http';
import { Router } from '@angular/router';

import { BehaviorSubject } from 'rxjs/BehaviorSubject';
import { Observable } from 'rxjs/Rx';
import { JwtHelper } from 'angular2-jwt';

Expand All @@ -12,16 +13,19 @@ import { AuthOptions } from '../shared';

@Injectable()
export class AuthService {
public authenticate$ = new BehaviorSubject<Boolean>(undefined);
public redirectUrl: string;
private options: AuthOptions;
private token: string;
private anonymous: boolean = false;

constructor(private http: Http,
private config: ConfigService,
private router: Router) {

this.options = this.config.getConfig('auth') || {};
this.token = localStorage.getItem(this.options.tokenKey);
this.authenticate$.next(this.authenticated);
}

login(username: string, password: string): any {
Expand All @@ -38,6 +42,7 @@ export class AuthService {
const data = res.json();
this.token = data.token;
localStorage.setItem(this.options.tokenKey, this.token);
this.authenticate$.next(true);
})
.catch((err: any) => {
const body = err.json();
Expand All @@ -59,16 +64,24 @@ export class AuthService {
const data = res.json();
this.token = data.token;
localStorage.setItem(this.options.tokenKey, this.token);
this.authenticate$.next(true);
})
.catch((err: any) => {
const body = err.json();
return Observable.throw([{text: body.message}]);
});
}

loginAnonymous() {
this.anonymous = true;
return Observable.of(true);
}

logout() {
this.anonymous = false;
this.token = undefined;
localStorage.removeItem(this.options.tokenKey);
this.authenticate$.next(false);
return Observable.of(true);
}

Expand Down Expand Up @@ -105,7 +118,15 @@ export class AuthService {
return Base64.encode(password);
}

get logged() {
get logged(): boolean {
return this.authenticated || this.isAnonymous;
}

get isAnonymous(): boolean {
return this.anonymous;
}

get authenticated(): boolean {
return this.isAuthenticated();
}
}
2 changes: 2 additions & 0 deletions src/lib/auth/shared/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ export * from './auth.interface';
export * from './auth-http.provider';
export * from './auth.guard';
export * from './protected.directive';
export * from './poi/poi.service';
export * from './poi/poi.interface';
7 changes: 7 additions & 0 deletions src/lib/auth/shared/poi/poi.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export interface Poi {
id?: string;
title: string;
x: number;
y: number;
zoom: number;
}
48 changes: 48 additions & 0 deletions src/lib/auth/shared/poi/poi.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';

import { RequestService, ConfigService } from '../../../core';
import { AuthHttp } from '../../../auth';
import { Poi } from './poi.interface';

@Injectable()
export class PoiService {

private baseUrl: string;

constructor(private authHttp: AuthHttp,
private requestService: RequestService,
private config: ConfigService) {

this.baseUrl = this.config.getConfig('context.url');
}

get(): Observable<Poi[]> {
const url = this.baseUrl + '/pois';
const request = this.authHttp.get(url);
return this.requestService.register(request, 'Get POIs error')
.map((res) => {
const pois: Poi[] = res.json();
return pois;
});
}

delete(id: string): Observable<void> {
const url = this.baseUrl + '/pois/' + id;
const request = this.authHttp.delete(url);
return this.requestService.register(request, 'Delete POI error')
.map((res) => {
return res;
});
}

create(context: Poi): Observable<Poi> {
const url = this.baseUrl + '/pois';
const request = this.authHttp.post(url, JSON.stringify(context));
return this.requestService.register(request, 'Create POI error')
.map((res) => {
return res.json();
});
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="igo-bookmark-container">
<div class="igo-bookmark-button-container">
<button
md-icon-button
[color]="color"
Expand Down
30 changes: 30 additions & 0 deletions src/lib/map/bookmark-button/bookmark-button.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* tslint:disable:no-unused-variable */
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { IgoSharedModule } from '../../shared';

import { BookmarkButtonComponent } from './bookmark-button.component';

describe('bookmarkButtonComponent', () => {
let component: BookmarkButtonComponent;
let fixture: ComponentFixture<BookmarkButtonComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
IgoSharedModule
],
declarations: [ BookmarkButtonComponent ]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(BookmarkButtonComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@require '../../../style/var.styl';

.igo-bookmark-container {
.igo-bookmark-button-container {
width: $igo-icon-size;
button {
background-color: #fff;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import { IgoMap } from '../shared';
import { BookmarkDialogComponent } from './bookmark-dialog.component';

@Component({
selector: 'igo-bookmark',
templateUrl: './bookmark.component.html',
styleUrls: ['./bookmark.component.styl']
selector: 'igo-bookmark-button',
templateUrl: './bookmark-button.component.html',
styleUrls: ['./bookmark-button.component.styl']
})
export class BookmarkComponent {
export class BookmarkButtonComponent {

@Input()
get map(): IgoMap { return this._map; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './bookmark.component';
export * from './bookmark-button.component';
export * from './bookmark-dialog.component';
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="igo-geolocate-container">
<div class="igo-geolocate-button-container">
<button
md-icon-button
[color]="color"
Expand Down
30 changes: 30 additions & 0 deletions src/lib/map/geolocate-button/geolocate-button.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* tslint:disable:no-unused-variable */
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { IgoSharedModule } from '../../shared';

import { GeolocateButtonComponent } from './geolocate-button.component';

describe('geolocateButtonComponent', () => {
let component: GeolocateButtonComponent;
let fixture: ComponentFixture<GeolocateButtonComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
IgoSharedModule
],
declarations: [ GeolocateButtonComponent ]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(GeolocateButtonComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@require '../../../style/var.styl';

.igo-geolocate-container {
.igo-geolocate-button-container {
width: $igo-icon-size;
background-color: #fff;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { Component, Input } from '@angular/core';
import { IgoMap } from '../shared/map';

@Component({
selector: 'igo-geolocate',
templateUrl: './geolocate.component.html',
styleUrls: ['./geolocate.component.styl']
selector: 'igo-geolocate-button',
templateUrl: './geolocate-button.component.html',
styleUrls: ['./geolocate-button.component.styl']
})
export class GeolocateComponent {
export class GeolocateButtonComponent {

@Input()
get map(): IgoMap { return this._map; }
Expand Down
1 change: 1 addition & 0 deletions src/lib/map/geolocate-button/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './geolocate-button.component';
1 change: 0 additions & 1 deletion src/lib/map/geolocate/index.ts

This file was deleted.

10 changes: 6 additions & 4 deletions src/lib/map/map-browser/map-browser.component.styl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
height: 100%;
}

:host >>> igo-zoom {
:host >>> igo-zoom-button {
position: absolute;
bottom: $igo-margin;
right: $igo-margin;
Expand All @@ -21,14 +21,16 @@
}
}

:host >>> igo-bookmark {
:host >>> igo-user-button {
position: absolute;
bottom: $igo-margin;
right: "calc(%s + 50px)" % $igo-margin;
width: $igo-icon-button-width;
+media(mobile) {
right: "calc(%s + 90px)" % $igo-margin;
}
}

:host >>> igo-geolocate {
:host >>> igo-geolocate-button {
position: absolute;
bottom: 95px;
right: $igo-margin;
Expand Down
40 changes: 26 additions & 14 deletions src/lib/map/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import { IgoSharedModule } from '../shared';

import { MapService } from './shared';
import { MapBrowserComponent, MapBrowserBindingDirective } from './map-browser';
import { ZoomComponent } from './zoom';
import { GeolocateComponent } from './geolocate';
import { BookmarkComponent, BookmarkDialogComponent } from './bookmark';
import { ZoomButtonComponent } from './zoom-button';
import { GeolocateButtonComponent } from './geolocate-button';
import { BookmarkButtonComponent, BookmarkDialogComponent } from './bookmark-button';
import { PoiButtonComponent, PoiDialogComponent } from './poi-button';
import { UserButtonComponent, UserDialogComponent } from './user-button';


@NgModule({
Expand All @@ -16,20 +18,28 @@ import { BookmarkComponent, BookmarkDialogComponent } from './bookmark';
exports: [
MapBrowserComponent,
MapBrowserBindingDirective,
ZoomComponent,
GeolocateComponent,
BookmarkComponent
ZoomButtonComponent,
GeolocateButtonComponent,
BookmarkButtonComponent,
PoiButtonComponent,
UserButtonComponent
],
declarations: [
MapBrowserComponent,
MapBrowserBindingDirective,
ZoomComponent,
GeolocateComponent,
BookmarkComponent,
BookmarkDialogComponent
ZoomButtonComponent,
GeolocateButtonComponent,
BookmarkButtonComponent,
BookmarkDialogComponent,
PoiButtonComponent,
PoiDialogComponent,
UserButtonComponent,
UserDialogComponent
],
entryComponents: [
BookmarkDialogComponent
BookmarkDialogComponent,
PoiDialogComponent,
UserDialogComponent
]
})
export class IgoMapModule {
Expand All @@ -44,7 +54,9 @@ export class IgoMapModule {
}

export * from './map-browser';
export * from './zoom';
export * from './geolocate';
export * from './bookmark';
export * from './zoom-button';
export * from './geolocate-button';
export * from './bookmark-button';
export * from './poi-button';
export * from './user-button';
export * from './shared';
2 changes: 2 additions & 0 deletions src/lib/map/poi-button/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './poi-button.component';
export * from './poi-dialog.component';
24 changes: 24 additions & 0 deletions src/lib/map/poi-button/poi-button.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<md-select placeholder="Zones of interest" floatPlaceholder="never" (change)="handlePoiChanged($event.value)">
<md-option>
<div class="titlePoi">Create a new zone</div>
<button igoStopPropagation class="addPoi buttonPoi"
md-icon-button
color="primary"
(click)="createPoi()">
<md-icon>
<span></span>
</md-icon>
</button>
</md-option>
<md-option *ngFor="let poi of pois" [value]="poi.id">
<div class="titlePoi">{{ poi.title }}</div>
<button igoStopPropagation class="deletePoi buttonPoi"
md-icon-button
color="warn"
(click)="deletePoi(poi)">
<md-icon>
<span></span>
</md-icon>
</button>
</md-option>
</md-select>
Loading

0 comments on commit 379b757

Please sign in to comment.