| @@ -0,0 +1,4 @@ | |||||
| // types.ts | |||||
| import { Observable } from 'rxjs'; | |||||
| export type ListGetDataFunctionType = (index: number, pageSize: number, term?: string) => Observable<any>; | |||||
| @@ -1,5 +1,5 @@ | |||||
| <app-paging #pagingComponent | <app-paging #pagingComponent | ||||
| [getDataFunction]="getDataFunction" | |||||
| [getDataFunction]="getData" | |||||
| [dataSource]="dataSource" | [dataSource]="dataSource" | ||||
| [searchable]="searchable" | [searchable]="searchable" | ||||
| [hidePageSize]="hidePageSize" | [hidePageSize]="hidePageSize" | ||||
| @@ -4,23 +4,22 @@ import {PagingComponent} from "@app/_components/paging/paging.component"; | |||||
| import {MatTableDataSource} from "@angular/material/table"; | import {MatTableDataSource} from "@angular/material/table"; | ||||
| import {ListColDefinition} from "@app/_components/list/list-col-definition"; | import {ListColDefinition} from "@app/_components/list/list-col-definition"; | ||||
| import {AppHelperService} from "@app/_helpers/app-helper.service"; | import {AppHelperService} from "@app/_helpers/app-helper.service"; | ||||
| type GeneralDataSource = MatTableDataSource<any>; | |||||
| import {ListGetDataFunctionType} from "@app/_components/list/list-get-data-function-type"; | |||||
| @Component({ | @Component({ | ||||
| selector: 'app-list', | selector: 'app-list', | ||||
| templateUrl: './list.component.html', | templateUrl: './list.component.html', | ||||
| styleUrl: './list.component.scss' | styleUrl: './list.component.scss' | ||||
| }) | }) | ||||
| export class ListComponent implements OnInit, AfterViewInit { | |||||
| @Input() public dataSource!: GeneralDataSource; | |||||
| @Input() public getDataFunction!: Function; | |||||
| export class ListComponent implements OnInit, AfterViewInit { | |||||
| @Input() public getDataFunction!: ListGetDataFunctionType; | |||||
| @Input() public onSortFunction!: Function; | @Input() public onSortFunction!: Function; | ||||
| @Input() public onNavigateToDetailsFunction!: Function; | @Input() public onNavigateToDetailsFunction!: Function; | ||||
| @Input() public onRemoveItemFunction!: Function; | @Input() public onRemoveItemFunction!: Function; | ||||
| @Input() public onEditFunction!: Function; | @Input() public onEditFunction!: Function; | ||||
| @Input() public onDownloadFunction!: Function; | @Input() public onDownloadFunction!: Function; | ||||
| @Input() public onRowSelectedFunction!: Function; | |||||
| @Input() public searchable: boolean; | @Input() public searchable: boolean; | ||||
| @Input() public showDetailButton: boolean; | @Input() public showDetailButton: boolean; | ||||
| @Input() public showPosition: boolean; | @Input() public showPosition: boolean; | ||||
| @@ -74,6 +73,7 @@ export class ListComponent implements OnInit, AfterViewInit { | |||||
| protected displayedColumns!: string[]; | protected displayedColumns!: string[]; | ||||
| protected selectedRowIndex: number | null = null; | protected selectedRowIndex: number | null = null; | ||||
| protected dataSource; | |||||
| constructor( | constructor( | ||||
| protected appHelperService: AppHelperService, | protected appHelperService: AppHelperService, | ||||
| @@ -83,45 +83,39 @@ export class ListComponent implements OnInit, AfterViewInit { | |||||
| this.showPosition = true; | this.showPosition = true; | ||||
| this.sort = new MatSort(); | this.sort = new MatSort(); | ||||
| this.hidePageSize = false; | this.hidePageSize = false; | ||||
| this.dataSource = new MatTableDataSource<any>(); | |||||
| } | } | ||||
| ngOnInit(): void { | ngOnInit(): void { | ||||
| this.displayedColumns = []; | |||||
| let defaultRows: ListColDefinition[] = []; | |||||
| if (this.showDetailButton) { | |||||
| defaultRows.push( | |||||
| { | |||||
| name: 'detail', | |||||
| text: 'overview.details', | |||||
| type: ListComponent.COLUMN_TYPE_DETAIL | |||||
| } as ListColDefinition | |||||
| ); | |||||
| } | |||||
| if (this.showPosition) { | if (this.showPosition) { | ||||
| defaultRows.push( | |||||
| { | |||||
| name: 'pos', | |||||
| text: 'overview.number', | |||||
| type: ListComponent.COLUMN_TYPE_POSITION | |||||
| } as ListColDefinition | |||||
| ); | |||||
| this.listColDefinitions.unshift(ListComponent.getDefaultColPosition()); | |||||
| } | |||||
| if (this.showDetailButton) { | |||||
| this.listColDefinitions.unshift(ListComponent.getDefaultColDetailBtn()); | |||||
| } | } | ||||
| this.listColDefinitions = defaultRows.concat(this.listColDefinitions); | |||||
| this.displayedColumns = []; | |||||
| this.listColDefinitions.forEach((value, index) => { | this.listColDefinitions.forEach((value, index) => { | ||||
| this.displayedColumns.push(value.name); | this.displayedColumns.push(value.name); | ||||
| }); | }); | ||||
| } | } | ||||
| ngAfterViewInit(): void { | ngAfterViewInit(): void { | ||||
| // this.searchBoxOpen = false; | |||||
| } | } | ||||
| getData(): void { | |||||
| this.getDataFunction() | |||||
| getData = (): void => { | |||||
| this.getDataFunction( | |||||
| this.pagingComponent.getPageIndex(), | |||||
| this.pagingComponent.getPageSize(), | |||||
| this.pagingComponent.getSearchValue() | |||||
| ).subscribe( | |||||
| data => { | |||||
| this.dataSource = new MatTableDataSource<any>(data['hydra:member']); | |||||
| this.pagingComponent.setDataLength(data["hydra:totalItems"]); | |||||
| } | |||||
| ) | |||||
| } | } | ||||
| setData(dataSource: any, dataLength: number): void { | setData(dataSource: any, dataLength: number): void { | ||||
| this.dataSource = dataSource; | |||||
| this.pagingComponent.dataSource = dataSource; | this.pagingComponent.dataSource = dataSource; | ||||
| this.pagingComponent.setDataLength(dataLength); | this.pagingComponent.setDataLength(dataLength); | ||||
| } | } | ||||
| @@ -133,6 +127,9 @@ export class ListComponent implements OnInit, AfterViewInit { | |||||
| onRowSelected(row: any, index: number) { | onRowSelected(row: any, index: number) { | ||||
| this.selectedRowIndex = index; | this.selectedRowIndex = index; | ||||
| if (this.onRowSelectedFunction !== undefined) { | |||||
| this.onRowSelectedFunction(row, index); | |||||
| } | |||||
| } | } | ||||
| getElementValue(element: any, column: ListColDefinition): string | null { | getElementValue(element: any, column: ListColDefinition): string | null { | ||||
| @@ -161,14 +158,6 @@ export class ListComponent implements OnInit, AfterViewInit { | |||||
| return "/assets/images/icons/dummy-product.png" | return "/assets/images/icons/dummy-product.png" | ||||
| } | } | ||||
| getElementId(element: any, column: ListColDefinition): string { | |||||
| if (column.subResource) { | |||||
| return column.subResource in element ? element[column.subResource]['id'] : null; | |||||
| } else { | |||||
| return element['id']; | |||||
| } | |||||
| } | |||||
| getColCssClass(column: ListColDefinition): string { | getColCssClass(column: ListColDefinition): string { | ||||
| switch (column.type) { | switch (column.type) { | ||||
| case ListComponent.COLUMN_TYPE_DETAIL: | case ListComponent.COLUMN_TYPE_DETAIL: | ||||
| @@ -180,10 +169,6 @@ export class ListComponent implements OnInit, AfterViewInit { | |||||
| } | } | ||||
| } | } | ||||
| public getSearchValue(): any { | |||||
| return this.pagingComponent.getSearchValue(); | |||||
| } | |||||
| public getPageIndex() { | public getPageIndex() { | ||||
| return this.pagingComponent.getPageIndex(); | return this.pagingComponent.getPageIndex(); | ||||
| } | } | ||||
| @@ -191,4 +176,20 @@ export class ListComponent implements OnInit, AfterViewInit { | |||||
| public getPageSize() { | public getPageSize() { | ||||
| return this.pagingComponent.getPageSize(); | return this.pagingComponent.getPageSize(); | ||||
| } | } | ||||
| public static getDefaultColDetailBtn(): ListColDefinition { | |||||
| return { | |||||
| name: 'detail', | |||||
| text: 'overview.details', | |||||
| type: ListComponent.COLUMN_TYPE_DETAIL | |||||
| } as ListColDefinition; | |||||
| } | |||||
| public static getDefaultColPosition(): ListColDefinition { | |||||
| return { | |||||
| name: 'pos', | |||||
| text: 'overview.number', | |||||
| type: ListComponent.COLUMN_TYPE_POSITION | |||||
| } as ListColDefinition; | |||||
| } | |||||
| } | } | ||||
| @@ -13,7 +13,8 @@ | |||||
| [pageSize]="pageSize" | [pageSize]="pageSize" | ||||
| [pageIndex]="pageIndex" | [pageIndex]="pageIndex" | ||||
| [hidePageSize]="hidePageSize" | [hidePageSize]="hidePageSize" | ||||
| showFirstLastButtons> | |||||
| showFirstLastButtons | |||||
| > | |||||
| </mat-paginator> | </mat-paginator> | ||||
| </div> | </div> | ||||
| <ng-content></ng-content> | <ng-content></ng-content> | ||||
| @@ -79,7 +79,11 @@ export class PagingComponent implements OnInit, AfterViewInit { | |||||
| } | } | ||||
| getData() { | getData() { | ||||
| this.getDataFunction(this.searchForm ? this.searchForm.get('inputText')?.value : undefined); | |||||
| this.getDataFunction( | |||||
| this.getPageIndex(), | |||||
| this.getPageSize(), | |||||
| this.searchForm ? this.searchForm.get('inputText')?.value : undefined | |||||
| ); | |||||
| } | } | ||||
| handlePageEvent(e: PageEvent) { | handlePageEvent(e: PageEvent) { | ||||
| @@ -5,51 +5,14 @@ | |||||
| </div> | </div> | ||||
| <!-- <p>NAME {{documentForm.get(formId)}}<span>X</span></p>--> | <!-- <p>NAME {{documentForm.get(formId)}}<span>X</span></p>--> | ||||
| <div class="search-toggle" [class.search-box-open]="searchBoxOpen"> | <div class="search-toggle" [class.search-box-open]="searchBoxOpen"> | ||||
| <app-paging #pagingComponent | |||||
| [getDataFunction]="getDataFunction" | |||||
| [dataSource]="dataSource" | |||||
| [searchable]="true" | |||||
| [hidePageSize]="true" | |||||
| <app-list #listComponent | |||||
| [getDataFunction]="getDataFunction" | |||||
| [onSortFunction]="onSortChange" | |||||
| [onRowSelectedFunction]="onRowSelected" | |||||
| [listColDefinitions]="listColDefinitions" | |||||
| [showDetailButton]="false" | |||||
| [showPosition]="false" | |||||
| > | > | ||||
| <div *ngIf="searchSelectColDefs" class="table-responsive"> | |||||
| <table mat-table [dataSource]="dataSource" matSort (matSortChange)="onSortChange($event)" class="mat-elevation-z8"> | |||||
| <ng-container *ngFor="let column of searchSelectColDefs" [matColumnDef]="column.column"> | |||||
| <th mat-header-cell *matHeaderCellDef> | |||||
| {{ column.columnHeader | translate }} | |||||
| </th> | |||||
| <ng-container *ngIf="column.columnType == COLUMN_TYPE_POSITION"> | |||||
| <td mat-cell *matCellDef="let element"> | |||||
| {{ pagingComponent.getPageSize() * (pagingComponent.getPageIndex()-1) + dataSource.filteredData.indexOf(element) + 1 }} | |||||
| </td> | |||||
| </ng-container> | |||||
| <ng-container *ngIf="column.columnType == COLUMN_TYPE_IMAGE"> | |||||
| <td mat-cell *matCellDef="let element"> | |||||
| X{{element.imageUrl}}X | |||||
| <img *ngIf="element.imageUrl !== null && element.imageUrl !== undefined" | |||||
| src="{{ getElementValue(element, column) }}" width="40" height="40"/> | |||||
| <img *ngIf="element.imageUrl === null || element.imageUrl === undefined" | |||||
| src="/assets/images/icons/dummy-product.png" width="40" height="40" alt="" /> | |||||
| </td> | |||||
| </ng-container> | |||||
| <ng-container *ngIf="column.columnType == COLUMN_TYPE_TEXT"> | |||||
| <td mat-cell *matCellDef="let element"> | |||||
| {{ getElementValue(element, column) }} | |||||
| </td> | |||||
| </ng-container> | |||||
| </ng-container> | |||||
| <tr mat-header-row *matHeaderRowDef="displayedColumns"></tr> | |||||
| <tr mat-row | |||||
| *matRowDef="let row; columns: displayedColumns; index as i;" | |||||
| (click)="onRowSelected(row, i)" | |||||
| [ngClass]="{'highlighted': selectedRowIndex === i}" | |||||
| ></tr> | |||||
| </table> | |||||
| </div> | |||||
| </app-paging> | |||||
| </app-list> | |||||
| </div> | </div> | ||||
| </div> | </div> | ||||
| @@ -4,6 +4,9 @@ import {FormGroup} from "@angular/forms"; | |||||
| import {SearchInputColDef} from "@app/_components/search-input/search-input-col-def"; | import {SearchInputColDef} from "@app/_components/search-input/search-input-col-def"; | ||||
| import {MatSort, Sort} from "@angular/material/sort"; | import {MatSort, Sort} from "@angular/material/sort"; | ||||
| import {OrderFilter} from "@app/_models/orderFilter"; | 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({ | @Component({ | ||||
| selector: 'app-search-select', | selector: 'app-search-select', | ||||
| @@ -11,41 +14,27 @@ import {OrderFilter} from "@app/_models/orderFilter"; | |||||
| styleUrl: './search-select.component.scss' | styleUrl: './search-select.component.scss' | ||||
| }) | }) | ||||
| export class SearchSelectComponent implements OnInit, AfterViewInit { | export class SearchSelectComponent implements OnInit, AfterViewInit { | ||||
| @Input() public formId!: string; | @Input() public formId!: string; | ||||
| @Input() public formLabelLangKey!: string; | @Input() public formLabelLangKey!: string; | ||||
| @Input() public documentForm!: FormGroup; | @Input() public documentForm!: FormGroup; | ||||
| @Input() public documentFormField!: string; | @Input() public documentFormField!: string; | ||||
| @Input() public getDataFunction!: Function; | |||||
| @Input() public getDataFunction!: (index: number, pageSize: number, term?: string) => Observable<any>; | |||||
| @Input() public dataSource: any; | @Input() public dataSource: any; | ||||
| @Input() public searchSelectColDefs!: SearchInputColDef[]; | |||||
| @Input() public dataSet!: any; | @Input() public dataSet!: any; | ||||
| @Input() public displayedDataField!: string; | @Input() public displayedDataField!: string; | ||||
| @Input() public displayedDataSubResource!: string; | @Input() public displayedDataSubResource!: string; | ||||
| @Input() public listColDefinitions!: ListColDefinition[]; | |||||
| @Output() rowSelected = new EventEmitter<any>(); | @Output() rowSelected = new EventEmitter<any>(); | ||||
| @ViewChild('paragraphRef', { static: false }) paragraphRef!: ElementRef; | @ViewChild('paragraphRef', { static: false }) paragraphRef!: ElementRef; | ||||
| @ViewChild("pagingComponent", { static: false }) pagingComponent!: PagingComponent | |||||
| @ViewChild(MatSort) sort; | |||||
| static COLUMN_TYPE_POSITION: string = 'position'; | |||||
| static COLUMN_TYPE_TEXT: string = 'text'; | |||||
| static COLUMN_TYPE_IMAGE: string = 'image'; | |||||
| static validColumnTypes: string[] = [ | |||||
| SearchSelectComponent.COLUMN_TYPE_POSITION, | |||||
| SearchSelectComponent.COLUMN_TYPE_TEXT, | |||||
| SearchSelectComponent.COLUMN_TYPE_IMAGE | |||||
| ]; | |||||
| protected displayedColumns!: string[]; | |||||
| @ViewChild("listComponent", { static: false }) listComponent!: ListComponent; | |||||
| protected readonly SearchSelectComponent = SearchSelectComponent; | |||||
| protected selectedRowIndex: number | null = null; | protected selectedRowIndex: number | null = null; | ||||
| protected searchBoxOpen: boolean; | protected searchBoxOpen: boolean; | ||||
| protected searchBoxInitialized: boolean; | protected searchBoxInitialized: boolean; | ||||
| protected searchBoxFilled: boolean; | protected searchBoxFilled: boolean; | ||||
| constructor() { | constructor() { | ||||
| this.sort = new MatSort(); | |||||
| this.searchBoxOpen = false; | this.searchBoxOpen = false; | ||||
| this.searchBoxInitialized = false; | this.searchBoxInitialized = false; | ||||
| this.searchBoxFilled = false; | this.searchBoxFilled = false; | ||||
| @@ -55,10 +44,6 @@ export class SearchSelectComponent implements OnInit, AfterViewInit { | |||||
| if (this.dataSet !== undefined) { | if (this.dataSet !== undefined) { | ||||
| this.searchBoxFilled = true; | this.searchBoxFilled = true; | ||||
| } | } | ||||
| this.displayedColumns = []; | |||||
| this.searchSelectColDefs.forEach((value, index) => { | |||||
| this.displayedColumns.push(value.column); | |||||
| }); | |||||
| } | } | ||||
| ngAfterViewInit(): void { | ngAfterViewInit(): void { | ||||
| @@ -67,33 +52,21 @@ export class SearchSelectComponent implements OnInit, AfterViewInit { | |||||
| } | } | ||||
| } | } | ||||
| getData(): void { | |||||
| } | |||||
| setData(dataSource: any, data: any[], dataLength: number): void { | setData(dataSource: any, data: any[], dataLength: number): void { | ||||
| this.dataSource = dataSource; | |||||
| this.pagingComponent.dataSource = dataSource; | |||||
| this.pagingComponent.setDataLength(dataLength); | |||||
| } | |||||
| getPagingComponent(): PagingComponent { | |||||
| return this.pagingComponent; | |||||
| this.listComponent.setData(dataSource, dataLength); | |||||
| } | } | ||||
| onSortChange = (sortState: Sort) => { | onSortChange = (sortState: Sort) => { | ||||
| this.pagingComponent.resetPageIndex() | |||||
| let order: OrderFilter; | let order: OrderFilter; | ||||
| if (sortState.direction === "") { | if (sortState.direction === "") { | ||||
| order = OrderFilter.Undefined; | order = OrderFilter.Undefined; | ||||
| } else { | } else { | ||||
| order = sortState.direction; | order = sortState.direction; | ||||
| } | } | ||||
| this.pagingComponent.getData(); | |||||
| this.listComponent.getData(); | |||||
| } | } | ||||
| onRowSelected(row: any, index: number) { | |||||
| onRowSelected = (row: any, index: number) => { | |||||
| this.selectedRowIndex = index; | this.selectedRowIndex = index; | ||||
| this.documentForm.get(this.formId)?.setValue(row.id); | this.documentForm.get(this.formId)?.setValue(row.id); | ||||
| if (this.displayedDataSubResource !== undefined) { | if (this.displayedDataSubResource !== undefined) { | ||||
| @@ -105,58 +78,97 @@ export class SearchSelectComponent implements OnInit, AfterViewInit { | |||||
| this.searchBoxOpen = false; | this.searchBoxOpen = false; | ||||
| } | } | ||||
| get COLUMN_TYPE_POSITION(): string { | |||||
| return SearchSelectComponent.COLUMN_TYPE_POSITION; | |||||
| openSearchBox() { | |||||
| this.searchBoxOpen = !this.searchBoxOpen; | |||||
| if (this.searchBoxOpen && !this.searchBoxInitialized) { | |||||
| this.listComponent.getData(); | |||||
| this.searchBoxInitialized = true; | |||||
| } | |||||
| } | } | ||||
| get COLUMN_TYPE_IMAGE(): string { | |||||
| return SearchSelectComponent.COLUMN_TYPE_IMAGE; | |||||
| clearSearch() { | |||||
| this.paragraphRef.nativeElement.textContent = ''; | |||||
| this.searchBoxFilled = false; | |||||
| this.documentForm.get(this.formId)?.setValue(undefined); | |||||
| } | } | ||||
| get COLUMN_TYPE_TEXT(): string { | |||||
| return SearchSelectComponent.COLUMN_TYPE_TEXT; | |||||
| public getPageIndex() { | |||||
| return this.listComponent.getPageIndex(); | |||||
| } | } | ||||
| getElementValue(element: any, column: SearchInputColDef): any { | |||||
| if (column.field) { | |||||
| return column.subResource ? element[column.subResource][column.field] : element[column.field]; | |||||
| } | |||||
| public getPageSize() { | |||||
| return this.listComponent.getPageSize(); | |||||
| } | } | ||||
| static createColDef( | |||||
| column: string, | |||||
| columnHeader: string, | |||||
| columnType: string, | |||||
| field?: string, | |||||
| subResource?: string | |||||
| ): SearchInputColDef { | |||||
| if (!this.validColumnTypes.includes(columnType)) { | |||||
| throw Error('invalid column type'); | |||||
| } | |||||
| public static getDefaultColDefPartners(): ListColDefinition[] { | |||||
| return [ | |||||
| ListComponent.getDefaultColPosition(), | |||||
| { | |||||
| name: 'img', | |||||
| text: 'overview.image', | |||||
| type: ListComponent.COLUMN_TYPE_IMAGE, | |||||
| field: 'logoUrl', | |||||
| } as ListColDefinition, | |||||
| { | |||||
| name: 'name', | |||||
| text: 'form.name', | |||||
| type: ListComponent.COLUMN_TYPE_TEXT, | |||||
| field: 'name', | |||||
| } | |||||
| ]; | |||||
| } | |||||
| let res: SearchInputColDef = {} as SearchInputColDef; | |||||
| res.column = column; | |||||
| res.columnHeader = columnHeader; | |||||
| res.columnType = columnType; | |||||
| res.field = field; | |||||
| res.subResource = subResource; | |||||
| return res; | |||||
| public static getDefaultColDefProducts(): ListColDefinition[] { | |||||
| return [ | |||||
| ListComponent.getDefaultColPosition(), | |||||
| { | |||||
| name: 'img', | |||||
| text: 'overview.image', | |||||
| type: ListComponent.COLUMN_TYPE_IMAGE, | |||||
| field: 'imageUrl', | |||||
| } as ListColDefinition, | |||||
| { | |||||
| name: 'name', | |||||
| text: 'form.product', | |||||
| type: ListComponent.COLUMN_TYPE_TEXT, | |||||
| field: 'name', | |||||
| } | |||||
| ]; | |||||
| } | } | ||||
| openSearchBox() { | |||||
| // if (this.paragraphRef.nativeElement.textContent !== '') { | |||||
| this.searchBoxOpen = !this.searchBoxOpen; | |||||
| if (this.searchBoxOpen && !this.searchBoxInitialized) { | |||||
| this.pagingComponent.getData(); | |||||
| this.searchBoxInitialized = true; | |||||
| } | |||||
| // } | |||||
| public static getDefaultColDefContacts(): ListColDefinition[] { | |||||
| return [ | |||||
| ListComponent.getDefaultColPosition(), | |||||
| { | |||||
| name: 'img', | |||||
| text: 'overview.image', | |||||
| type: ListComponent.COLUMN_TYPE_IMAGE, | |||||
| field: 'imageUrl', | |||||
| } as ListColDefinition, | |||||
| { | |||||
| name: 'name', | |||||
| text: 'form.name', | |||||
| type: ListComponent.COLUMN_TYPE_TEXT, | |||||
| field: 'fullName', | |||||
| } | |||||
| ]; | |||||
| } | } | ||||
| clearSearch() { | |||||
| this.paragraphRef.nativeElement.textContent = ''; | |||||
| this.searchBoxFilled = false; | |||||
| this.documentForm.get(this.formId)?.setValue(undefined); | |||||
| // this.searchBoxOpen = true; | |||||
| public static getDefaultColDefUsers(): ListColDefinition[] { | |||||
| return [ | |||||
| ListComponent.getDefaultColPosition(), | |||||
| { | |||||
| name: 'img', | |||||
| text: 'overview.image', | |||||
| type: ListComponent.COLUMN_TYPE_IMAGE, | |||||
| field: 'imageUrl', | |||||
| } as ListColDefinition, | |||||
| { | |||||
| name: 'name', | |||||
| text: 'form.name', | |||||
| type: ListComponent.COLUMN_TYPE_TEXT, | |||||
| field: 'fullName', | |||||
| } | |||||
| ]; | |||||
| } | } | ||||
| } | } | ||||
| @@ -22,7 +22,6 @@ export class NewContactComponent implements OnInit, AfterViewInit { | |||||
| protected selectedImage: File | null; | protected selectedImage: File | null; | ||||
| protected contactSub: Subscription; | protected contactSub: Subscription; | ||||
| protected mediaSub: Subscription; | protected mediaSub: Subscription; | ||||
| protected birthdayValue: string; | protected birthdayValue: string; | ||||
| constructor( | constructor( | ||||
| @@ -33,12 +32,9 @@ export class NewContactComponent implements OnInit, AfterViewInit { | |||||
| ) { | ) { | ||||
| this.contactForm = contactForm; | this.contactForm = contactForm; | ||||
| this.selectedImage = null; | this.selectedImage = null; | ||||
| this.contactSub = new Subscription(); | this.contactSub = new Subscription(); | ||||
| this.mediaSub = new Subscription(); | this.mediaSub = new Subscription(); | ||||
| this.birthdayValue = ""; | this.birthdayValue = ""; | ||||
| } | } | ||||
| ngOnInit(): void { | ngOnInit(): void { | ||||
| @@ -48,8 +44,6 @@ export class NewContactComponent implements OnInit, AfterViewInit { | |||||
| ngAfterViewInit(): void { | ngAfterViewInit(): void { | ||||
| } | } | ||||
| protected onBirthdayChange(selectedItem: any) { | protected onBirthdayChange(selectedItem: any) { | ||||
| // Set T12:00 for correct string | // Set T12:00 for correct string | ||||
| let selectedItemValue = null; | let selectedItemValue = null; | ||||
| @@ -75,7 +69,6 @@ export class NewContactComponent implements OnInit, AfterViewInit { | |||||
| } | } | ||||
| } | } | ||||
| // Submit all values of the form to the backend | |||||
| submitForm() { | submitForm() { | ||||
| if (this.contactForm.valid) { | if (this.contactForm.valid) { | ||||
| if (this.contact.id === null || this.contact.id === undefined) { | if (this.contact.id === null || this.contact.id === undefined) { | ||||
| @@ -3,14 +3,12 @@ | |||||
| <button class="btn btn-primary" (click)="openModalNewDocument()">+ {{ 'basic.new-document' | translate }}</button> | <button class="btn btn-primary" (click)="openModalNewDocument()">+ {{ 'basic.new-document' | translate }}</button> | ||||
| </div> | </div> | ||||
| <app-list #listComponent | <app-list #listComponent | ||||
| [dataSource]="dataSource" | |||||
| [getDataFunction]="getData" | [getDataFunction]="getData" | ||||
| [onSortFunction]="onSortChange" | [onSortFunction]="onSortChange" | ||||
| [onDownloadFunction]="navigateToDocumentFile" | [onDownloadFunction]="navigateToDocumentFile" | ||||
| [onEditFunction]="openModalEditDocument" | [onEditFunction]="openModalEditDocument" | ||||
| [listColDefinitions]="listColDefinitions" | [listColDefinitions]="listColDefinitions" | ||||
| [searchable]="true" | [searchable]="true" | ||||
| [hidePageSize]="false" | |||||
| [showDetailButton]="false" | [showDetailButton]="false" | ||||
| ></app-list> | ></app-list> | ||||
| </div> | </div> | ||||
| @@ -2,9 +2,7 @@ import {AfterViewInit, Component, Input, OnInit, ViewChild} from '@angular/core' | |||||
| import {DocumentJsonld, DocumentService, PartnerJsonld, ProductJsonld} from "@app/core/api/v1"; | import {DocumentJsonld, DocumentService, PartnerJsonld, ProductJsonld} from "@app/core/api/v1"; | ||||
| import {AppHelperService} from "@app/_helpers/app-helper.service"; | import {AppHelperService} from "@app/_helpers/app-helper.service"; | ||||
| import {MatSort, Sort} from "@angular/material/sort"; | import {MatSort, Sort} from "@angular/material/sort"; | ||||
| import {Subscription} from "rxjs"; | |||||
| import {MatTableDataSource} from "@angular/material/table"; | import {MatTableDataSource} from "@angular/material/table"; | ||||
| import {PagingComponent} from "@app/_components/paging/paging.component"; | |||||
| import {OrderFilter} from "@app/_models/orderFilter"; | import {OrderFilter} from "@app/_models/orderFilter"; | ||||
| import {NewDocumentComponent} from "@app/_views/documents/new-document/new-document.component"; | import {NewDocumentComponent} from "@app/_views/documents/new-document/new-document.component"; | ||||
| import {ListComponent} from "@app/_components/list/list.component"; | import {ListComponent} from "@app/_components/list/list.component"; | ||||
| @@ -21,19 +19,12 @@ export class DocumentListComponent implements OnInit, AfterViewInit { | |||||
| @Input() public partner!: PartnerJsonld; | @Input() public partner!: PartnerJsonld; | ||||
| @ViewChild("listComponent", { static: false }) listComponent!: ListComponent; | @ViewChild("listComponent", { static: false }) listComponent!: ListComponent; | ||||
| protected documentsSub: Subscription; | |||||
| protected documents: Array<DocumentJsonld>; | |||||
| protected dataSource; | |||||
| protected listColDefinitions!: ListColDefinition[]; | protected listColDefinitions!: ListColDefinition[]; | ||||
| constructor( | constructor( | ||||
| private documentService: DocumentService, | private documentService: DocumentService, | ||||
| protected appHelperService: AppHelperService | protected appHelperService: AppHelperService | ||||
| ) { | ) { | ||||
| this.documentsSub = new Subscription(); | |||||
| this.documents = []; | |||||
| this.dataSource = new MatTableDataSource<DocumentJsonld>(this.documents); | |||||
| this.listColDefinitions = [ | this.listColDefinitions = [ | ||||
| { | { | ||||
| name: 'name', | name: 'name', | ||||
| @@ -83,7 +74,6 @@ export class DocumentListComponent implements OnInit, AfterViewInit { | |||||
| type: ListComponent.COLUMN_TYPE_BTN_EDIT, | type: ListComponent.COLUMN_TYPE_BTN_EDIT, | ||||
| } as ListColDefinition, | } as ListColDefinition, | ||||
| ]; | ]; | ||||
| } | } | ||||
| ngOnInit(){ | ngOnInit(){ | ||||
| @@ -93,22 +83,15 @@ export class DocumentListComponent implements OnInit, AfterViewInit { | |||||
| this.listComponent.getData(); | this.listComponent.getData(); | ||||
| } | } | ||||
| getData = () => { | |||||
| this.documentsSub = this.documentService.documentsGetCollection( | |||||
| this.listComponent.getPageIndex(), | |||||
| this.listComponent.getPageSize(), | |||||
| getData = (index: number, pageSize: number, term?: string) => { | |||||
| return this.documentService.documentsGetCollection( | |||||
| index, | |||||
| pageSize, | |||||
| undefined, | undefined, | ||||
| undefined, | undefined, | ||||
| this.partner !== undefined ? this.partner.id : undefined, | this.partner !== undefined ? this.partner.id : undefined, | ||||
| undefined, | undefined, | ||||
| this.product !== undefined ? this.product.id : undefined | this.product !== undefined ? this.product.id : undefined | ||||
| ).subscribe( | |||||
| data => { | |||||
| this.documents = data["hydra:member"]; | |||||
| this.dataSource = new MatTableDataSource<DocumentJsonld>(this.documents); | |||||
| this.listComponent.setData(this.dataSource, Number(data["hydra:totalItems"])); | |||||
| } | |||||
| ); | ); | ||||
| } | } | ||||
| @@ -129,11 +112,11 @@ export class DocumentListComponent implements OnInit, AfterViewInit { | |||||
| openModalNewDocument() { | openModalNewDocument() { | ||||
| let document: DocumentJsonld = {} as DocumentJsonld; | let document: DocumentJsonld = {} as DocumentJsonld; | ||||
| this.appHelperService.openModal(NewDocumentComponent, { 'document': document }, this.getData); | |||||
| this.appHelperService.openModal(NewDocumentComponent, { 'document': document }, this.listComponent.getData); | |||||
| } | } | ||||
| openModalEditDocument(element: DocumentJsonld) { | openModalEditDocument(element: DocumentJsonld) { | ||||
| this.appHelperService.openModal(NewDocumentComponent, { 'document': element }, this.getData); | |||||
| this.appHelperService.openModal(NewDocumentComponent, { 'document': element }, this.listComponent.getData); | |||||
| } | } | ||||
| } | } | ||||
| @@ -19,10 +19,9 @@ | |||||
| [formLabelLangKey]="'form.partner'" | [formLabelLangKey]="'form.partner'" | ||||
| [documentForm]="documentForm" | [documentForm]="documentForm" | ||||
| [getDataFunction]="getPartners" | [getDataFunction]="getPartners" | ||||
| [dataSource]="dataSourcePartners" | |||||
| [searchSelectColDefs]="colDefPartners" | |||||
| [displayedDataField]="'name'" | [displayedDataField]="'name'" | ||||
| [dataSet]="document.partner" | [dataSet]="document.partner" | ||||
| [listColDefinitions]="SearchSelectComponent.getDefaultColDefPartners()" | |||||
| > | > | ||||
| </app-search-select> | </app-search-select> | ||||
| <input type="hidden" id="partner" formControlName="partner"/> | <input type="hidden" id="partner" formControlName="partner"/> | ||||
| @@ -35,10 +34,9 @@ | |||||
| [formLabelLangKey]="'form.product'" | [formLabelLangKey]="'form.product'" | ||||
| [documentForm]="documentForm" | [documentForm]="documentForm" | ||||
| [getDataFunction]="getProducts" | [getDataFunction]="getProducts" | ||||
| [dataSource]="dataSourceProducts" | |||||
| [searchSelectColDefs]="colDefProducts" | |||||
| [displayedDataField]="'name'" | [displayedDataField]="'name'" | ||||
| [dataSet]="document.product" | [dataSet]="document.product" | ||||
| [listColDefinitions]="SearchSelectComponent.getDefaultColDefProducts()" | |||||
| > | > | ||||
| </app-search-select> | </app-search-select> | ||||
| <input type="hidden" id="product" formControlName="product"/> | <input type="hidden" id="product" formControlName="product"/> | ||||
| @@ -1,18 +1,17 @@ | |||||
| import {AfterViewInit, Component, EventEmitter, Input, OnInit, Output, ViewChild} from '@angular/core'; | import {AfterViewInit, Component, EventEmitter, Input, OnInit, Output, ViewChild} from '@angular/core'; | ||||
| import { | import { | ||||
| DocumentJsonld, DocumentObjectService, | DocumentJsonld, DocumentObjectService, | ||||
| DocumentService, PartnerJsonld, PartnerService, ProductJsonld, ProductService, UserJsonld, UserService | |||||
| DocumentService, PartnerService, ProductService | |||||
| } from "@app/core/api/v1"; | } from "@app/core/api/v1"; | ||||
| import {ModalStatus} from "@app/_helpers/modal.states"; | import {ModalStatus} from "@app/_helpers/modal.states"; | ||||
| import {FormGroup} from "@angular/forms"; | import {FormGroup} from "@angular/forms"; | ||||
| import {Observable, Subscription} from "rxjs"; | |||||
| import {Observable} from "rxjs"; | |||||
| import {TranslateService} from "@ngx-translate/core"; | import {TranslateService} from "@ngx-translate/core"; | ||||
| import {FormGroupInitializer} from "@app/_helpers/formgroup.initializer"; | import {FormGroupInitializer} from "@app/_helpers/formgroup.initializer"; | ||||
| import {documentForm} from "@app/_forms/apiForms"; | import {documentForm} from "@app/_forms/apiForms"; | ||||
| import {AppHelperService} from "@app/_helpers/app-helper.service"; | import {AppHelperService} from "@app/_helpers/app-helper.service"; | ||||
| import {SearchSelectComponent} from "@app/_components/search-select/search-select.component"; | import {SearchSelectComponent} from "@app/_components/search-select/search-select.component"; | ||||
| import {MatTableDataSource} from "@angular/material/table"; | |||||
| import {SearchInputColDef} from "@app/_components/search-input/search-input-col-def"; | |||||
| import {ListGetDataFunctionType} from "@app/_components/list/list-get-data-function-type"; | |||||
| @Component({ | @Component({ | ||||
| selector: 'app-new-document', | selector: 'app-new-document', | ||||
| @@ -22,20 +21,12 @@ import {SearchInputColDef} from "@app/_components/search-input/search-input-col- | |||||
| export class NewDocumentComponent implements OnInit, AfterViewInit { | export class NewDocumentComponent implements OnInit, AfterViewInit { | ||||
| @Input() public document!: DocumentJsonld; | @Input() public document!: DocumentJsonld; | ||||
| @Output() public submit: EventEmitter<ModalStatus> = new EventEmitter<ModalStatus>(); | @Output() public submit: EventEmitter<ModalStatus> = new EventEmitter<ModalStatus>(); | ||||
| @ViewChild('partnerSearchSelect', { static: false }) partnerSearchSelect!: SearchSelectComponent; | @ViewChild('partnerSearchSelect', { static: false }) partnerSearchSelect!: SearchSelectComponent; | ||||
| @ViewChild('productSearchSelect', { static: false }) productSearchSelect!: SearchSelectComponent; | @ViewChild('productSearchSelect', { static: false }) productSearchSelect!: SearchSelectComponent; | ||||
| protected readonly SearchSelectComponent = SearchSelectComponent; | |||||
| protected documentForm: FormGroup; | protected documentForm: FormGroup; | ||||
| protected documentSub: Subscription; | |||||
| protected selectedFile: File | null; | protected selectedFile: File | null; | ||||
| protected documentObjectSub: Subscription; | |||||
| protected partners: Array<PartnerJsonld>; | |||||
| protected dataSourcePartners; | |||||
| protected products: Array<ProductJsonld>; | |||||
| protected dataSourceProducts; | |||||
| protected colDefPartners: SearchInputColDef[]; | |||||
| protected colDefProducts: SearchInputColDef[]; | |||||
| constructor( | constructor( | ||||
| protected documentService: DocumentService, | protected documentService: DocumentService, | ||||
| @@ -45,25 +36,8 @@ export class NewDocumentComponent implements OnInit, AfterViewInit { | |||||
| protected productService: ProductService, | protected productService: ProductService, | ||||
| protected appHelperService: AppHelperService, | protected appHelperService: AppHelperService, | ||||
| ) { | ) { | ||||
| this.partners = []; | |||||
| this.dataSourcePartners = new MatTableDataSource<PartnerJsonld>(this.partners); | |||||
| this.products = []; | |||||
| this.dataSourceProducts = new MatTableDataSource<ProductJsonld>(this.products); | |||||
| this.documentForm = documentForm; | this.documentForm = documentForm; | ||||
| this.documentSub = new Subscription(); | |||||
| this.selectedFile = null; | this.selectedFile = null; | ||||
| this.documentObjectSub = new Subscription(); | |||||
| this.colDefPartners = [ | |||||
| SearchSelectComponent.createColDef('pos', 'overview.number', SearchSelectComponent.COLUMN_TYPE_POSITION), | |||||
| SearchSelectComponent.createColDef('img', 'overview.image', SearchSelectComponent.COLUMN_TYPE_IMAGE, 'logoUrl'), | |||||
| SearchSelectComponent.createColDef('name', 'form.name', SearchSelectComponent.COLUMN_TYPE_TEXT, 'name'), | |||||
| ]; | |||||
| this.colDefProducts = [ | |||||
| SearchSelectComponent.createColDef('pos', 'overview.number', SearchSelectComponent.COLUMN_TYPE_POSITION), | |||||
| SearchSelectComponent.createColDef('img', 'overview.image', SearchSelectComponent.COLUMN_TYPE_IMAGE, 'imageUrl'), | |||||
| SearchSelectComponent.createColDef('name', 'form.product', SearchSelectComponent.COLUMN_TYPE_TEXT, 'name'), | |||||
| ]; | |||||
| } | } | ||||
| ngOnInit(): void { | ngOnInit(): void { | ||||
| @@ -71,44 +45,29 @@ export class NewDocumentComponent implements OnInit, AfterViewInit { | |||||
| } | } | ||||
| ngAfterViewInit(): void { | ngAfterViewInit(): void { | ||||
| this.partnerSearchSelect.getData(); | |||||
| this.productSearchSelect.getData(); | |||||
| } | } | ||||
| getPartners = (term: string): void => { | |||||
| this.partnerService.partnersGetCollection( | |||||
| this.partnerSearchSelect.pagingComponent.getPageIndex(), | |||||
| this.partnerSearchSelect.pagingComponent.getPageSize(), | |||||
| getPartners: ListGetDataFunctionType = (index: number, pageSize: number, term?: string): Observable<any> => { | |||||
| return this.partnerService.partnersGetCollection( | |||||
| index, | |||||
| pageSize, | |||||
| undefined, | undefined, | ||||
| undefined, | undefined, | ||||
| term | term | ||||
| ).subscribe( | |||||
| data => { | |||||
| this.partners = data['hydra:member']; | |||||
| this.dataSourcePartners = new MatTableDataSource<PartnerJsonld>(this.partners); | |||||
| this.partnerSearchSelect.setData(this.dataSourcePartners, this.partners, Number(data["hydra:totalItems"])); | |||||
| } | |||||
| ) | |||||
| ); | |||||
| } | } | ||||
| getProducts = (term?: string): void => { | |||||
| // NOTE: all products that are not assigned to partner yet | |||||
| this.productService.productsGetCollection( | |||||
| this.productSearchSelect.pagingComponent.getPageIndex(), | |||||
| this.productSearchSelect.pagingComponent.getPageSize(), | |||||
| getProducts: ListGetDataFunctionType = (index: number, pageSize: number, term?: string): Observable<any> => { | |||||
| return this.productService.productsGetCollection( | |||||
| index, | |||||
| pageSize, | |||||
| term | term | ||||
| ).subscribe( | |||||
| data => { | |||||
| this.products = data['hydra:member']; | |||||
| this.dataSourceProducts = new MatTableDataSource<ProductJsonld>(this.products); | |||||
| this.productSearchSelect.setData(this.dataSourceProducts, this.products, Number(data["hydra:totalItems"])); | |||||
| } | |||||
| ); | ); | ||||
| } | } | ||||
| onSubmit() { | onSubmit() { | ||||
| if (this.selectedFile !== null) { | if (this.selectedFile !== null) { | ||||
| this.documentObjectSub = this.documentObjectService.documentObjectsPost( | |||||
| this.documentObjectService.documentObjectsPost( | |||||
| this.selectedFile | this.selectedFile | ||||
| ).subscribe( | ).subscribe( | ||||
| data => { | data => { | ||||
| @@ -125,7 +84,7 @@ export class NewDocumentComponent implements OnInit, AfterViewInit { | |||||
| if (this.documentForm.valid) { | if (this.documentForm.valid) { | ||||
| if (this.document.id === null || this.document.id === undefined) { | if (this.document.id === null || this.document.id === undefined) { | ||||
| // Create new product | // Create new product | ||||
| this.documentSub = this.documentService.documentsPost( | |||||
| this.documentService.documentsPost( | |||||
| this.documentForm.value as DocumentJsonld | this.documentForm.value as DocumentJsonld | ||||
| ).subscribe( | ).subscribe( | ||||
| data => { | data => { | ||||
| @@ -135,7 +94,7 @@ export class NewDocumentComponent implements OnInit, AfterViewInit { | |||||
| ); | ); | ||||
| } else { | } else { | ||||
| // Edit contact | // Edit contact | ||||
| this.documentSub = this.documentService.documentsIdPatch( | |||||
| this.documentService.documentsIdPatch( | |||||
| this.appHelperService.extractId(this.document.id), | this.appHelperService.extractId(this.document.id), | ||||
| this.documentForm.value as DocumentJsonld | this.documentForm.value as DocumentJsonld | ||||
| ).subscribe( | ).subscribe( | ||||
| @@ -3,8 +3,7 @@ | |||||
| <button class="btn btn-primary" (click)="openModalNewPartner()">+ {{ 'basic.new' | translate }} {{ partnerColumnHeadline }}</button> | <button class="btn btn-primary" (click)="openModalNewPartner()">+ {{ 'basic.new' | translate }} {{ partnerColumnHeadline }}</button> | ||||
| </div> | </div> | ||||
| <app-list #listComponent | <app-list #listComponent | ||||
| [dataSource]="getDataSource()" | |||||
| [getDataFunction]="getData" | |||||
| [getDataFunction]="getDataFunction" | |||||
| [onNavigateToDetailsFunction]="navigateToPartnerDetails" | [onNavigateToDetailsFunction]="navigateToPartnerDetails" | ||||
| [onSortFunction]="onSortChange" | [onSortFunction]="onSortChange" | ||||
| [onRemoveItemFunction]="unassignPartner" | [onRemoveItemFunction]="unassignPartner" | ||||
| @@ -1,12 +1,10 @@ | |||||
| import {AfterViewInit, Component, Input, OnInit, ViewChild} from '@angular/core'; | import {AfterViewInit, Component, Input, OnInit, ViewChild} from '@angular/core'; | ||||
| import {PagingComponent} from "@app/_components/paging/paging.component"; | |||||
| import {AppHelperService} from "@app/_helpers/app-helper.service"; | import {AppHelperService} from "@app/_helpers/app-helper.service"; | ||||
| import {MatSort, Sort} from "@angular/material/sort"; | |||||
| import {Subscription} from "rxjs"; | |||||
| import {Sort} from "@angular/material/sort"; | |||||
| import {Observable} from "rxjs"; | |||||
| import { | import { | ||||
| PartnerFollowJsonld, | |||||
| PartnerFollowService, | PartnerFollowService, | ||||
| PartnerJsonld, PartnerProductJsonld, | |||||
| PartnerJsonld, | |||||
| PartnerProductService, | PartnerProductService, | ||||
| PartnerService, | PartnerService, | ||||
| ProductJsonld, | ProductJsonld, | ||||
| @@ -14,14 +12,13 @@ import { | |||||
| } from "@app/core/api/v1"; | } from "@app/core/api/v1"; | ||||
| import {OrderFilter} from "@app/_models/orderFilter"; | import {OrderFilter} from "@app/_models/orderFilter"; | ||||
| import {Router} from "@angular/router"; | import {Router} from "@angular/router"; | ||||
| import {MatTableDataSource} from "@angular/material/table"; | |||||
| import {NewPartnerComponent} from "@app/_views/partners/new-partner/new-partner.component"; | import {NewPartnerComponent} from "@app/_views/partners/new-partner/new-partner.component"; | ||||
| import TypeEnum = PartnerJsonld.PartnerTypeEnum; | import TypeEnum = PartnerJsonld.PartnerTypeEnum; | ||||
| import {ListColDefinition} from "@app/_components/list/list-col-definition"; | import {ListColDefinition} from "@app/_components/list/list-col-definition"; | ||||
| import {ListComponent} from "@app/_components/list/list.component"; | import {ListComponent} from "@app/_components/list/list.component"; | ||||
| import {TranslateService} from "@ngx-translate/core"; | import {TranslateService} from "@ngx-translate/core"; | ||||
| import {ListColTypeAddress} from "@app/_components/list/list-col-type-address"; | import {ListColTypeAddress} from "@app/_components/list/list-col-type-address"; | ||||
| type GeneralDataSource = MatTableDataSource<any>; | |||||
| import {ListGetDataFunctionType} from "@app/_components/list/list-get-data-function-type"; | |||||
| @Component({ | @Component({ | ||||
| selector: 'app-partner-list', | selector: 'app-partner-list', | ||||
| @@ -33,22 +30,14 @@ export class PartnerListComponent implements OnInit, AfterViewInit { | |||||
| @Input() public user!: UserJsonld; | @Input() public user!: UserJsonld; | ||||
| @Input() public product!: ProductJsonld; | @Input() public product!: ProductJsonld; | ||||
| @Input("partnerType") partnerType!: string; | @Input("partnerType") partnerType!: string; | ||||
| @ViewChild(MatSort) sort; | |||||
| @ViewChild("listComponent", { static: false }) listComponent!: ListComponent; | @ViewChild("listComponent", { static: false }) listComponent!: ListComponent; | ||||
| @ViewChild("pagingComponent", { static: false }) pagingComponent!: PagingComponent; | |||||
| protected partnersSub: Subscription; | |||||
| protected partners: Array<PartnerJsonld>; | |||||
| protected userPartners: Array<PartnerFollowJsonld>; | |||||
| protected partnerProducts: Array<PartnerProductJsonld>; | |||||
| protected dataSourcePartners; | |||||
| protected dataSourceUserPartners; | |||||
| protected dataSourcePartnerProducts; | |||||
| protected nameOrderAsc: OrderFilter; | protected nameOrderAsc: OrderFilter; | ||||
| protected cityOrderAsc: OrderFilter; | protected cityOrderAsc: OrderFilter; | ||||
| protected websiteOrderAsc: OrderFilter; | protected websiteOrderAsc: OrderFilter; | ||||
| protected partnerColumnHeadline: string; | protected partnerColumnHeadline: string; | ||||
| protected listColDefinitions!: ListColDefinition[]; | protected listColDefinitions!: ListColDefinition[]; | ||||
| protected getDataFunction!: ListGetDataFunctionType; | |||||
| constructor( | constructor( | ||||
| protected partnerService: PartnerService, | protected partnerService: PartnerService, | ||||
| @@ -58,14 +47,6 @@ export class PartnerListComponent implements OnInit, AfterViewInit { | |||||
| protected appHelperService: AppHelperService, | protected appHelperService: AppHelperService, | ||||
| protected translateService: TranslateService, | protected translateService: TranslateService, | ||||
| ) { | ) { | ||||
| this.sort = new MatSort(); | |||||
| this.partnersSub = new Subscription(); | |||||
| this.partners = []; | |||||
| this.userPartners = []; | |||||
| this.partnerProducts = []; | |||||
| this.dataSourcePartners = new MatTableDataSource<PartnerJsonld>(this.partners); | |||||
| this.dataSourceUserPartners = new MatTableDataSource<PartnerFollowJsonld>(this.userPartners); | |||||
| this.dataSourcePartnerProducts = new MatTableDataSource<PartnerProductJsonld>(this.partnerProducts); | |||||
| this.nameOrderAsc = OrderFilter.Asc; | this.nameOrderAsc = OrderFilter.Asc; | ||||
| this.cityOrderAsc = OrderFilter.Asc; | this.cityOrderAsc = OrderFilter.Asc; | ||||
| this.websiteOrderAsc = OrderFilter.Asc; | this.websiteOrderAsc = OrderFilter.Asc; | ||||
| @@ -73,6 +54,10 @@ export class PartnerListComponent implements OnInit, AfterViewInit { | |||||
| } | } | ||||
| ngOnInit() { | ngOnInit() { | ||||
| this.translateService.get('basic.' + this.partnerType + 'One').subscribe((translation: string) => { | |||||
| this.partnerColumnHeadline = translation; | |||||
| }); | |||||
| let withSubResource: boolean = (this.user !== undefined || this.product !== undefined); | let withSubResource: boolean = (this.user !== undefined || this.product !== undefined); | ||||
| this.listColDefinitions = [ | this.listColDefinitions = [ | ||||
| { | { | ||||
| @@ -101,7 +86,7 @@ export class PartnerListComponent implements OnInit, AfterViewInit { | |||||
| city: 'city', | city: 'city', | ||||
| country: 'country', | country: 'country', | ||||
| } as ListColTypeAddress, | } as ListColTypeAddress, | ||||
| sortable: false, | |||||
| sortable: true, | |||||
| subResource: withSubResource ? 'partner' : undefined | subResource: withSubResource ? 'partner' : undefined | ||||
| } as ListColDefinition, | } as ListColDefinition, | ||||
| { | { | ||||
| @@ -122,94 +107,69 @@ export class PartnerListComponent implements OnInit, AfterViewInit { | |||||
| } as ListColDefinition | } as ListColDefinition | ||||
| ) | ) | ||||
| } | } | ||||
| } | |||||
| ngAfterViewInit() { | |||||
| this.listComponent.getData(); | |||||
| } | |||||
| getDataSource(): GeneralDataSource { | |||||
| if (this.user !== undefined) { | if (this.user !== undefined) { | ||||
| return this.dataSourceUserPartners; | |||||
| this.getDataFunction = this.getPartnerData; | |||||
| } else if (this.product !== undefined) { | } else if (this.product !== undefined) { | ||||
| return this.dataSourcePartnerProducts; | |||||
| this.getDataFunction = this.getUserPartnerData | |||||
| } else { | } else { | ||||
| return this.dataSourcePartners; | |||||
| this.getDataFunction = this.getPartnerData; | |||||
| } | } | ||||
| } | } | ||||
| getData = (searchValue = undefined) => { | |||||
| ngAfterViewInit() { | |||||
| this.listComponent.getData(); | |||||
| } | |||||
| getData = (): ListGetDataFunctionType => { | |||||
| if (this.user !== undefined) { | if (this.user !== undefined) { | ||||
| this.getUserPartnerData(searchValue); | |||||
| return this.getUserPartnerData; | |||||
| } else if (this.product !== undefined) { | } else if (this.product !== undefined) { | ||||
| this.getPartnerProducts(searchValue); | |||||
| } else { | |||||
| this.getPartnerData(searchValue); | |||||
| return this.getPartnerProducts; | |||||
| } | } | ||||
| return this.getPartnerData; | |||||
| } | } | ||||
| getPartnerData = (searchValue = undefined) => { | |||||
| this.partnersSub = this.partnerService.partnersGetCollection( | |||||
| this.listComponent.getPageIndex(), | |||||
| this.listComponent.getPageSize(), | |||||
| getPartnerData: ListGetDataFunctionType = (index: number, pageSize: number, term?: string): Observable<any> => { | |||||
| return this.partnerService.partnersGetCollection( | |||||
| index, | |||||
| pageSize, | |||||
| this.partnerType, | this.partnerType, | ||||
| undefined, | undefined, | ||||
| searchValue, | |||||
| term, | |||||
| this.nameOrderAsc, | this.nameOrderAsc, | ||||
| this.cityOrderAsc, | this.cityOrderAsc, | ||||
| this.websiteOrderAsc | this.websiteOrderAsc | ||||
| ).subscribe( | |||||
| data => { | |||||
| this.partners = data["hydra:member"]; | |||||
| console.log(this.partners); | |||||
| this.dataSourcePartners = new MatTableDataSource<PartnerJsonld>(this.partners); | |||||
| this.listComponent.setData(this.dataSourcePartners, Number(data["hydra:totalItems"])); | |||||
| } | |||||
| ); | ); | ||||
| } | } | ||||
| getUserPartnerData = (searchValue = undefined) => { | |||||
| this.partnersSub = this.partnerFollowService.partnerFollowsGetCollection( | |||||
| this.listComponent.getPageIndex(), | |||||
| this.listComponent.getPageSize(), | |||||
| getUserPartnerData: ListGetDataFunctionType = (index: number, pageSize: number, term?: string): Observable<any> => { | |||||
| return this.partnerFollowService.partnerFollowsGetCollection( | |||||
| index, | |||||
| pageSize, | |||||
| undefined, | undefined, | ||||
| undefined, | undefined, | ||||
| searchValue, | |||||
| term, | |||||
| this.user.id, | this.user.id, | ||||
| undefined, | undefined, | ||||
| this.partnerType | this.partnerType | ||||
| ).subscribe( | |||||
| data => { | |||||
| this.userPartners = data["hydra:member"]; | |||||
| this.dataSourceUserPartners = new MatTableDataSource<PartnerFollowJsonld>(this.userPartners); | |||||
| this.listComponent.setData(this.dataSourcePartners, Number(data["hydra:totalItems"])); | |||||
| } | |||||
| ); | ); | ||||
| } | } | ||||
| getPartnerProducts = (searchValue = undefined) => { | |||||
| this.partnersSub = this.partnerProductService.partnerProductsGetCollection( | |||||
| this.listComponent.getPageIndex(), | |||||
| this.listComponent.getPageSize(), | |||||
| getPartnerProducts: ListGetDataFunctionType = (index: number, pageSize: number, term?: string): Observable<any> => { | |||||
| return this.partnerProductService.partnerProductsGetCollection( | |||||
| index, | |||||
| pageSize, | |||||
| undefined, | undefined, | ||||
| undefined, | undefined, | ||||
| searchValue, | |||||
| term, | |||||
| this.product.id, | this.product.id, | ||||
| undefined, | undefined, | ||||
| undefined, | undefined, | ||||
| this.partnerType, | this.partnerType, | ||||
| ).subscribe( | |||||
| data => { | |||||
| this.partnerProducts = data["hydra:member"]; | |||||
| this.dataSourcePartnerProducts = new MatTableDataSource<PartnerProductJsonld>(this.partnerProducts); | |||||
| this.listComponent.setData(this.dataSourcePartnerProducts, Number(data["hydra:totalItems"])); | |||||
| } | |||||
| ); | ); | ||||
| } | } | ||||
| onSortChange = (sortState: Sort) => { | onSortChange = (sortState: Sort) => { | ||||
| this.pagingComponent.resetPageIndex() | |||||
| let order: OrderFilter; | let order: OrderFilter; | ||||
| if (sortState.direction === "") { | if (sortState.direction === "") { | ||||
| order = OrderFilter.Undefined; | order = OrderFilter.Undefined; | ||||
| @@ -231,7 +191,7 @@ export class PartnerListComponent implements OnInit, AfterViewInit { | |||||
| this.websiteOrderAsc = order; | this.websiteOrderAsc = order; | ||||
| break; | break; | ||||
| } | } | ||||
| this.pagingComponent.getData(); | |||||
| this.listComponent.getData(); | |||||
| } | } | ||||
| navigateToPartnerDetails = (element: any) => { | navigateToPartnerDetails = (element: any) => { | ||||
| @@ -260,13 +220,13 @@ export class PartnerListComponent implements OnInit, AfterViewInit { | |||||
| if (this.user) { | if (this.user) { | ||||
| this.partnerFollowService.partnerFollowsIdDelete(this.appHelperService.extractId(element.id)).subscribe( | this.partnerFollowService.partnerFollowsIdDelete(this.appHelperService.extractId(element.id)).subscribe( | ||||
| data => { | data => { | ||||
| this.getData(this.listComponent.getSearchValue()); | |||||
| this.listComponent.getData(); | |||||
| } | } | ||||
| ); | ); | ||||
| } else if (this.product) { | } else if (this.product) { | ||||
| this.partnerProductService.partnerProductsIdDelete(this.appHelperService.extractId(element.id)).subscribe( | this.partnerProductService.partnerProductsIdDelete(this.appHelperService.extractId(element.id)).subscribe( | ||||
| data => { | data => { | ||||
| this.getData(this.listComponent.getSearchValue()); | |||||
| this.listComponent.getData(); | |||||
| } | } | ||||
| ); | ); | ||||
| } | } | ||||
| @@ -20,8 +20,8 @@ | |||||
| [documentForm]="postForm" | [documentForm]="postForm" | ||||
| [getDataFunction]="getProducts" | [getDataFunction]="getProducts" | ||||
| [dataSource]="dataSourceProducts" | [dataSource]="dataSourceProducts" | ||||
| [searchSelectColDefs]="colDefProducts" | |||||
| [displayedDataField]="'name'" | [displayedDataField]="'name'" | ||||
| [listColDefinitions]="SearchSelectComponent.getDefaultColDefPartners()" | |||||
| > | > | ||||
| </app-search-select> | </app-search-select> | ||||
| <input id="product" type="hidden" *ngIf="this.posting.id === null || this.posting.id === undefined" | <input id="product" type="hidden" *ngIf="this.posting.id === null || this.posting.id === undefined" | ||||
| @@ -14,6 +14,7 @@ import {Subscription} from "rxjs"; | |||||
| import {SearchSelectComponent} from "@app/_components/search-select/search-select.component"; | import {SearchSelectComponent} from "@app/_components/search-select/search-select.component"; | ||||
| import {MatTableDataSource} from "@angular/material/table"; | import {MatTableDataSource} from "@angular/material/table"; | ||||
| import {SearchInputColDef} from "@app/_components/search-input/search-input-col-def"; | import {SearchInputColDef} from "@app/_components/search-input/search-input-col-def"; | ||||
| import {ListGetDataFunctionType} from "@app/_components/list/list-get-data-function-type"; | |||||
| @Component({ | @Component({ | ||||
| selector: 'app-new-post', | selector: 'app-new-post', | ||||
| @@ -25,12 +26,12 @@ export class NewPostComponent implements OnInit { | |||||
| @Input() public product!: ProductJsonld; | @Input() public product!: ProductJsonld; | ||||
| @Output() public submit: EventEmitter<ModalStatus> = new EventEmitter<ModalStatus>(); | @Output() public submit: EventEmitter<ModalStatus> = new EventEmitter<ModalStatus>(); | ||||
| @ViewChild('productSearchSelect', { static: false }) productSearchSelect!: SearchSelectComponent; | @ViewChild('productSearchSelect', { static: false }) productSearchSelect!: SearchSelectComponent; | ||||
| protected readonly SearchSelectComponent = SearchSelectComponent; | |||||
| protected postForm: FormGroup; | protected postForm: FormGroup; | ||||
| protected postSub: Subscription; | protected postSub: Subscription; | ||||
| protected products: Array<ProductJsonld>; | protected products: Array<ProductJsonld>; | ||||
| protected dataSourceProducts; | protected dataSourceProducts; | ||||
| protected colDefProducts: SearchInputColDef[]; | |||||
| constructor( | constructor( | ||||
| private postService: PostService, | private postService: PostService, | ||||
| @@ -41,29 +42,17 @@ export class NewPostComponent implements OnInit { | |||||
| this.postSub = new Subscription(); | this.postSub = new Subscription(); | ||||
| this.products = []; | this.products = []; | ||||
| this.dataSourceProducts = new MatTableDataSource<ProductJsonld>(this.products); | this.dataSourceProducts = new MatTableDataSource<ProductJsonld>(this.products); | ||||
| this.colDefProducts = [ | |||||
| SearchSelectComponent.createColDef('pos', 'overview.number', SearchSelectComponent.COLUMN_TYPE_POSITION), | |||||
| SearchSelectComponent.createColDef('img', 'overview.image', SearchSelectComponent.COLUMN_TYPE_IMAGE, 'imageUrl'), | |||||
| SearchSelectComponent.createColDef('name', 'form.product', SearchSelectComponent.COLUMN_TYPE_TEXT, 'name'), | |||||
| ]; | |||||
| } | } | ||||
| ngOnInit(): void { | ngOnInit(): void { | ||||
| this.postForm = FormGroupInitializer.initFormGroup(this.postForm, this.posting); | this.postForm = FormGroupInitializer.initFormGroup(this.postForm, this.posting); | ||||
| } | } | ||||
| getProducts = (term?: string): void => { | |||||
| // NOTE: all products that are not assigned to partner yet | |||||
| this.productService.productsGetCollection( | |||||
| this.productSearchSelect.pagingComponent.getPageIndex(), | |||||
| this.productSearchSelect.pagingComponent.getPageSize(), | |||||
| getProducts: ListGetDataFunctionType = (index: number, pageSize: number, term?: string) => { | |||||
| return this.productService.productsGetCollection( | |||||
| index, | |||||
| pageSize, | |||||
| term | term | ||||
| ).subscribe( | |||||
| data => { | |||||
| this.products = data['hydra:member']; | |||||
| this.dataSourceProducts = new MatTableDataSource<ProductJsonld>(this.products); | |||||
| this.productSearchSelect.setData(this.dataSourceProducts, this.products, Number(data["hydra:totalItems"])); | |||||
| } | |||||
| ); | ); | ||||
| } | } | ||||
| @@ -10,8 +10,8 @@ | |||||
| [documentForm]="form" | [documentForm]="form" | ||||
| [getDataFunction]="getUnassignedProducts" | [getDataFunction]="getUnassignedProducts" | ||||
| [dataSource]="dataSourceProducts" | [dataSource]="dataSourceProducts" | ||||
| [searchSelectColDefs]="colDefProducts" | |||||
| [displayedDataField]="'name'" | [displayedDataField]="'name'" | ||||
| [listColDefinitions]="SearchSelectComponent.getDefaultColDefPartners()" | |||||
| > | > | ||||
| <input type="hidden" id="product" formControlName="productIri" value="{{partnerProduct.productIri}}"/> | <input type="hidden" id="product" formControlName="productIri" value="{{partnerProduct.productIri}}"/> | ||||
| </app-search-select> | </app-search-select> | ||||
| @@ -24,9 +24,9 @@ | |||||
| [documentForm]="form" | [documentForm]="form" | ||||
| [getDataFunction]="getUnassignedPartnerProducts" | [getDataFunction]="getUnassignedPartnerProducts" | ||||
| [dataSource]="dataSourcePartnerProducts" | [dataSource]="dataSourcePartnerProducts" | ||||
| [searchSelectColDefs]="colDefPartnerProducts" | |||||
| [displayedDataField]="'name'" | [displayedDataField]="'name'" | ||||
| [displayedDataSubResource]="'product'" | [displayedDataSubResource]="'product'" | ||||
| [listColDefinitions]="SearchSelectComponent.getDefaultColDefPartners()" | |||||
| > | > | ||||
| <input type="hidden" id="partnerProduct" formControlName="partnerProductIri" value="{{contactPartnerProduct.partnerProductIri}}"/> | <input type="hidden" id="partnerProduct" formControlName="partnerProductIri" value="{{contactPartnerProduct.partnerProductIri}}"/> | ||||
| </app-search-select> | </app-search-select> | ||||
| @@ -12,6 +12,7 @@ import {SearchSelectComponent} from "@app/_components/search-select/search-selec | |||||
| import {MatTableDataSource} from "@angular/material/table"; | import {MatTableDataSource} from "@angular/material/table"; | ||||
| import {SearchInputColDef} from "@app/_components/search-input/search-input-col-def"; | import {SearchInputColDef} from "@app/_components/search-input/search-input-col-def"; | ||||
| import {AppHelperService} from "@app/_helpers/app-helper.service"; | import {AppHelperService} from "@app/_helpers/app-helper.service"; | ||||
| import {ListGetDataFunctionType} from "@app/_components/list/list-get-data-function-type"; | |||||
| @Component({ | @Component({ | ||||
| selector: 'app-assign-product', | selector: 'app-assign-product', | ||||
| @@ -23,7 +24,8 @@ export class AssignProductComponent implements OnInit, AfterViewInit { | |||||
| @Input() public partnerProduct!: PartnerProductJsonld; | @Input() public partnerProduct!: PartnerProductJsonld; | ||||
| @Input() public contactPartnerProduct!: ContactPartnerProductJsonld; | @Input() public contactPartnerProduct!: ContactPartnerProductJsonld; | ||||
| @Output() public submit: EventEmitter<ModalStatus> = new EventEmitter<ModalStatus>(); | @Output() public submit: EventEmitter<ModalStatus> = new EventEmitter<ModalStatus>(); | ||||
| @ViewChild('productSearchSelect', { static: false }) productSearchSelect!: SearchSelectComponent; | |||||
| @ViewChild('productSearchSelect', { static: false }) productSearchSelect!: SearchSelectComponent | |||||
| protected readonly SearchSelectComponent = SearchSelectComponent; | |||||
| protected products: Array<ProductJsonld>; | protected products: Array<ProductJsonld>; | ||||
| protected dataSourceProducts; | protected dataSourceProducts; | ||||
| @@ -31,9 +33,6 @@ export class AssignProductComponent implements OnInit, AfterViewInit { | |||||
| protected dataSourcePartnerProducts; | protected dataSourcePartnerProducts; | ||||
| protected form!: FormGroup; | protected form!: FormGroup; | ||||
| protected colDefProducts: SearchInputColDef[]; | |||||
| protected colDefPartnerProducts: SearchInputColDef[]; | |||||
| constructor( | constructor( | ||||
| protected productService: ProductService, | protected productService: ProductService, | ||||
| protected partnerProductService: PartnerProductService, | protected partnerProductService: PartnerProductService, | ||||
| @@ -45,18 +44,6 @@ export class AssignProductComponent implements OnInit, AfterViewInit { | |||||
| this.partnerProducts = []; | this.partnerProducts = []; | ||||
| this.dataSourcePartnerProducts = new MatTableDataSource<PartnerProductJsonld>(this.partnerProducts); | this.dataSourcePartnerProducts = new MatTableDataSource<PartnerProductJsonld>(this.partnerProducts); | ||||
| this.colDefProducts = [ | |||||
| SearchSelectComponent.createColDef('pos', 'overview.number', SearchSelectComponent.COLUMN_TYPE_POSITION), | |||||
| SearchSelectComponent.createColDef('img', 'overview.image', SearchSelectComponent.COLUMN_TYPE_IMAGE, 'imageUrl'), | |||||
| SearchSelectComponent.createColDef('name', 'overview.productname', SearchSelectComponent.COLUMN_TYPE_TEXT, 'name') | |||||
| ]; | |||||
| this.colDefPartnerProducts = [ | |||||
| SearchSelectComponent.createColDef('pos', 'overview.number', SearchSelectComponent.COLUMN_TYPE_POSITION), | |||||
| SearchSelectComponent.createColDef('img', 'overview.image', SearchSelectComponent.COLUMN_TYPE_IMAGE, 'imageUrl', 'product'), | |||||
| SearchSelectComponent.createColDef('name', 'overview.productname', SearchSelectComponent.COLUMN_TYPE_TEXT, 'name', 'product') | |||||
| ]; | |||||
| } | } | ||||
| ngOnInit(): void { | ngOnInit(): void { | ||||
| @@ -69,30 +56,21 @@ export class AssignProductComponent implements OnInit, AfterViewInit { | |||||
| } | } | ||||
| ngAfterViewInit(): void { | ngAfterViewInit(): void { | ||||
| this.productSearchSelect.getData(); | |||||
| } | } | ||||
| getUnassignedProducts = (term?: string): void => { | |||||
| // NOTE: all products that are not assigned to partner yet | |||||
| this.productService.productsGetCollection( | |||||
| this.productSearchSelect.pagingComponent.getPageIndex(), | |||||
| this.productSearchSelect.pagingComponent.getPageSize(), | |||||
| getUnassignedProducts: ListGetDataFunctionType = (index: number, pageSize: number, term?: string) => { | |||||
| return this.productService.productsGetCollection( | |||||
| index, | |||||
| pageSize, | |||||
| term, | term, | ||||
| this.appHelperService.extractId(this.partnerProduct.partnerIri) | this.appHelperService.extractId(this.partnerProduct.partnerIri) | ||||
| ).subscribe( | |||||
| data => { | |||||
| this.products = data['hydra:member']; | |||||
| this.dataSourceProducts = new MatTableDataSource<ProductJsonld>(this.products); | |||||
| this.productSearchSelect.setData(this.dataSourceProducts, this.products, Number(data["hydra:totalItems"])); | |||||
| } | |||||
| ); | ); | ||||
| } | } | ||||
| getUnassignedPartnerProducts = (term: string) => { | |||||
| // NOTE: all partner products that are not assigned to contact yet | |||||
| this.partnerProductService.partnerProductsGetCollection( | |||||
| 1, | |||||
| 50, | |||||
| getUnassignedPartnerProducts: ListGetDataFunctionType = (index: number, pageSize: number, term?: string) => { | |||||
| return this.partnerProductService.partnerProductsGetCollection( | |||||
| index, | |||||
| pageSize, | |||||
| this.partnerIri, | this.partnerIri, | ||||
| undefined, | undefined, | ||||
| undefined, | undefined, | ||||
| @@ -103,12 +81,6 @@ export class AssignProductComponent implements OnInit, AfterViewInit { | |||||
| undefined, | undefined, | ||||
| undefined, | undefined, | ||||
| this.appHelperService.extractId(this.contactPartnerProduct.contactIri) | this.appHelperService.extractId(this.contactPartnerProduct.contactIri) | ||||
| ).subscribe( | |||||
| data => { | |||||
| this.partnerProducts = data['hydra:member']; | |||||
| this.dataSourcePartnerProducts = new MatTableDataSource<PartnerProductJsonld>(this.partnerProducts); | |||||
| this.productSearchSelect.setData(this.dataSourceProducts, this.partnerProducts, Number(data["hydra:totalItems"])); | |||||
| } | |||||
| ); | ); | ||||
| } | } | ||||
| @@ -4,8 +4,7 @@ | |||||
| <button *ngIf="!bShowNewProductButton" class="btn btn-primary" (click)="openModalAssignProduct()">+ {{ 'basic.assign-product' | translate }}</button> | <button *ngIf="!bShowNewProductButton" class="btn btn-primary" (click)="openModalAssignProduct()">+ {{ 'basic.assign-product' | translate }}</button> | ||||
| </div> | </div> | ||||
| <app-list #listComponent | <app-list #listComponent | ||||
| [dataSource]="getDataSource()" | |||||
| [getDataFunction]="getData" | |||||
| [getDataFunction]="getDataFunction" | |||||
| [onNavigateToDetailsFunction]="navigateToProductDetails" | [onNavigateToDetailsFunction]="navigateToProductDetails" | ||||
| [onRemoveItemFunction]="unassignProduct" | [onRemoveItemFunction]="unassignProduct" | ||||
| [onSortFunction]="onSortChange" | [onSortFunction]="onSortChange" | ||||
| @@ -1,25 +1,24 @@ | |||||
| import {AfterViewInit, Component, Input, OnInit, ViewChild} from '@angular/core'; | import {AfterViewInit, Component, Input, OnInit, ViewChild} from '@angular/core'; | ||||
| import {MatSort, Sort} from "@angular/material/sort"; | |||||
| import {Subscription} from "rxjs"; | |||||
| import {Sort} from "@angular/material/sort"; | |||||
| import {Observable} from "rxjs"; | |||||
| import { | import { | ||||
| ContactJsonld, ContactPartnerProductJsonld, ContactPartnerProductService, | ContactJsonld, ContactPartnerProductJsonld, ContactPartnerProductService, | ||||
| PartnerJsonld, PartnerProductJsonld, | PartnerJsonld, PartnerProductJsonld, | ||||
| PartnerProductService, | PartnerProductService, | ||||
| ProductJsonld, | ProductJsonld, | ||||
| ProductService, | ProductService, | ||||
| UserJsonld, UserProductJsonld, | |||||
| UserJsonld, | |||||
| UserProductService | UserProductService | ||||
| } from "@app/core/api/v1"; | } from "@app/core/api/v1"; | ||||
| import {Router} from "@angular/router"; | import {Router} from "@angular/router"; | ||||
| import {AppHelperService} from "@app/_helpers/app-helper.service"; | import {AppHelperService} from "@app/_helpers/app-helper.service"; | ||||
| import {MatTableDataSource} from "@angular/material/table"; | |||||
| import {OrderFilter} from "@app/_models/orderFilter"; | import {OrderFilter} from "@app/_models/orderFilter"; | ||||
| import {NewProductComponent} from "@app/_views/products/new-product/new-product.component"; | import {NewProductComponent} from "@app/_views/products/new-product/new-product.component"; | ||||
| import {AssignProductComponent} from "@app/_views/products/assign-product/assign-product.component"; | import {AssignProductComponent} from "@app/_views/products/assign-product/assign-product.component"; | ||||
| import {TranslateService} from "@ngx-translate/core"; | import {TranslateService} from "@ngx-translate/core"; | ||||
| import {ListColDefinition} from "@app/_components/list/list-col-definition"; | import {ListColDefinition} from "@app/_components/list/list-col-definition"; | ||||
| import {ListComponent} from "@app/_components/list/list.component"; | import {ListComponent} from "@app/_components/list/list.component"; | ||||
| type GeneralDataSource = MatTableDataSource<any>; | |||||
| import {ListGetDataFunctionType} from "@app/_components/list/list-get-data-function-type"; | |||||
| @Component({ | @Component({ | ||||
| selector: 'app-product-list', | selector: 'app-product-list', | ||||
| @@ -33,18 +32,10 @@ export class ProductListComponent implements OnInit, AfterViewInit { | |||||
| @Input() public contact!: ContactJsonld; | @Input() public contact!: ContactJsonld; | ||||
| @ViewChild("listComponent", { static: false }) listComponent!: ListComponent; | @ViewChild("listComponent", { static: false }) listComponent!: ListComponent; | ||||
| protected productsSub: Subscription; | |||||
| protected products: Array<ProductJsonld>; | |||||
| protected userProducts: Array<UserProductJsonld>; | |||||
| protected partnerProducts: Array<PartnerProductJsonld>; | |||||
| protected contactPartnerProducts: Array<ContactPartnerProductJsonld>; | |||||
| protected dataSourceProducts; | |||||
| protected dataSourceUserProducts; | |||||
| protected dataSourcePartnerProducts; | |||||
| protected dataSourceContactPartnerProducts; | |||||
| protected bShowNewProductButton: boolean; | protected bShowNewProductButton: boolean; | ||||
| protected nameOrderFilter: OrderFilter; | protected nameOrderFilter: OrderFilter; | ||||
| protected listColDefinitions!: ListColDefinition[]; | protected listColDefinitions!: ListColDefinition[]; | ||||
| protected getDataFunction!: ListGetDataFunctionType; | |||||
| constructor( | constructor( | ||||
| private router: Router, | private router: Router, | ||||
| @@ -55,15 +46,6 @@ export class ProductListComponent implements OnInit, AfterViewInit { | |||||
| private contactPartnerProductService: ContactPartnerProductService, | private contactPartnerProductService: ContactPartnerProductService, | ||||
| protected appHelperService: AppHelperService, | protected appHelperService: AppHelperService, | ||||
| ) { | ) { | ||||
| this.productsSub = new Subscription(); | |||||
| this.products = []; | |||||
| this.userProducts = []; | |||||
| this.partnerProducts = []; | |||||
| this.contactPartnerProducts = []; | |||||
| this.dataSourceProducts = new MatTableDataSource<ProductJsonld>(this.products); | |||||
| this.dataSourceUserProducts = new MatTableDataSource<UserProductJsonld>(this.userProducts); | |||||
| this.dataSourcePartnerProducts = new MatTableDataSource<PartnerProductJsonld>(this.partnerProducts); | |||||
| this.dataSourceContactPartnerProducts = new MatTableDataSource<ContactPartnerProductJsonld>(this.contactPartnerProducts); | |||||
| this.bShowNewProductButton = true; | this.bShowNewProductButton = true; | ||||
| this.nameOrderFilter = OrderFilter.Asc; | this.nameOrderFilter = OrderFilter.Asc; | ||||
| } | } | ||||
| @@ -101,106 +83,68 @@ export class ProductListComponent implements OnInit, AfterViewInit { | |||||
| this.bShowNewProductButton = | this.bShowNewProductButton = | ||||
| this.user === undefined && this.partner === undefined && this.contact === undefined; | this.user === undefined && this.partner === undefined && this.contact === undefined; | ||||
| } | |||||
| ngAfterViewInit() { | |||||
| this.listComponent.getData(); | |||||
| } | |||||
| getDataSource(): GeneralDataSource { | |||||
| if (this.user !== undefined) { | if (this.user !== undefined) { | ||||
| return this.dataSourceUserProducts; | |||||
| this.getDataFunction = this.getUserProducts; | |||||
| } else if (this.partner !== undefined) { | } else if (this.partner !== undefined) { | ||||
| return this.dataSourcePartnerProducts; | |||||
| this.getDataFunction = this.getPartnerProducts; | |||||
| } else if (this.contact !== undefined) { | } else if (this.contact !== undefined) { | ||||
| return this.dataSourceContactPartnerProducts; | |||||
| this.getDataFunction = this.getContactPartnerProduct; | |||||
| } else { | } else { | ||||
| return this.dataSourceProducts; | |||||
| this.getDataFunction = this.getProducts; | |||||
| } | } | ||||
| } | } | ||||
| getData = (searchValue = undefined) => { | |||||
| if (this.user !== undefined) { | |||||
| this.getUserProducts(searchValue); | |||||
| } else if (this.partner !== undefined) { | |||||
| this.getPartnerProducts(searchValue); | |||||
| } else if (this.contact !== undefined) { | |||||
| this.getContactPartnerProduct(searchValue); | |||||
| } else { | |||||
| this.getProducts(searchValue); | |||||
| } | |||||
| ngAfterViewInit() { | |||||
| this.listComponent.getData(); | |||||
| } | } | ||||
| getProducts = (searchValue = undefined) => { | |||||
| this.productsSub = this.productService.productsGetCollection( | |||||
| this.listComponent.getPageIndex(), | |||||
| this.listComponent.getPageSize(), | |||||
| searchValue, | |||||
| getProducts: ListGetDataFunctionType = (index: number, pageSize: number, term?: string): Observable<any> => { | |||||
| return this.productService.productsGetCollection( | |||||
| index, | |||||
| pageSize, | |||||
| term, | |||||
| undefined, | undefined, | ||||
| this.nameOrderFilter, | this.nameOrderFilter, | ||||
| ).subscribe( | |||||
| data => { | |||||
| this.products = data["hydra:member"]; | |||||
| this.dataSourceProducts = new MatTableDataSource<ProductJsonld>(this.products); | |||||
| this.listComponent.setData(this.dataSourceProducts, Number(data["hydra:totalItems"])); | |||||
| } | |||||
| ); | ); | ||||
| } | } | ||||
| getUserProducts = (searchValue = undefined) => { | |||||
| this.productsSub = this.userProductService.userProductsGetCollection( | |||||
| this.listComponent.getPageIndex(), | |||||
| this.listComponent.getPageSize(), | |||||
| getUserProducts: ListGetDataFunctionType = (index: number, pageSize: number, term?: string) => { | |||||
| return this.userProductService.userProductsGetCollection( | |||||
| index, | |||||
| pageSize, | |||||
| this.user.id, | this.user.id, | ||||
| undefined, | undefined, | ||||
| undefined, | undefined, | ||||
| undefined, | undefined, | ||||
| this.nameOrderFilter, | this.nameOrderFilter, | ||||
| ).subscribe( | |||||
| data => { | |||||
| this.userProducts = data["hydra:member"]; | |||||
| this.dataSourceUserProducts = new MatTableDataSource<UserProductJsonld>(this.userProducts); | |||||
| this.listComponent.setData(this.dataSourceUserProducts, Number(data["hydra:totalItems"])); | |||||
| } | |||||
| ); | ); | ||||
| } | } | ||||
| getPartnerProducts = (searchValue= undefined) => { | |||||
| this.productsSub = this.partnerProductService.partnerProductsGetCollection( | |||||
| this.listComponent.getPageIndex(), | |||||
| this.listComponent.getPageSize(), | |||||
| getPartnerProducts: ListGetDataFunctionType = (index: number, pageSize: number, term?: string) => { | |||||
| return this.partnerProductService.partnerProductsGetCollection( | |||||
| index, | |||||
| pageSize, | |||||
| this.partner.id, | this.partner.id, | ||||
| undefined, | undefined, | ||||
| undefined, | undefined, | ||||
| undefined, | undefined, | ||||
| undefined, | undefined, | ||||
| searchValue, | |||||
| term, | |||||
| undefined, | undefined, | ||||
| undefined, | undefined, | ||||
| this.nameOrderFilter, | this.nameOrderFilter, | ||||
| ).subscribe( | |||||
| data => { | |||||
| this.partnerProducts = data["hydra:member"]; | |||||
| this.dataSourcePartnerProducts = new MatTableDataSource<PartnerProductJsonld>(this.partnerProducts); | |||||
| this.listComponent.setData(this.dataSourcePartnerProducts, Number(data["hydra:totalItems"])); | |||||
| } | |||||
| ); | ); | ||||
| } | } | ||||
| getContactPartnerProduct = (searchValue = undefined) => { | |||||
| this.productsSub = this.contactPartnerProductService.contactPartnerProductsGetCollection( | |||||
| getContactPartnerProduct: ListGetDataFunctionType = (index: number, pageSize: number, term?: string) => { | |||||
| return this.contactPartnerProductService.contactPartnerProductsGetCollection( | |||||
| this.listComponent.getPageIndex(), | this.listComponent.getPageIndex(), | ||||
| this.listComponent.getPageSize(), | this.listComponent.getPageSize(), | ||||
| this.contact.id, | this.contact.id, | ||||
| undefined, | undefined, | ||||
| searchValue, | |||||
| term, | |||||
| this.nameOrderFilter, | this.nameOrderFilter, | ||||
| ).subscribe( | |||||
| data => { | |||||
| this.contactPartnerProducts = data["hydra:member"]; | |||||
| this.dataSourceContactPartnerProducts = new MatTableDataSource<ContactPartnerProductJsonld>(this.contactPartnerProducts); | |||||
| this.listComponent.setData(this.dataSourceContactPartnerProducts, Number(data["hydra:totalItems"])); | |||||
| } | |||||
| ); | ); | ||||
| } | } | ||||
| @@ -227,7 +171,7 @@ export class ProductListComponent implements OnInit, AfterViewInit { | |||||
| openModalNewProduct() { | openModalNewProduct() { | ||||
| let product: ProductJsonld = {} as ProductJsonld; | let product: ProductJsonld = {} as ProductJsonld; | ||||
| this.appHelperService.openModal(NewProductComponent, { 'product': product }, this.getData); | |||||
| this.appHelperService.openModal(NewProductComponent, { 'product': product }, this.listComponent.getData); | |||||
| } | } | ||||
| openModalAssignProduct() { | openModalAssignProduct() { | ||||
| @@ -235,7 +179,7 @@ export class ProductListComponent implements OnInit, AfterViewInit { | |||||
| this.appHelperService.openModal( | this.appHelperService.openModal( | ||||
| AssignProductComponent, | AssignProductComponent, | ||||
| { 'user' : this.user }, | { 'user' : this.user }, | ||||
| this.getUserProducts | |||||
| this.listComponent.getData | |||||
| ); | ); | ||||
| } else if (this.partner !== undefined) { | } else if (this.partner !== undefined) { | ||||
| let partnerProduct: PartnerProductJsonld = {} as PartnerProductJsonld; | let partnerProduct: PartnerProductJsonld = {} as PartnerProductJsonld; | ||||
| @@ -243,7 +187,7 @@ export class ProductListComponent implements OnInit, AfterViewInit { | |||||
| this.appHelperService.openModal( | this.appHelperService.openModal( | ||||
| AssignProductComponent, | AssignProductComponent, | ||||
| { 'partnerProduct' : partnerProduct }, | { 'partnerProduct' : partnerProduct }, | ||||
| this.getPartnerProducts | |||||
| this.listComponent.getData | |||||
| ); | ); | ||||
| } else if (this.contact !== undefined) { | } else if (this.contact !== undefined) { | ||||
| let contactPartnerProduct: ContactPartnerProductJsonld = {} as ContactPartnerProductJsonld; | let contactPartnerProduct: ContactPartnerProductJsonld = {} as ContactPartnerProductJsonld; | ||||
| @@ -251,7 +195,7 @@ export class ProductListComponent implements OnInit, AfterViewInit { | |||||
| this.appHelperService.openModal( | this.appHelperService.openModal( | ||||
| AssignProductComponent, | AssignProductComponent, | ||||
| { 'contactPartnerProduct' : contactPartnerProduct, 'partnerIri' : this.contact.partnerIri }, | { 'contactPartnerProduct' : contactPartnerProduct, 'partnerIri' : this.contact.partnerIri }, | ||||
| this.getContactPartnerProduct | |||||
| this.listComponent.getData | |||||
| ); | ); | ||||
| } else { | } else { | ||||
| throw new Error('data not found') | throw new Error('data not found') | ||||
| @@ -268,22 +212,19 @@ export class ProductListComponent implements OnInit, AfterViewInit { | |||||
| if (this.partner) { | if (this.partner) { | ||||
| this.partnerProductService.partnerProductsIdDelete(this.appHelperService.extractId(element.id)).subscribe( | this.partnerProductService.partnerProductsIdDelete(this.appHelperService.extractId(element.id)).subscribe( | ||||
| data => { | data => { | ||||
| //this.getData(this.pagingComponent.getSearchValue()); | |||||
| this.getData(this.listComponent.getSearchValue()); | |||||
| this.listComponent.getData(); | |||||
| } | } | ||||
| ); | ); | ||||
| } else if (this.contact) { | } else if (this.contact) { | ||||
| this.contactPartnerProductService.contactPartnerProductsIdDelete(this.appHelperService.extractId(element.id)).subscribe( | this.contactPartnerProductService.contactPartnerProductsIdDelete(this.appHelperService.extractId(element.id)).subscribe( | ||||
| data => { | data => { | ||||
| //this.getData(this.pagingComponent.getSearchValue()); | |||||
| this.getData(this.listComponent.getSearchValue()); | |||||
| this.listComponent.getData(); | |||||
| } | } | ||||
| ); | ); | ||||
| } else if (this.user) { | } else if (this.user) { | ||||
| this.userProductService.userProductsIdDelete(this.appHelperService.extractId(element.id)).subscribe( | this.userProductService.userProductsIdDelete(this.appHelperService.extractId(element.id)).subscribe( | ||||
| data => { | data => { | ||||
| //this.getData(this.pagingComponent.getSearchValue()); | |||||
| this.getData(this.listComponent.getSearchValue()); | |||||
| this.listComponent.getData(); | |||||
| } | } | ||||
| ) | ) | ||||
| } | } | ||||
| @@ -1,3 +1,3 @@ | |||||
| <app-user-detail | |||||
| <app-user-detail *ngIf="user" | |||||
| [user]="user" | [user]="user" | ||||
| ></app-user-detail> | ></app-user-detail> | ||||
| @@ -1,7 +1,8 @@ | |||||
| import {AfterViewInit, Component, OnInit, ViewChild} from '@angular/core'; | import {AfterViewInit, Component, OnInit, ViewChild} from '@angular/core'; | ||||
| import {AccountService} from "@app/_services"; | import {AccountService} from "@app/_services"; | ||||
| import {UserJsonld} from "@app/core/api/v1"; | |||||
| import {UserJsonld, UserService} from "@app/core/api/v1"; | |||||
| import {UserDetailComponent} from "@app/_views/user/user-detail/user-detail.component"; | import {UserDetailComponent} from "@app/_views/user/user-detail/user-detail.component"; | ||||
| import {AppHelperService} from "@app/_helpers/app-helper.service"; | |||||
| @Component({ | @Component({ | ||||
| selector: 'app-profile', | selector: 'app-profile', | ||||
| @@ -16,13 +17,23 @@ export class ProfileComponent implements OnInit, AfterViewInit { | |||||
| constructor( | constructor( | ||||
| private accountService: AccountService, | private accountService: AccountService, | ||||
| private userService: UserService, | |||||
| private appHelperService: AppHelperService | |||||
| ) { | ) { | ||||
| if (this.accountService.userValue?.userResource) { | |||||
| this.user = this.accountService.userValue?.userResource; | |||||
| const user = this.accountService.userValue; | |||||
| if (user?.id !== null && user?.id !== undefined) { | |||||
| this.userService.usersIdGet( | |||||
| this.appHelperService.extractId(user.id) | |||||
| ).subscribe( | |||||
| data => { | |||||
| this.user = data; | |||||
| } | |||||
| ); | |||||
| } | } | ||||
| } | } | ||||
| ngOnInit() { | ngOnInit() { | ||||
| } | } | ||||
| ngAfterViewInit(): void { | ngAfterViewInit(): void { | ||||
| @@ -10,8 +10,8 @@ | |||||
| [documentForm]="saleForm" | [documentForm]="saleForm" | ||||
| [getDataFunction]="getPartners" | [getDataFunction]="getPartners" | ||||
| [dataSource]="dataSourcePartners" | [dataSource]="dataSourcePartners" | ||||
| [searchSelectColDefs]="colDefPartners" | |||||
| [displayedDataField]="'name'" | [displayedDataField]="'name'" | ||||
| [listColDefinitions]="SearchSelectComponent.getDefaultColDefPartners()" | |||||
| > | > | ||||
| </app-search-select> | </app-search-select> | ||||
| <input type="hidden" formControlName="partnerIri"/> | <input type="hidden" formControlName="partnerIri"/> | ||||
| @@ -24,8 +24,8 @@ | |||||
| [documentForm]="saleForm" | [documentForm]="saleForm" | ||||
| [getDataFunction]="getProducts" | [getDataFunction]="getProducts" | ||||
| [dataSource]="dataSourceProducts" | [dataSource]="dataSourceProducts" | ||||
| [searchSelectColDefs]="colDefProducts" | |||||
| [displayedDataField]="'name'" | [displayedDataField]="'name'" | ||||
| [listColDefinitions]="SearchSelectComponent.getDefaultColDefProducts()" | |||||
| > | > | ||||
| </app-search-select> | </app-search-select> | ||||
| <input type="hidden" formControlName="productIri"/> | <input type="hidden" formControlName="productIri"/> | ||||
| @@ -8,7 +8,7 @@ import { | |||||
| } from "@app/core/api/v1"; | } from "@app/core/api/v1"; | ||||
| import {ModalStatus} from "@app/_helpers/modal.states"; | import {ModalStatus} from "@app/_helpers/modal.states"; | ||||
| import {FormGroup} from "@angular/forms"; | import {FormGroup} from "@angular/forms"; | ||||
| import {Subscription} from "rxjs"; | |||||
| import {Observable, Subscription} from "rxjs"; | |||||
| import {TranslateService} from "@ngx-translate/core"; | import {TranslateService} from "@ngx-translate/core"; | ||||
| import {FormGroupInitializer} from "@app/_helpers/formgroup.initializer"; | import {FormGroupInitializer} from "@app/_helpers/formgroup.initializer"; | ||||
| import {saleForm} from "@app/_forms/apiForms"; | import {saleForm} from "@app/_forms/apiForms"; | ||||
| @@ -16,6 +16,8 @@ import {AppHelperService} from "@app/_helpers/app-helper.service"; | |||||
| import {SearchSelectComponent} from "@app/_components/search-select/search-select.component"; | import {SearchSelectComponent} from "@app/_components/search-select/search-select.component"; | ||||
| import {MatTableDataSource} from "@angular/material/table"; | import {MatTableDataSource} from "@angular/material/table"; | ||||
| import {SearchInputColDef} from "@app/_components/search-input/search-input-col-def"; | import {SearchInputColDef} from "@app/_components/search-input/search-input-col-def"; | ||||
| import {ListComponent} from "@app/_components/list/list.component"; | |||||
| import {ListColDefinition} from "@app/_components/list/list-col-definition"; | |||||
| @Component({ | @Component({ | ||||
| selector: 'app-new-sale', | selector: 'app-new-sale', | ||||
| @@ -25,9 +27,9 @@ import {SearchInputColDef} from "@app/_components/search-input/search-input-col- | |||||
| export class NewSaleComponent implements OnInit, AfterViewInit { | export class NewSaleComponent implements OnInit, AfterViewInit { | ||||
| @Input() public sale!: SaleJsonld; | @Input() public sale!: SaleJsonld; | ||||
| @Output() public submit: EventEmitter<ModalStatus> = new EventEmitter<ModalStatus>(); | @Output() public submit: EventEmitter<ModalStatus> = new EventEmitter<ModalStatus>(); | ||||
| @ViewChild('partnerSearchSelect', { static: false }) partnerSearchSelect!: SearchSelectComponent; | @ViewChild('partnerSearchSelect', { static: false }) partnerSearchSelect!: SearchSelectComponent; | ||||
| @ViewChild('productSearchSelect', { static: false }) productSearchSelect!: SearchSelectComponent; | @ViewChild('productSearchSelect', { static: false }) productSearchSelect!: SearchSelectComponent; | ||||
| protected readonly SearchSelectComponent = SearchSelectComponent; | |||||
| protected saleForm: FormGroup; | protected saleForm: FormGroup; | ||||
| protected saleSub: Subscription; | protected saleSub: Subscription; | ||||
| @@ -35,10 +37,6 @@ export class NewSaleComponent implements OnInit, AfterViewInit { | |||||
| protected dataSourcePartners; | protected dataSourcePartners; | ||||
| protected products: Array<ProductJsonld>; | protected products: Array<ProductJsonld>; | ||||
| protected dataSourceProducts; | protected dataSourceProducts; | ||||
| protected colDefPartners: SearchInputColDef[]; | |||||
| protected colDefProducts: SearchInputColDef[]; | |||||
| protected formatter = (apiData: any) => apiData.name; | |||||
| constructor( | constructor( | ||||
| private saleService: SaleService, | private saleService: SaleService, | ||||
| @@ -53,16 +51,6 @@ export class NewSaleComponent implements OnInit, AfterViewInit { | |||||
| this.dataSourcePartners = new MatTableDataSource<PartnerJsonld>(this.partners); | this.dataSourcePartners = new MatTableDataSource<PartnerJsonld>(this.partners); | ||||
| this.products = []; | this.products = []; | ||||
| this.dataSourceProducts = new MatTableDataSource<ProductJsonld>(this.products); | this.dataSourceProducts = new MatTableDataSource<ProductJsonld>(this.products); | ||||
| this.colDefPartners = [ | |||||
| SearchSelectComponent.createColDef('pos', 'overview.number', SearchSelectComponent.COLUMN_TYPE_POSITION), | |||||
| SearchSelectComponent.createColDef('img', 'overview.image', SearchSelectComponent.COLUMN_TYPE_IMAGE, 'logoUrl'), | |||||
| SearchSelectComponent.createColDef('name', 'form.name', SearchSelectComponent.COLUMN_TYPE_TEXT, 'name'), | |||||
| ]; | |||||
| this.colDefProducts = [ | |||||
| SearchSelectComponent.createColDef('pos', 'overview.number', SearchSelectComponent.COLUMN_TYPE_POSITION), | |||||
| SearchSelectComponent.createColDef('img', 'overview.image', SearchSelectComponent.COLUMN_TYPE_IMAGE, 'imageUrl'), | |||||
| SearchSelectComponent.createColDef('name', 'form.product', SearchSelectComponent.COLUMN_TYPE_TEXT, 'name'), | |||||
| ]; | |||||
| } | } | ||||
| ngOnInit(): void { | ngOnInit(): void { | ||||
| @@ -70,38 +58,23 @@ export class NewSaleComponent implements OnInit, AfterViewInit { | |||||
| } | } | ||||
| ngAfterViewInit(): void { | ngAfterViewInit(): void { | ||||
| this.partnerSearchSelect.getData(); | |||||
| this.productSearchSelect.getData(); | |||||
| } | } | ||||
| getPartners = (term: string): void => { | |||||
| this.partnerService.partnersGetCollection( | |||||
| this.partnerSearchSelect.pagingComponent.getPageIndex(), | |||||
| this.partnerSearchSelect.pagingComponent.getPageSize(), | |||||
| getPartners = (index: number, pageSize: number, term?: string): Observable<any> => { | |||||
| return this.partnerService.partnersGetCollection( | |||||
| index, | |||||
| pageSize, | |||||
| undefined, | undefined, | ||||
| undefined, | undefined, | ||||
| term | term | ||||
| ).subscribe( | |||||
| data => { | |||||
| this.partners = data['hydra:member']; | |||||
| this.dataSourcePartners = new MatTableDataSource<PartnerJsonld>(this.partners); | |||||
| this.partnerSearchSelect.setData(this.dataSourcePartners, this.partners, Number(data["hydra:totalItems"])); | |||||
| } | |||||
| ) | |||||
| ); | |||||
| } | } | ||||
| getProducts = (term?: string): void => { | |||||
| // NOTE: all products that are not assigned to partner yet | |||||
| this.productService.productsGetCollection( | |||||
| this.productSearchSelect.pagingComponent.getPageIndex(), | |||||
| this.productSearchSelect.pagingComponent.getPageSize(), | |||||
| getProducts = (index: number, pageSize: number, term?: string): Observable<any> => { | |||||
| return this.productService.productsGetCollection( | |||||
| index, | |||||
| pageSize, | |||||
| term | term | ||||
| ).subscribe( | |||||
| data => { | |||||
| this.products = data['hydra:member']; | |||||
| this.dataSourceProducts = new MatTableDataSource<ProductJsonld>(this.products); | |||||
| this.productSearchSelect.setData(this.dataSourceProducts, this.products, Number(data["hydra:totalItems"])); | |||||
| } | |||||
| ); | ); | ||||
| } | } | ||||
| @@ -3,7 +3,6 @@ | |||||
| <button *ngIf="!this.user" class="btn btn-primary" (click)="openModalNewSale()">+ {{ 'basic.new-sale' | translate }}</button> | <button *ngIf="!this.user" class="btn btn-primary" (click)="openModalNewSale()">+ {{ 'basic.new-sale' | translate }}</button> | ||||
| </div> | </div> | ||||
| <app-list #listComponent | <app-list #listComponent | ||||
| [dataSource]="dataSource" | |||||
| [getDataFunction]="getData" | [getDataFunction]="getData" | ||||
| [onNavigateToDetailsFunction]="navigateToSaleDetails" | [onNavigateToDetailsFunction]="navigateToSaleDetails" | ||||
| [onSortFunction]="onSortChange" | [onSortFunction]="onSortChange" | ||||
| @@ -25,11 +25,6 @@ export class SaleListComponent implements OnInit, AfterViewInit { | |||||
| @Input() public partner!: PartnerJsonld; | @Input() public partner!: PartnerJsonld; | ||||
| @ViewChild("listComponent", { static: false }) listComponent!: ListComponent; | @ViewChild("listComponent", { static: false }) listComponent!: ListComponent; | ||||
| protected salesSub: Subscription; | |||||
| protected sales: Array<SaleJsonld>; | |||||
| protected salesSummarySub: Subscription; | |||||
| protected saleSummaries: Array<SaleSummaryJsonld>; | |||||
| protected dataSource; | |||||
| protected listColDefinitions!: ListColDefinition[]; | protected listColDefinitions!: ListColDefinition[]; | ||||
| constructor( | constructor( | ||||
| @@ -38,11 +33,6 @@ export class SaleListComponent implements OnInit, AfterViewInit { | |||||
| protected appHelperService: AppHelperService, | protected appHelperService: AppHelperService, | ||||
| protected accountService: AccountService, | protected accountService: AccountService, | ||||
| ) { | ) { | ||||
| this.salesSub = new Subscription(); | |||||
| this.sales = []; | |||||
| this.salesSummarySub = new Subscription(); | |||||
| this.saleSummaries = []; | |||||
| this.dataSource = new MatTableDataSource<SaleJsonld>(this.sales); | |||||
| this.listColDefinitions = [ | this.listColDefinitions = [ | ||||
| { | { | ||||
| name: 'user', | name: 'user', | ||||
| @@ -99,22 +89,16 @@ export class SaleListComponent implements OnInit, AfterViewInit { | |||||
| this.listComponent.getData(); | this.listComponent.getData(); | ||||
| } | } | ||||
| getData = () => { | |||||
| this.salesSub = this.saleService.salesGetCollection( | |||||
| this.listComponent.getPageIndex(), | |||||
| this.listComponent.getPageSize(), | |||||
| getData = (index: number, pageSize: number, term?: string) => { | |||||
| return this.saleService.salesGetCollection( | |||||
| index, | |||||
| pageSize, | |||||
| this.user !== undefined ? this.user.id : undefined, | this.user !== undefined ? this.user.id : undefined, | ||||
| undefined, | undefined, | ||||
| this.partner !== undefined ? this.partner.id : undefined, | this.partner !== undefined ? this.partner.id : undefined, | ||||
| undefined, | undefined, | ||||
| this.product !== undefined ? this.product.id : undefined, | this.product !== undefined ? this.product.id : undefined, | ||||
| ).subscribe( | |||||
| data => { | |||||
| this.sales = data["hydra:member"]; | |||||
| this.dataSource = new MatTableDataSource<SaleJsonld>(this.sales); | |||||
| this.listComponent.setData(this.dataSource, Number(data["hydra:totalItems"])); | |||||
| } | |||||
| ) | |||||
| ); | |||||
| } | } | ||||
| onSortChange = (sortState: Sort)=> { | onSortChange = (sortState: Sort)=> { | ||||
| @@ -130,14 +114,13 @@ export class SaleListComponent implements OnInit, AfterViewInit { | |||||
| } | } | ||||
| navigateToSaleDetails = (element: any) => { | navigateToSaleDetails = (element: any) => { | ||||
| console.log(element); | |||||
| const sale: SaleJsonld = element as SaleJsonld; | const sale: SaleJsonld = element as SaleJsonld; | ||||
| this.router.navigate(['/sale', this.appHelperService.extractId(sale.id)]); | this.router.navigate(['/sale', this.appHelperService.extractId(sale.id)]); | ||||
| } | } | ||||
| openModalNewSale() { | openModalNewSale() { | ||||
| let sale: SaleJsonld = {} as SaleJsonld; | let sale: SaleJsonld = {} as SaleJsonld; | ||||
| this.appHelperService.openModal(NewSaleComponent, { 'sale': sale }, this.getData); | |||||
| this.appHelperService.openModal(NewSaleComponent, { 'sale': sale }, this.listComponent.getData); | |||||
| } | } | ||||
| } | } | ||||
| @@ -21,7 +21,6 @@ export class SaleSummaryComponent implements OnInit, AfterViewInit { | |||||
| constructor( | constructor( | ||||
| private saleSummaryService: SaleSummaryService, | private saleSummaryService: SaleSummaryService, | ||||
| private router: Router, | |||||
| protected appHelperService: AppHelperService, | protected appHelperService: AppHelperService, | ||||
| ) { | ) { | ||||
| this.salesSummarySub = new Subscription(); | this.salesSummarySub = new Subscription(); | ||||
| @@ -30,10 +29,10 @@ export class SaleSummaryComponent implements OnInit, AfterViewInit { | |||||
| } | } | ||||
| ngOnInit(): void { | ngOnInit(): void { | ||||
| this.getData(); | |||||
| } | } | ||||
| ngAfterViewInit(): void { | ngAfterViewInit(): void { | ||||
| this.getData(); | |||||
| } | } | ||||
| getData() { | getData() { | ||||
| @@ -18,9 +18,9 @@ | |||||
| [documentForm]="taskNoteForm" | [documentForm]="taskNoteForm" | ||||
| [getDataFunction]="getContacts" | [getDataFunction]="getContacts" | ||||
| [dataSource]="dataSourceContacts" | [dataSource]="dataSourceContacts" | ||||
| [searchSelectColDefs]="colDefContacts" | |||||
| [displayedDataField]="'fullName'" | [displayedDataField]="'fullName'" | ||||
| [dataSet]="taskNote.contact" | [dataSet]="taskNote.contact" | ||||
| [listColDefinitions]="SearchSelectComponent.getDefaultColDefContacts()" | |||||
| > | > | ||||
| </app-search-select> | </app-search-select> | ||||
| <input type="hidden" formControlName="contactIri" value="{{taskNote.contactIri}}"/> | <input type="hidden" formControlName="contactIri" value="{{taskNote.contactIri}}"/> | ||||
| @@ -15,6 +15,7 @@ import {taskNoteForm} from "@app/_forms/apiForms"; | |||||
| import {SearchSelectComponent} from "@app/_components/search-select/search-select.component"; | import {SearchSelectComponent} from "@app/_components/search-select/search-select.component"; | ||||
| import {MatTableDataSource} from "@angular/material/table"; | import {MatTableDataSource} from "@angular/material/table"; | ||||
| import {SearchInputColDef} from "@app/_components/search-input/search-input-col-def"; | import {SearchInputColDef} from "@app/_components/search-input/search-input-col-def"; | ||||
| import {ListGetDataFunctionType} from "@app/_components/list/list-get-data-function-type"; | |||||
| @Component({ | @Component({ | ||||
| selector: 'app-new-task-note', | selector: 'app-new-task-note', | ||||
| @@ -26,13 +27,13 @@ export class NewTaskNoteComponent implements OnInit, AfterViewInit { | |||||
| @Input() public taskNote!: TaskNoteJsonld; | @Input() public taskNote!: TaskNoteJsonld; | ||||
| @Output() public submit: EventEmitter<ModalStatus> = new EventEmitter<ModalStatus>(); | @Output() public submit: EventEmitter<ModalStatus> = new EventEmitter<ModalStatus>(); | ||||
| @ViewChild('contactSearchSelect', { static: false }) contactSearchSelect!: SearchSelectComponent; | @ViewChild('contactSearchSelect', { static: false }) contactSearchSelect!: SearchSelectComponent; | ||||
| protected readonly SearchSelectComponent = SearchSelectComponent; | |||||
| protected taskNoteForm: FormGroup; | protected taskNoteForm: FormGroup; | ||||
| protected taskNoteSub: Subscription; | protected taskNoteSub: Subscription; | ||||
| protected contactTypes = Object.values(TaskNoteJsonld.ContactTypeEnum); | protected contactTypes = Object.values(TaskNoteJsonld.ContactTypeEnum); | ||||
| protected contacts: Array<ContactJsonld>; | protected contacts: Array<ContactJsonld>; | ||||
| protected dataSourceContacts; | protected dataSourceContacts; | ||||
| protected colDefContacts: SearchInputColDef[]; | |||||
| constructor( | constructor( | ||||
| protected taskNoteService: TaskNoteService, | protected taskNoteService: TaskNoteService, | ||||
| @@ -43,12 +44,6 @@ export class NewTaskNoteComponent implements OnInit, AfterViewInit { | |||||
| this.taskNoteSub = new Subscription(); | this.taskNoteSub = new Subscription(); | ||||
| this.contacts = []; | this.contacts = []; | ||||
| this.dataSourceContacts = new MatTableDataSource<ContactJsonld>(this.contacts); | this.dataSourceContacts = new MatTableDataSource<ContactJsonld>(this.contacts); | ||||
| this.colDefContacts = [ | |||||
| SearchSelectComponent.createColDef('pos', 'overview.number', SearchSelectComponent.COLUMN_TYPE_POSITION), | |||||
| SearchSelectComponent.createColDef('img', 'overview.image', SearchSelectComponent.COLUMN_TYPE_IMAGE, 'imageUrl'), | |||||
| SearchSelectComponent.createColDef('name', 'form.name', SearchSelectComponent.COLUMN_TYPE_TEXT, 'fullName') | |||||
| ]; | |||||
| } | } | ||||
| ngOnInit(): void { | ngOnInit(): void { | ||||
| @@ -64,19 +59,13 @@ export class NewTaskNoteComponent implements OnInit, AfterViewInit { | |||||
| } | } | ||||
| getContacts = (term?: string): void => { | |||||
| this.contactService.contactsGetCollection( | |||||
| this.contactSearchSelect.pagingComponent.getPageIndex(), | |||||
| this.contactSearchSelect.pagingComponent.getPageSize(), | |||||
| getContacts: ListGetDataFunctionType = (index: number, pageSize: number, term?: string) => { | |||||
| return this.contactService.contactsGetCollection( | |||||
| this.contactSearchSelect.getPageIndex(), | |||||
| this.contactSearchSelect.getPageSize(), | |||||
| this.task.partnerIri!, | this.task.partnerIri!, | ||||
| undefined, | undefined, | ||||
| term | term | ||||
| ).subscribe( | |||||
| data => { | |||||
| this.contacts = data['hydra:member']; | |||||
| this.dataSourceContacts = new MatTableDataSource<ContactJsonld>(this.contacts); | |||||
| this.contactSearchSelect.setData(this.dataSourceContacts, this.contacts, Number(data["hydra:totalItems"])); | |||||
| } | |||||
| ); | ); | ||||
| } | } | ||||
| @@ -26,9 +26,9 @@ | |||||
| [documentForm]="taskForm" | [documentForm]="taskForm" | ||||
| [getDataFunction]="getProducts" | [getDataFunction]="getProducts" | ||||
| [dataSource]="dataSourceProducts" | [dataSource]="dataSourceProducts" | ||||
| [searchSelectColDefs]="colDefProducts" | |||||
| [displayedDataField]="'name'" | [displayedDataField]="'name'" | ||||
| [dataSet]="task.product" | [dataSet]="task.product" | ||||
| [listColDefinitions]="SearchSelectComponent.getDefaultColDefProducts()" | |||||
| > | > | ||||
| <input type="hidden" formControlName="productIri" value="{{task.productIri}}"/> | <input type="hidden" formControlName="productIri" value="{{task.productIri}}"/> | ||||
| </app-search-select> | </app-search-select> | ||||
| @@ -43,9 +43,9 @@ | |||||
| [documentForm]="taskForm" | [documentForm]="taskForm" | ||||
| [getDataFunction]="getUsers" | [getDataFunction]="getUsers" | ||||
| [dataSource]="dataSourceUsers" | [dataSource]="dataSourceUsers" | ||||
| [searchSelectColDefs]="colDefUsers" | |||||
| [displayedDataField]="'fullName'" | [displayedDataField]="'fullName'" | ||||
| [dataSet]="task.assignedTo" | [dataSet]="task.assignedTo" | ||||
| [listColDefinitions]="SearchSelectComponent.getDefaultColDefUsers()" | |||||
| > | > | ||||
| <input type="hidden" formControlName="assignedToIri" value="{{task.productIri}}"/> | <input type="hidden" formControlName="assignedToIri" value="{{task.productIri}}"/> | ||||
| </app-search-select> | </app-search-select> | ||||
| @@ -18,6 +18,7 @@ import {filter, map} from "rxjs/operators"; | |||||
| import {MatTableDataSource} from "@angular/material/table"; | import {MatTableDataSource} from "@angular/material/table"; | ||||
| import {SearchSelectComponent} from "@app/_components/search-select/search-select.component"; | import {SearchSelectComponent} from "@app/_components/search-select/search-select.component"; | ||||
| import {SearchInputColDef} from "@app/_components/search-input/search-input-col-def"; | import {SearchInputColDef} from "@app/_components/search-input/search-input-col-def"; | ||||
| import {ListGetDataFunctionType} from "@app/_components/list/list-get-data-function-type"; | |||||
| @Component({ | @Component({ | ||||
| selector: 'app-new-task', | selector: 'app-new-task', | ||||
| @@ -29,6 +30,7 @@ export class NewTaskComponent implements OnInit, AfterViewInit { | |||||
| @Output() public submit: EventEmitter<ModalStatus> = new EventEmitter<ModalStatus>(); | @Output() public submit: EventEmitter<ModalStatus> = new EventEmitter<ModalStatus>(); | ||||
| @ViewChild('userSearchSelect', { static: false }) userSearchSelect!: SearchSelectComponent; | @ViewChild('userSearchSelect', { static: false }) userSearchSelect!: SearchSelectComponent; | ||||
| @ViewChild('productSearchSelect', { static: false }) productSearchSelect!: SearchSelectComponent; | @ViewChild('productSearchSelect', { static: false }) productSearchSelect!: SearchSelectComponent; | ||||
| protected readonly SearchSelectComponent = SearchSelectComponent; | |||||
| protected taskForm: FormGroup; | protected taskForm: FormGroup; | ||||
| protected taskSub: Subscription; | protected taskSub: Subscription; | ||||
| @@ -40,15 +42,9 @@ export class NewTaskComponent implements OnInit, AfterViewInit { | |||||
| protected products: Array<ProductJsonld>; | protected products: Array<ProductJsonld>; | ||||
| protected dataSourceProducts; | protected dataSourceProducts; | ||||
| protected colDefUsers: SearchInputColDef[]; | |||||
| protected colDefProducts: SearchInputColDef[]; | |||||
| protected formatter = (apiData: any) => apiData.name; | |||||
| constructor( | constructor( | ||||
| protected taskService: TaskService, | protected taskService: TaskService, | ||||
| protected userService: UserService, | protected userService: UserService, | ||||
| protected partnerService: PartnerService, | |||||
| protected productService: ProductService, | protected productService: ProductService, | ||||
| protected appHelperService: AppHelperService | protected appHelperService: AppHelperService | ||||
| ) { | ) { | ||||
| @@ -59,17 +55,6 @@ export class NewTaskComponent implements OnInit, AfterViewInit { | |||||
| this.taskForm = taskForm; | this.taskForm = taskForm; | ||||
| this.taskSub = new Subscription(); | this.taskSub = new Subscription(); | ||||
| this.dueAtValue = ""; | this.dueAtValue = ""; | ||||
| this.colDefUsers = [ | |||||
| SearchSelectComponent.createColDef('pos', 'overview.number', SearchSelectComponent.COLUMN_TYPE_POSITION), | |||||
| SearchSelectComponent.createColDef('img', 'overview.image', SearchSelectComponent.COLUMN_TYPE_IMAGE, 'imageUrl'), | |||||
| SearchSelectComponent.createColDef('name', 'form.name', SearchSelectComponent.COLUMN_TYPE_TEXT, 'fullName'), | |||||
| ]; | |||||
| this.colDefProducts = [ | |||||
| SearchSelectComponent.createColDef('pos', 'overview.number', SearchSelectComponent.COLUMN_TYPE_POSITION), | |||||
| SearchSelectComponent.createColDef('img', 'overview.image', SearchSelectComponent.COLUMN_TYPE_IMAGE, 'imageUrl'), | |||||
| SearchSelectComponent.createColDef('name', 'form.product', SearchSelectComponent.COLUMN_TYPE_TEXT, 'name'), | |||||
| ]; | |||||
| } | } | ||||
| ngOnInit(): void { | ngOnInit(): void { | ||||
| @@ -86,81 +71,26 @@ export class NewTaskComponent implements OnInit, AfterViewInit { | |||||
| } | } | ||||
| ngAfterViewInit(): void { | ngAfterViewInit(): void { | ||||
| this.userSearchSelect.getData(); | |||||
| this.productSearchSelect.getData(); | |||||
| } | } | ||||
| getUsers = (term?: string): void => { | |||||
| this.userService.usersGetCollection(1, 50, undefined, term) | |||||
| this.userService.usersGetCollection( | |||||
| this.userSearchSelect.pagingComponent.getPageIndex(), | |||||
| this.userSearchSelect.pagingComponent.getPageSize(), | |||||
| getUsers: ListGetDataFunctionType = (index: number, pageSize: number, term?: string) => { | |||||
| return this.userService.usersGetCollection( | |||||
| index, | |||||
| pageSize, | |||||
| undefined, | undefined, | ||||
| undefined, | undefined, | ||||
| term | term | ||||
| ).subscribe( | |||||
| data => { | |||||
| this.users = data['hydra:member']; | |||||
| this.dataSourceUsers = new MatTableDataSource<UserJsonld>(this.users); | |||||
| this.userSearchSelect.setData(this.dataSourceUsers, this.users, Number(data["hydra:totalItems"])); | |||||
| } | |||||
| ) | |||||
| } | |||||
| getProducts = (term?: string): void => { | |||||
| // NOTE: all products that are not assigned to partner yet | |||||
| this.productService.productsGetCollection( | |||||
| this.productSearchSelect.pagingComponent.getPageIndex(), | |||||
| this.productSearchSelect.pagingComponent.getPageSize(), | |||||
| term | |||||
| ).subscribe( | |||||
| data => { | |||||
| this.products = data['hydra:member']; | |||||
| this.dataSourceProducts = new MatTableDataSource<ProductJsonld>(this.products); | |||||
| this.productSearchSelect.setData(this.dataSourceProducts, this.products, Number(data["hydra:totalItems"])); | |||||
| } | |||||
| ); | |||||
| } | |||||
| protected searchUsers: OperatorFunction<string, readonly { id: any; name: any }[]> = (text$: Observable<string>) => | |||||
| text$.pipe( | |||||
| debounceTime(200), | |||||
| distinctUntilChanged(), | |||||
| filter((term) => term.length >= 2), | |||||
| switchMap((term) => this.fetchUsers(term)), | |||||
| map((users) => users.slice(0, 10)), | |||||
| ); | |||||
| protected searchPartners: OperatorFunction<string, readonly { id: any; name: any }[]> = (text$: Observable<string>) => | |||||
| text$.pipe( | |||||
| debounceTime(200), | |||||
| distinctUntilChanged(), | |||||
| filter((term) => term.length >= 2), | |||||
| switchMap((term) => this.fetchPartners(term)), | |||||
| map((partners) => partners.slice(0, 10)), | |||||
| ); | |||||
| protected fetchUsers(term: string): Observable<{ id: any; name: any }[]> { | |||||
| return this.userService.usersGetCollection(1, 50, undefined, term).pipe( | |||||
| map((response) => response['hydra:member'].map(user => ({ id: user.id, name: user.firstName + ' ' + user.lastName }))), | |||||
| ); | ); | ||||
| } | } | ||||
| protected fetchPartners(term: string): Observable<{ id: any; name: any }[]> { | |||||
| return this.partnerService.partnersGetCollection(1, 50, undefined, undefined, term).pipe( | |||||
| map((response) => response['hydra:member'].map(partner => ({ id: partner.id, name: partner.name }))), | |||||
| getProducts: ListGetDataFunctionType = (index: number, pageSize: number, term?: string) => { | |||||
| return this.productService.productsGetCollection( | |||||
| index, | |||||
| pageSize, | |||||
| term | |||||
| ); | ); | ||||
| } | } | ||||
| protected onPartnerSelect(selectedItem: any): void { | |||||
| this.taskForm.get('partner')?.setValue(selectedItem.item.id); | |||||
| } | |||||
| protected onAssignedToSelect(selectedItem: any): void { | |||||
| this.taskForm.get('assignedTo')?.setValue(selectedItem.item.id); | |||||
| } | |||||
| protected onDueAtChange(selectedItem: any) { | protected onDueAtChange(selectedItem: any) { | ||||
| // Set T12:00 for correct string | // Set T12:00 for correct string | ||||
| let selectedItemValue = selectedItem.target.value + "T12:00"; | let selectedItemValue = selectedItem.target.value + "T12:00"; | ||||
| @@ -193,5 +123,4 @@ export class NewTaskComponent implements OnInit, AfterViewInit { | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @@ -1,15 +1,7 @@ | |||||
| import {AfterViewInit, ChangeDetectorRef, Component, OnInit, ViewChild} from '@angular/core'; | |||||
| import {NewTaskComponent} from "@app/_views/tasks/new-task/new-task.component"; | |||||
| import {NgbModal, NgbModalOptions} from "@ng-bootstrap/ng-bootstrap"; | |||||
| import {AfterViewInit, Component, OnInit, ViewChild} from '@angular/core'; | |||||
| import {AppHelperService} from "@app/_helpers/app-helper.service"; | import {AppHelperService} from "@app/_helpers/app-helper.service"; | ||||
| import {Subscription} from "rxjs"; | |||||
| import {TaskJsonld, TaskNoteJsonld, TaskService} from "@app/core/api/v1"; | |||||
| import {MatPaginator, MatPaginatorIntl, PageEvent} from "@angular/material/paginator"; | |||||
| import {MatTableDataSource} from "@angular/material/table"; | |||||
| import {User} from "@app/_models"; | import {User} from "@app/_models"; | ||||
| import {AccountService} from "@app/_services"; | 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"; | import {TaskListComponent} from "@app/_views/tasks/task-list/task-list.component"; | ||||
| @Component({ | @Component({ | ||||
| @@ -39,7 +39,7 @@ | |||||
| > | > | ||||
| </app-sale-list> | </app-sale-list> | ||||
| <app-sale-summary *ngIf="toggleSales.isOpened" #saleSummaryComponent | <app-sale-summary *ngIf="toggleSales.isOpened" #saleSummaryComponent | ||||
| [user]="user" | |||||
| [user]="user" | |||||
| > | > | ||||
| </app-sale-summary> | </app-sale-summary> | ||||
| </app-toggle> | </app-toggle> | ||||
| @@ -20,7 +20,6 @@ import {ActivatedRoute} from "@angular/router"; | |||||
| }) | }) | ||||
| export class UserDetailComponent implements OnInit, AfterViewInit { | export class UserDetailComponent implements OnInit, AfterViewInit { | ||||
| @Input() public user!: UserJsonld; | @Input() public user!: UserJsonld; | ||||
| @ViewChild("togglePosts", { static: true }) togglePosts!: ToggleComponent; | @ViewChild("togglePosts", { static: true }) togglePosts!: ToggleComponent; | ||||
| @ViewChild("postListComponent", { static: false }) postsComponent!: PostListComponent; | @ViewChild("postListComponent", { static: false }) postsComponent!: PostListComponent; | ||||
| @ViewChild("toggleTasks", { static: true }) toggleTasks!: ToggleComponent; | @ViewChild("toggleTasks", { static: true }) toggleTasks!: ToggleComponent; | ||||
| @@ -51,6 +50,7 @@ export class UserDetailComponent implements OnInit, AfterViewInit { | |||||
| } | } | ||||
| ngOnInit() { | ngOnInit() { | ||||
| console.log(this.user); | |||||
| if (this.user === undefined) { | if (this.user === undefined) { | ||||
| this.route.params.subscribe(params => { | this.route.params.subscribe(params => { | ||||
| this.getUserData(params['id']); | this.getUserData(params['id']); | ||||
| @@ -61,13 +61,7 @@ export class UserDetailComponent implements OnInit, AfterViewInit { | |||||
| } | } | ||||
| ngAfterViewInit(): void { | ngAfterViewInit(): void { | ||||
| // if (this.accountService.userValue?.userResource) { | |||||
| // let user = this.accountService.userValue?.userResource; | |||||
| // if (this.user.id === user.id) { | |||||
| // this.isCurrentUser = true; | |||||
| // } | |||||
| // this.isCurrentUser = this.userId == user?.id; | |||||
| // } | |||||
| } | } | ||||
| getUserData(userId: string) { | getUserData(userId: string) { | ||||
| @@ -1,6 +1,5 @@ | |||||
| <div class="spt-container"> | <div class="spt-container"> | ||||
| <app-list #listComponent | <app-list #listComponent | ||||
| [dataSource]="dataSource" | |||||
| [getDataFunction]="getData" | [getDataFunction]="getData" | ||||
| [onNavigateToDetailsFunction]="navigateToUserDetails" | [onNavigateToDetailsFunction]="navigateToUserDetails" | ||||
| [onSortFunction]="onSortChange" | [onSortFunction]="onSortChange" | ||||
| @@ -10,6 +10,7 @@ import {AppHelperService} from "@app/_helpers/app-helper.service"; | |||||
| import {ListComponent} from "@app/_components/list/list.component"; | import {ListComponent} from "@app/_components/list/list.component"; | ||||
| import {ListColDefinition} from "@app/_components/list/list-col-definition"; | import {ListColDefinition} from "@app/_components/list/list-col-definition"; | ||||
| import {ListColTypeAddress} from "@app/_components/list/list-col-type-address"; | import {ListColTypeAddress} from "@app/_components/list/list-col-type-address"; | ||||
| import {ListGetDataFunctionType} from "@app/_components/list/list-get-data-function-type"; | |||||
| @Component({ | @Component({ | ||||
| selector: 'app-user-list', | selector: 'app-user-list', | ||||
| @@ -20,9 +21,6 @@ export class UserListComponent implements OnInit, AfterViewInit { | |||||
| @ViewChild("listComponent", { static: false }) listComponent!: ListComponent; | @ViewChild("listComponent", { static: false }) listComponent!: ListComponent; | ||||
| protected usersSub: Subscription; | |||||
| protected users: Array<UserJsonld>; | |||||
| protected dataSource; | |||||
| protected listColDefinitions!: ListColDefinition[]; | protected listColDefinitions!: ListColDefinition[]; | ||||
| constructor( | constructor( | ||||
| @@ -30,9 +28,6 @@ export class UserListComponent implements OnInit, AfterViewInit { | |||||
| private router: Router, | private router: Router, | ||||
| protected appHelperService: AppHelperService, | protected appHelperService: AppHelperService, | ||||
| ) { | ) { | ||||
| this.usersSub = new Subscription(); | |||||
| this.users = []; | |||||
| this.dataSource = new MatTableDataSource<UserJsonld>(this.users); | |||||
| this.listColDefinitions = [ | this.listColDefinitions = [ | ||||
| { | { | ||||
| name: 'image', | name: 'image', | ||||
| @@ -72,19 +67,13 @@ export class UserListComponent implements OnInit, AfterViewInit { | |||||
| this.listComponent.getData(); | this.listComponent.getData(); | ||||
| } | } | ||||
| getData = (term? : string): void => { | |||||
| this.usersSub = this.userService.usersGetCollection( | |||||
| this.listComponent.getPageIndex(), | |||||
| this.listComponent.getPageSize(), | |||||
| getData: ListGetDataFunctionType = (index: number, pageSize: number, term?: string) => { | |||||
| return this.userService.usersGetCollection( | |||||
| index, | |||||
| pageSize, | |||||
| undefined, | undefined, | ||||
| undefined, | undefined, | ||||
| term | term | ||||
| ).subscribe( | |||||
| data => { | |||||
| this.users = data["hydra:member"]; | |||||
| this.dataSource = new MatTableDataSource<UserJsonld>(this.users); | |||||
| this.listComponent.setData(this.dataSource, Number(data["hydra:totalItems"])); | |||||
| } | |||||
| ); | ); | ||||
| } | } | ||||
| @@ -20,16 +20,18 @@ import {UsersComponent} from "@app/_views/user/users.component"; | |||||
| const accountModule = () => import('@app/_views/account/account.module').then(x => x.AccountModule); | const accountModule = () => import('@app/_views/account/account.module').then(x => x.AccountModule); | ||||
| export const ROUTE_CUSTOMER = 'customer'; | |||||
| export const ROUTE_SUPPLIER = 'supplier'; | |||||
| export const ROUTE_SERVICE = 'service'; | |||||
| export const ROUTE_CONTACT = 'contact'; | export const ROUTE_CONTACT = 'contact'; | ||||
| export const ROUTE_PRODUCT = 'product'; | |||||
| export const ROUTE_TASK = 'task'; | |||||
| export const ROUTE_CUSTOMER = 'customer'; | |||||
| export const ROUTE_DOCUMENT = 'document'; | export const ROUTE_DOCUMENT = 'document'; | ||||
| export const ROUTE_PRODUCT = 'product'; | |||||
| export const ROUTE_PROFILE = 'profile'; | |||||
| export const ROUTE_SALE = 'sale'; | export const ROUTE_SALE = 'sale'; | ||||
| export const ROUTE_SERVICE = 'service'; | |||||
| export const ROUTE_SUPPLIER = 'supplier'; | |||||
| export const ROUTE_TASK = 'task'; | |||||
| export const ROUTE_USER = 'user'; | export const ROUTE_USER = 'user'; | ||||
| const routes: Routes = [ | const routes: Routes = [ | ||||
| {path: '', component: HomeComponent, canActivate: [userGuard]}, | {path: '', component: HomeComponent, canActivate: [userGuard]}, | ||||
| {path: 'account', loadChildren: accountModule}, | {path: 'account', loadChildren: accountModule}, | ||||
| @@ -104,7 +106,7 @@ const routes: Routes = [ | |||||
| ] | ] | ||||
| }, | }, | ||||
| { | { | ||||
| path: ROUTE_PRODUCT, | |||||
| path: ROUTE_PROFILE, | |||||
| component: TwoColumnComponent, | component: TwoColumnComponent, | ||||
| canActivate: [userGuard], | canActivate: [userGuard], | ||||
| children: [ | children: [ | ||||