From 44baf66c032352822a237f23837fcbeb5857f584 Mon Sep 17 00:00:00 2001 From: Florian Eisenmenger Date: Fri, 17 May 2024 17:53:14 +0200 Subject: [PATCH] Posts fixed --- .../linked-label/linked-label.component.html | 7 +-- .../posts/new-post/new-post.component.html | 5 +- .../posts/post-list/post-list.component.html | 12 ++-- .../posts/post-list/post-list.component.ts | 50 +++++++++------- .../sales/sale-list/sale-list.component.html | 6 +- .../sales-detail/sales-detail.component.html | 57 ++----------------- .../sales-detail/sales-detail.component.ts | 2 +- 7 files changed, 50 insertions(+), 89 deletions(-) diff --git a/matsen-tool/src/app/_components/linked-label/linked-label.component.html b/matsen-tool/src/app/_components/linked-label/linked-label.component.html index 807914d..37573db 100644 --- a/matsen-tool/src/app/_components/linked-label/linked-label.component.html +++ b/matsen-tool/src/app/_components/linked-label/linked-label.component.html @@ -5,10 +5,9 @@ {{product.name}} - - {{contact.firstName}} {{contact.lastName}} + + {{contact.firstName}} {{contact.lastName}} - - {{user.firstName}} {{user.lastName}} + {{user.firstName}} {{user.lastName}} diff --git a/matsen-tool/src/app/_views/posts/new-post/new-post.component.html b/matsen-tool/src/app/_views/posts/new-post/new-post.component.html index c317d54..5e6c5c5 100644 --- a/matsen-tool/src/app/_views/posts/new-post/new-post.component.html +++ b/matsen-tool/src/app/_views/posts/new-post/new-post.component.html @@ -11,7 +11,7 @@
- - + +
diff --git a/matsen-tool/src/app/_views/posts/post-list/post-list.component.html b/matsen-tool/src/app/_views/posts/post-list/post-list.component.html index 1732152..52651da 100644 --- a/matsen-tool/src/app/_views/posts/post-list/post-list.component.html +++ b/matsen-tool/src/app/_views/posts/post-list/post-list.component.html @@ -4,7 +4,7 @@
@@ -21,23 +21,23 @@

-

{{ post.owner?.firstName }} {{ post.owner?.lastName }}

+

{{ post.owner?.fullName }}

{{ post.headline }}

-
- {{ 'basic.hide-comments' | translate }} {{ 'basic.show-comments' | translate }} + *ngIf="post.id && !commentsVisibility.get(post.id)">{{ 'basic.show-comments' | translate }} ({{post.numComments}}) {{ 'basic.comment-it' | translate }} @@ -55,7 +55,7 @@

