From a6b120fc1c1b46973a6855111311106257dbce96 Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 15 Apr 2024 12:20:19 +0200 Subject: [PATCH] refactoring --- .../_components/paging/paging.component.ts | 5 + .../contact-list/contact-list.component.ts | 13 +- .../contacts-detail.component.html | 10 +- .../contacts-detail.component.ts | 41 ++- .../_views/documents/documents.component.ts | 2 +- .../partner-list/partner-list.component.html | 1 + .../partner-list/partner-list.component.scss | 0 .../partner-list.component.spec.ts | 23 ++ .../partner-list/partner-list.component.ts | 26 ++ .../posts/new-post/new-post.component.html | 12 + .../posts/new-post/new-post.component.ts | 26 +- .../posts/post-list/post-list.component.html | 2 +- .../posts/post-list/post-list.component.ts | 65 +--- .../sales-detail/sales-detail.component.html | 77 +++-- .../sales-detail/sales-detail.component.ts | 313 ++++++++---------- .../tasks/task-list/task-list.component.html | 2 +- .../tasks/task-list/task-list.component.ts | 59 +--- .../src/app/_views/tasks/tasks.component.html | 52 +-- .../src/app/_views/tasks/tasks.component.ts | 112 +------ matsen-tool/src/app/app.module.ts | 2 + 20 files changed, 359 insertions(+), 484 deletions(-) create mode 100644 matsen-tool/src/app/_views/partners/partner-list/partner-list.component.html create mode 100644 matsen-tool/src/app/_views/partners/partner-list/partner-list.component.scss create mode 100644 matsen-tool/src/app/_views/partners/partner-list/partner-list.component.spec.ts create mode 100644 matsen-tool/src/app/_views/partners/partner-list/partner-list.component.ts diff --git a/matsen-tool/src/app/_components/paging/paging.component.ts b/matsen-tool/src/app/_components/paging/paging.component.ts index 93732c0..a7e3ade 100644 --- a/matsen-tool/src/app/_components/paging/paging.component.ts +++ b/matsen-tool/src/app/_components/paging/paging.component.ts @@ -42,6 +42,11 @@ export class PagingComponent implements OnInit { ngAfterViewInit() { this.dataSource = this.paginator; +console.log('paging after init'); + //this.getDataFunction(); + } + + initData() { this.getDataFunction(); } diff --git a/matsen-tool/src/app/_views/contacts/contact-list/contact-list.component.ts b/matsen-tool/src/app/_views/contacts/contact-list/contact-list.component.ts index dc2ce69..5fa6b5b 100644 --- a/matsen-tool/src/app/_views/contacts/contact-list/contact-list.component.ts +++ b/matsen-tool/src/app/_views/contacts/contact-list/contact-list.component.ts @@ -1,4 +1,4 @@ -import {Component, Input, ViewChild} from '@angular/core'; +import {AfterViewInit, Component, Input, OnInit, ViewChild} from '@angular/core'; import {Subscription} from "rxjs"; import {ContactJsonld, ContactService, PartnerJsonld} from "@app/core/api/v1"; import {MatTableDataSource} from "@angular/material/table"; @@ -12,10 +12,10 @@ import {PagingComponent} from "@app/_components/paging/paging.component"; templateUrl: './contact-list.component.html', styleUrl: './contact-list.component.scss' }) -export class ContactListComponent { +export class ContactListComponent implements OnInit, AfterViewInit { @Input() public partner!: PartnerJsonld; - @ViewChild("pagingComponent", { static: false }) pagingComponent: PagingComponent = new PagingComponent(); + @ViewChild("pagingComponent", { static: false }) pagingComponent!: PagingComponent; protected contactsSub: Subscription; protected contacts: Array; @@ -31,6 +31,13 @@ export class ContactListComponent { this.dataSource = new MatTableDataSource(this.contacts); } + ngOnInit(): void { + } + + ngAfterViewInit(): void { + this.pagingComponent.initData(); + } + getData = () => { this.contactsSub = this.contactService.contactsGetCollection( this.pagingComponent.getPageIndex(), diff --git a/matsen-tool/src/app/_views/contacts/contacts-detail/contacts-detail.component.html b/matsen-tool/src/app/_views/contacts/contacts-detail/contacts-detail.component.html index 32ed1d4..5a173ac 100644 --- a/matsen-tool/src/app/_views/contacts/contacts-detail/contacts-detail.component.html +++ b/matsen-tool/src/app/_views/contacts/contacts-detail/contacts-detail.component.html @@ -20,7 +20,15 @@ alt="{{contact.firstName}} {{contact.lastName}}" title="{{contact.firstName}} {{contact.lastName}}"/> + (click)="openModalEditContact()"> + + 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 bfa6886..f2b951f 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 @@ -1,26 +1,16 @@ -import {AfterViewInit, ChangeDetectorRef, Component, OnInit, ViewChild} from '@angular/core'; +import {AfterViewInit, Component, OnInit, ViewChild} from '@angular/core'; import { - CommentJsonld, - ContactJsonld, + ContactJsonld, ContactPartnerProduct, ContactPartnerProductService, ContactService, PartnerJsonld, PartnerService, - PostJsonld, - PostService } from "@app/core/api/v1"; import {Subscription} from "rxjs"; import {ActivatedRoute} from "@angular/router"; -import {MatPaginator, MatPaginatorIntl, PageEvent} from "@angular/material/paginator"; -import {MatTableDataSource} from "@angular/material/table"; -import {NewPostComponent} from "@app/_views/posts/new-post/new-post.component"; -import {NgbModal, NgbModalOptions} from "@ng-bootstrap/ng-bootstrap"; import {NewContactComponent} from "@app/_views/contacts/new-contact/new-contact.component"; -import {ModalStatus} from "@app/_helpers/modal.states"; import {User} from "@app/_models"; import {AccountService} from "@app/_services"; -import {NewCommentComponent} from "@app/_views/posts/new-comment/new-comment.component"; import {AppHelperService} from "@app/_helpers/app-helper.service"; -import {constructorParametersDownlevelTransform} from "@angular/compiler-cli"; import {PostListComponent} from "@app/_views/posts/post-list/post-list.component"; import {ToggleComponent} from "@app/_components/toggle/toggle.component"; @@ -39,16 +29,17 @@ export class ContactsDetailComponent implements OnInit, AfterViewInit { protected contact!: ContactJsonld; protected contactSub: Subscription; protected partner!: PartnerJsonld; + protected contactPartnerProducts: Array; + protected partnerSub: Subscription; + protected contactProductSub: Subscription; protected commentsVisibility: Map; - protected modalOptions: NgbModalOptions = { - centered: true - }; constructor( private contactService: ContactService, private partnerService: PartnerService, private accountService: AccountService, + private contactProductService: ContactPartnerProductService, private route: ActivatedRoute, protected appHelperService: AppHelperService ) { @@ -56,6 +47,8 @@ export class ContactsDetailComponent implements OnInit, AfterViewInit { this.contactSub = new Subscription(); this.commentsVisibility = new Map(); this.partnerSub = new Subscription(); + this.contactProductSub = new Subscription(); + this.contactPartnerProducts = []; } ngOnInit() { @@ -76,12 +69,14 @@ export class ContactsDetailComponent implements OnInit, AfterViewInit { ).subscribe( data => { this.contact = data; - this.getPartnerData() + this.getPartnerData(); + this.getContactProducts(); + } ); } - getPartnerData() { + getPartnerData = () => { this.partnerSub = this.partnerService.partnersIdGet( this.appHelperService.extractId(this.contact.partner) ).subscribe( @@ -91,6 +86,18 @@ export class ContactsDetailComponent implements OnInit, AfterViewInit { ) } + getContactProducts() { + this.contactProductSub = this.contactProductService.contactPartnerProductsGetCollection( + 1, + 50, + this.contact.id + ).subscribe( + data => { + this.contactPartnerProducts = data["hydra:member"]; + } + ); + } + openModalEditContact() { let data: any = { 'contact': this.contact } if (this.contact.birthday !== undefined) { diff --git a/matsen-tool/src/app/_views/documents/documents.component.ts b/matsen-tool/src/app/_views/documents/documents.component.ts index 4985035..275b15a 100644 --- a/matsen-tool/src/app/_views/documents/documents.component.ts +++ b/matsen-tool/src/app/_views/documents/documents.component.ts @@ -2,7 +2,7 @@ import {ChangeDetectorRef, Component, ViewChild} from '@angular/core'; import {MatSort, MatSortModule, Sort} from "@angular/material/sort"; import {MatPaginator, MatPaginatorIntl, MatPaginatorModule, PageEvent} from "@angular/material/paginator"; import {Subscription} from "rxjs"; -import {DocumentJsonld, DocumentService, ProductJsonld} from "@app/core/api/v1"; +import {DocumentJsonld, DocumentService} from "@app/core/api/v1"; import {Router, RouterLink, RouterLinkActive} from "@angular/router"; import {MatTableDataSource, MatTableModule} from "@angular/material/table"; import {OrderFilter} from "@app/_models/orderFilter"; diff --git a/matsen-tool/src/app/_views/partners/partner-list/partner-list.component.html b/matsen-tool/src/app/_views/partners/partner-list/partner-list.component.html new file mode 100644 index 0000000..88dcace --- /dev/null +++ b/matsen-tool/src/app/_views/partners/partner-list/partner-list.component.html @@ -0,0 +1 @@ +

partner-list works!

diff --git a/matsen-tool/src/app/_views/partners/partner-list/partner-list.component.scss b/matsen-tool/src/app/_views/partners/partner-list/partner-list.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/matsen-tool/src/app/_views/partners/partner-list/partner-list.component.spec.ts b/matsen-tool/src/app/_views/partners/partner-list/partner-list.component.spec.ts new file mode 100644 index 0000000..4e6182c --- /dev/null +++ b/matsen-tool/src/app/_views/partners/partner-list/partner-list.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { PartnerListComponent } from './partner-list.component'; + +describe('PartnerListComponent', () => { + let component: PartnerListComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [PartnerListComponent] + }) + .compileComponents(); + + fixture = TestBed.createComponent(PartnerListComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/matsen-tool/src/app/_views/partners/partner-list/partner-list.component.ts b/matsen-tool/src/app/_views/partners/partner-list/partner-list.component.ts new file mode 100644 index 0000000..e63f042 --- /dev/null +++ b/matsen-tool/src/app/_views/partners/partner-list/partner-list.component.ts @@ -0,0 +1,26 @@ +import {AfterViewInit, Component, OnInit, ViewChild} from '@angular/core'; +import {PagingComponent} from "@app/_components/paging/paging.component"; +import {AppHelperService} from "@app/_helpers/app-helper.service"; + +@Component({ + selector: 'app-partner-list', + templateUrl: './partner-list.component.html', + styleUrl: './partner-list.component.scss' +}) +export class PartnerListComponent implements OnInit, AfterViewInit { + + @ViewChild("pagingComponent", { static: false }) pagingComponent!: PagingComponent; + + + constructor( + protected appHelperService: AppHelperService, + ) { + } + + ngOnInit(): void { + } + + ngAfterViewInit(): void { + this.pagingComponent.initData(); + } +} 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 e27dca9..d9283c3 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 @@ -10,6 +10,18 @@ +
+ + + +
+
diff --git a/matsen-tool/src/app/_views/posts/new-post/new-post.component.ts b/matsen-tool/src/app/_views/posts/new-post/new-post.component.ts index 241f3ce..f094f70 100644 --- a/matsen-tool/src/app/_views/posts/new-post/new-post.component.ts +++ b/matsen-tool/src/app/_views/posts/new-post/new-post.component.ts @@ -1,11 +1,13 @@ -import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core'; +import {Component, EventEmitter, Input, OnInit, Output, ViewChild} from '@angular/core'; import {ModalStatus} from "@app/_helpers/modal.states"; import {FormGroup} from "@angular/forms"; import {postForm} from "@app/_forms/apiForms"; -import {PartnerJsonld, PostJsonld, PostService} from "@app/core/api/v1"; +import {PartnerJsonld, PartnerProductService, PostJsonld, PostService} from "@app/core/api/v1"; import {FormGroupInitializer} from "@app/_helpers/formgroup.initializer"; import {AppHelperService} from "@app/_helpers/app-helper.service"; -import {Subscription} from "rxjs"; +import {Observable, Subscription} from "rxjs"; +import {SearchInputComponent} from "@app/_components/search-input/search-input.component"; +import {map} from "rxjs/operators"; @Component({ selector: 'app-new-post', @@ -15,12 +17,14 @@ import {Subscription} from "rxjs"; export class NewPostComponent implements OnInit { @Input() public posting!: PostJsonld; @Output() public submit: EventEmitter = new EventEmitter(); + @ViewChild('partnerProductSearchInput', { static: false }) $partnerProductSearchInput!: SearchInputComponent; protected postForm: FormGroup; protected postSub: Subscription; constructor( private postService: PostService, + private partnerProductService: PartnerProductService, protected appHelperService: AppHelperService, ) { this.postForm = postForm; @@ -32,6 +36,22 @@ export class NewPostComponent implements OnInit { console.log(this.posting); } + fetchPartnerProducts = (term: string): Observable<{ id: any; name: any }[]> => { + return this.partnerProductService.partnerProductsGetCollection( + 1, + 50, + String(this.posting.partner), + undefined, + undefined, + undefined, + term + ).pipe( + map((response) => + response['hydra:member'].map( + partnerProduct => ({id: partnerProduct.product, name: partnerProduct.productName}))), + ); + } + onSubmit() { if (this.postForm.valid) { if (this.posting.id === null || this.posting.id === undefined) { 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 5506ea6..371c0a9 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 @@ -3,7 +3,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 97a106b..8978c7f 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 @@ -1,4 +1,4 @@ -import {AfterViewInit, ChangeDetectorRef, Component, Input, OnInit, ViewChild} from '@angular/core'; +import {AfterViewInit, Component, Input, OnInit, ViewChild} from '@angular/core'; import {Subscription} from "rxjs"; import { CommentJsonld, @@ -9,14 +9,12 @@ import { PostService, SaleJsonld, UserJsonld } from "@app/core/api/v1"; -import {MatPaginator, MatPaginatorIntl} from "@angular/material/paginator"; import {MatTableDataSource} from "@angular/material/table"; import {NewPostComponent} from "@app/_views/posts/new-post/new-post.component"; -import {ModalStatus} from "@app/_helpers/modal.states"; import {NgbModal, NgbModalOptions} from "@ng-bootstrap/ng-bootstrap"; import {AppHelperService} from "@app/_helpers/app-helper.service"; -import {NewCommentComponent} from "@app/_views/posts/new-comment/new-comment.component"; import {PagingComponent} from "@app/_components/paging/paging.component"; +import {NewCommentComponent} from "@app/_views/posts/new-comment/new-comment.component"; @Component({ selector: 'app-post-list', @@ -32,14 +30,13 @@ export class PostListComponent implements OnInit, AfterViewInit { @Input() public existsContact!: boolean; @Input() public existsSale!: boolean; - @ViewChild("pagingComponent", { static: false }) pagingComponent: PagingComponent = new PagingComponent(); - @ViewChild(MatPaginator) postsPaginator: MatPaginator; + @ViewChild("pagingComponent", { static: false }) pagingComponent!: PagingComponent; protected postsSub: Subscription; protected posts: Array; protected partnerProductsSub: Subscription; protected partnerProducts: Array; - protected postsDataSource; + protected dataSource; protected commentsVisibility: Map; protected modalOptions: NgbModalOptions = { centered: true @@ -54,17 +51,15 @@ export class PostListComponent implements OnInit, AfterViewInit { this.posts = []; this.partnerProductsSub = new Subscription(); this.partnerProducts = []; - this.postsPaginator = new MatPaginator(new MatPaginatorIntl(), ChangeDetectorRef.prototype); - this.postsDataSource = new MatTableDataSource(this.posts); + this.dataSource = new MatTableDataSource(this.posts); this.commentsVisibility = new Map(); } ngOnInit() { - this.getData(); } ngAfterViewInit() { - this.postsDataSource.paginator = this.postsPaginator; + this.pagingComponent.initData(); } getData = () => { @@ -102,50 +97,24 @@ export class PostListComponent implements OnInit, AfterViewInit { } openModalNewPost() { - const modalRefPosting = this.modalService.open(NewPostComponent, this.appHelperService.getModalOptions()); - let posting: PostJsonld = {} as PostJsonld; - posting.partner = this.partner.id ?? null; - modalRefPosting.componentInstance.posting = posting; - modalRefPosting.componentInstance.submit.subscribe((modalStatus: ModalStatus) => { - if (modalStatus === ModalStatus.Submitted) { - modalRefPosting.dismiss(); - this.getData(); - } - }); + let post: PostJsonld = {} as PostJsonld; + post.partner = this.partner.id ?? null; + this.appHelperService.openModal(NewPostComponent, { 'posting': post }, this.getData); } openModalEditPost(post: PostJsonld) { - const modalRefPostingEdit = this.modalService.open(NewPostComponent, this.appHelperService.getModalOptions()); - modalRefPostingEdit.componentInstance.posting = post; - modalRefPostingEdit.componentInstance.submit.subscribe((modalStatus: ModalStatus) => { - if (modalStatus === ModalStatus.Submitted) { - modalRefPostingEdit.dismiss(); - this.getData(); - } - }); - } - - openModalEditComment(comment: CommentJsonld) { - const modalRefComment = this.modalService.open(NewCommentComponent, this.appHelperService.getModalOptions()); - modalRefComment.componentInstance.comment = comment; - modalRefComment.componentInstance.submit.subscribe((modalStatus: ModalStatus) => { - if (modalStatus === ModalStatus.Submitted) { - modalRefComment.dismiss(); - this.getData(); - } - }); + this.appHelperService.openModal(NewPostComponent, { 'posting': post }, this.getData); } openModalNewComment(post: PostJsonld) { - const modalRefComment = this.modalService.open(NewCommentComponent, this.appHelperService.getModalOptions()); 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.getData(); - } - }); + this.appHelperService.openModal(NewCommentComponent, { 'comment': comment }, this.getData); } + + openModalEditComment(comment: CommentJsonld) { + this.appHelperService.openModal(NewCommentComponent, { 'comment': comment }, this.getData); + } + + } 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 3902314..e4f224f 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 @@ -1,6 +1,6 @@
-
+

{{'overview.sale-user' | translate }}: {{ sale.ownerName }}

@@ -27,54 +27,51 @@
-
-
-
-
-

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

-

{{ post.ownerName }}

-
-
-

{{ post.headline }}

-

-
- -
-
-
-
+ +
+
-

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

-

{{ comment.ownerName }}

+

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

+

{{ post.ownerName }}

-

+

{{ post.headline }}

+

+
+ +
+
+
+
+
+
+

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

+

{{ comment.ownerName }}

+
+
+

+
+
-
-
-
- - {{ 'basic.hide-comments' | translate }} - {{ 'basic.show-comments' | translate }} - - {{'basic.comment-it' | translate}} +
+ + {{ 'basic.hide-comments' | translate }} + {{ 'basic.show-comments' | translate }} + + {{'basic.comment-it' | translate}} +
-
- - +
\ 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 fa05d43..91c7e1e 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 @@ -1,18 +1,17 @@ import {AfterViewInit, ChangeDetectorRef, Component, OnInit, ViewChild} from '@angular/core'; -import {MatPaginator, MatPaginatorIntl, PageEvent} from "@angular/material/paginator"; import {Subscription} from "rxjs"; import {MatTableDataSource} from "@angular/material/table"; -import {CommentJsonld, ContactJsonld, PostJsonld, PostService, SaleJsonld, SaleService} from "@app/core/api/v1"; +import {CommentJsonld, PostJsonld, PostService, SaleJsonld, SaleService} from "@app/core/api/v1"; import {NgbModal, NgbModalOptions} from "@ng-bootstrap/ng-bootstrap"; import {User} from "@app/_models"; import {AccountService} from "@app/_services"; import {NewPostComponent} from "@app/_views/posts/new-post/new-post.component"; import {ModalStatus} from "@app/_helpers/modal.states"; import {NewCommentComponent} from "@app/_views/posts/new-comment/new-comment.component"; -import {NewContactComponent} from "@app/_views/contacts/new-contact/new-contact.component"; import {NewSaleComponent} from "@app/_views/sales/new-sale/new-sale.component"; import {ActivatedRoute} from "@angular/router"; import {AppHelperService} from "@app/_helpers/app-helper.service"; +import {PagingComponent} from "@app/_components/paging/paging.component"; @Component({ selector: 'app-sales-detail', @@ -20,177 +19,157 @@ import {AppHelperService} from "@app/_helpers/app-helper.service"; styleUrl: './sales-detail.component.scss' }) export class SalesDetailComponent implements OnInit, AfterViewInit { - @ViewChild(MatPaginator) postsPaginator: MatPaginator; + @ViewChild("pagingComponent", { static: false }) pagingComponent!: PagingComponent; - protected user: User | null; + protected user: User | null; - protected id: string; - protected sale: SaleJsonld; - protected saleSub: Subscription; + protected saleId: string; + protected sale!: SaleJsonld; + protected saleSub: Subscription; - protected postsSub: Subscription; - protected posts: Array; - protected postsDataSource; - protected postsLength: number; - protected postsPageEvent: PageEvent; - protected postsPageSize: number; - protected postsPageIndex: number; - protected commentsVisibility: Map; + protected postsSub: Subscription; + protected posts: Array; + protected dataSource; + protected commentsVisibility: Map; - protected modalOptions: NgbModalOptions = { + protected modalOptions: NgbModalOptions = { centered: true - }; - - constructor( - private accountService: AccountService, - private saleService: SaleService, - private route: ActivatedRoute, - private postService: PostService, - private modalService: NgbModal, - protected appHelperService: AppHelperService - ) { - this.user = this.accountService.userValue; - - this.id = ""; - this.sale = {} as SaleJsonld; - this.saleSub = new Subscription(); - - this.postsSub = new Subscription(); - this.posts = []; - this.postsPaginator = new MatPaginator(new MatPaginatorIntl(), ChangeDetectorRef.prototype); - this.postsDataSource = new MatTableDataSource(this.posts); - this.postsLength = 0; - this.postsPageEvent = new PageEvent(); - this.postsPageSize = 10; - this.postsPageIndex = 0; - this.commentsVisibility = new Map(); - } - - ngOnInit() { - this.route.params.subscribe(params => { - this.id = params['id']; - }); - this.getSaleData(); - } - - ngAfterViewInit() { - this.postsDataSource.paginator = this.postsPaginator; - } - - getSaleData() { - console.log(this.id); - this.saleSub = this.saleService.salesIdGet( - this.id - ).subscribe( - data => { - this.sale = data; - this.getPostsData(); - } - ); - } - - getPostsData() { - this.postsSub = this.postService.postsGetCollection( - this.postsPageIndex + 1, - this.postsPageSize, - this.sale.partner + '', - undefined, - undefined, - undefined, - this.id, - undefined, - undefined, - undefined, - undefined, - true - ).subscribe( - data => { - this.posts = data["hydra:member"]; - console.log(this.posts); - this.postsLength = Number(data["hydra:totalItems"]); - this.posts.forEach(posts => { - if (posts.id) { - this.commentsVisibility.set(posts.id, false); + }; + + constructor( + private accountService: AccountService, + private saleService: SaleService, + private route: ActivatedRoute, + private postService: PostService, + private modalService: NgbModal, + protected appHelperService: AppHelperService + ) { + this.user = this.accountService.userValue; + + this.saleId = ""; + this.saleSub = new Subscription(); + + this.postsSub = new Subscription(); + this.posts = []; + this.dataSource = new MatTableDataSource(this.posts); + this.commentsVisibility = new Map(); + } + + ngOnInit() { + this.route.params.subscribe(params => { + this.saleId = params['id']; + }); + + } + + ngAfterViewInit() { + this.getSaleData(); + } + + getSaleData = () => { + this.saleSub = this.saleService.salesIdGet( + this.saleId + ).subscribe( + data => { + this.sale = data; + this.pagingComponent.initData(); + } + ); + } + + getPostsData = () => { + this.postsSub = this.postService.postsGetCollection( + this.pagingComponent.getPageIndex(), + this.pagingComponent.getPageSize(), + this.sale.partner + '', + undefined, + undefined, + undefined, + this.saleId, + undefined, + undefined, + undefined, + undefined, + true + ).subscribe( + 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); + } + }); } - }); + ); + } + + openModalNewPosting() { + const modalRefPosting = this.modalService.open(NewPostComponent, this.appHelperService.getModalOptions()); + let posting: PostJsonld = {} as PostJsonld; + posting.sale = this.sale.id ?? null; + posting.partner = this.sale.partner ?? null; + posting.product = this.sale.product ?? 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, this.appHelperService.getModalOptions()); + 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(NewPostComponent, this.appHelperService.getModalOptions()); + modalRefPostingEdit.componentInstance.posting = post; + modalRefPostingEdit.componentInstance.submit.subscribe((modalStatus: ModalStatus) => { + if (modalStatus === ModalStatus.Submitted) { + modalRefPostingEdit.dismiss(); + this.getPostsData(); + } + }); + } + + openModalEditComment(comment: CommentJsonld) { + const modalRefComment = this.modalService.open(NewCommentComponent, this.appHelperService.getModalOptions()); + modalRefComment.componentInstance.comment = comment; + modalRefComment.componentInstance.submit.subscribe((modalStatus: ModalStatus) => { + if (modalStatus === ModalStatus.Submitted) { + modalRefComment.dismiss(); + this.getPostsData(); + } + }); + } + + openModalEditSale() { + const modalRefSale = this.modalService.open(NewSaleComponent, this.appHelperService.getModalOptions()); + modalRefSale.componentInstance.sale = this.sale; + modalRefSale.componentInstance.submit.subscribe((modalStatus: ModalStatus) => { + if (modalStatus === ModalStatus.Submitted) { + modalRefSale.dismiss(); + this.getSaleData(); + } + }); + } + + showComments(post: PostJsonld) { + if (post.id) { + const currentVisibility = this.commentsVisibility.get(post.id); + this.commentsVisibility.set(post.id, !currentVisibility); } - ); - } - - postsHandlePageEvent(e: PageEvent) { - this.postsPageEvent = e; - this.postsLength = e.length; - this.postsPageIndex = e.pageIndex.valueOf(); - this.postsPageSize = e.pageSize.valueOf(); - this.getPostsData(); - } - - openModalNewPosting() { - const modalRefPosting = this.modalService.open(NewPostComponent, this.appHelperService.getModalOptions()); - let posting: PostJsonld = {} as PostJsonld; - posting.sale = this.sale.id ?? null; - posting.partner = this.sale.partner ?? null; - posting.product = this.sale.product ?? 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, this.appHelperService.getModalOptions()); - 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(NewPostComponent, this.appHelperService.getModalOptions()); - modalRefPostingEdit.componentInstance.posting = post; - modalRefPostingEdit.componentInstance.submit.subscribe((modalStatus: ModalStatus) => { - if (modalStatus === ModalStatus.Submitted) { - modalRefPostingEdit.dismiss(); - this.getPostsData(); - } - }); - } - - openModalEditComment(comment: CommentJsonld) { - const modalRefComment = this.modalService.open(NewCommentComponent, this.appHelperService.getModalOptions()); - modalRefComment.componentInstance.comment = comment; - modalRefComment.componentInstance.submit.subscribe((modalStatus: ModalStatus) => { - if (modalStatus === ModalStatus.Submitted) { - modalRefComment.dismiss(); - this.getPostsData(); - } - }); - } - - openModalEditSale() { - const modalRefSale = this.modalService.open(NewSaleComponent, this.appHelperService.getModalOptions()); - modalRefSale.componentInstance.sale = this.sale; - modalRefSale.componentInstance.submit.subscribe((modalStatus: ModalStatus) => { - if (modalStatus === ModalStatus.Submitted) { - modalRefSale.dismiss(); - this.getSaleData(); - } - }); - } - - showComments(post: PostJsonld) { - if (post.id) { - const currentVisibility = this.commentsVisibility.get(post.id); - this.commentsVisibility.set(post.id, !currentVisibility); } - } } 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 787e620..7ecf353 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 @@
- + { this.tasksSub = this.taskService.tasksGetCollection( this.pagingComponent.getPageIndex(), this.pagingComponent.getPageSize(), undefined, undefined, - this.partner.id + this.partner ? this.partner.id : undefined ).subscribe( data => { this.tasks = data["hydra:member"]; @@ -69,52 +73,23 @@ export class TaskListComponent { } openModalNewTask() { - const modalRefTask = this.modalService.open(NewTaskComponent, this.appHelperService.getModalOptions()); let task: TaskJsonld = {} as TaskJsonld; task.partner = this.partner.id ?? null; task.completed = false; - modalRefTask.componentInstance.task = task; - modalRefTask.componentInstance.submit.subscribe((modalStatus: ModalStatus) => { - if (modalStatus === ModalStatus.Submitted) { - modalRefTask.dismiss(); - this.getData(); - } - }); + this.appHelperService.openModal(NewTaskComponent, { 'task': task }, this.getData); + } + + openModalEditTask(task: TaskJsonld) { + this.appHelperService.openModal(NewTaskComponent, { 'task': task }, this.getData); } openModalNewTaskNote(task: TaskJsonld) { - const modalRefTaskNote = this.modalService.open(NewTaskNoteComponent, this.appHelperService.getModalOptions()); let taskNote: TaskNoteJsonld = {} as TaskNoteJsonld; taskNote.task = task.id ?? null; - modalRefTaskNote.componentInstance.taskNote = taskNote; - modalRefTaskNote.componentInstance.submit.subscribe((modalStatus: ModalStatus) => { - if (modalStatus === ModalStatus.Submitted) { - modalRefTaskNote.dismiss(); - this.getData(); - } - }); - } - - openModalEditTask(task: TaskJsonld) { - const modalRefTaskEdit = this.modalService.open(NewTaskComponent, this.appHelperService.getModalOptions()); - modalRefTaskEdit.componentInstance.task = task; - modalRefTaskEdit.componentInstance.dueAtValue = this.appHelperService.convertDate(task.dueAt); - modalRefTaskEdit.componentInstance.submit.subscribe((modalStatus: ModalStatus) => { - if (modalStatus === ModalStatus.Submitted) { - modalRefTaskEdit.dismiss(); - this.getData(); - } - }); + this.appHelperService.openModal(NewTaskNoteComponent, { 'taskNote': taskNote }, this.getData); } openModalEditTaskNote(taskNote: TaskNoteJsonld) { - const modalRefTaskNote = this.modalService.open(NewTaskNoteComponent, this.appHelperService.getModalOptions()); - modalRefTaskNote.componentInstance.taskNote = taskNote; - modalRefTaskNote.componentInstance.submit.subscribe((modalStatus: ModalStatus) => { - if (modalStatus === ModalStatus.Submitted) { - modalRefTaskNote.dismiss(); - this.getData(); - } - }); + this.appHelperService.openModal(NewTaskNoteComponent, { 'taskNote': taskNote }, this.getData); } } diff --git a/matsen-tool/src/app/_views/tasks/tasks.component.html b/matsen-tool/src/app/_views/tasks/tasks.component.html index adb0f9c..15e5f03 100644 --- a/matsen-tool/src/app/_views/tasks/tasks.component.html +++ b/matsen-tool/src/app/_views/tasks/tasks.component.html @@ -2,57 +2,7 @@

{{'basic.tasks' | translate}}

-
-
-
-
-

{{task.partnerName}}

- - {{ task.dueAt | date:'dd.MM.YYYY':'GMT+0000' }} - - -

{{task.headline}}

-
-

-

Zugewiesen an: {{task.assignedToName}}

- -
-
-
-
-
-
-
-

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

-

{{ taskNote.ownerName }}

-
-
-

-
- -
-
-
- -
- - {{ 'basic.hide-comments' | translate }} - {{ 'basic.show-comments' | translate }} - - {{'basic.comment-it' | translate}} -
-
- - +
\ No newline at end of file diff --git a/matsen-tool/src/app/_views/tasks/tasks.component.ts b/matsen-tool/src/app/_views/tasks/tasks.component.ts index bd3b480..19eb743 100644 --- a/matsen-tool/src/app/_views/tasks/tasks.component.ts +++ b/matsen-tool/src/app/_views/tasks/tasks.component.ts @@ -10,6 +10,7 @@ import {User} from "@app/_models"; import {AccountService} from "@app/_services"; import {ModalStatus} from "@app/_helpers/modal.states"; import {NewTaskNoteComponent} from "@app/_views/tasks/new-task-note/new-task-note.component"; +import {TaskListComponent} from "@app/_views/tasks/task-list/task-list.component"; @Component({ selector: 'app-tasks', @@ -17,130 +18,23 @@ import {NewTaskNoteComponent} from "@app/_views/tasks/new-task-note/new-task-not styleUrl: './tasks.component.scss' }) export class TasksComponent implements OnInit, AfterViewInit { - @ViewChild(MatPaginator) tasksPaginator: MatPaginator; + @ViewChild("taskListComponent", { static: false }) taskListComponent!: TaskListComponent; protected user: User | null; - protected tasksSub: Subscription; - protected tasks: Array; - protected tasksDataSource; - protected tasksLength: number; - protected tasksPageEvent: PageEvent; - protected tasksPageSize: number; - protected tasksPageIndex: number; - - protected taskNotesVisibility: Map; - - protected modalOptions: NgbModalOptions = { - centered: true - }; - constructor( - private modalService: NgbModal, private accountService: AccountService, - private taskService: TaskService, protected appHelperService: AppHelperService ) { this.user = this.accountService.userValue; - - this.tasksSub = new Subscription(); - this.tasks = []; - this.tasksPaginator = new MatPaginator(new MatPaginatorIntl(), ChangeDetectorRef.prototype); - this.tasksDataSource = new MatTableDataSource(this.tasks); - this.tasksLength = 0; - this.tasksPageEvent = new PageEvent(); - this.tasksPageSize = 10; - this.tasksPageIndex = 0; - this.taskNotesVisibility = new Map(); } ngOnInit() { - this.getTasksData(); + // this.getTasksData(); } ngAfterViewInit() { - this.tasksDataSource.paginator = this.tasksPaginator; - } - - getTasksData() { - this.tasksSub = this.taskService.tasksGetCollection( - this.tasksPageIndex + 1, - this.tasksPageSize - ).subscribe( - data => { - this.tasks = data["hydra:member"]; - this.tasksLength = Number(data["hydra:totalItems"]); - this.tasks.forEach(task => { - if (task.id) { - this.taskNotesVisibility.set(task.id, false); - } - }); - } - ); - } - - tasksHandlePageEvent(e: PageEvent) { - this.tasksPageEvent = e; - this.tasksLength = e.length; - this.tasksPageIndex = e.pageIndex.valueOf(); - this.tasksPageSize = e.pageSize.valueOf(); - this.getTasksData(); } - openModalNewTask() { - const modalRefTask = this.modalService.open(NewTaskComponent, this.appHelperService.getModalOptions()); - let task: TaskJsonld = {} as TaskJsonld; - task.partner = null; - task.completed = false; - modalRefTask.componentInstance.task = task; - modalRefTask.componentInstance.submit.subscribe((modalStatus: ModalStatus) => { - if (modalStatus === ModalStatus.Submitted) { - modalRefTask.dismiss(); - this.getTasksData(); - } - }); - } - - openModalNewTaskNote(task: TaskJsonld) { - const modalRefTaskNote = this.modalService.open(NewTaskNoteComponent, this.appHelperService.getModalOptions()); - let taskNote: TaskNoteJsonld = {} as TaskNoteJsonld; - taskNote.task = task.id ?? null; - modalRefTaskNote.componentInstance.taskNote = taskNote; - modalRefTaskNote.componentInstance.submit.subscribe((modalStatus: ModalStatus) => { - if (modalStatus === ModalStatus.Submitted) { - modalRefTaskNote.dismiss(); - this.getTasksData(); - } - }); - } - - openModalEditTask(task: TaskJsonld) { - const modalRefTaskEdit = this.modalService.open(NewTaskComponent, this.appHelperService.getModalOptions()); - modalRefTaskEdit.componentInstance.task = task; - modalRefTaskEdit.componentInstance.dueAtValue = this.appHelperService.convertDate(task.dueAt); - modalRefTaskEdit.componentInstance.submit.subscribe((modalStatus: ModalStatus) => { - if (modalStatus === ModalStatus.Submitted) { - modalRefTaskEdit.dismiss(); - this.getTasksData(); - } - }); - } - - openModalEditTaskNote(taskNote: TaskNoteJsonld) { - const modalRefTaskNote = this.modalService.open(NewTaskNoteComponent, this.appHelperService.getModalOptions()); - modalRefTaskNote.componentInstance.taskNote = taskNote; - modalRefTaskNote.componentInstance.submit.subscribe((modalStatus: ModalStatus) => { - if (modalStatus === ModalStatus.Submitted) { - modalRefTaskNote.dismiss(); - this.getTasksData(); - } - }); - } - showTaskNotes(task: TaskJsonld) { - if (task.id) { - const currentVisibility = this.taskNotesVisibility.get(task.id); - this.taskNotesVisibility.set(task.id, !currentVisibility); - } - } } diff --git a/matsen-tool/src/app/app.module.ts b/matsen-tool/src/app/app.module.ts index 9e1494c..b2e22e9 100644 --- a/matsen-tool/src/app/app.module.ts +++ b/matsen-tool/src/app/app.module.ts @@ -54,6 +54,7 @@ import {ApiModule, Configuration, ConfigurationParameters} from "@app/core/api/v import { TaskListComponent } from './_views/tasks/task-list/task-list.component'; import { SearchInputComponent } from './_components/search-input/search-input.component'; import { PagingComponent } from '@app/_components/paging/paging.component'; +import { PartnerListComponent } from './_views/partners/partner-list/partner-list.component'; export function apiConfigFactory(): Configuration { const params: ConfigurationParameters = { @@ -129,6 +130,7 @@ export function HttpLoaderFactory(http: HttpClient) { TaskListComponent, SearchInputComponent, PagingComponent, + PartnerListComponent, ], providers: [ {provide: HTTP_INTERCEPTORS, useClass: JwtInterceptor, multi: true},