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(); DescriptionLookup descriptionLookup = model.asDescriptionLookup();
if (descriptionLookup != null) { if (descriptionLookup != null) {
descriptionLookup.getPage().setOffset(0); 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)); 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())) { 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())); 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(); DmpLookup dmpLookup = model.asDmpLookup();
if (dmpLookup != null){ if (dmpLookup != null){
dmpLookup.getPage().setOffset(0); 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)); 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())) { 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())); 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> </div>
<!-- End of Search Filter --> <!-- End of Search Filter -->
</div> </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> <button type="button" class="btn-load-more" (click)="loadLess()">{{'GENERAL.ACTIONS.LOAD-LESS' | translate}}</button>
</div> </div>
<div *ngFor="let item of listingItems; let i = index"> <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"> <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}} {{'GENERAL.ACTIONS.NO-MORE-AVAILABLE' | translate}}
</div> </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> <button type="button" class="btn-load-more" (click)="loadMore()">{{'GENERAL.ACTIONS.LOAD-MORE' | translate}}</button>
</div> </div>
</div> </div>

View File

@ -33,9 +33,16 @@ import { nameof } from 'ts-simple-nameof';
export class RecentEditedActivityComponent extends BaseComponent implements OnInit { export class RecentEditedActivityComponent extends BaseComponent implements OnInit {
lookup: RecentActivityItemLookup = new RecentActivityItemLookup(); lookup: RecentActivityItemLookup = new RecentActivityItemLookup();
currentPage: number = 0;
pageSize: number = 5; pageSize: number = 5;
pageLessSize= this.pageSize; latestBatchCount: number = 0;
listingItems: RecentActivityItem[]= []; listingItems: RecentActivityItem[]= [];
@Input() includeDescriptions: boolean = true;
@Input() includeDmps: boolean = true;
pageLessSize= this.pageSize;
public formGroup = new UntypedFormBuilder().group({ public formGroup = new UntypedFormBuilder().group({
like: new UntypedFormControl(), like: new UntypedFormControl(),
@ -129,12 +136,74 @@ export class RecentEditedActivityComponent extends BaseComponent implements OnIn
} }
refresh(): void { 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.orderField = this.formGroup.get('order').value ?? this.order.UpdatedAt;
this.lookup.like = this.formGroup.get('like').value; this.lookup.like = this.formGroup.get('like').value;
this.lookup.project = { this.lookup.project = {
fields : [ 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.id)].join('.'),
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.label)].join('.'), [nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.label)].join('.'),
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.description)].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.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.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('.'), [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.id)].join('.'),
[nameof<RecentActivityItem>(x => x.description), nameof<Description>(x => x.label)].join('.'), [nameof<RecentActivityItem>(x => x.description), nameof<Description>(x => x.label)].join('.'),
[nameof<RecentActivityItem>(x => x.description), nameof<Description>(x => x.status)].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.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('.'), [nameof<RecentActivityItem>(x => x.description), nameof<Description>(x => x.dmp), nameof<Dmp>(x => x.dmpReferences), nameof<DmpReference>(x => x.isActive)].join('.'),
] ]
}; }
this.getItems();
} }
loadMore() { export enum PaginationAction {
this.pageSize = this.pageSize + this.pageLessSize; LoadMore = 0,
this.lookup.page = { size: this.pageSize, offset: 0 }; LoadLess = 1
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);
}
})
});
}
} }