-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add comment and discussion module to record page
feat: add comment and discussion module to record page css ajouts
- Loading branch information
Romuald Caplier
committed
Apr 10, 2024
1 parent
70a9dc1
commit 9245dee
Showing
38 changed files
with
663 additions
and
18 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
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
Empty file.
50 changes: 50 additions & 0 deletions
50
apps/datahub/src/app/record/record-user-feedbacks/record-user-feedbacks.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,50 @@ | ||
<p | ||
class="font-title text-[28px] text-title font-medium mb-11" | ||
translate | ||
> | ||
record.metadata.userFeedbacks | ||
</p> | ||
<div | ||
id="new-comment" | ||
class="my-5 flex flex-col" | ||
> | ||
<gn-ui-text-input | ||
[(value)]="newComment" | ||
(valueChange)="onNewCommentValueChange()" | ||
[hint]="'Rédiger votre commentaire ici...'" | ||
(keyup.enter)="publishNewComment()" | ||
class="" | ||
extraClass="bg-transparent" | ||
></gn-ui-text-input> | ||
<div | ||
*ngIf="!isNewCommentEmpty" | ||
id="new-comment-buttons" | ||
class="flex flex-row justify-end p-2" | ||
> | ||
<gn-ui-button | ||
[type]="'outline'" | ||
(buttonClick)="publishNewComment()" | ||
title="Publish" | ||
extraClass="!p-[0.5em]" | ||
> | ||
<span translate> | ||
Publish | ||
</span> | ||
</gn-ui-button> | ||
</div> | ||
</div> | ||
<div *ngIf="userFeedbacksParents"> | ||
<div | ||
class="mb-4 w-full" | ||
*ngFor="let userFeedback of userFeedbacksParents" | ||
> | ||
<gn-ui-user-feedback-item | ||
[userFeedback]="userFeedback" | ||
[userFeedBacksAnswers]="userFeedBacksAnswers.get(userFeedback.uuid)" | ||
[isActiveUserEditor]="isActiveUserEditor" | ||
[activeUser]="activeUser" | ||
(newAnswerEmitter)="onNewAnswer($event)" | ||
></gn-ui-user-feedback-item> | ||
</div> | ||
</div> | ||
|
24 changes: 24 additions & 0 deletions
24
apps/datahub/src/app/record/record-user-feedbacks/record-user-feedbacks.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,24 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing' | ||
|
||
import { RecordUserFeedbacksComponent } from './record-user-feedbacks.component' | ||
|
||
describe('RelatedRecordsComponent', () => { | ||
let component: RecordUserFeedbacksComponent | ||
let fixture: ComponentFixture<RecordUserFeedbacksComponent> | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
declarations: [RecordUserFeedbacksComponent], | ||
}).compileComponents() | ||
}) | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(RecordUserFeedbacksComponent) | ||
component = fixture.componentInstance | ||
fixture.detectChanges() | ||
}) | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy() | ||
}) | ||
}) |
109 changes: 109 additions & 0 deletions
109
apps/datahub/src/app/record/record-user-feedbacks/record-user-feedbacks.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,109 @@ | ||
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Input, OnDestroy, OnInit } from '@angular/core' | ||
import { MdViewFacade } from '@geonetwork-ui/feature/record' | ||
import { filter, takeUntil } from 'rxjs/operators' | ||
import { RecordUserFeedbacksService } from './record-user-feedbacks.service' | ||
import { Observable, Subject } from 'rxjs' | ||
import { UserFeedback } from '@geonetwork-ui/common/domain/model/record' | ||
import { PlatformServiceInterface } from '@geonetwork-ui/common/domain/platform.service.interface' | ||
import { UserModel } from '@geonetwork-ui/common/domain/model/user' | ||
|
||
@Component({ | ||
selector: 'datahub-record-user-feedbacks', | ||
templateUrl: './record-user-feedbacks.component.html', | ||
styleUrls: ['./record-user-feedbacks.component.css'], | ||
changeDetection: ChangeDetectionStrategy.OnPush | ||
}) | ||
|
||
export class RecordUserFeedbacksComponent implements OnInit, OnDestroy { | ||
|
||
@Input() organisationName$: Observable<string> | ||
|
||
private destroy$ = new Subject<void>() | ||
|
||
userFeedbacksParents: UserFeedback[] = [] | ||
userFeedBacksAnswers: Map<string, UserFeedback[]> = new Map() | ||
|
||
isActiveUserEditor = false | ||
newComment = '' | ||
|
||
isNewCommentEmpty = true | ||
|
||
activeUser?: UserModel | ||
|
||
constructor( | ||
private facade: MdViewFacade, | ||
private userFeedBackService: RecordUserFeedbacksService, | ||
private cdr: ChangeDetectorRef, | ||
private platformServiceInterface: PlatformServiceInterface | ||
) { | ||
} | ||
|
||
ngOnInit(): void { | ||
|
||
this.platformServiceInterface.getMe() | ||
.pipe( | ||
filter(Boolean), | ||
takeUntil(this.destroy$) | ||
).subscribe(user => { | ||
this.activeUser = user | ||
this.isActiveUserEditor = | ||
user.profile === 'Administrator' | ||
|| user.profile === 'UserAdmin' | ||
|| user.profile === 'Reviewer' | ||
|| user.profile === 'Editor' | ||
}) | ||
|
||
this.facade.userFeedbacks$.pipe( | ||
filter(Boolean), | ||
takeUntil(this.destroy$) | ||
).subscribe(userFeedbacks => { | ||
|
||
this.userFeedbacksParents = userFeedbacks | ||
.filter(userFeedbacks => userFeedbacks.parentUuid === null) | ||
.sort(this.userFeedBackService.sortByDateFromNewestToOldest) | ||
|
||
const enfants = userFeedbacks | ||
.filter(userFeedbacks => userFeedbacks.parentUuid !== null) | ||
.sort(this.userFeedBackService.sortByDateFromOldestToNewest) | ||
|
||
enfants.forEach(userFeedbacksAnswer => { | ||
const parent = this.userFeedBacksAnswers.get(userFeedbacksAnswer.parentUuid) | ||
if (parent) { | ||
parent.push(userFeedbacksAnswer) | ||
} else { | ||
this.userFeedBacksAnswers.set(userFeedbacksAnswer.parentUuid, [userFeedbacksAnswer]) | ||
} | ||
}) | ||
|
||
this.cdr.markForCheck() | ||
}) | ||
} | ||
|
||
ngOnDestroy(): void { | ||
this.destroy$.next() | ||
this.destroy$.complete() | ||
} | ||
|
||
onNewCommentValueChange() { | ||
this.isNewCommentEmpty = this.newComment.length === 0 | ||
} | ||
|
||
onNewAnswer(newUserFeedback: UserFeedback) { | ||
this.userFeedBackService.postUserFeedback(newUserFeedback) | ||
} | ||
|
||
publishNewComment() { | ||
const newFeedback: UserFeedback = { | ||
uuid: undefined, | ||
comment: this.newComment, | ||
parentUuid: null, | ||
date: undefined, | ||
authorUserId: Number.parseInt(this.activeUser?.id), // todo: il faut faire quelque chose avec ces userId number alors que tout le reste est en uuid... | ||
authorEmail: this.activeUser?.email, | ||
authorName: `${this.activeUser?.name} ${this.activeUser?.surname}` | ||
} | ||
|
||
this.userFeedBackService.postUserFeedback(newFeedback) | ||
this.newComment = '' | ||
} | ||
} |
Empty file.
26 changes: 26 additions & 0 deletions
26
apps/datahub/src/app/record/record-user-feedbacks/record-user-feedbacks.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,26 @@ | ||
import { Injectable } from '@angular/core' | ||
import { UserFeedback } from '@geonetwork-ui/common/domain/model/record' | ||
import { PlatformServiceInterface } from '@geonetwork-ui/common/domain/platform.service.interface' | ||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class RecordUserFeedbacksService { | ||
|
||
constructor( | ||
private platformServiceInterface: PlatformServiceInterface | ||
) { | ||
} | ||
|
||
postUserFeedback(userFeedback: UserFeedback): void { | ||
this.platformServiceInterface.postUserFeedbacks(userFeedback) | ||
} | ||
|
||
sortByDateFromNewestToOldest(userFeedbackA: UserFeedback, userFeedbackB: UserFeedback): number { | ||
return new Date(userFeedbackB.date).getTime() - new Date(userFeedbackA.date).getTime() | ||
} | ||
|
||
sortByDateFromOldestToNewest(userFeedbackA: UserFeedback, userFeedbackB: UserFeedback): number { | ||
return new Date(userFeedbackA.date).getTime() - new Date(userFeedbackB.date).getTime() | ||
} | ||
} |
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
Oops, something went wrong.