Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development: Migrate client code for posting header and footer components #9932

Merged
merged 22 commits into from
Dec 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
}
@if (!isConsecutive()) {
<div class="ps-3">
<jhi-answer-post-header
<jhi-posting-header
[posting]="posting"
[isReadOnlyMode]="isReadOnlyMode"
[readOnlyMode]="isReadOnlyMode"
asliayk marked this conversation as resolved.
Show resolved Hide resolved
[isCommunicationPage]="isCommunicationPage"
[lastReadDate]="lastReadDate"
[isDeleted]="isDeleted"
Expand Down
15 changes: 6 additions & 9 deletions src/main/webapp/app/shared/metis/metis.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ import { ArtemisMarkdownModule } from 'app/shared/markdown.module';
import { ArtemisMarkdownEditorModule } from 'app/shared/markdown-editor/markdown-editor.module';
import { PostingButtonComponent } from 'app/shared/metis/posting-button/posting-button.component';
import { PostingMarkdownEditorComponent } from 'app/shared/metis/posting-markdown-editor/posting-markdown-editor.component';
import { AnswerPostHeaderComponent } from 'app/shared/metis/posting-header/answer-post-header/answer-post-header.component';
import { PostHeaderComponent } from 'app/shared/metis/posting-header/post-header/post-header.component';
import { PostingHeaderComponent } from 'app/shared/metis/posting-header/posting-header.component';
import { AnswerPostCreateEditModalComponent } from 'app/shared/metis/posting-create-edit-modal/answer-post-create-edit-modal/answer-post-create-edit-modal.component';
import { PostCreateEditModalComponent } from 'app/shared/metis/posting-create-edit-modal/post-create-edit-modal/post-create-edit-modal.component';
import { PostFooterComponent } from 'app/shared/metis/posting-footer/post-footer/post-footer.component';
import { PostingFooterComponent } from 'app/shared/metis/posting-footer/posting-footer.component';
import { PostTagSelectorComponent } from 'app/shared/metis/posting-create-edit-modal/post-create-edit-modal/post-tag-selector/post-tag-selector.component';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { ArtemisSharedComponentModule } from 'app/shared/components/shared-component.module';
Expand Down Expand Up @@ -70,11 +69,10 @@ import { ProfilePictureComponent } from 'app/shared/profile-picture/profile-pict
],
declarations: [
PostingThreadComponent,
PostHeaderComponent,
AnswerPostHeaderComponent,
PostingHeaderComponent,
PostCreateEditModalComponent,
PostTagSelectorComponent,
PostFooterComponent,
PostingFooterComponent,
AnswerPostCreateEditModalComponent,
PostingButtonComponent,
PostingMarkdownEditorComponent,
Expand All @@ -93,12 +91,11 @@ import { ProfilePictureComponent } from 'app/shared/profile-picture/profile-pict
],
exports: [
PostingThreadComponent,
PostHeaderComponent,
AnswerPostHeaderComponent,
PostingHeaderComponent,
PostCreateEditModalComponent,
PostTagSelectorComponent,
AnswerPostCreateEditModalComponent,
PostFooterComponent,
PostingFooterComponent,
PostingButtonComponent,
PostingMarkdownEditorComponent,
PostComponent,
Expand Down
4 changes: 2 additions & 2 deletions src/main/webapp/app/shared/metis/post/post.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
}
@if (!isConsecutive()) {
<div class="ps-3">
<jhi-post-header
<jhi-posting-header
[previewMode]="previewMode"
[readOnlyMode]="readOnlyMode"
[posting]="posting"
Expand Down Expand Up @@ -147,7 +147,7 @@
</div>
}
</div>
<jhi-post-footer
<jhi-posting-footer
#postFooter
[readOnlyMode]="readOnlyMode"
[modalRef]="modalRef"
Expand Down
4 changes: 2 additions & 2 deletions src/main/webapp/app/shared/metis/post/post.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
import { ContextInformation, DisplayPriority, PageType, RouteComponents } from '../metis.util';
import { faBookmark, faBullhorn, faCheckSquare, faComments, faPencilAlt, faSmile, faThumbtack, faTrash } from '@fortawesome/free-solid-svg-icons';
import dayjs from 'dayjs/esm';
import { PostFooterComponent } from 'app/shared/metis/posting-footer/post-footer/post-footer.component';
import { PostingFooterComponent } from 'app/shared/metis/posting-footer/posting-footer.component';
import { isCommunicationEnabled } from 'app/entities/course.model';
import { getAsChannelDTO } from 'app/entities/metis/conversation/channel.model';
import { AnswerPost } from 'app/entities/metis/answer-post.model';
Expand Down Expand Up @@ -57,7 +57,7 @@ export class PostComponent extends PostingDirective<Post> implements OnInit, OnC
@ViewChild('createAnswerPostModal') createAnswerPostModalComponent: AnswerPostCreateEditModalComponent;
@ViewChild('createEditModal') createEditModal!: PostCreateEditModalComponent;
@ViewChild('createEditAnswerPostContainer', { read: ViewContainerRef }) containerRef: ViewContainerRef;
@ViewChild('postFooter') postFooterComponent: PostFooterComponent;
@ViewChild('postFooter') postFooterComponent: PostingFooterComponent;
showReactionSelector = false;
@ViewChild('emojiPickerTrigger') emojiPickerTrigger!: CdkOverlayOrigin;
static activeDropdownPost: PostComponent | null = null;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
@if (showAnswers) {
@if (showAnswers()) {
<div class="d-flex align-items-center mt-2">
<div class="fs-x-small fw-900 me-2">
{{
sortedAnswerPosts.length === 1
sortedAnswerPosts().length === 1
? ('artemisApp.metis.singleAnswer' | artemisTranslate)
: ('artemisApp.metis.multipleAnswers' | artemisTranslate: { number: sortedAnswerPosts.length })
: ('artemisApp.metis.multipleAnswers' | artemisTranslate: { number: sortedAnswerPosts().length })
}}
</div>
<div class="flex-grow-1">
Expand All @@ -15,17 +15,17 @@
@for (group of groupedAnswerPosts; track trackGroupByFn($index, group)) {
@for (answerPost of group.posts; track trackPostByFn($index, answerPost)) {
<jhi-answer-post
[lastReadDate]="lastReadDate"
[isReadOnlyMode]="readOnlyMode"
[lastReadDate]="lastReadDate()"
[isReadOnlyMode]="readOnlyMode()"
[posting]="answerPost"
[isConsecutive]="answerPost.isConsecutive || false"
[isLastAnswer]="isLastPost(group, answerPost)"
[isCommunicationPage]="isCommunicationPage"
[isThreadSidebar]="isThreadSidebar"
[isCommunicationPage]="isCommunicationPage()"
[isThreadSidebar]="isThreadSidebar()"
(openPostingCreateEditModal)="createAnswerPostModal.open()"
(userReferenceClicked)="userReferenceClicked.emit($event)"
(channelReferenceClicked)="channelReferenceClicked.emit($event)"
[hasChannelModerationRights]="hasChannelModerationRights"
[hasChannelModerationRights]="hasChannelModerationRights()"
/>
}
}
Expand All @@ -38,6 +38,6 @@
#createAnswerPostModal
[posting]="createdAnswerPost"
[createEditAnswerPostContainerRef]="containerRef"
(onCreate)="createdAnswerPost = createEmptyAnswerPost(); showAnswers = true"
(onCreate)="createdAnswerPost = createEmptyAnswerPost(); showAnswers()"
/>
</div>
Original file line number Diff line number Diff line change
@@ -1,49 +1,38 @@
import {
AfterContentChecked,
ChangeDetectorRef,
Component,
EventEmitter,
Input,
OnChanges,
OnDestroy,
OnInit,
Output,
SimpleChanges,
ViewChild,
ViewContainerRef,
} from '@angular/core';
import { PostingFooterDirective } from 'app/shared/metis/posting-footer/posting-footer.directive';
import { AfterContentChecked, ChangeDetectorRef, Component, OnChanges, OnDestroy, OnInit, SimpleChanges, ViewChild, ViewContainerRef, inject, input, output } from '@angular/core';
import { Post } from 'app/entities/metis/post.model';
import { MetisService } from 'app/shared/metis/metis.service';
import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
import { AnswerPostCreateEditModalComponent } from 'app/shared/metis/posting-create-edit-modal/answer-post-create-edit-modal/answer-post-create-edit-modal.component';
import { AnswerPost } from 'app/entities/metis/answer-post.model';
import dayjs from 'dayjs/esm';
import { User } from 'app/core/user/user.model';
import { Posting } from 'app/entities/metis/posting.model';

asliayk marked this conversation as resolved.
Show resolved Hide resolved
interface PostGroup {
author: User | undefined;
posts: AnswerPost[];
}

@Component({
selector: 'jhi-post-footer',
templateUrl: './post-footer.component.html',
styleUrls: ['./post-footer.component.scss'],
selector: 'jhi-posting-footer',
templateUrl: './posting-footer.component.html',
})
export class PostFooterComponent extends PostingFooterDirective<Post> implements OnInit, OnDestroy, AfterContentChecked, OnChanges {
@Input() lastReadDate?: dayjs.Dayjs;
@Input() readOnlyMode = false;
@Input() previewMode = false;
@Input() modalRef?: NgbModalRef;
@Input() hasChannelModerationRights = false;
@Input() showAnswers = false;
@Input() isCommunicationPage = false;
@Input() sortedAnswerPosts: AnswerPost[] = [];

@Output() openThread = new EventEmitter<void>();
@Output() userReferenceClicked = new EventEmitter<string>();
@Output() channelReferenceClicked = new EventEmitter<number>();
export class PostingFooterComponent implements OnInit, OnDestroy, AfterContentChecked, OnChanges {
lastReadDate = input<dayjs.Dayjs | undefined>();
readOnlyMode = input<boolean>(false);
previewMode = input<boolean>(false);
modalRef = input<NgbModalRef | undefined>();
hasChannelModerationRights = input<boolean>(false);
showAnswers = input<boolean>(false);
isCommunicationPage = input<boolean>(false);
sortedAnswerPosts = input<AnswerPost[]>([]);
isThreadSidebar = input<boolean>(false);
posting = input<Posting>();

// Output Signals
openThread = output<void>();
userReferenceClicked = output<string>();
channelReferenceClicked = output<number>();

@ViewChild(AnswerPostCreateEditModalComponent) answerPostCreateEditModal?: AnswerPostCreateEditModalComponent;
@ViewChild('createEditAnswerPostContainer', { read: ViewContainerRef }) containerRef!: ViewContainerRef;
Expand All @@ -54,12 +43,8 @@ export class PostFooterComponent extends PostingFooterDirective<Post> implements
courseId!: number;
groupedAnswerPosts: PostGroup[] = [];

constructor(
private metisService: MetisService,
protected changeDetector: ChangeDetectorRef,
) {
super();
}
protected metisService: MetisService = inject(MetisService);
protected changeDetector: ChangeDetectorRef = inject(ChangeDetectorRef);

asliayk marked this conversation as resolved.
Show resolved Hide resolved
ngOnInit(): void {
this.courseId = this.metisService.getCourse().id!;
Expand Down Expand Up @@ -94,26 +79,26 @@ export class PostFooterComponent extends PostingFooterDirective<Post> implements
createEmptyAnswerPost(): AnswerPost {
const answerPost = new AnswerPost();
answerPost.content = '';
answerPost.post = this.posting;
answerPost.post = this.posting();
answerPost.resolvesPost = this.isAtLeastTutorInCourse;
asliayk marked this conversation as resolved.
Show resolved Hide resolved
return answerPost;
}

groupAnswerPosts(): void {
if (!this.sortedAnswerPosts || this.sortedAnswerPosts.length === 0) {
if (!this.sortedAnswerPosts() || this.sortedAnswerPosts().length === 0) {
this.groupedAnswerPosts = [];
return;
}

this.sortedAnswerPosts = this.sortedAnswerPosts
const sortedAnswerPosts = this.sortedAnswerPosts()
.slice()
.reverse()
.map((post) => {
(post as any).creationDateDayjs = post.creationDate ? dayjs(post.creationDate) : undefined;
return post;
});

const sortedPosts = this.sortedAnswerPosts.sort((a, b) => {
const sortedPosts = sortedAnswerPosts.sort((a, b) => {
const aDate = (a as any).creationDateDayjs;
const bDate = (b as any).creationDateDayjs;
return aDate?.valueOf() - bDate?.valueOf();
Expand Down Expand Up @@ -170,14 +155,14 @@ export class PostFooterComponent extends PostingFooterDirective<Post> implements
* Open create answer modal
*/
openCreateAnswerPostModal() {
this.createAnswerPostModalComponent.open();
this.createAnswerPostModalComponent?.open();
}

/**
* Close create answer modal
*/
closeCreateAnswerPostModal() {
this.createAnswerPostModalComponent.close();
this.createAnswerPostModalComponent?.close();
}
asliayk marked this conversation as resolved.
Show resolved Hide resolved

protected postsTrackByFn(index: number, post: Post): number {
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Loading
Loading