Skip to content

Commit

Permalink
Merge pull request #44 from infra-geo-ouverte/next
Browse files Browse the repository at this point in the history
Next
  • Loading branch information
drekss authored Jun 30, 2020
2 parents aac0c7e + 29bf796 commit 04a2901
Show file tree
Hide file tree
Showing 28 changed files with 674 additions and 186 deletions.
8 changes: 8 additions & 0 deletions packages/auth/src/lib/shared/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,14 @@ export class AuthService {
return this.isAuthenticated();
}

get isAdmin(): boolean {
const token = this.decodeToken();
if (token && token.user && token.user.isAdmin) {
return true;
}
return false;
}

private loginCall(body, headers) {
const url = this.config.getConfig('auth.url');
return this.http.post(`${url}/login`, body, { headers }).pipe(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
<button class="buttonOverlay"
mat-icon-button
[matMenuTriggerFor]="actionbarMenu"
[disabled]="store.view.empty">
[disabled]="store.view.empty"
[color]="iconColor">
<mat-icon [svgIcon]="icon"></mat-icon>
</button>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ export class ActionbarComponent implements OnDestroy, OnChanges {
*/
@Input() color = 'default';

/**
* Color of the button if action mode === overlay
*/
@Input() iconColor = 'default';

/**
* Whether action titles are displayed
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<mat-list-item>
<mat-list-item
class="mat-list-item"
[ngClass]="{'mat-list-item-light': hidden}">
<button mat-list-avatar
*ngIf="auth.authenticated"
mat-icon-button
Expand All @@ -12,26 +14,11 @@
</button>
<h4 matLine>{{context.title}}</h4>

<div *ngIf="auth.authenticated && context.permission === typePermission[typePermission.read]"
<div *ngIf="auth.authenticated"
igoStopPropagation
class="igo-actions-container">

<button
mat-icon-button
[matTooltip]="'igo.context.contextManager.clone' | translate"
matTooltipShowDelay="500"
[color]="color"
(click)="clone.emit(context)">
<mat-icon svgIcon="content-copy"></mat-icon>
</button>
</div>


<div *ngIf="context.permission === typePermission[typePermission.write]"
igoStopPropagation
class="igo-actions-container">

<button *ngIf="collapsed"
<button *ngIf="collapsed && selected && context.permission === typePermission[typePermission.write]"
mat-icon-button
[matTooltip]="'igo.context.contextManager.save' | translate"
matTooltipShowDelay="500"
Expand All @@ -42,13 +29,13 @@ <h4 matLine>{{context.title}}</h4>

<div #actions class="igo-actions-expand-container">

<button
<button *ngIf="context.permission === typePermission[typePermission.write]"
mat-icon-button
[matTooltip]="'igo.context.contextManager.managePermissions' | translate"
matTooltipShowDelay="500"
[color]="color"
(click)="managePermissions.emit(context)">
<mat-icon svgIcon="account-outline"></mat-icon>
<mat-icon svgIcon="account-arrow-right"></mat-icon>
</button>

<!--button
Expand All @@ -68,7 +55,7 @@ <h4 matLine>{{context.title}}</h4>
<mat-icon svgIcon="content-copy"></mat-icon>
</button>

<button
<button *ngIf="context.permission === typePermission[typePermission.write]"
mat-icon-button
[color]="color"
[matTooltip]="'igo.context.contextManager.edit' | translate"
Expand All @@ -77,7 +64,25 @@ <h4 matLine>{{context.title}}</h4>
<mat-icon svgIcon="pencil"></mat-icon>
</button>

<button
<button *ngIf="!context.hidden"
mat-icon-button
[color]="color"
[matTooltip]="'igo.context.contextManager.hide' | translate"
matTooltipShowDelay="500"
(click)="hide.emit(context)">
<mat-icon svgIcon="eye"></mat-icon>
</button>

<button *ngIf="context.hidden"
mat-icon-button
[color]="color"
[matTooltip]="'igo.context.contextManager.show' | translate"
matTooltipShowDelay="500"
(click)="show.emit(context)">
<mat-icon svgIcon="eye-off"></mat-icon>
</button>

<button *ngIf="context.permission === typePermission[typePermission.write]"
mat-icon-button
color="warn"
[matTooltip]="'igo.context.contextManager.delete' | translate"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ mat-list-item >>> .mat-list-item-content .mat-list-text {
mat-icon.disabled {
color: rgba(0, 0, 0, 0.38);
}

mat-list-item.mat-list-item-light >>> .mat-list-item-content {
color: rgba(150, 150, 150, 1);
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,22 @@ export class ContextItemComponent {
}
private _default = false;

@Input() selected: boolean;

@Output() edit = new EventEmitter<DetailedContext>();
@Output() delete = new EventEmitter<DetailedContext>();
@Output() save = new EventEmitter<DetailedContext>();
@Output() clone = new EventEmitter<DetailedContext>();
@Output() hide = new EventEmitter<DetailedContext>();
@Output() show = new EventEmitter<DetailedContext>();
@Output() favorite = new EventEmitter<DetailedContext>();
@Output() managePermissions = new EventEmitter<DetailedContext>();
@Output() manageTools = new EventEmitter<DetailedContext>();

get hidden(): boolean {
return this.context.hidden;
}

constructor(public auth: AuthService) {}

favoriteClick(context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ import {
import { Subscription } from 'rxjs';
import { debounceTime } from 'rxjs/operators';

import { MessageService, LanguageService } from '@igo2/core';
import { MessageService, LanguageService, StorageService } from '@igo2/core';
import { AuthService } from '@igo2/auth';
import { ConfirmDialogService } from '@igo2/common';
import { MapService } from '@igo2/geo';

import {
Context,
DetailedContext,
ContextsList
ContextsList,
ContextUserPermission
} from '../shared/context.interface';
import { ContextService } from '../shared/context.service';
import { ContextListComponent } from './context-list.component';
Expand Down Expand Up @@ -140,20 +142,81 @@ export class ContextListBindingDirective implements OnInit, OnDestroy {
});
}

@HostListener('create', ['$event'])
onCreate(opts: { title: string; empty: boolean }) {
const { title, empty } = opts;
const context = this.contextService.getContextFromMap(
this.component.map,
empty
);
context.title = title;
this.contextService.create(context).subscribe(() => {
const translate = this.languageService.translate;
const titleD = translate.instant(
'igo.context.bookmarkButton.dialog.createTitle'
);
const message = translate.instant(
'igo.context.bookmarkButton.dialog.createMsg',
{
value: context.title
}
);
this.messageService.success(message, titleD);
this.contextService.loadContext(context.uri);
});
}

@HostListener('filterPermissionsChanged')
loadContexts() {
const permissions = ['none'];
for (const p of this.component.permissions) {
if (p.checked === true || p.indeterminate === true) {
permissions.push(p.name);
}
}
this.component.showHidden
? this.contextService.loadContexts(permissions, true)
: this.contextService.loadContexts(permissions, false);
}

@HostListener('showHiddenContexts')
showHiddenContexts() {
this.component.showHidden = !this.component.showHidden;
this.storageService.set(
'contexts.showHidden',
this.component.showHidden.toString()
);
this.loadContexts();
}

@HostListener('show', ['$event'])
onShowContext(context: DetailedContext) {
this.contextService.showContext(context.id).subscribe();
}

@HostListener('hide', ['$event'])
onHideContext(context: DetailedContext) {
this.contextService.hideContext(context.id).subscribe();
}

constructor(
@Self() component: ContextListComponent,
private contextService: ContextService,
private mapService: MapService,
private languageService: LanguageService,
private confirmDialogService: ConfirmDialogService,
private messageService: MessageService
private messageService: MessageService,
private auth: AuthService,
private storageService: StorageService
) {
this.component = component;
}

ngOnInit() {
// Override input contexts
this.component.contexts = { ours: [] };
this.component.showHidden =
this.storageService.get('contexts.showHidden') === 'true' ? true : false;

this.contexts$$ = this.contextService.contexts$.subscribe(contexts =>
this.handleContextsChange(contexts)
Expand All @@ -170,7 +233,39 @@ export class ContextListBindingDirective implements OnInit, OnDestroy {
.pipe(debounceTime(100))
.subscribe(context => (this.component.selectedContext = context));

this.contextService.loadContexts();
this.auth.authenticate$.subscribe(authenticate => {
if (authenticate) {
this.contextService.getProfilByUser().subscribe(profils => {
this.component.users = profils;
this.component.permissions = [];
const profilsAcc = this.component.users.reduce((acc, cur) => {
acc = acc.concat(cur);
acc = cur.childs ? acc.concat(cur.childs) : acc;
return acc;
}, []);
for (const user of profilsAcc) {
const permission: ContextUserPermission = {
name: user.name,
checked:
this.storageService.get('contexts.permissions.' + user.name) ===
'false'
? false
: true
};
this.component.permissions.push(permission);
}
const permissions = ['none'];
for (const p of this.component.permissions) {
if (p.checked === true || p.indeterminate === true) {
permissions.push(p.name);
}
}
this.component.showHidden
? this.contextService.loadContexts(permissions, true)
: this.contextService.loadContexts(permissions, false);
});
}
});
}

ngOnDestroy() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,35 +35,70 @@
<mat-icon color="warn" svgIcon="sort-variant-remove"></mat-icon>
</button>

<button *ngIf="auth.authenticated"
mat-icon-button
[matTooltip]="'igo.context.bookmarkButton.create' | translate"
matTooltipShowDelay="500"
(click)="createContext()">
<mat-icon color="primary" svgIcon="star"></mat-icon>
</button>
<igo-actionbar *ngIf="auth.authenticated"
class="add-context-button"
[iconColor]="color"
[store]="actionStore"
[withIcon]="true"
icon="plus"
[withTitle]="actionbarMode === 'overlay'"
[horizontal]="false"
[mode]="actionbarMode">
</igo-actionbar>

<!-- <button *ngIf="authenticated"
<button *ngIf="auth.authenticated && users && users.length"
mat-icon-button
[matTooltip]="'igo.context.contextManager.userAccount' | translate"
[matTooltip]="'igo.context.contextManager.filterUser' | translate"
matTooltipShowDelay="500"
[matMenuTriggerFor]="accountMenu">
<mat-icon color="primary" svgIcon="account"></mat-icon>
<mat-icon color="primary" svgIcon="filter-menu"></mat-icon>
</button>

<mat-menu #accountMenu="matMenu">
<ng-container *ngFor="let user of users">
<mat-checkbox
class="mat-menu-item"
[checked]="true"
(change)="userSelection()">
{{user}}
</mat-checkbox>
<span class="profilsMenu">
<mat-checkbox
class="mat-menu-item"
[checked]="getPermission(user).checked"
[indeterminate]="getPermission(user).indeterminate"
(click)="$event.stopPropagation()"
(change)="userSelection(user)">
</mat-checkbox>
<button *ngIf="user.childs"
[matMenuTriggerFor]="subAccountMenu"
mat-menu-item>
{{user.title}}
</button>
<button
mat-menu-item
*ngIf="!user.childs">
{{user.title}}
</button>
</span>

<mat-menu #subAccountMenu="matMenu">
<mat-checkbox *ngFor="let child of user.childs"
class="mat-menu-item"
[checked]="getPermission(child).checked"
(click)="$event.stopPropagation()"
(change)="userSelection(child, user)">
{{child.title}}
</mat-checkbox>
</mat-menu>
</ng-container>
</mat-menu> -->
<mat-checkbox
class="mat-menu-item"
[checked]="showHidden"
(click)="$event.stopPropagation()"
(change)="showHiddenContexts.emit()">
{{ 'igo.context.contextManager.showHidden' | translate }}
</mat-checkbox>
</mat-menu>

<ng-template ngFor let-groupContexts [ngForOf]="contexts$ | async | keyvalue">

<igo-collapsible *ngIf="groupContexts.value.length && auth.authenticated" [title]="titleMapping[groupContexts.key] | translate">
<igo-collapsible *ngIf="groupContexts.value.length && auth.authenticated" [title]="titleMapping[groupContexts.key] | translate"
[collapsed]="collapsed[titleMapping[groupContexts.key]]" (toggle)="collapsed[titleMapping[groupContexts.key]] = $event">

<ng-template ngFor let-context [ngForOf]="groupContexts.value">
<igo-context-item
Expand All @@ -76,6 +111,8 @@
(delete)="delete.emit(context)"
(clone)="clone.emit(context)"
(save)="save.emit(context)"
(hide)="hideContext(context)"
(show)="showContext(context)"
(favorite)="favorite.emit(context)"
(manageTools)="manageTools.emit(context)"
(managePermissions)="managePermissions.emit(context)"
Expand Down
Loading

0 comments on commit 04a2901

Please sign in to comment.