Skip to content
Snippets Groups Projects
Commit 289302f1 authored by Rémi PAILHAREY's avatar Rémi PAILHAREY :fork_knife_plate:
Browse files

feat(profile): logged in users can access the profile of other users

parent aa3a29f0
No related branches found
No related tags found
4 merge requests!418V2.1.0,!400V2.0,!314Feat/us178 user profile,!230V2.0
...@@ -9,7 +9,16 @@ import { StructureEditionSummaryComponent } from './structure-edition-summary/st ...@@ -9,7 +9,16 @@ import { StructureEditionSummaryComponent } from './structure-edition-summary/st
const routes: Routes = [ const routes: Routes = [
{ {
path: '', path: '',
component: ProfileComponent, children: [
{
path: '',
component: ProfileComponent,
},
{
path: ':id',
component: ProfileComponent,
},
],
}, },
{ {
path: 'edit-structure/:id', path: 'edit-structure/:id',
......
...@@ -7,8 +7,17 @@ ...@@ -7,8 +7,17 @@
> >
<section> <section>
<div fxLayout="row" fxLayoutAlign="start center" fxFill> <div fxLayout="row" fxLayoutAlign="start center" fxFill>
<app-svg-icon
*ngIf="isPublic"
(click)="goBack()"
[iconClass]="'backArrow'"
[type]="'ico'"
[icon]="'arrowBack'"
class="backArrow"
></app-svg-icon>
<h1>Profil</h1> <h1>Profil</h1>
<app-button <app-button
*ngIf="!isPublic"
class="hide-on-mobile" class="hide-on-mobile"
[type]="'button'" [type]="'button'"
[iconBtn]="'edit'" [iconBtn]="'edit'"
...@@ -18,6 +27,7 @@ ...@@ -18,6 +27,7 @@
[routerLinkActive]="'active'" [routerLinkActive]="'active'"
></app-button> ></app-button>
<app-button <app-button
*ngIf="!isPublic"
class="hide-on-desktop" class="hide-on-desktop"
[type]="'button'" [type]="'button'"
[iconBtn]="'edit'" [iconBtn]="'edit'"
...@@ -44,6 +54,7 @@ ...@@ -44,6 +54,7 @@
</div> </div>
<div class="call-to-action" *ngIf="!userProfile.description" fxLayoutAlign="center center" fxFill> <div class="call-to-action" *ngIf="!userProfile.description" fxLayoutAlign="center center" fxFill>
<app-button <app-button
*ngIf="!isPublic"
[type]="'button'" [type]="'button'"
[iconBtn]="'edit'" [iconBtn]="'edit'"
[text]="'Ajouter une description'" [text]="'Ajouter une description'"
...@@ -59,6 +70,7 @@ ...@@ -59,6 +70,7 @@
<div fxLayout="row" fxLayoutAlign="start center" fxFill> <div fxLayout="row" fxLayoutAlign="start center" fxFill>
<h1>Structures</h1> <h1>Structures</h1>
<app-button <app-button
*ngIf="!isPublic"
class="hide-on-mobile" class="hide-on-mobile"
[type]="'button'" [type]="'button'"
[iconBtn]="'edit'" [iconBtn]="'edit'"
...@@ -82,10 +94,11 @@ ...@@ -82,10 +94,11 @@
<div class="structureCard" *ngFor="let s of structures; let i = index"> <div class="structureCard" *ngFor="let s of structures; let i = index">
<div class="structureInfo" fxLayout="column" fxLayoutGap="14px"> <div class="structureInfo" fxLayout="column" fxLayoutGap="14px">
<div fxLayout="row" fxLayoutAlign="space-between start" fxLayoutGap="20px"> <div fxLayout="row" fxLayoutAlign="space-between start" fxLayoutGap="20px">
<a class="structureName" [routerLink]="['/profile']" [queryParams]="{ id: s.structure._id }">{{ <a class="structureName" [routerLink]="['./']" [queryParams]="{ id: s.structure._id }">{{
s.structure.structureName s.structure.structureName
}}</a> }}</a>
<app-structure-options-modal <app-structure-options-modal
*ngIf="!isPublic"
[structure]="s" [structure]="s"
(closed)="ngOnInit()" (closed)="ngOnInit()"
(closedWithRefresh)="ngOnInit()" (closedWithRefresh)="ngOnInit()"
...@@ -101,12 +114,12 @@ ...@@ -101,12 +114,12 @@
</div> </div>
</section> </section>
<section> <section *ngIf="!isPublic">
<div fxLayout="row" fxLayoutAlign="start center" fxFill> <div fxLayout="row" fxLayoutAlign="start center" fxFill>
<h1>Ressources</h1> <h1>Ressources</h1>
</div> </div>
</section> </section>
<section> <section *ngIf="!isPublic">
<div fxLayout="row" fxLayoutAlign="start center" fxFill> <div fxLayout="row" fxLayoutAlign="start center" fxFill>
<h1>Newsletter</h1> <h1>Newsletter</h1>
</div> </div>
......
...@@ -33,6 +33,10 @@ section { ...@@ -33,6 +33,10 @@ section {
.call-to-action { .call-to-action {
margin-top: 40px; margin-top: 40px;
} }
.backArrow {
cursor: pointer;
}
} }
.profile { .profile {
......
import { UserService } from './../services/user.service';
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router'; import { Router, ActivatedRoute } from '@angular/router';
import { ButtonType } from '@gouvfr-anct/mediation-numerique/shared'; import { ButtonType } from '@gouvfr-anct/mediation-numerique/shared';
import { StructureWithOwners } from '../models/structureWithOwners.model'; import { StructureWithOwners } from '../models/structureWithOwners.model';
import { User } from '../models/user.model'; import { User } from '../models/user.model';
import { StructureService } from '../services/structure.service'; import { StructureService } from '../services/structure.service';
import { ProfileService } from './services/profile.service'; import { ProfileService } from './services/profile.service';
import { Utils } from '../utils/utils'; import { Utils } from '../utils/utils';
import { catchError, map } from 'rxjs/operators';
import { Observable } from 'rxjs';
import { Location } from '@angular/common';
@Component({ @Component({
selector: 'app-profile', selector: 'app-profile',
templateUrl: './profile.component.html', templateUrl: './profile.component.html',
styleUrls: ['./profile.component.scss'], styleUrls: ['./profile.component.scss']
}) })
export class ProfileComponent implements OnInit { export class ProfileComponent implements OnInit {
public userProfile: User; public userProfile: User;
public structures: StructureWithOwners[] = []; public structures: StructureWithOwners[] = [];
public buttonTypeEnum = ButtonType; public buttonTypeEnum = ButtonType;
public isPublic: boolean;
constructor( constructor(
private profileService: ProfileService, private profileService: ProfileService,
private structureService: StructureService, private structureService: StructureService,
private userService: UserService,
private route: ActivatedRoute,
private router: Router, private router: Router,
private location: Location,
public utils: Utils public utils: Utils
) {} ) {}
ngOnInit(): void { ngOnInit(): void {
this.profileService.getProfile().then((profile: User) => { this.route.params.subscribe((urlParams) => {
this.userProfile = profile; const userId = urlParams.id ? urlParams.id : '';
this.structures = []; if (userId) {
profile.structuresLink.forEach((structureId) => { this.isPublic = true;
this.structureService.getStructureWithOwners(structureId, null).subscribe((s) => { this.userService
this.structures.push(s); .getUser(userId)
.pipe(
map((res) => res),
catchError(() => {
this.router.navigate(['/home']);
return new Observable<User>();
})
)
.subscribe((user) => {
this.userProfile = user;
this.getStructuresFromProfile();
});
} else {
this.isPublic = false;
this.profileService.getProfile().then((profile: User) => {
this.userProfile = profile;
this.getStructuresFromProfile();
}); });
}
});
}
private getStructuresFromProfile() {
this.structures = [];
this.userProfile.structuresLink.forEach((structureId) => {
this.structureService.getStructureWithOwners(structureId, null).subscribe((s) => {
this.structures.push(s);
}); });
}); });
} }
public goBack(): void {
this.location.back();
}
public addStructure(): void { public addStructure(): void {
this.router.navigateByUrl('/form/structure'); this.router.navigateByUrl('/form/structure');
} }
......
...@@ -39,11 +39,18 @@ ...@@ -39,11 +39,18 @@
<h2>Membres</h2> <h2>Membres</h2>
<div fxLayout="column" fxLayoutGap="8px" fxLayoutAlign="baseline baseline"> <div fxLayout="column" fxLayoutGap="8px" fxLayoutAlign="baseline baseline">
<div *ngFor="let member of structureAdmins" class="member-card"> <div *ngFor="let member of structureAdmins" class="member-card">
<app-svg-icon class="avatar" [type]="'avatar'" [icon]="'defaultAvatar'" [iconClass]="'icon-40'"></app-svg-icon> <a [routerLink]="'/profile/' + member._id">
<div class="info-member"> <app-svg-icon
<p class="member">{{ member.name | uppercase }} {{ member.surname | titlecase }}</p> class="avatar"
<p class="job" *ngIf="displayJobEmployer(member)">{{ displayJobEmployer(member) }}</p> [type]="'avatar'"
</div> [icon]="'defaultAvatar'"
[iconClass]="'icon-40'"
></app-svg-icon>
<div class="info-member">
<p class="member">{{ member.name | uppercase }} {{ member.surname | titlecase }}</p>
<p class="job" *ngIf="displayJobEmployer(member)">{{ displayJobEmployer(member) }}</p>
</div>
</a>
</div> </div>
</div> </div>
</div> </div>
......
...@@ -33,6 +33,14 @@ h3 { ...@@ -33,6 +33,14 @@ h3 {
display: flex; display: flex;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
a {
text-decoration: none;
display: flex;
align-items: center;
}
a:hover {
text-decoration: underline;
}
.avatar { .avatar {
background-color: $grey-8; background-color: $grey-8;
border-radius: 4px; border-radius: 4px;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment