Reworked Recent Activity ordering and force status to be ordered in reverse of the others

This commit is contained in:
George Kalampokis 2020-07-27 18:16:32 +03:00
parent 662bad6e47
commit eb8e4a96e6
9 changed files with 51 additions and 21 deletions

View File

@ -21,9 +21,12 @@ public class PaginationService {
items.withFields(Arrays.asList(tableRequest.getSelection().getFields()));
return items;
}
public static <T extends DataEntity> void applyOrder(QueryableList<T> items, TableQuery tableRequest) {
ColumnOrderings columnOrderings = tableRequest.getOrderings();
applyOrder(items, tableRequest.getOrderings());
}
public static <T extends DataEntity> void applyOrder(QueryableList<T> items, ColumnOrderings columnOrderings) {
for (Ordering ordering : columnOrderings.getFieldOrderings()) {
if (ordering.getOrderByType() == Ordering.OrderByType.ASC)
applyAscOrder(items, ordering);

View File

@ -7,6 +7,7 @@ import eu.eudat.data.dao.entities.DatasetDao;
import eu.eudat.data.dao.entities.OrganisationDao;
import eu.eudat.data.dao.entities.GrantDao;
import eu.eudat.data.entities.*;
import eu.eudat.data.query.PaginationService;
import eu.eudat.data.query.items.table.dmp.DataManagmentPlanPublicTableRequest;
import eu.eudat.elastic.entities.Dmp;
import eu.eudat.logic.builders.model.models.RecentActivityDataBuilder;
@ -263,10 +264,12 @@ public class DashBoardManager {
}
PaginationService.applyOrder(dmpList, tableRequest.getOrderings());
/*CompletableFuture future = CompletableFuture.runAsync(() -> */{
recentActivityModels.addAll(dmpList
.withHint(HintedModelFactory.getHint(RecentDmpModel.class))
.orderBy((builder, root) -> builder.desc(root.get(tableRequest.getCriteria().getOrder())))
// .orderBy((builder, root) -> builder.desc(root.get(tableRequest.getCriteria().getOrder())))
.skip(tableRequest.getDmpOffset())
.take(tableRequest.getLength())
.select(item -> {
@ -282,7 +285,7 @@ public class DashBoardManager {
recentActivityModels.addAll(datasetList
.withHint(HintedModelFactory.getHint(RecentDatasetModel.class))
.orderBy((builder, root) -> builder.desc(root.get(tableRequest.getCriteria().getOrder())))
// .orderBy((builder, root) -> builder.desc(root.get(tableRequest.getCriteria().getOrder())))
.skip(tableRequest.getDatasetOffset())
.take(tableRequest.getLength())
.select(item -> {
@ -290,6 +293,20 @@ public class DashBoardManager {
}));
}/*);*/
//GK: Shuffle the deck otherwise we will summon the DMPodia when sorting with status
int pos = -1;
for (int i = (recentActivityModels.size() / 2); i < recentActivityModels.size(); i++) {
RecentActivityModel recentActivityModel = recentActivityModels.remove(i);
while (pos < recentActivityModels.size()) {
pos++;
if (pos % 2 != 0) {
break;
}
}
recentActivityModels.add(pos, recentActivityModel);
}
//CompletableFuture.allOf(future).join();
// CompletableFuture.allOf(dmps, datasets).join();

View File

@ -1,8 +1,10 @@
package eu.eudat.models.data.dashboard.recent.tablerequest;
import eu.eudat.criteria.RecentActivityCriteria;
import eu.eudat.data.query.definition.helpers.ColumnOrderings;
public class RecentActivityTableRequest {
private ColumnOrderings orderings;
private RecentActivityCriteria criteria;
private int dmpOffset;
private int datasetOffset;
@ -39,4 +41,12 @@ public class RecentActivityTableRequest {
public void setCriteria(RecentActivityCriteria criteria) {
this.criteria = criteria;
}
public ColumnOrderings getOrderings() {
return orderings;
}
public void setOrderings(ColumnOrderings orderings) {
this.orderings = orderings;
}
}

View File

@ -69,7 +69,7 @@ export class DraftsComponent extends BaseComponent implements OnInit {
// const fields: Array<string> = [];
// fields.push('-modified');
this.formGroup.get('order').setValue(this.order.MODIFIED);
const fields: Array<string> = ["-" + this.formGroup.get('order').value];
const fields: Array<string> = [(this.formGroup.get('order').value === 'status' ? '+' : "-") + this.formGroup.get('order').value];
const dmpDataTableRequest: DataTableRequest<DatasetCriteria> = new DataTableRequest(0, 5, { fields: fields });
dmpDataTableRequest.criteria = new DatasetCriteria();
dmpDataTableRequest.criteria.status = DmpStatus.Draft;
@ -301,7 +301,7 @@ export class DraftsComponent extends BaseComponent implements OnInit {
refresh(): void {
// const fields: Array<string> = [];
// fields.push('-modified');
const fields: Array<string> = ["-" + this.formGroup.get('order').value];
const fields: Array<string> = [(this.formGroup.get('order').value === 'status' ? '+' : "-") + this.formGroup.get('order').value];
this.startIndex = 0;
const dmpDataTableRequest: DataTableRequest<DatasetCriteria> = new DataTableRequest(0, 5, { fields: fields });
dmpDataTableRequest.criteria = new DatasetCriteria();
@ -317,7 +317,7 @@ export class DraftsComponent extends BaseComponent implements OnInit {
public loadMore() {
this.startIndex = this.startIndex + this.pageSize;
// const fields: Array<string> = ["-modified"];
const fields: Array<string> = ["-" + this.formGroup.get('order').value];
const fields: Array<string> = [(this.formGroup.get('order').value === 'status' ? '+' : "-") + this.formGroup.get('order').value];
const request = new DataTableRequest<DatasetCriteria>(this.startIndex, this.pageSize, { fields: fields });
request.criteria = new DatasetCriteria();
request.criteria.status = DmpStatus.Draft;

View File

@ -75,12 +75,12 @@ export class RecentEditedActivityComponent extends BaseComponent implements OnIn
ngOnInit() {
if (this.isAuthenticated()) {
const fields: Array<string> = [];
this.formGroup.get('order').setValue(this.order.MODIFIED);
const fields: Array<string> = [(this.formGroup.get('order').value === 'status' ? '+' : "-") + this.formGroup.get('order').value];
// const fields: Array<string> = ["-modified"];
const allDataTableRequest: DataTableMultiTypeRequest<RecentActivityCriteria> = new DataTableMultiTypeRequest(0, 0, 5, { fields: fields });
allDataTableRequest.criteria = new RecentActivityCriteria();
allDataTableRequest.criteria.like = "";
this.formGroup.get('order').setValue(this.order.MODIFIED);
allDataTableRequest.criteria.order = this.formGroup.get('order').value;
this.dashboardService
.getRecentActivity(allDataTableRequest)
@ -458,7 +458,7 @@ export class RecentEditedActivityComponent extends BaseComponent implements OnIn
}
refresh(): void {
const fields: Array<string> = [];
const fields: Array<string> = [(this.formGroup.get('order').value === 'status' ? '+' : "-") + this.formGroup.get('order').value];
// const fields: Array<string> = ["-modified"];
this.startIndex = 0;
const allDataTableRequest: DataTableMultiTypeRequest<RecentActivityCriteria> = new DataTableMultiTypeRequest(0, 0, this.pageSize, { fields: fields });
@ -481,7 +481,7 @@ export class RecentEditedActivityComponent extends BaseComponent implements OnIn
}
public loadMore() {
const fields: Array<string> = [];
const fields: Array<string> = [(this.formGroup.get('order').value === 'status' ? '+' : "-") + this.formGroup.get('order').value];
// const fields: Array<string> = ["-modified"];
const request = new DataTableMultiTypeRequest<RecentActivityCriteria>(this.dmpOffset, this.datasetOffset, this.pageSize, { fields: fields });
request.criteria = new RecentActivityCriteria();

View File

@ -66,7 +66,7 @@ export class RecentEditedDatasetActivityComponent extends BaseComponent implemen
if (this.isAuthenticated()) {
// const fields: Array<string> = ["-modified"];
this.formGroup.get('order').setValue(this.order.MODIFIED);
const fields: Array<string> = ["-" + this.formGroup.get('order').value];
const fields: Array<string> = [(this.formGroup.get('order').value === 'status' ? '+' : "-") + this.formGroup.get('order').value];
const datasetDataTableRequest: DataTableRequest<DatasetCriteria> = new DataTableRequest(0, this.pageSize, { fields: fields });
datasetDataTableRequest.criteria = new DatasetCriteria();
datasetDataTableRequest.criteria.like = "";
@ -88,7 +88,7 @@ export class RecentEditedDatasetActivityComponent extends BaseComponent implemen
refresh(): void {
// const fields: Array<string> = ["-modified"];
const fields: Array<string> = ["-" + this.formGroup.get('order').value];
const fields: Array<string> = [(this.formGroup.get('order').value === 'status' ? '+' : "-") + this.formGroup.get('order').value];
this.startIndex = 0;
const datasetDataTableRequest: DataTableRequest<DatasetCriteria> = new DataTableRequest(0, this.pageSize, { fields: fields });
datasetDataTableRequest.criteria = new DatasetCriteria();
@ -105,7 +105,7 @@ export class RecentEditedDatasetActivityComponent extends BaseComponent implemen
public loadMore() {
this.startIndex = this.startIndex + this.pageSize;
// const fields: Array<string> = ["-modified"];
const fields: Array<string> = ["-" + this.formGroup.get('order').value];
const fields: Array<string> = [(this.formGroup.get('order').value === 'status' ? '+' : "-") + this.formGroup.get('order').value];
const request = new DataTableRequest<DatasetCriteria>(this.startIndex, this.pageSize, { fields: fields });
request.criteria = new DatasetCriteria();

View File

@ -68,7 +68,7 @@ export class RecentEditedDmpActivityComponent extends BaseComponent implements O
if (this.isAuthenticated()) {
// const fields: Array<string> = ["-modified"];
this.formGroup.get('order').setValue(this.order.MODIFIED);
const fields: Array<string> = ["-" + this.formGroup.get('order').value];
const fields: Array<string> = [(this.formGroup.get('order').value === 'status' ? '+' : "-") + this.formGroup.get('order').value];
const dmpDataTableRequest: DataTableRequest<DmpCriteria> = new DataTableRequest(0, 5, { fields: fields });
dmpDataTableRequest.criteria = new DmpCriteria();
dmpDataTableRequest.criteria.like = "";
@ -345,7 +345,7 @@ export class RecentEditedDmpActivityComponent extends BaseComponent implements O
refresh(): void {
// const fields: Array<string> = ["-modified"];
const fields: Array<string> = ["-" + this.formGroup.get('order').value];
const fields: Array<string> = [(this.formGroup.get('order').value === 'status' ? '+' : "-") + this.formGroup.get('order').value];
this.startIndex = 0;
const dmpDataTableRequest: DataTableRequest<DmpCriteria> = new DataTableRequest(this.startIndex, this.pageSize, { fields: fields });
dmpDataTableRequest.criteria = new DmpCriteria();
@ -362,7 +362,7 @@ export class RecentEditedDmpActivityComponent extends BaseComponent implements O
public loadMore() {
this.startIndex = this.startIndex + this.pageSize;
// const fields: Array<string> = ["-modified"];
const fields: Array<string> = ["-" + this.formGroup.get('order').value];
const fields: Array<string> = [(this.formGroup.get('order').value === 'status' ? '+' : "-") + this.formGroup.get('order').value];
const request = new DataTableRequest<DmpCriteria>(this.startIndex, this.pageSize, { fields: fields });
request.criteria = new DmpCriteria();

View File

@ -152,7 +152,7 @@ export class DatasetListingComponent extends BaseComponent implements OnInit, IB
// let fields: Array<string> = new Array();
// fields.push('-modified');
//if (this.sort && this.sort.active) { fields = this.sort.direction === 'asc' ? ['+' + this.sort.active] : ['-' + this.sort.active]; }
const fields: Array<string> = ["-" + this.formGroup.get('order').value];
const fields: Array<string> = [(this.formGroup.get('order').value === 'status' ? '+' : "-") + this.formGroup.get('order').value];
const request = new DataTableRequest<DatasetCriteria>(this.startIndex, this.pageSize, { fields: fields });
this.criteria.isPublic = this.isPublic;
request.criteria = this.criteria;
@ -168,7 +168,7 @@ export class DatasetListingComponent extends BaseComponent implements OnInit, IB
public loadMore() {
this.startIndex = this.startIndex + this.pageSize;
// const fields: Array<string> = ["-modified"];
const fields: Array<string> = ["-" + this.formGroup.get('order').value];
const fields: Array<string> = [(this.formGroup.get('order').value === 'status' ? '+' : "-") + this.formGroup.get('order').value];
const request = new DataTableRequest<DatasetCriteria>(this.startIndex, this.pageSize, { fields: fields });
this.criteria.isPublic = this.isPublic;
request.criteria = this.criteria;

View File

@ -185,7 +185,7 @@ export class DmpListingComponent extends BaseComponent implements OnInit, IBread
// let fields: Array<string> = new Array();
// if (this.sort && this.sort.active) { fields = this.sort.direction === 'asc' ? ['+' + this.sort.active] : ['-' + this.sort.active]; }
// fields.push('-modified');
const fields: Array<string> = ["-" + this.formGroup.get('order').value];
const fields: Array<string> = [(this.formGroup.get('order').value === 'status' ? '+' : "-") + this.formGroup.get('order').value];
const request = new DataTableRequest<DmpCriteria>(this.startIndex, this.pageSize, { fields: fields });
this.setPublicCriteria();
@ -209,7 +209,7 @@ export class DmpListingComponent extends BaseComponent implements OnInit, IBread
public loadMore() {
this.startIndex = this.startIndex + this.pageSize;
// const fields: Array<string> = ["-modified"];
const fields: Array<string> = ["-" + this.formGroup.get('order').value];
const fields: Array<string> = [(this.formGroup.get('order').value === 'status' ? '+' : "-") + this.formGroup.get('order').value];
const request = new DataTableRequest<DmpCriteria>(this.startIndex, this.pageSize, { fields: fields });
this.setPublicCriteria();
request.criteria = this.criteria;