From abd5dd61e2de052c929ab716a82b33fade1dbaeb Mon Sep 17 00:00:00 2001 From: Florian Eisenmenger Date: Wed, 19 Jun 2024 16:24:45 +0200 Subject: [PATCH] refactoring --- .../search-select/search-select.component.ts | 16 ++---- .../contacts-detail.component.ts | 5 +- .../posts/new-post/new-post.component.html | 10 ++-- .../posts/post-list/post-list.component.html | 8 +-- .../posts/post-list/post-list.component.ts | 55 +++++++++---------- .../tasks/task-list/task-list.component.html | 12 ++-- .../tasks/task-list/task-list.component.ts | 36 +++++------- 7 files changed, 63 insertions(+), 79 deletions(-) diff --git a/matsen-tool/src/app/_components/search-select/search-select.component.ts b/matsen-tool/src/app/_components/search-select/search-select.component.ts index 17c8e83..72e958e 100644 --- a/matsen-tool/src/app/_components/search-select/search-select.component.ts +++ b/matsen-tool/src/app/_components/search-select/search-select.component.ts @@ -1,17 +1,13 @@ import {AfterViewInit, Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild} from '@angular/core'; -import {PagingComponent} from "@app/_components/paging/paging.component"; import {FormGroup} from "@angular/forms"; -import {SearchInputColDef} from "@app/_components/search-input/search-input-col-def"; -import {MatSort, Sort} from "@angular/material/sort"; -import {OrderFilter} from "@app/_models/orderFilter"; import {ListComponent} from "@app/_components/list/list.component"; import {ListColDefinition} from "@app/_components/list/list-col-definition"; import {Observable} from "rxjs"; @Component({ - selector: 'app-search-select', - templateUrl: './search-select.component.html', - styleUrl: './search-select.component.scss' + selector: 'app-search-select', + templateUrl: './search-select.component.html', + styleUrl: './search-select.component.scss' }) export class SearchSelectComponent implements OnInit, AfterViewInit { @Input() public formId!: string; @@ -24,8 +20,8 @@ export class SearchSelectComponent implements OnInit, AfterViewInit { @Input() public displayedDataSubResource!: string; @Input() public listColDefinitions!: ListColDefinition[]; @Output() rowSelected = new EventEmitter(); - @ViewChild('paragraphRef', { static: false }) paragraphRef!: ElementRef; - @ViewChild("listComponent", { static: false }) listComponent!: ListComponent; + @ViewChild('paragraphRef', {static: false}) paragraphRef!: ElementRef; + @ViewChild("listComponent", {static: false}) listComponent!: ListComponent; protected readonly SearchSelectComponent = SearchSelectComponent; protected selectedRowIndex: number | null = null; @@ -47,7 +43,7 @@ export class SearchSelectComponent implements OnInit, AfterViewInit { ngAfterViewInit(): void { if (this.dataSet !== undefined) { - this.paragraphRef.nativeElement.textContent = this.dataSet[this.displayedDataField]; + this.paragraphRef.nativeElement.textContent = this.dataSet[this.displayedDataField]; } } diff --git a/matsen-tool/src/app/_views/contacts/contacts-detail/contacts-detail.component.ts b/matsen-tool/src/app/_views/contacts/contacts-detail/contacts-detail.component.ts index 6cfd93f..c6634bd 100644 --- a/matsen-tool/src/app/_views/contacts/contacts-detail/contacts-detail.component.ts +++ b/matsen-tool/src/app/_views/contacts/contacts-detail/contacts-detail.component.ts @@ -103,7 +103,10 @@ export class ContactsDetailComponent implements OnInit, AfterViewInit { } openModalEditContact() { - let data: any = {'contact': this.contact} + let data: any = { + 'contact': this.contact, + 'partner': this.partner + } if (this.contact.birthday !== undefined) { data.birthdayValue = this.appHelperService.convertDate(this.contact.birthday); } 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 33a51dd..b0bccc8 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 @@ -17,8 +17,8 @@
- - + - -
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 fb2ffe5..37e4d51 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 @@ -1,7 +1,7 @@
- +

+ data-action="edit" (click)="openModalNewEditPost(post)">
{{ 'basic.comment-it' | translate }} + (click)="openModalNewEditComment(post)">{{ 'basic.comment-it' | translate }}
@@ -61,7 +61,7 @@ + (click)="openModalNewEditComment(undefined, comment)"> 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 93526bc..786eaca 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 @@ -2,7 +2,7 @@ import {AfterViewInit, Component, Input, OnInit, ViewChild} from '@angular/core' import {Subscription} from "rxjs"; import { CommentJsonld, CommentService, - ContactJsonld, + ContactJsonld, DocumentJsonld, PartnerJsonld, PartnerProductJsonld, PostJsonld, @@ -16,6 +16,7 @@ import {PagingComponent} from "@app/_components/paging/paging.component"; import {NewCommentComponent} from "@app/_views/posts/new-comment/new-comment.component"; import {User} from "@app/_models"; import {AccountService} from "@app/_services"; +import {NewDocumentComponent} from "@app/_views/documents/new-document/new-document.component"; @Component({ selector: 'app-post-list', @@ -133,40 +134,34 @@ export class PostListComponent implements OnInit, AfterViewInit { this.getPostData(postIri); } - openModalNewPost() { - let postInputs: any = {}; - let post: PostJsonld = {} as PostJsonld; + openModalNewEditPost(post?: PostJsonld) { + const postInputs: any = {}; + const posting: PostJsonld = post || {} as PostJsonld; - if (this.partner !== undefined) { - post.partnerIri = this.partner?.id; - postInputs['partner'] = this.partner; - } - if (this.contact !== undefined) { - post.contactIri = this.contact.id; - } - if (this.sale !== undefined) { - post.partnerIri = this.sale?.partnerIri; - post.productIri = this.sale?.productIri; - post.saleIri = this.sale?.id; - postInputs['product'] = this.sale.product; + if (!post) { + if (this.partner) { + posting.partnerIri = this.partner.id; + postInputs['partner'] = this.partner; + } + if (this.contact) { + posting.contactIri = this.contact.id; + } + if (this.sale) { + posting.partnerIri = this.sale.partnerIri; + posting.productIri = this.sale.productIri; + posting.saleIri = this.sale.id; + postInputs['product'] = this.sale.product; + } } - postInputs['posting'] = post; - this.appHelperService.openModal(NewPostComponent, postInputs, this.getPostsData); - } - openModalEditPost(post: PostJsonld) { - this.appHelperService.openModal(NewPostComponent, { 'posting': post }, this.getPostsData); + postInputs['posting'] = posting; + this.appHelperService.openModal(NewPostComponent, postInputs, this.getPostsData); } - openModalNewComment(post: PostJsonld) { - let comment: CommentJsonld = {} as CommentJsonld; - comment.postIri = post.id; - this.appHelperService.openModal(NewCommentComponent, { 'comment': comment }, this.afterCommentCreation, post.id); - } + openModalNewEditComment(post?: PostJsonld, comment?: CommentJsonld) { + const commentData: CommentJsonld = comment || { postIri: post?.id } as CommentJsonld; + const postId = comment ? comment.postIri : post?.id; - openModalEditComment(comment: CommentJsonld) { - this.appHelperService.openModal(NewCommentComponent, { 'comment': comment }, this.afterCommentCreation, comment.postIri); + this.appHelperService.openModal(NewCommentComponent, { 'comment': commentData }, this.afterCommentCreation, postId); } - - } diff --git a/matsen-tool/src/app/_views/tasks/task-list/task-list.component.html b/matsen-tool/src/app/_views/tasks/task-list/task-list.component.html index a4aec90..d02266e 100644 --- a/matsen-tool/src/app/_views/tasks/task-list/task-list.component.html +++ b/matsen-tool/src/app/_views/tasks/task-list/task-list.component.html @@ -1,6 +1,6 @@
-
@@ -29,7 +29,7 @@ class="position-absolute bi bi-pencil p-2" data-type="user-tool" data-action="edit" - (click)="openModalEditTask(task)" + (click)="openModalNewEditTask(task)" > @@ -65,7 +65,7 @@ ({{ task.numTaskNotes }}) {{ 'basic.comment-it' | translate }} + (click)="openModalNewEditTaskNote(task)">{{ 'basic.comment-it' | translate }}
@@ -92,7 +92,7 @@ + (click)="openModalNewEditTask(task)">
{{ 'basic.comment-it' | translate }} + (click)="openModalNewEditTaskNote(task)">{{ 'basic.comment-it' | translate }}
@@ -132,7 +132,7 @@ + (click)="openModalNewEditTaskNote(task, taskNote)"> diff --git a/matsen-tool/src/app/_views/tasks/task-list/task-list.component.ts b/matsen-tool/src/app/_views/tasks/task-list/task-list.component.ts index e643684..1f6cfc4 100644 --- a/matsen-tool/src/app/_views/tasks/task-list/task-list.component.ts +++ b/matsen-tool/src/app/_views/tasks/task-list/task-list.component.ts @@ -131,33 +131,23 @@ export class TaskListComponent implements OnInit, AfterViewInit { this.getTaskData(taskIri); } - openModalNewTask() { - let postInputs: any = {}; - let task: TaskJsonld = {} as TaskJsonld; - task.partnerIri = this.partner.id; - task.completed = false; - if (this.partner !== undefined) { - postInputs['partner'] = this.partner; - } - postInputs['task'] = task; - this.appHelperService.openModal(NewTaskComponent, postInputs, this.getTasksData); - } - - openModalEditTask(task: TaskJsonld) { - this.appHelperService.openModal(NewTaskComponent, {'task': task}, this.getTasksData); + openModalNewEditTask(task?: TaskJsonld) { + const taskInputs: any = { + partner: this.partner, + task: task || { + partnerIri: this.partner?.id, + completed: false + } as TaskJsonld + }; + + this.appHelperService.openModal(NewTaskComponent, taskInputs, this.getTasksData); } - openModalNewTaskNote(task: TaskJsonld) { - let taskNote: TaskNoteJsonld = {} as TaskNoteJsonld; - taskNote.taskIri = task.id ?? null; - this.appHelperService.openModal( - NewTaskNoteComponent, {'taskNote': taskNote, 'task': task}, this.afterCommentCreation, task.id - ); - } + openModalNewEditTaskNote(task: TaskJsonld, taskNote?: TaskNoteJsonld) { + const taskNoteData: TaskNoteJsonld = taskNote || { taskIri: task.id ?? null } as TaskNoteJsonld; - openModalEditTaskNote(taskNote: TaskNoteJsonld, task: TaskJsonld) { this.appHelperService.openModal( - NewTaskNoteComponent, {'taskNote': taskNote, 'task': task}, this.afterCommentCreation, task.id + NewTaskNoteComponent, { 'taskNote': taskNoteData, 'task': task }, this.afterCommentCreation, task.id ); }