refactor latest-activity in progress

*added new items instead of replacing the whole listing
This commit is contained in:
Sofia Papacharalampous 2024-05-23 13:17:03 +03:00
parent 34f471fb30
commit 5a57313c0d
3 changed files with 127 additions and 86 deletions

View File

@ -75,6 +75,8 @@ public class DashboardServiceImpl implements DashboardService {
DescriptionLookup descriptionLookup = model.asDescriptionLookup();
if (descriptionLookup != null) {
descriptionLookup.getPage().setOffset(0);
descriptionLookup.getPage().setSize(model.getPage().getSize()+model.getPage().getOffset());
QueryResult<Description> descriptions = this.elasticQueryHelperService.collect(descriptionLookup, AuthorizationFlags.OwnerOrDmpAssociatedOrPermission, new BaseFieldSet().ensure(Description._id).ensure(Description._updatedAt).ensure(Description._status).ensure(Description._label));
if (!this.conventionService.isListNullOrEmpty(descriptions.getItems())) {
for (Description description : descriptions.getItems()) recentActivityItemEntities.add(new RecentActivityItemEntity(RecentActivityItemType.Description, description.getId(), description.getUpdatedAt(), description.getLabel(), description.getStatus().getValue()));
@ -84,6 +86,8 @@ public class DashboardServiceImpl implements DashboardService {
DmpLookup dmpLookup = model.asDmpLookup();
if (dmpLookup != null){
dmpLookup.getPage().setOffset(0);
dmpLookup.getPage().setSize(model.getPage().getSize()+model.getPage().getOffset());
QueryResult<Dmp> dmps = this.elasticQueryHelperService.collect(dmpLookup, AuthorizationFlags.OwnerOrDmpAssociatedOrPermission, new BaseFieldSet().ensure(Dmp._id).ensure(Dmp._updatedAt).ensure(Dmp._label).ensure(Dmp._status));
if (!this.conventionService.isListNullOrEmpty(dmps.getItems())) {
for (Dmp dmp : dmps.getItems()) recentActivityItemEntities.add(new RecentActivityItemEntity(RecentActivityItemType.Dmp, dmp.getId(), dmp.getUpdatedAt(), dmp.getLabel(), dmp.getStatus().getValue()));

View File

@ -30,7 +30,7 @@
</div>
<!-- End of Search Filter -->
</div>
<div *ngIf="listingItems && listingItems.length > 0 && pageSize > pageLessSize" class="d-flex justify-content-center">
<div *ngIf="listingItems && listingItems.length > 0 && currentPage > 1" class="d-flex justify-content-center">
<button type="button" class="btn-load-more" (click)="loadLess()">{{'GENERAL.ACTIONS.LOAD-LESS' | translate}}</button>
</div>
<div *ngFor="let item of listingItems; let i = index">
@ -40,7 +40,7 @@
<div class="text-muted d-flex justify-content-center mt-5" *ngIf="listingItems && listingItems.length > 0 && listingItems.length < pageSize">
{{'GENERAL.ACTIONS.NO-MORE-AVAILABLE' | translate}}
</div>
<div *ngIf="listingItems && listingItems.length > 0 && listingItems.length >= startIndex + pageSize" class="d-flex justify-content-center">
<div *ngIf="listingItems && listingItems.length > 0 && listingItems.length >= currentPage*pageSize" class="d-flex justify-content-center">
<button type="button" class="btn-load-more" (click)="loadMore()">{{'GENERAL.ACTIONS.LOAD-MORE' | translate}}</button>
</div>
</div>

View File

@ -33,9 +33,16 @@ import { nameof } from 'ts-simple-nameof';
export class RecentEditedActivityComponent extends BaseComponent implements OnInit {
lookup: RecentActivityItemLookup = new RecentActivityItemLookup();
currentPage: number = 0;
pageSize: number = 5;
pageLessSize= this.pageSize;
latestBatchCount: number = 0;
listingItems: RecentActivityItem[]= [];
@Input() includeDescriptions: boolean = true;
@Input() includeDmps: boolean = true;
pageLessSize= this.pageSize;
public formGroup = new UntypedFormBuilder().group({
like: new UntypedFormControl(),
@ -129,12 +136,74 @@ export class RecentEditedActivityComponent extends BaseComponent implements OnIn
}
refresh(): void {
this.lookup.page = { size: this.pageSize, offset: 0 };
this._resetPagination();
this.lookup.orderField = this.formGroup.get('order').value ?? this.order.UpdatedAt;
this.lookup.like = this.formGroup.get('like').value;
this.lookup.project = {
fields : [
...(this.includeDmps ? this._getDmpLookup() : []),
...(this.includeDescriptions ? this._getDescriptionLookup() : [])
]
};
this.loadMore();
}
loadMore() {
this.lookup.page = { size: this.pageSize, offset: this.pageSize*this.currentPage };
this.loadItems(PaginationAction.LoadMore);
}
loadLess() {
this.loadItems(PaginationAction.LoadLess);
}
private loadItems(action: PaginationAction){
if (action == PaginationAction.LoadLess) {
this.listingItems = this.listingItems.slice(0, this.listingItems.length-this.latestBatchCount);
this.latestBatchCount = this.pageSize;
this.currentPage --;
return;
}
this.dashboardService
.getMyRecentActivityItems(this.lookup)
.pipe(takeUntil(this._destroyed))
.subscribe(response => {
if (response == null) return;
this.latestBatchCount = response.length;
response.forEach(item => {
if (item.dmp){
if (item.dmp.descriptions) {
if (item.dmp.status == DmpStatus.Finalized) {
item.dmp.descriptions = item.dmp.descriptions.filter(x => x.isActive === IsActive.Active && x.status === DescriptionStatus.Finalized);
} else {
item.dmp.descriptions = item.dmp.descriptions.filter(x => x.isActive === IsActive.Active && x.status != DescriptionStatus.Canceled);
}
}
item.dmp.dmpUsers = item.dmp.dmpUsers.filter(x=> x.isActive === IsActive.Active);
this.listingItems.push(item);
}
if (item.description){
if (item.description.status != DescriptionStatus.Canceled) this.listingItems.push(item);
}
})
if (response.length > 0) this.currentPage ++;
});
}
private _resetPagination(): void {
this.pageSize = 5;
this.currentPage = 0;
}
private _getDmpLookup(): string[] {
return [
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.id)].join('.'),
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.label)].join('.'),
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.description)].join('.'),
@ -171,7 +240,11 @@ export class RecentEditedActivityComponent extends BaseComponent implements OnIn
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.dmpReferences), nameof<DmpReference>(x => x.reference), nameof<Reference>(x => x.label)].join('.'),
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.dmpReferences), nameof<DmpReference>(x => x.reference), nameof<Reference>(x => x.type), nameof<ReferenceType>(x => x.id)].join('.'),
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.dmpReferences), nameof<DmpReference>(x => x.isActive)].join('.'),
];
}
private _getDescriptionLookup(): string[] {
return [
[nameof<RecentActivityItem>(x => x.description), nameof<Description>(x => x.id)].join('.'),
[nameof<RecentActivityItem>(x => x.description), nameof<Description>(x => x.label)].join('.'),
[nameof<RecentActivityItem>(x => x.description), nameof<Description>(x => x.status)].join('.'),
@ -202,46 +275,10 @@ export class RecentEditedActivityComponent extends BaseComponent implements OnIn
[nameof<RecentActivityItem>(x => x.description), nameof<Description>(x => x.dmp), nameof<Dmp>(x => x.dmpReferences), nameof<DmpReference>(x => x.reference), nameof<Reference>(x => x.reference)].join('.'),
[nameof<RecentActivityItem>(x => x.description), nameof<Description>(x => x.dmp), nameof<Dmp>(x => x.dmpReferences), nameof<DmpReference>(x => x.isActive)].join('.'),
]
};
this.getItems();
}
}
loadMore() {
this.pageSize = this.pageSize + this.pageLessSize;
this.lookup.page = { size: this.pageSize, offset: 0 };
this.getItems();
}
loadLess() {
this.pageSize = this.pageSize - this.pageLessSize;
this.lookup.page = { size: this.pageSize, offset: 0 };
this.getItems();
}
private getItems(){
this.listingItems = [];
this.dashboardService
.getMyRecentActivityItems(this.lookup)
.pipe(takeUntil(this._destroyed))
.subscribe(response => {
response.forEach(item => {
if (item.dmp){
if (item.dmp.descriptions) {
if (item.dmp.status == DmpStatus.Finalized) {
item.dmp.descriptions = item.dmp.descriptions.filter(x => x.isActive === IsActive.Active && x.status === DescriptionStatus.Finalized);
} else {
item.dmp.descriptions = item.dmp.descriptions.filter(x => x.isActive === IsActive.Active && x.status != DescriptionStatus.Canceled);
}
}
item.dmp.dmpUsers = item.dmp.dmpUsers.filter(x=> x.isActive === IsActive.Active);
this.listingItems.push(item);
}
if (item.description){
if (item.description.status != DescriptionStatus.Canceled) this.listingItems.push(item);
}
})
});
}
export enum PaginationAction {
LoadMore = 0,
LoadLess = 1
}