Skip to content

Commit

Permalink
feat(auth): only show auth form if define in config
Browse files Browse the repository at this point in the history
  • Loading branch information
mbarbeau committed Sep 15, 2017
1 parent 158c7e0 commit bb496a5
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 31 deletions.
5 changes: 2 additions & 3 deletions src/demo-app/app/app.component.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<igo-spinner igoSpinnerBinding></igo-spinner>
<igo-message-center></igo-message-center>
<!--igo-auth-form></igo-auth-form-->
<igo-auth-form></igo-auth-form>

<md-sidenav-container>

Expand Down Expand Up @@ -95,7 +95,7 @@
[map]="map">
<igo-zoom-button [map]="map" color="primary"></igo-zoom-button>
<igo-geolocate-button [map]="map" color="primary"></igo-geolocate-button>
<!--igo-user-button [map]="map" color="primary"></igo-user-button-->
<igo-user-button [map]="map" color="primary"></igo-user-button>
</igo-map-browser>
</md-card-content>
</md-card>
Expand Down Expand Up @@ -173,5 +173,4 @@
</form>
</md-card-content>
</md-card>

</md-sidenav-container>
4 changes: 2 additions & 2 deletions src/demo-app/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ export class AppComponent implements OnInit {

if (map !== undefined) {
this.dataSourceService
.createAsyncDataSource(feature.properties as AnyDataSourceContext)
.createAsyncDataSource(feature.layer as AnyDataSourceContext)
.subscribe(dataSource => {
map.addLayer(
this.layerService.createLayer(dataSource, feature.properties));
this.layerService.createLayer(dataSource, feature.layer));
});
}
}
Expand Down
40 changes: 21 additions & 19 deletions src/lib/auth/auth-form/auth-form.component.html
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
<div *ngIf="!auth.logged && backgroundDisable" class="backgroundDisable"></div>
<div *ngIf="visible">
<div *ngIf="!auth.logged && backgroundDisable" class="backgroundDisable"></div>

<div *ngIf="!auth.logged" class="login center-block">
<h1>{{'igo.auth.connection' | translate}}</h1>
<div *ngIf="!auth.logged" class="login center-block">
<h1>{{'igo.auth.connection' | translate}}</h1>

<igo-auth-google
*ngIf="options.google && options.google.enabled !== false"
(onLogin)="login()">
</igo-auth-google>
<igo-auth-facebook
*ngIf="options.facebook && options.facebook.enabled !== false"
(onLogin)="login()">
</igo-auth-facebook>
<igo-auth-intern
*ngIf="!options.intern || options.intern.enabled !== false"
(onLogin)="login()">
</igo-auth-intern>
</div>
<igo-auth-google
*ngIf="options.google && options.google.enabled !== false"
(onLogin)="login()">
</igo-auth-google>
<igo-auth-facebook
*ngIf="options.facebook && options.facebook.enabled !== false"
(onLogin)="login()">
</igo-auth-facebook>
<igo-auth-intern
*ngIf="!options.intern || options.intern.enabled !== false"
(onLogin)="login()">
</igo-auth-intern>
</div>

<div *ngIf="auth.logged && alreadyConnectedDiv" class="login center-block">
<p>{{'igo.auth.welcome' | translate: user}}</p>
<button type="button" (click)="logout()">{{'igo.auth.signOut' | translate}}</button>
<div *ngIf="auth.logged && alreadyConnectedDiv" class="login center-block">
<p>{{'igo.auth.welcome' | translate: user}}</p>
<button type="button" (click)="logout()">{{'igo.auth.signOut' | translate}}</button>
</div>
</div>
3 changes: 3 additions & 0 deletions src/lib/auth/auth-form/auth-form.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,15 @@ export class AuthFormComponent implements OnInit {
private options: AuthOptions;
private user;

public visible: boolean = true;

constructor(
public auth: AuthService,
private config: ConfigService,
@Optional() private router: Router
) {
this.options = this.config.getConfig('auth') || {};
this.visible = Object.getOwnPropertyNames(this.options).length !== 0;

if (this.auth.decodeToken()) {
this.user = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export class CatalogListBindingDirective implements OnInit, OnDestroy {
// Override input catalogs
this.catalogs$$ = this.catalogService.catalogs$
.subscribe(catalogs => this.handleCatalogsChange(catalogs));

this.catalogService.load();
}

ngOnDestroy() {
Expand Down
19 changes: 14 additions & 5 deletions src/lib/catalog/shared/catalog.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,8 @@ export class CatalogService {
private config: ConfigService) {

const options = this.config.getConfig('context') || {};
const catalog = this.config.getConfig('catalog') || {};
this.baseUrl = options.url;

if (catalog.sources) {
this.catalogs$.next(catalog.sources);
}
this.baseUrl = options.url;
}

get(): Observable<Catalog[]> {
Expand Down Expand Up @@ -53,4 +49,17 @@ export class CatalogService {
}
}

load() {
this.get().subscribe((catalogs) => {
const catalogConfig = this.config.getConfig('catalog') || {};

if (catalogConfig.sources) {
catalogs = catalogs.concat(catalogConfig.sources);
}
if (catalogs) {
this.catalogs$.next(catalogs);
}
});
}

}
2 changes: 1 addition & 1 deletion src/lib/map/user-button/user-button.component.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="igo-user-button-container">
<div *ngIf="visible" class="igo-user-button-container">
<div class="igo-user-button-more-container" [@userButtonState]="expand ? 'expand' : 'collapse'">

<igo-poi-button [color]="color" [map]="map"></igo-poi-button>
Expand Down
7 changes: 6 additions & 1 deletion src/lib/map/user-button/user-button.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Component, Input } from '@angular/core';
import { MdDialog } from '@angular/material';

import { ConfigService } from '../../core';
import { AuthService } from '../../auth';
import { IgoMap } from '../shared';
import { UserDialogComponent } from './user-dialog.component';
Expand Down Expand Up @@ -31,11 +32,15 @@ export class UserButtonComponent {
private _color: string;

public expand: boolean = false;
public visible: boolean = false;

constructor(
private dialog: MdDialog,
private config: ConfigService,
public auth: AuthService
) {}
) {
this.visible = this.config.getConfig('auth') ? true : false;
}

accountClick() {
if (this.auth.authenticated) {
Expand Down
12 changes: 12 additions & 0 deletions src/locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,18 @@
"title": "Title"
},
"searchResults": "Search Results",
"search": {
"dataSources": {
"name": "Layers",
"properties": {
"title": "Title",
"group": "Group",
"abstract": "Abstract",
"url": "URL",
"type": "Type"
}
}
},
"table": {
"filter": "Filter"
},
Expand Down
12 changes: 12 additions & 0 deletions src/locale/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,18 @@
"resolution": "Résolution",
"title": "Titre"
},
"search": {
"dataSources": {
"name": "Couches",
"properties": {
"title": "Titre",
"group": "Groupe",
"abstract": "Description",
"url": "URL",
"type": "Type"
}
}
},
"searchResults": "Résultats de recherche",
"table": {
"filter": "Filtre"
Expand Down

0 comments on commit bb496a5

Please sign in to comment.