From dcc5f9f0768a6bb87b9febc7c6ae6c7d065425d4 Mon Sep 17 00:00:00 2001 From: Florian Eisenmenger Date: Wed, 6 Mar 2024 17:16:41 +0100 Subject: [PATCH] comments on partners and contacts --- matsen-tool/src/app/app.module.ts | 4 +- .../contacts-detail.component.html | 62 +++++++--------- .../contacts-detail.component.ts | 72 ++++++++++++++++--- .../two-column/two-column.component.html | 6 +- .../partners-detail.component.html | 5 +- .../partners-detail.component.ts | 37 +++++++++- .../new-comment/new-comment.component.html | 15 ++++ .../new-comment/new-comment.component.scss | 0 .../new-comment/new-comment.component.spec.ts | 23 ++++++ .../new-comment/new-comment.component.ts | 60 ++++++++++++++++ .../new-posting/new-posting.component.ts | 2 +- 11 files changed, 233 insertions(+), 53 deletions(-) create mode 100644 matsen-tool/src/app/postings/new-comment/new-comment.component.html create mode 100644 matsen-tool/src/app/postings/new-comment/new-comment.component.scss create mode 100644 matsen-tool/src/app/postings/new-comment/new-comment.component.spec.ts create mode 100644 matsen-tool/src/app/postings/new-comment/new-comment.component.ts diff --git a/matsen-tool/src/app/app.module.ts b/matsen-tool/src/app/app.module.ts index 318336c..4dd805e 100644 --- a/matsen-tool/src/app/app.module.ts +++ b/matsen-tool/src/app/app.module.ts @@ -37,6 +37,7 @@ import { NewTaskComponent } from './tasks/new-task/new-task.component'; import { NewPartnerComponent } from './partners/new-partner/new-partner.component'; import { NewDocumentComponent } from './documents/new-document/new-document.component'; import { NewProductComponent } from './products/new-product/new-product.component'; +import { NewCommentComponent } from './postings/new-comment/new-comment.component'; export function apiConfigFactory(): Configuration { const params: ConfigurationParameters = { @@ -94,7 +95,8 @@ export function HttpLoaderFactory(http: HttpClient) { NewTaskComponent, NewPartnerComponent, NewDocumentComponent, - NewProductComponent + NewProductComponent, + NewCommentComponent ], providers: [ {provide: HTTP_INTERCEPTORS, useClass: JwtInterceptor, multi: true}, diff --git a/matsen-tool/src/app/contacts/contacts-detail/contacts-detail.component.html b/matsen-tool/src/app/contacts/contacts-detail/contacts-detail.component.html index 88b27ba..a155d61 100644 --- a/matsen-tool/src/app/contacts/contacts-detail/contacts-detail.component.html +++ b/matsen-tool/src/app/contacts/contacts-detail/contacts-detail.component.html @@ -27,48 +27,40 @@

Notizen

-
-
-
-
-
-

{{ post.createdAt | date:'dd.MM.YYYY hh:mm' }}

-

{{ post.ownerName }}

-
-
-

{{ post.headline }}

-

{{ post.message }}

-
+
+
+
+
+

{{ post.createdAt | date:'dd.MM.YYYY HH:mm' }}

+

{{ post.ownerName }}

-
-
-
-
-

04.10.2023

-

Jan Hansen

-
-
-

Leider geht er mobil selten dran. Eher E-Mails schicken!

-
+
+

{{ post.headline }}

+

{{ post.message }}

+
-
-
-
-

02.10.2023

-

Florian Eisenmenger

-
-
-

Ich habe mit FAX die besten Erfahrungen gemacht...

-
+
+
+
+
+

{{ comment.createdAt | date:'dd.MM.YYYY HH:mm' }}

+

{{ comment.ownerName }}

+
+

{{ comment.message }}

+
+
- +
+ +
+ Kommentieren
- (this.posts); this.postsLength = 0; this.postsPageEvent = new PageEvent(); - this.postsPageSize = 30; + this.postsPageSize = 10; this.postsPageIndex = 0; } @@ -59,6 +66,8 @@ export class ContactsDetailComponent implements OnInit, AfterViewInit { this.id = params['id']; }); this.getContactData(); + this.getPostsData(); + console.log(this.posts); } ngAfterViewInit() { @@ -80,16 +89,14 @@ export class ContactsDetailComponent implements OnInit, AfterViewInit { getPostsData() { this.postsSub = this.postService.postsGetCollection( this.postsPageIndex + 1, - 10, - undefined, - undefined, + this.postsPageSize, + this.contact.partner + '', + [], this.id ).subscribe( data => { - console.log(data); this.posts = data["hydra:member"]; this.postsLength = Number(data["hydra:totalItems"]); - this.postsPaginator.length = this.postsLength; } ); } @@ -103,8 +110,53 @@ export class ContactsDetailComponent implements OnInit, AfterViewInit { } openModalNewPosting() { - const modalRef = this.modalService.open(ModalComponent); - modalRef.componentInstance.dynamicComponent = NewPostingComponent; + const modalRefPosting = this.modalService.open(NewPostingComponent); + let posting: PostJsonld = {} as PostJsonld; + posting.contact = this.contact.id ?? null; + posting.partner = this.contact.partner ?? null; + modalRefPosting.componentInstance.posting = posting; + modalRefPosting.componentInstance.submit.subscribe((modalStatus: ModalStatus) => { + if (modalStatus === ModalStatus.Submitted) { + modalRefPosting.dismiss(); + this.getPostsData(); + } + }); + } + + openModalNewComment(post: PostJsonld) { + const modalRefComment = this.modalService.open(NewCommentComponent); + let comment: CommentJsonld = {} as CommentJsonld; + comment.post = post.id ?? null; + modalRefComment.componentInstance.comment = comment; + modalRefComment.componentInstance.submit.subscribe((modalStatus: ModalStatus) => { + if (modalStatus === ModalStatus.Submitted) { + modalRefComment.dismiss(); + this.getPostsData(); + } + }); + } + + openModalEditPosting(post: PostJsonld) { + const modalRefPostingEdit = this.modalService.open(NewPostingComponent); + modalRefPostingEdit.componentInstance.posting = post; + modalRefPostingEdit.componentInstance.submit.subscribe((modalStatus: ModalStatus) => { + if (modalStatus === ModalStatus.Submitted) { + modalRefPostingEdit.dismiss(); + this.getPostsData(); + } + }); + } + + openModalEditComment(comment: CommentJsonld) { + console.log(comment); + const modalRefComment = this.modalService.open(NewCommentComponent); + modalRefComment.componentInstance.comment = comment; + modalRefComment.componentInstance.submit.subscribe((modalStatus: ModalStatus) => { + if (modalStatus === ModalStatus.Submitted) { + modalRefComment.dismiss(); + this.getPostsData(); + } + }); } openModalEditContact() { diff --git a/matsen-tool/src/app/layout/two-column/two-column.component.html b/matsen-tool/src/app/layout/two-column/two-column.component.html index 19c0050..44204e5 100644 --- a/matsen-tool/src/app/layout/two-column/two-column.component.html +++ b/matsen-tool/src/app/layout/two-column/two-column.component.html @@ -46,7 +46,9 @@
- - +
+ + +
\ No newline at end of file diff --git a/matsen-tool/src/app/partners/partners-detail/partners-detail.component.html b/matsen-tool/src/app/partners/partners-detail/partners-detail.component.html index 2d946ef..18e56c7 100644 --- a/matsen-tool/src/app/partners/partners-detail/partners-detail.component.html +++ b/matsen-tool/src/app/partners/partners-detail/partners-detail.component.html @@ -157,17 +157,18 @@
-

{{ comment.createdAt | date:'dd.MM.YYYY hh:mm' }}

+

{{ comment.createdAt | date:'dd.MM.YYYY HH:mm' }}

{{ comment.ownerName }}

{{ comment.message }}

+
- Kommentieren + Kommentieren
{ this.posts = data["hydra:member"]; this.postsLength = Number(data["hydra:totalItems"]); - // this.postsPaginator.length = this.postsLength; } ); } @@ -209,6 +217,19 @@ export class PartnersDetailComponent implements OnInit, AfterViewInit { }); } + openModalNewComment(post: PostJsonld) { + const modalRefComment = this.modalService.open(NewCommentComponent); + let comment: CommentJsonld = {} as CommentJsonld; + comment.post = post.id ?? null; + modalRefComment.componentInstance.comment = comment; + modalRefComment.componentInstance.submit.subscribe((modalStatus: ModalStatus) => { + if (modalStatus === ModalStatus.Submitted) { + modalRefComment.dismiss(); + this.getPostsData(); + } + }); + } + openModalEditPosting(post: PostJsonld) { const modalRefPostingEdit = this.modalService.open(NewPostingComponent); modalRefPostingEdit.componentInstance.posting = post; @@ -220,6 +241,18 @@ export class PartnersDetailComponent implements OnInit, AfterViewInit { }); } + openModalEditComment(comment: CommentJsonld) { + console.log(comment); + const modalRefComment = this.modalService.open(NewCommentComponent); + modalRefComment.componentInstance.comment = comment; + modalRefComment.componentInstance.submit.subscribe((modalStatus: ModalStatus) => { + if (modalStatus === ModalStatus.Submitted) { + modalRefComment.dismiss(); + this.getPostsData(); + } + }); + } + openModalNewTask() { // TODO const modalRef = this.modalService.open(ModalComponent); diff --git a/matsen-tool/src/app/postings/new-comment/new-comment.component.html b/matsen-tool/src/app/postings/new-comment/new-comment.component.html new file mode 100644 index 0000000..bf14d59 --- /dev/null +++ b/matsen-tool/src/app/postings/new-comment/new-comment.component.html @@ -0,0 +1,15 @@ +

Neuer Kommentar

+
+
+
+ + +
+ Kommentar ist erforderlich. +
+
+ + +
+
+ diff --git a/matsen-tool/src/app/postings/new-comment/new-comment.component.scss b/matsen-tool/src/app/postings/new-comment/new-comment.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/matsen-tool/src/app/postings/new-comment/new-comment.component.spec.ts b/matsen-tool/src/app/postings/new-comment/new-comment.component.spec.ts new file mode 100644 index 0000000..2281b38 --- /dev/null +++ b/matsen-tool/src/app/postings/new-comment/new-comment.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { NewCommentComponent } from './new-comment.component'; + +describe('NewCommentComponent', () => { + let component: NewCommentComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [NewCommentComponent] + }) + .compileComponents(); + + fixture = TestBed.createComponent(NewCommentComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/matsen-tool/src/app/postings/new-comment/new-comment.component.ts b/matsen-tool/src/app/postings/new-comment/new-comment.component.ts new file mode 100644 index 0000000..c14c27e --- /dev/null +++ b/matsen-tool/src/app/postings/new-comment/new-comment.component.ts @@ -0,0 +1,60 @@ +import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core'; +import {ModalStatus} from "@app/_helpers/modal.states"; +import {CommentJsonld, CommentService, PostJsonld, PostService} from "@app/core/api/v1"; +import {Subscription} from "rxjs"; +import {FormGroupInitializer} from "@app/_helpers/formgroup.initializer"; +import {FormGroup} from "@angular/forms"; +import {commentForm} from "@app/_forms/apiForms"; +import {ApiConverter} from "@app/_helpers/api.converter"; + +@Component({ + selector: 'app-new-comment', + templateUrl: './new-comment.component.html', + styleUrl: './new-comment.component.scss' +}) +export class NewCommentComponent implements OnInit { + @Input() public comment!: CommentJsonld; + @Output() public submit: EventEmitter = new EventEmitter(); + + protected commentForm: FormGroup; + protected commentSub: Subscription; + + constructor( + private commentService: CommentService + ) { + this.commentForm = commentForm; + this.commentSub = new Subscription(); + } + + ngOnInit(): void { + this.commentForm = FormGroupInitializer.initFormGroup(this.commentForm, this.comment); + console.log(this.comment); + } + + onSubmit() { + if (this.commentForm.valid) { + if (this.comment.id === null || this.comment.id === undefined) { + // Create new post + this.commentSub = this.commentService.commentsPost( + this.commentForm.value as PostJsonld + ).subscribe( + data => { + this.commentForm.reset(); + this.submit.emit(ModalStatus.Submitted); + } + ); + } else { + // Edit post + this.commentSub = this.commentService.commentsIdPatch( + ApiConverter.extractId(this.comment.id), + this.commentForm.value as PostJsonld + ).subscribe( + data => { + this.commentForm.reset(); + this.submit.emit(ModalStatus.Submitted); + } + ); + } + } + } +} diff --git a/matsen-tool/src/app/postings/new-posting/new-posting.component.ts b/matsen-tool/src/app/postings/new-posting/new-posting.component.ts index 0a0639c..49c6218 100644 --- a/matsen-tool/src/app/postings/new-posting/new-posting.component.ts +++ b/matsen-tool/src/app/postings/new-posting/new-posting.component.ts @@ -2,7 +2,7 @@ import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core'; import {ModalStatus} from "@app/_helpers/modal.states"; import {FormGroup} from "@angular/forms"; import {postForm} from "@app/_forms/apiForms"; -import {ContactJsonld, PostJsonld, PostService} from "@app/core/api/v1"; +import {PostJsonld, PostService} from "@app/core/api/v1"; import {FormGroupInitializer} from "@app/_helpers/formgroup.initializer"; import {ApiConverter} from "@app/_helpers/api.converter"; import {Subscription} from "rxjs";