refactor latest-activity in progress
*added pagination info on url
This commit is contained in:
parent
86e665452d
commit
0ed00a9dd8
|
@ -22,6 +22,7 @@ import { DmpService } from '@app/core/services/dmp/dmp.service';
|
|||
import { MatomoService } from '@app/core/services/matomo/matomo-service';
|
||||
import { EnumUtils } from '@app/core/services/utilities/enum-utils.service';
|
||||
import { BaseComponent } from '@common/base/base.component';
|
||||
import { Lookup } from '@common/model/lookup';
|
||||
import { debounceTime, takeUntil } from 'rxjs/operators';
|
||||
import { nameof } from 'ts-simple-nameof';
|
||||
|
||||
|
@ -36,7 +37,6 @@ export class RecentEditedActivityComponent extends BaseComponent implements OnIn
|
|||
|
||||
currentPage: number = 0;
|
||||
pageSize: number = 5;
|
||||
latestBatchCount: number = 0;
|
||||
listingItems: RecentActivityItem[]= [];
|
||||
@Input() includeDescriptions: boolean = true;
|
||||
@Input() includeDmps: boolean = true;
|
||||
|
@ -53,9 +53,7 @@ export class RecentEditedActivityComponent extends BaseComponent implements OnIn
|
|||
order = RecentActivityOrder;
|
||||
|
||||
totalCount: number;
|
||||
startIndex: number = 0;
|
||||
offsetLess: number = 0;
|
||||
page: number = 1;
|
||||
@Input() isActive: boolean = false;
|
||||
|
||||
constructor(
|
||||
|
@ -75,13 +73,9 @@ export class RecentEditedActivityComponent extends BaseComponent implements OnIn
|
|||
this.matomoService.trackPageView('Recent DMP Activity');
|
||||
this.route.queryParams.subscribe(params => {
|
||||
if (this.isActive) {
|
||||
let page = (params['page'] === undefined) ? 1 : +params['page'];
|
||||
this.page = (page <= 0) ? 1 : page;
|
||||
let page = (params['page'] === undefined) ? 0 : + params['page'];
|
||||
this.currentPage = (page <= 0) ? 0 : page;
|
||||
|
||||
this.startIndex = (this.page - 1) * this.pageSize;
|
||||
if (this.page > 1) {
|
||||
this.offsetLess = (this.page - 2) * this.pageSize;
|
||||
}
|
||||
|
||||
let order = params['order'];
|
||||
if (this.isAuthenticated()) {
|
||||
|
@ -123,11 +117,19 @@ export class RecentEditedActivityComponent extends BaseComponent implements OnIn
|
|||
}
|
||||
|
||||
updateUrl() {
|
||||
let parameters = "" +
|
||||
(this.page != 1 ? "&page=" + this.page : "") +
|
||||
//TODO refactor
|
||||
// (((this.formGroup.get("order").value != this.order.UpdatedAt && !this.publicMode) || (this.formGroup.get("order").value != this.order.Published && this.publicMode)) ? "&order=" + this.formGroup.get("order").value : "") +
|
||||
(this.formGroup.get("like").value ? ("&keyword=" + this.formGroup.get("like").value) : "");
|
||||
let parametersArray: string[] = [
|
||||
...(this.currentPage > 1 ? ["page=" + this.currentPage] : []),
|
||||
...(this.formGroup.get("like").value ? ["&keyword=" + this.formGroup.get("like").value] : [])
|
||||
]
|
||||
|
||||
let parameters = "";
|
||||
|
||||
if (parametersArray.length > 0){
|
||||
parameters = "?";
|
||||
|
||||
parameters += parametersArray.join('&');
|
||||
}
|
||||
|
||||
this.location.go(this.router.url.split('?')[0] + parameters);
|
||||
}
|
||||
|
||||
|
@ -135,8 +137,8 @@ export class RecentEditedActivityComponent extends BaseComponent implements OnIn
|
|||
return this.authentication.currentAccountIsAuthenticated();
|
||||
}
|
||||
|
||||
refresh(): void {
|
||||
this._resetPagination();
|
||||
refresh(resetPagination: boolean = false): void {
|
||||
if (resetPagination) this._resetPagination();
|
||||
this.lookup.orderField = this.formGroup.get('order').value ?? this.order.UpdatedAt;
|
||||
this.lookup.like = this.formGroup.get('like').value;
|
||||
this.lookup.project = {
|
||||
|
@ -146,24 +148,25 @@ export class RecentEditedActivityComponent extends BaseComponent implements OnIn
|
|||
]
|
||||
};
|
||||
|
||||
this.loadMore();
|
||||
this.loadMore({ size: this.pageSize*this.currentPage, offset: 0 }, false);
|
||||
}
|
||||
|
||||
loadMore() {
|
||||
this.lookup.page = { size: this.pageSize, offset: this.pageSize*this.currentPage };
|
||||
this.loadItems(PaginationAction.LoadMore);
|
||||
loadMore(page?: Lookup.Paging, updatePage: boolean = true) {
|
||||
if (!page) page = { size: this.pageSize, offset: this.pageSize*this.currentPage };
|
||||
this.lookup.page = page;
|
||||
this.loadItems(PaginationAction.LoadMore, updatePage);
|
||||
}
|
||||
|
||||
loadLess() {
|
||||
this.loadItems(PaginationAction.LoadLess);
|
||||
}
|
||||
|
||||
private loadItems(action: PaginationAction){
|
||||
private loadItems(action: PaginationAction, updatePage: boolean = true){
|
||||
if (action == PaginationAction.LoadLess) {
|
||||
this.listingItems = this.listingItems.slice(0, this.listingItems.length-this.latestBatchCount);
|
||||
let latestBatchCount = this.listingItems.length%this.pageSize == 0 ? this.pageSize : this.listingItems.length%this.pageSize;
|
||||
this.listingItems = this.listingItems.slice(0, this.listingItems.length-latestBatchCount);
|
||||
|
||||
this.latestBatchCount = this.pageSize;
|
||||
this.currentPage --;
|
||||
this._setPage(this.currentPage-1);
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -174,8 +177,6 @@ export class RecentEditedActivityComponent extends BaseComponent implements OnIn
|
|||
.subscribe(response => {
|
||||
if (response == null) return;
|
||||
|
||||
this.latestBatchCount = response.length;
|
||||
|
||||
response.forEach(item => {
|
||||
if (item.dmp){
|
||||
if (item.dmp.descriptions) {
|
||||
|
@ -193,7 +194,7 @@ export class RecentEditedActivityComponent extends BaseComponent implements OnIn
|
|||
}
|
||||
})
|
||||
|
||||
if (response.length > 0) this.currentPage ++;
|
||||
if (updatePage && response.length > 0 && this.listingItems.length >= this.currentPage*this.pageSize) this._setPage(this.currentPage+1);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -202,6 +203,11 @@ export class RecentEditedActivityComponent extends BaseComponent implements OnIn
|
|||
this.currentPage = 0;
|
||||
}
|
||||
|
||||
private _setPage(page: number) {
|
||||
this.currentPage = page;
|
||||
this.updateUrl();
|
||||
}
|
||||
|
||||
private _getDmpLookup(): string[] {
|
||||
return [
|
||||
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.id)].join('.'),
|
||||
|
|
Loading…
Reference in New Issue