-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pagination #408
Merged
Merged
Pagination #408
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
27345e9
fisrt try
litvinets 3f8bd5e
new v
litvinets c5c8b0c
isActive
litvinets 1801288
Merge branch 'develop' into Pagination
litvinets 77be2db
DOOOOOOOONE
litvinets e75664c
WORKS
litvinets 3cdb82d
Update constants.ts
litvinets befb3ef
test fix
litvinets c4d310d
test fixing
litvinets d122750
Update result.component.spec.ts
litvinets ec86751
Update paginator.component.spec.ts
litvinets 14c35c4
refactor
litvinets 106179a
Merge branch 'develop' into Pagination
litvinets File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
src/app/shared/components/paginator/paginator.component.html
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,15 @@ | ||
<div fxLayout='row' fxLayoutAlign='center center'> | ||
<button mat-button *ngIf="!(currentPage.element === 1)" class="page arrow" (click)="onArroveClick(false)"> | ||
<mat-icon>arrow_back</mat-icon> | ||
</button> | ||
|
||
<button mat-button *ngFor="let page of carouselPageList" class="page" | ||
[ngClass]="page.isActive && ((page.element === currentPage.element) ? 'page-selected' : 'page-unselected')" | ||
(click)="onPageChange(page)">{{page.element}}</button> | ||
|
||
|
||
<button mat-button *ngIf="currentPage.element !== totalPageAmount" class="page arrow" (click)="onArroveClick(true)"> | ||
<mat-icon>arrow_forward</mat-icon> | ||
</button> | ||
|
||
</div> |
25 changes: 25 additions & 0 deletions
25
src/app/shared/components/paginator/paginator.component.scss
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,25 @@ | ||
.page{ | ||
font-family: Innerspace; | ||
font-style: normal; | ||
font-weight: bold; | ||
font-size: 13px; | ||
line-height: 15px; | ||
color: #444444; | ||
pointer-events: none; | ||
padding: 1rem; | ||
min-width: 20px !important; | ||
|
||
&-selected{ | ||
color: #3849F9; | ||
} | ||
} | ||
.arrow, .page-selected, .page-unselected{ | ||
pointer-events: all; | ||
} | ||
.arrow:hover{ | ||
color: #3849F9; | ||
} | ||
.page-selected:hover, .page-unselected:hover, .arrow:hover{ | ||
cursor: pointer; | ||
opacity: 0.5; | ||
} |
35 changes: 35 additions & 0 deletions
35
src/app/shared/components/paginator/paginator.component.spec.ts
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,35 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { MatButtonModule } from '@angular/material/button'; | ||
import { MatIconModule } from '@angular/material/icon'; | ||
|
||
import { PaginatorComponent } from './paginator.component'; | ||
|
||
describe('PaginatorComponent', () => { | ||
let component: PaginatorComponent; | ||
let fixture: ComponentFixture<PaginatorComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [ | ||
MatButtonModule, | ||
MatIconModule | ||
], | ||
declarations: [PaginatorComponent] | ||
}) | ||
.compileComponents(); | ||
}); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(PaginatorComponent); | ||
component = fixture.componentInstance; | ||
component.currentPage = { | ||
element: 1, | ||
isActive: true | ||
} | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
162 changes: 162 additions & 0 deletions
162
src/app/shared/components/paginator/paginator.component.ts
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,162 @@ | ||
import { Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges } from '@angular/core'; | ||
import { Constants } from '../../constants/constants'; | ||
import { PaginationElement } from '../../models/paginationElement.model'; | ||
@Component({ | ||
selector: 'app-paginator', | ||
templateUrl: './paginator.component.html', | ||
styleUrls: ['./paginator.component.scss'] | ||
}) | ||
export class PaginatorComponent implements OnInit, OnChanges { | ||
|
||
private readonly FIRST_PAGINATION_PAGE = 1; | ||
private readonly MAX_PAGE_PAGINATOR_DISPLAY = 7; | ||
private readonly PAGINATION_DOTS = '...'; | ||
private readonly PAGINATION_SHIFT_DELTA = 3; | ||
|
||
@Input() currentPage: PaginationElement; | ||
@Input() totalEntities: number; | ||
|
||
carouselPageList: PaginationElement[] = []; | ||
totalPageAmount: number; | ||
size: number = Constants.WORKSHOPS_PER_PAGE; | ||
|
||
@Output() pageChange = new EventEmitter<PaginationElement>(); | ||
|
||
constructor() { } | ||
|
||
ngOnInit(): void { | ||
this.totalPageAmount = this.getTotalPageAmount(); | ||
|
||
this.createPageList(); | ||
} | ||
|
||
ngOnChanges(changes: SimpleChanges): void { | ||
if (!changes.currentPage.isFirstChange()) { | ||
const currentPage = this.carouselPageList.find((page: PaginationElement) => page.element === this.currentPage.element); | ||
|
||
let isForward: boolean = changes.currentPage.previousValue.element < changes.currentPage.currentValue.element; | ||
if (isForward) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. those two conditions could be meged |
||
if (this.carouselPageList.indexOf(currentPage) >= this.PAGINATION_SHIFT_DELTA) { | ||
this.createPageList(); | ||
} | ||
} else { | ||
if (this.carouselPageList.indexOf(currentPage) <= this.PAGINATION_SHIFT_DELTA) { | ||
this.createPageList(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
private createPageList(): void { | ||
this.carouselPageList = []; | ||
|
||
let firstPage = +this.currentPage.element - this.PAGINATION_SHIFT_DELTA; | ||
firstPage = firstPage < this.FIRST_PAGINATION_PAGE ? this.FIRST_PAGINATION_PAGE : firstPage; | ||
|
||
let lastPage = +this.currentPage.element + this.PAGINATION_SHIFT_DELTA; | ||
lastPage = lastPage > this.totalPageAmount ? this.totalPageAmount : lastPage; | ||
|
||
let pageList = this.createDisplayedPageList(firstPage); | ||
|
||
if (this.totalPageAmount < this.MAX_PAGE_PAGINATOR_DISPLAY) { | ||
this.carouselPageList = pageList; | ||
} else { | ||
this.createCarouselPageList(pageList, pageList[0]?.element !== this.FIRST_PAGINATION_PAGE, true); | ||
} | ||
|
||
} | ||
|
||
onPageChange(page: PaginationElement): void { | ||
this.pageChange.emit(page); | ||
} | ||
|
||
onArroveClick(isForward: boolean): void { | ||
let page: PaginationElement = { | ||
element: '', | ||
isActive: true, | ||
} | ||
if (isForward) { | ||
page.element = +this.currentPage.element + 1; | ||
} else { | ||
page.element = +this.currentPage.element - 1; | ||
} | ||
|
||
this.pageChange.emit(page); | ||
} | ||
|
||
private getTotalPageAmount(): number { | ||
return Math.ceil(this.totalEntities / this.size); | ||
} | ||
|
||
private createDisplayedPageList(startPage: number): PaginationElement[] { | ||
let i: number; | ||
let end: number; | ||
if (this.totalPageAmount > this.MAX_PAGE_PAGINATOR_DISPLAY) { | ||
const isMaxAmountFit = (startPage + this.MAX_PAGE_PAGINATOR_DISPLAY) < this.totalPageAmount; | ||
i = (isMaxAmountFit) ? startPage : this.totalPageAmount - this.MAX_PAGE_PAGINATOR_DISPLAY; | ||
end = this.MAX_PAGE_PAGINATOR_DISPLAY; | ||
} else { | ||
i = startPage; | ||
end = this.totalPageAmount; | ||
} | ||
|
||
let pageList: PaginationElement[] = []; | ||
while (pageList.length < end) { | ||
pageList.push({ | ||
element: i, | ||
isActive: true | ||
}); | ||
i++; | ||
} | ||
return pageList; | ||
} | ||
|
||
private createCarouselPageList(pageList: PaginationElement[], isOnStart?: boolean, isOnEnd?: boolean) { | ||
if (isOnStart) { | ||
let start: PaginationElement[] = [ | ||
{ | ||
element: this.FIRST_PAGINATION_PAGE, | ||
isActive: true | ||
} | ||
]; | ||
|
||
if (pageList[0]?.element !== 2) { | ||
start.push( | ||
{ | ||
element: this.PAGINATION_DOTS, | ||
isActive: false | ||
}) | ||
} | ||
|
||
this.carouselPageList = this.carouselPageList.concat(start); | ||
}; | ||
|
||
if (pageList[0]?.element === 2) { | ||
pageList.pop(); | ||
} | ||
|
||
if (pageList[pageList.length - 1]?.element === this.totalPageAmount - 1) { | ||
pageList.shift(); | ||
} | ||
|
||
this.carouselPageList = this.carouselPageList.concat(pageList); | ||
|
||
|
||
if (isOnEnd) { | ||
let end: PaginationElement[] = [ | ||
{ | ||
element: this.totalPageAmount, | ||
isActive: true | ||
} | ||
]; | ||
if (pageList[pageList.length - 1]?.element !== this.totalPageAmount - 1) { | ||
end.unshift({ | ||
element: this.PAGINATION_DOTS, | ||
isActive: false | ||
}) | ||
} | ||
this.carouselPageList = this.carouselPageList.concat(end); | ||
} | ||
} | ||
|
||
} |
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 |
---|---|---|
|
@@ -13,6 +13,8 @@ export class Constants { | |
static readonly PHONE_LENGTH = 10; | ||
static readonly PROVIDER_ENTITY_TYPE = 1; | ||
static readonly WORKSHOP_ENTITY_TYPE = 2; | ||
static readonly WORKSHOPS_PER_PAGE = 4; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 12? |
||
|
||
|
||
static readonly RATE_ONE_STAR = 1; | ||
static readonly RATE_TWO_STAR = 2; | ||
|
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,4 @@ | ||
export interface PaginationElement { | ||
element: number | string, | ||
isActive: boolean | ||
} |
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please check mobile view