-
diff --git a/matsen-tool/src/app/_views/posts/post-list/post-list.component.ts b/matsen-tool/src/app/_views/posts/post-list/post-list.component.ts index 85a8f49..ba5e9e9 100644 --- a/matsen-tool/src/app/_views/posts/post-list/post-list.component.ts +++ b/matsen-tool/src/app/_views/posts/post-list/post-list.component.ts @@ -43,6 +43,7 @@ export class PostListComponent implements OnInit, AfterViewInit { protected commentsVisibility: Map; protected commentsSub: Subscription; protected comments: Map; + protected postSub: Subscription; constructor( private postService: PostService, @@ -59,6 +60,7 @@ export class PostListComponent implements OnInit, AfterViewInit { this.currentUser = this.accountService.userValue; this.commentsSub = new Subscription(); this.comments = new Map(); + this.postSub = new Subscription(); } ngOnInit() { @@ -68,7 +70,7 @@ export class PostListComponent implements OnInit, AfterViewInit { this.pagingComponent.getData(); } - getData = () => { + getPostsData = () => { this.postsSub = this.postService.postsGetCollection( this.pagingComponent.getPageIndex(), this.pagingComponent.getPageSize(), @@ -86,11 +88,20 @@ export class PostListComponent implements OnInit, AfterViewInit { data => { this.posts = data["hydra:member"]; this.pagingComponent.dataLength = Number(data["hydra:totalItems"]); - // this.posts.forEach(posts => { - // if (posts.id) { - // this.commentsVisibility.set(posts.id, false); - // } - // }); + } + ); + } + + getPostData = (postIri: string) => { + this.postSub = this.postService.postsIdGet(this.appHelperService.extractId(postIri)).subscribe( + data => { + for (let index = 0; index < this.posts.length; index++) { + const item = this.posts[index]; + if (data.id === item.id) { + this.posts[index] = data; + break; + } + } } ); } @@ -100,48 +111,47 @@ export class PostListComponent implements OnInit, AfterViewInit { const currentVisibility = this.commentsVisibility.get(post.id); this.commentsVisibility.set(post.id, !currentVisibility); if (this.comments.get(post.id) === undefined) { - this.getComments(post); + this.getComments(post.id); } } - - } - getComments = (post: PostJsonld) => { - if (post.id) { + getComments = (postIri: string) => { // TODO: Weiterblättern, 50 comments only this.commentsSub = this.commentService.commentsGetCollection( 1, 50, - post.id + postIri ).subscribe( data => { - if (post.id) { - this.comments.set(post.id, data["hydra:member"]); - } + this.comments.set(postIri, data["hydra:member"]); } ); - } + } + + afterCommentCreation = (postIri: string) => { + this.getComments(postIri); + this.getPostData(postIri); } openModalNewPost() { let post: PostJsonld = {} as PostJsonld; post.partnerIri = this.partner.id; - this.appHelperService.openModal(NewPostComponent, { 'posting': post }, this.getData); + this.appHelperService.openModal(NewPostComponent, { 'posting': post }, this.getPostsData); } openModalEditPost(post: PostJsonld) { - this.appHelperService.openModal(NewPostComponent, { 'posting': post }, this.getData); + this.appHelperService.openModal(NewPostComponent, { 'posting': post }, this.getPostsData); } openModalNewComment(post: PostJsonld) { let comment: CommentJsonld = {} as CommentJsonld; comment.postIri = post.id; - this.appHelperService.openModal(NewCommentComponent, { 'comment': comment }, this.getComments, post); + this.appHelperService.openModal(NewCommentComponent, { 'comment': comment }, this.afterCommentCreation, post.id); } openModalEditComment(comment: CommentJsonld) { - this.appHelperService.openModal(NewCommentComponent, { 'comment': comment }, this.getData); + this.appHelperService.openModal(NewCommentComponent, { 'comment': comment }, this.afterCommentCreation, comment.postIri); } diff --git a/matsen-tool/src/app/_views/sales/sale-list/sale-list.component.html b/matsen-tool/src/app/_views/sales/sale-list/sale-list.component.html index 0adc422..228b0ee 100644 --- a/matsen-tool/src/app/_views/sales/sale-list/sale-list.component.html +++ b/matsen-tool/src/app/_views/sales/sale-list/sale-list.component.html @@ -24,7 +24,7 @@ {{ 'overview.sale-user' | translate }} - {{ element.ownerName }} + {{ element.owner.fullName }} @@ -34,7 +34,7 @@ {{ 'overview.sale-partner' | translate }} - {{ element.partnerName }} + {{ element.partner.name }} @@ -44,7 +44,7 @@ {{ 'overview.productname' | translate }} - {{ element.productName }} + {{ element.product.name }} diff --git a/matsen-tool/src/app/_views/sales/sales-detail/sales-detail.component.html b/matsen-tool/src/app/_views/sales/sales-detail/sales-detail.component.html index 8acfd93..f3b3c29 100644 --- a/matsen-tool/src/app/_views/sales/sales-detail/sales-detail.component.html +++ b/matsen-tool/src/app/_views/sales/sales-detail/sales-detail.component.html @@ -24,56 +24,7 @@ -
-
-
- -
- -
-
-
-
-

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

-

{{ post.owner?.fullName }}

-
-
-

{{ post.headline }}

-

-
- -
-
-
- - - - - - - - - - - - - -
- -
- - - - - - -
-
-
-
-
-
\ No newline at end of file + + diff --git a/matsen-tool/src/app/_views/sales/sales-detail/sales-detail.component.ts b/matsen-tool/src/app/_views/sales/sales-detail/sales-detail.component.ts index a9c3406..475f19a 100644 --- a/matsen-tool/src/app/_views/sales/sales-detail/sales-detail.component.ts +++ b/matsen-tool/src/app/_views/sales/sales-detail/sales-detail.component.ts @@ -68,7 +68,7 @@ export class SalesDetailComponent implements OnInit, AfterViewInit { ).subscribe( data => { this.sale = data; - this.pagingComponent.getData(); + // this.pagingComponent.getData(); } ); }