refactor latest-activity in progress
*added new items instead of replacing the whole listing
This commit is contained in:
parent
34f471fb30
commit
5a57313c0d
|
@ -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()));
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -31,11 +31,18 @@ import { nameof } from 'ts-simple-nameof';
|
|||
styleUrls: ['./recent-edited-activity.component.css']
|
||||
})
|
||||
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(),
|
||||
|
@ -121,7 +128,7 @@ export class RecentEditedActivityComponent extends BaseComponent implements OnIn
|
|||
//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) : "");
|
||||
this.location.go(this.router.url.split('?')[0] + parameters);
|
||||
this.location.go(this.router.url.split('?')[0] + parameters);
|
||||
}
|
||||
|
||||
public isAuthenticated(): boolean {
|
||||
|
@ -129,50 +136,116 @@ 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();
|
||||
}
|
||||
|
||||
fields: [
|
||||
[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('.'),
|
||||
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.status)].join('.'),
|
||||
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.accessType)].join('.'),
|
||||
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.version)].join('.'),
|
||||
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.versionStatus)].join('.'),
|
||||
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.groupId)].join('.'),
|
||||
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.updatedAt)].join('.'),
|
||||
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.isActive)].join('.'),
|
||||
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.hash)].join('.'),
|
||||
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.authorizationFlags), AppPermission.CreateNewVersionDmp].join('.'),
|
||||
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.authorizationFlags), AppPermission.DeleteDmp].join('.'),
|
||||
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.authorizationFlags), AppPermission.CloneDmp].join('.'),
|
||||
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.authorizationFlags), AppPermission.FinalizeDmp].join('.'),
|
||||
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.authorizationFlags), AppPermission.ExportDmp].join('.'),
|
||||
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.authorizationFlags), AppPermission.InviteDmpUsers].join('.'),
|
||||
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.authorizationFlags), AppPermission.AssignDmpUsers].join('.'),
|
||||
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.authorizationFlags), AppPermission.EditDmp].join('.'),
|
||||
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.descriptions), nameof<Description>(x => x.id)].join('.'),
|
||||
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.descriptions), nameof<Description>(x => x.label)].join('.'),
|
||||
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.descriptions), nameof<Description>(x => x.status)].join('.'),
|
||||
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.descriptions), nameof<Description>(x => x.isActive)].join('.'),
|
||||
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.blueprint), nameof<DmpBlueprint>(x => x.id)].join('.'),
|
||||
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.blueprint), nameof<DmpBlueprint>(x => x.label)].join('.'),
|
||||
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.blueprint), nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.id)].join('.'),
|
||||
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.blueprint), nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.label)].join('.'),
|
||||
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.dmpUsers), nameof<DmpUser>(x => x.id)].join('.'),
|
||||
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.dmpUsers), nameof<DmpUser>(x => x.user.id)].join('.'),
|
||||
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.dmpUsers), nameof<DmpUser>(x => x.role)].join('.'),
|
||||
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.dmpUsers), nameof<DmpUser>(x => x.isActive)].join('.'),
|
||||
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.dmpReferences), nameof<DmpReference>(x => x.id)].join('.'),
|
||||
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.dmpReferences), nameof<DmpReference>(x => x.reference), nameof<Reference>(x => x.id)].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.isActive)].join('.'),
|
||||
loadMore() {
|
||||
this.lookup.page = { size: this.pageSize, offset: this.pageSize*this.currentPage };
|
||||
this.loadItems(PaginationAction.LoadMore);
|
||||
}
|
||||
|
||||
[nameof<RecentActivityItem>(x => x.description), nameof<Description>(x => x.id)].join('.'),
|
||||
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('.'),
|
||||
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.status)].join('.'),
|
||||
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.accessType)].join('.'),
|
||||
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.version)].join('.'),
|
||||
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.versionStatus)].join('.'),
|
||||
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.groupId)].join('.'),
|
||||
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.updatedAt)].join('.'),
|
||||
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.isActive)].join('.'),
|
||||
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.hash)].join('.'),
|
||||
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.authorizationFlags), AppPermission.CreateNewVersionDmp].join('.'),
|
||||
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.authorizationFlags), AppPermission.DeleteDmp].join('.'),
|
||||
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.authorizationFlags), AppPermission.CloneDmp].join('.'),
|
||||
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.authorizationFlags), AppPermission.FinalizeDmp].join('.'),
|
||||
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.authorizationFlags), AppPermission.ExportDmp].join('.'),
|
||||
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.authorizationFlags), AppPermission.InviteDmpUsers].join('.'),
|
||||
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.authorizationFlags), AppPermission.AssignDmpUsers].join('.'),
|
||||
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.authorizationFlags), AppPermission.EditDmp].join('.'),
|
||||
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.descriptions), nameof<Description>(x => x.id)].join('.'),
|
||||
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.descriptions), nameof<Description>(x => x.label)].join('.'),
|
||||
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.descriptions), nameof<Description>(x => x.status)].join('.'),
|
||||
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.descriptions), nameof<Description>(x => x.isActive)].join('.'),
|
||||
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.blueprint), nameof<DmpBlueprint>(x => x.id)].join('.'),
|
||||
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.blueprint), nameof<DmpBlueprint>(x => x.label)].join('.'),
|
||||
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.blueprint), nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.id)].join('.'),
|
||||
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.blueprint), nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.label)].join('.'),
|
||||
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.dmpUsers), nameof<DmpUser>(x => x.id)].join('.'),
|
||||
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.dmpUsers), nameof<DmpUser>(x => x.user.id)].join('.'),
|
||||
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.dmpUsers), nameof<DmpUser>(x => x.role)].join('.'),
|
||||
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.dmpUsers), nameof<DmpUser>(x => x.isActive)].join('.'),
|
||||
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.dmpReferences), nameof<DmpReference>(x => x.id)].join('.'),
|
||||
[nameof<RecentActivityItem>(x => x.dmp), nameof<Dmp>(x => x.dmpReferences), nameof<DmpReference>(x => x.reference), nameof<Reference>(x => x.id)].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.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('.'),
|
||||
[nameof<RecentActivityItem>(x => x.description), nameof<Description>(x => x.updatedAt)].join('.'),
|
||||
|
@ -201,47 +274,11 @@ 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.type), nameof<ReferenceType>(x => x.id)].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('.'),
|
||||
]
|
||||
};
|
||||
|
||||
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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue