-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
214 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
@use "header"; | ||
@use "form"; | ||
@use "logs"; | ||
@use "pagination"; | ||
@use "footer"; | ||
@use "notifications"; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
@use 'colors'; | ||
|
||
#pagination-wrapper { | ||
display: block; | ||
margin: 4em auto; | ||
padding: 2em 0; | ||
text-align: center; | ||
border-top: 1px solid colors.$oc-gray-4; | ||
border-bottom: 1px solid colors.$oc-gray-4; | ||
|
||
li { | ||
display: inline-block; | ||
|
||
&.page { | ||
padding: 4px 10px; | ||
margin: 0 7px; | ||
border-radius: 5px; | ||
} | ||
|
||
&.page.clickable { | ||
border: 1px solid colors.$oc-gray-2; | ||
} | ||
|
||
&.page.current { | ||
border: 1px solid colors.$oc-blue-2; | ||
background: colors.$oc-blue-2; | ||
} | ||
|
||
&.ellipsis { | ||
margin: 0 20px; | ||
color: colors.$oc-gray-5; | ||
} | ||
|
||
&.previous { | ||
margin-right: 20px; | ||
} | ||
|
||
&.next { | ||
margin-left: 20px; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import {IgBuildLog} from "./api"; | ||
|
||
export class Pagination { | ||
|
||
private _currentPage: number = 1; | ||
private numberOfPages: number = 0; | ||
|
||
constructor(private readonly pageSize: number, | ||
private readonly logRenderer: (logs: IgBuildLog[]) => void, | ||
private readonly paginationRenderer: (item: PaginationItem[], pagination: Pagination) => void) { | ||
} | ||
|
||
private _logs: IgBuildLog[] = []; | ||
|
||
set logs(logs: IgBuildLog[]) { | ||
this._logs = logs; | ||
this.numberOfPages = Math.ceil(logs.length / this.pageSize); | ||
if (this._currentPage > this.numberOfPages) { | ||
this.page = 1; | ||
// The setter has called render() already | ||
} else { | ||
this.render(); | ||
} | ||
} | ||
|
||
set page(page: number) { | ||
if (page < 1 || page > this.numberOfPages) { | ||
return; | ||
} | ||
this._currentPage = page; | ||
this.render(); | ||
} | ||
|
||
render(): void { | ||
const start = (this._currentPage - 1) * this.pageSize; | ||
const end = start + this.pageSize; | ||
this.logRenderer(this._logs.slice(start, end)); | ||
|
||
const nbPagesToShow = 4; | ||
|
||
const items: PaginationItem[] = []; | ||
|
||
// Show the first page and the 'previous' button | ||
if (this._currentPage > 1) { | ||
items.push(new PaginationPreviousPage(this._currentPage - 1)); | ||
items.push(new PaginationPage(1)); | ||
} | ||
// If there are more than _nbPagesToShow_ pages, we need to show an ellipsis | ||
if (this._currentPage > (nbPagesToShow + 2)) { | ||
items.push(new PaginationEllipsis()); | ||
} | ||
|
||
// Show the _nbPagesToShow_ pages before the current page | ||
for (let i = Math.max(2, this._currentPage - nbPagesToShow); i <= this._currentPage - 1; i++) { | ||
items.push(new PaginationPage(i)); | ||
} | ||
|
||
// The current page | ||
items.push(new PaginationCurrentPage(this._currentPage)); | ||
|
||
// Show the _nbPagesToShow_ pages after the current page | ||
for (let i = this._currentPage + 1; i <= Math.min(this._currentPage + nbPagesToShow, this.numberOfPages - 1); i++) { | ||
items.push(new PaginationPage(i)); | ||
} | ||
|
||
// If there are more than _nbPagesToShow_ pages, we need to show an ellipsis | ||
if (this._currentPage < (this.numberOfPages - nbPagesToShow - 2)) { | ||
items.push(new PaginationEllipsis()); | ||
} | ||
|
||
// Show the last page and the 'next' button | ||
if (this._currentPage < this.numberOfPages) { | ||
items.push(new PaginationPage(this.numberOfPages)); | ||
items.push(new PaginationNextPage(this._currentPage + 1)); | ||
} | ||
|
||
this.paginationRenderer(items, this); | ||
} | ||
} | ||
|
||
export class PaginationItem { | ||
} | ||
|
||
export class PaginationPreviousPage extends PaginationItem { | ||
constructor(public readonly page: number) { | ||
super(); | ||
} | ||
} | ||
|
||
export class PaginationNextPage extends PaginationItem { | ||
constructor(public readonly page: number) { | ||
super(); | ||
} | ||
} | ||
|
||
export class PaginationPage extends PaginationItem { | ||
constructor(public readonly page: number) { | ||
super(); | ||
} | ||
} | ||
|
||
export class PaginationCurrentPage extends PaginationItem { | ||
constructor(public readonly page: number) { | ||
super(); | ||
} | ||
} | ||
|
||
export class PaginationEllipsis extends PaginationItem { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters