Skip to content

Commit

Permalink
feat(stark-ui): add support for displaying the "items per page" dropd…
Browse files Browse the repository at this point in the history
…own also in Pagination on "compact" mode

ISSUES CLOSED: NationalBankBelgium#1248
  • Loading branch information
christophercr authored and nicanac committed Jan 6, 2020
1 parent c123ef4 commit 187b1b4
Show file tree
Hide file tree
Showing 13 changed files with 150 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface StarkPaginationConfig {

/**
* If false, then itemsPerPage dropdown will not be present.
* Default: true
* Default: true on "default" mode, false on "compact" mode
*/
itemsPerPageIsPresent?: boolean;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,15 @@
</button>
</li>
</ul>

<div class="pagination-items-per-page" *ngIf="!!paginationConfig.itemsPerPageIsPresent">
<stark-dropdown
[options]="paginationConfig.itemsPerPageOptions"
[value]="paginationConfig.itemsPerPage"
placeholder=""
(selectionChanged)="onChangeItemsPerPage($event)"
dropdownId="items-per-page-{{ htmlSuffixId }}"
dropdownName="items-per-page-{{ htmlSuffixId }}"
></stark-dropdown>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export class StarkPaginationComponent extends MatPaginator implements OnInit, On
}

/**
* Component lifecycle hook
* CodefaultItemsPerPageIsPresentmponent lifecycle hook
*/
public ngOnChanges(changesObj: SimpleChanges): void {
if (changesObj["paginationConfig"]) {
Expand Down Expand Up @@ -165,16 +165,22 @@ export class StarkPaginationComponent extends MatPaginator implements OnInit, On
public normalizePaginationConfig(config: StarkPaginationConfig): StarkPaginationConfig {
if (!config) {
// initialize paginationConfig to prevent errors in other functions depending on this config
this.logger.warn(componentName + ": No configuration defined in pagination component. TotalItems set to 0 by default");
this.logger.warn(componentName + ": No configuration defined in pagination component. TotalIt ems set to 0 by default");
return { totalItems: 0 };
}

let defaultItemsPerPageIsPresent: StarkPaginationConfig["itemsPerPageIsPresent"];

if (typeof config.itemsPerPageIsPresent === "undefined") {
defaultItemsPerPageIsPresent = this.mode !== "compact"; // true on "default" mode, false on "compact" mode
}

return {
itemsPerPageOptions: config.itemsPerPageOptions || [5, 10, 15],
itemsPerPage: config.itemsPerPage || (config.itemsPerPageOptions ? config.itemsPerPageOptions[0] : 5),
page: config.page || 1,
isExtended: config.isExtended !== undefined ? config.isExtended : false,
itemsPerPageIsPresent: config.itemsPerPageIsPresent !== undefined ? config.itemsPerPageIsPresent : true,
itemsPerPageIsPresent: config.itemsPerPageIsPresent !== undefined ? config.itemsPerPageIsPresent : defaultItemsPerPageIsPresent,
pageNavIsPresent: config.pageNavIsPresent !== undefined ? config.pageNavIsPresent : true,
pageInputIsPresent: config.pageInputIsPresent !== undefined ? config.pageInputIsPresent : true,
totalItems: config.totalItems !== undefined ? config.totalItems : 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ export class StarkTableComponent extends AbstractStarkUiComponent implements OnI

/**
* {@link StarkPaginationConfig} configuration object for embedded pagination component
*
* **IMPORTANT:** the pagination component is displayed in "compact" mode
*/
@Input()
public paginationConfig: StarkPaginationConfig = {};
Expand Down
1 change: 1 addition & 0 deletions showcase/src/app/demo-ui/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from "./table-regular";
export * from "./table-with-items-per-page-selector";
export * from "./table-with-selection";
export * from "./table-with-custom-actions";
export * from "./table-with-transcluded-action-bar";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./table-with-items-per-page-selector.component";
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<stark-table
[data]="data"
[columnProperties]="columns"
[filter]="filter"
[orderProperties]="order"
[paginationConfig]="pagination"
[tableRowActions]="tableRowActions"
showRowIndex
multiSort
showRowsCounter
(rowClicked)="handleRowClicked($event)"
>
<header><h1 class="mb0" translate>SHOWCASE.DEMO.TABLE.WITH_ITEMS_PER_PAGE_SELECTOR</h1></header>
</stark-table>
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import { Component, Inject } from "@angular/core";
import { STARK_LOGGING_SERVICE, StarkLoggingService } from "@nationalbankbelgium/stark-core";
import { StarkPaginationConfig, StarkTableColumnProperties, StarkTableFilter, StarkTableRowActions } from "@nationalbankbelgium/stark-ui";

const DUMMY_DATA: object[] = [
{
id: 1,
title: { label: "first title (value: 1)", value: 1 },
description: "first one",
extra: "number one has some extra information"
},
{ id: 10, title: { label: "second title (value: 2)", value: 2 }, description: "second description" },
{ id: 12, title: { label: "third title (value: 3)", value: 3 }, description: "the third description" },
{ id: 2, title: { label: "fourth title (value: 4)", value: 4 }, description: "description number four" },
{
id: 23,
title: { label: "fifth title (value: 5)", value: 5 },
description: "fifth description",
extra: "The fifth row has some extra information"
},
{ id: 222, title: { label: "sixth title (value: 6)", value: 6 }, description: "the sixth description" },
{
id: 112,
title: { label: "seventh title (value: 7)", value: 7 },
description: "seventh description",
extra: "This row has some extra information"
},
{ id: 232, title: { label: "eighth title (value: 8)", value: 8 }, description: "description number eight" },
{ id: 154, title: { label: "ninth title (value: 9)", value: 9 }, description: "the ninth description" },
{ id: 27, title: { label: "tenth title (value: 10)", value: 10 }, description: "description number ten", extra: "extra info" },
{ id: 86, title: { label: "eleventh title (value: 11)", value: 11 }, description: "eleventh description" },
{ id: 44, title: { label: "twelfth title (value: 12)", value: 12 }, description: "the twelfth description" }
];

@Component({
selector: "showcase-table-with-items-per-page-selector",
templateUrl: "./table-with-items-per-page-selector.component.html"
})
export class TableWithItemsPerPageSelectorComponent {
public data: object[] = DUMMY_DATA;

public columns: StarkTableColumnProperties[] = [
{ name: "id", label: "Id" },
{
name: "title",
label: "SHOWCASE.DEMO.TABLE.LABELS.TITLE",
cellFormatter: (value: { label: string }): string => "~" + value.label,
compareFn: (n1: { value: number }, n2: { value: number }): number => n1.value - n2.value
},
{ name: "description", label: "SHOWCASE.DEMO.TABLE.LABELS.DESCRIPTION" },
{
name: "extra",
label: "SHOWCASE.DEMO.TABLE.LABELS.EXTRA_INFO",
isFilterable: false,
isSortable: false,
isVisible: false
}
];

public filter: StarkTableFilter = {
globalFilterPresent: true,
columns: [
{ columnName: "id", filterPosition: "below" },
{ columnName: "title", filterPosition: "above" }
],
filterPosition: "below"
};

public order: string[] = ["title", "-description", "id"];

public pagination: StarkPaginationConfig = { totalItems: DUMMY_DATA.length, page: 1, itemsPerPage: 10, itemsPerPageIsPresent: true };

public tableRowActions: StarkTableRowActions = {
actions: [
{
id: "edit-item",
label: "STARK.ICONS.EDIT_ITEM",
icon: "pencil",
actionCall: ($event: Event, data: object): void => this.logger.debug("EDIT", $event, data),
isEnabled: true
},
{
id: "delete-item",
label: "STARK.ICONS.DELETE_ITEM",
icon: "delete",
actionCall: ($event: Event, data: object): void => this.logger.debug("DELETE", $event, data),
isEnabled: false
}
]
};

public constructor(@Inject(STARK_LOGGING_SERVICE) private logger: StarkLoggingService) {}

public handleRowClicked(data: object): void {
this.logger.debug("ROW CLICKED:", data);
}
}
2 changes: 2 additions & 0 deletions showcase/src/app/demo-ui/demo-ui.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ import { SharedModule } from "../shared/shared.module";
import { DEMO_STATES } from "./routes";
import {
TableRegularComponent,
TableWithItemsPerPageSelectorComponent,
TableWithCustomActionsComponent,
TableWithCustomStylingComponent,
TableWithFixedActionsComponent,
Expand Down Expand Up @@ -141,6 +142,7 @@ import {
DemoSliderPageComponent,
DemoTablePageComponent,
TableRegularComponent,
TableWithItemsPerPageSelectorComponent,
TableWithSelectionComponent,
TableWithCustomActionsComponent,
TableWithTranscludedActionBarComponent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ <h1 translate>SHOWCASE.DEMO.SHARED.EXAMPLE_VIEWER_LIST</h1>
<showcase-table-regular></showcase-table-regular>
</example-viewer>

<example-viewer
id="items-per-page-selection"
exampleTitle="SHOWCASE.DEMO.TABLE.WITH_ITEMS_PER_PAGE_SELECTOR"
filesPath="fix-me"
[extensions]="['HTML', 'TS', 'SCSS']"
>
<showcase-table-with-items-per-page-selector></showcase-table-with-items-per-page-selector>
</example-viewer>

<example-viewer
id="selection"
exampleTitle="SHOWCASE.DEMO.TABLE.WITH_SELECTION"
Expand Down
1 change: 1 addition & 0 deletions showcase/src/assets/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@
},
"REGULAR": "Regular Table",
"WITH_SELECTION": "Table with selection",
"WITH_ITEMS_PER_PAGE_SELECTOR": "Table with custom number of items per page",
"WITH_CUSTOM_ACTIONS": "Table with custom actions",
"WITH_FIXED_HEADER": "Table with fixed header",
"WITH_TRANSCLUDED_ACTION_BAR": "Table with transcluded Action bar",
Expand Down
1 change: 1 addition & 0 deletions showcase/src/assets/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@
},
"REGULAR": "Table régulière",
"WITH_SELECTION": "Table avec sélection",
"WITH_ITEMS_PER_PAGE_SELECTOR": "Table avec la sélection du nombre d'éléments à afficher",
"WITH_CUSTOM_ACTIONS": "Table avec actions personalisé",
"WITH_FIXED_HEADER": "Table avec en-tête fixe",
"WITH_TRANSCLUDED_ACTION_BAR": "Table avec Action Bar 'transcluded'",
Expand Down
1 change: 1 addition & 0 deletions showcase/src/assets/translations/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@
},
"REGULAR": "Normale tabel",
"WITH_SELECTION": "Tabel met selectie",
"WITH_ITEMS_PER_PAGE_SELECTOR": "Tabel met aangepaste items per page",
"WITH_CUSTOM_ACTIONS": "Tabel met aangepaste acties",
"WITH_FIXED_HEADER": "Tabel met vaste header",
"WITH_TRANSCLUDED_ACTION_BAR": "Tabel met 'transcluded' Action Bar",
Expand Down

0 comments on commit 187b1b4

Please sign in to comment.