Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | 5x 5x 5x 5x 5x 5x 5x 2x 2x 2x 5x 2x 2x 2x | import { ChangeDetectionStrategy, Component, Input, OnChanges, SimpleChanges } from '@angular/core';
import { LineItemView } from 'ish-core/models/line-item/line-item.model';
import { OrderLineItem } from 'ish-core/models/order/order.model';
import { Price } from 'ish-core/models/price/price.model';
/**
* The Line Item List Component displays line items of orders and baskets.
* It provides optional delete and edit functionality
* It provides optional lineItemView (string 'simple')
* It provides optional total cost output
*
* @example
* <ish-line-item-list
* [lineItems]="lineItems"
* [editable]="editable"
* [total]="total"
* lineItemViewType="simple" // simple = no edit-button, inventory, shipment
* ></ish-line-item-list>
*/
@Component({
selector: 'ish-line-item-list',
templateUrl: './line-item-list.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class LineItemListComponent implements OnChanges {
@Input({ required: true }) lineItems: Partial<LineItemView & OrderLineItem>[];
@Input() editable = true;
@Input() total: Price;
@Input() lineItemViewType: 'simple' | 'availability';
/**
* If pageSize > 0 only <pageSize> items are shown at once and a paging bar is shown below the line item list.
*/
@Input() pageSize = 25;
currentPage = 1;
lastPage: number;
displayItems: Partial<LineItemView & OrderLineItem>[] = [];
ngOnChanges(c: SimpleChanges) {
if (c.lineItems) {
this.lastPage = Math.ceil(this.lineItems?.length / this.pageSize);
this.goToPage(this.currentPage);
}
}
get showPagingBar() {
return this.pageSize && this.lineItems?.length > this.pageSize;
}
trackByFn(_: number, item: Partial<LineItemView & OrderLineItem>) {
return item.id;
}
/**
* Refresh items to display after changing the current page
*
* @param page current page
*/
goToPage(page: number) {
this.currentPage = page;
this.displayItems = this.pageSize
? this.lineItems.slice((page - 1) * this.pageSize, page * this.pageSize)
: this.lineItems;
}
}
|