Skip to content

Commit

Permalink
#3783 - Ability to sort projects by created date
Browse files Browse the repository at this point in the history
- Added ability to sort project dashboard by different criteria
  • Loading branch information
reckart committed Feb 22, 2023
1 parent 68f27fc commit 6e3a2fa
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import static org.apache.wicket.extensions.markup.html.repeater.data.sort.SortOrder.ASCENDING;

import java.io.Serializable;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Stream;
Expand All @@ -40,6 +41,8 @@ public class ProjectListDataProvider
{
private static final long serialVersionUID = 2144634813265254948L;

private static final Date BEGINNING_OF_TIME = new Date(0);

private ProjectListFilterState filterState;
private IModel<List<ProjectEntry>> source;
private IModel<List<ProjectEntry>> data;
Expand Down Expand Up @@ -81,10 +84,20 @@ private int comparator(ProjectEntry ob1, ProjectEntry ob2)
return dir * (o1.getName().compareTo(o2.getName()));
case STATE:
return dir * (o1.getState().getName().compareTo(o2.getState().getName()));
case CREATED:
return dir * (o1.getCreated().compareTo(o2.getCreated()));
case UPDATED:
return dir * (o1.getUpdated().compareTo(o2.getUpdated()));
case CREATED: {
var d1 = o1.getCreated();
var d2 = o2.getCreated();
d1 = d1 != null ? d1 : BEGINNING_OF_TIME;
d2 = d2 != null ? d2 : BEGINNING_OF_TIME;
return dir * (d1.compareTo(d2));
}
case UPDATED: {
var d1 = o1.getUpdated();
var d2 = o2.getUpdated();
d1 = d1 != null ? d1 : BEGINNING_OF_TIME;
d2 = d2 != null ? d2 : BEGINNING_OF_TIME;
return dir * (d1.compareTo(d2));
}
default:
return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@
</button>
</div>
<div class="flex-content"/>
<div>
<div class="input-group">
<div class="input-group-text">
<i class="fas fa-sort"/>
</div>
<select wicket:id="sortOrder" class="form-select"/>
</div>
</div>
<div wicket:id="roleFilter"/>
</div>
<div class="flex-h-container">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import static de.tudarmstadt.ukp.clarin.webanno.model.PermissionLevel.MANAGER;
import static de.tudarmstadt.ukp.clarin.webanno.security.model.Role.ROLE_ADMIN;
import static de.tudarmstadt.ukp.clarin.webanno.security.model.Role.ROLE_PROJECT_CREATOR;
import static de.tudarmstadt.ukp.clarin.webanno.support.lambda.HtmlElementEvents.CHANGE_EVENT;
import static de.tudarmstadt.ukp.clarin.webanno.support.lambda.HtmlElementEvents.INPUT_EVENT;
import static de.tudarmstadt.ukp.clarin.webanno.support.lambda.HtmlElementEvents.KEYDOWN_EVENT;
import static de.tudarmstadt.ukp.clarin.webanno.support.lambda.KeyCodes.ENTER;
Expand All @@ -35,6 +36,8 @@
import static java.util.stream.Collectors.toList;
import static org.apache.wicket.RuntimeConfigurationType.DEVELOPMENT;
import static org.apache.wicket.authroles.authorization.strategies.role.metadata.MetaDataRoleAuthorizationStrategy.authorize;
import static org.apache.wicket.extensions.markup.html.repeater.data.sort.SortOrder.ASCENDING;
import static org.apache.wicket.extensions.markup.html.repeater.data.sort.SortOrder.DESCENDING;

import java.io.IOException;
import java.text.SimpleDateFormat;
Expand All @@ -47,10 +50,13 @@
import org.apache.wicket.Component;
import org.apache.wicket.RestartResponseException;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.extensions.markup.html.repeater.data.sort.SortOrder;
import org.apache.wicket.feedback.IFeedback;
import org.apache.wicket.markup.head.IHeaderResponse;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.EnumChoiceRenderer;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.html.list.ListItem;
Expand Down Expand Up @@ -147,7 +153,9 @@ public ProjectsOverviewPage()
currentUser = LoadableDetachableModel.of(userRepository::getCurrentUser);
allAccessibleProjects = LoadableDetachableModel.of(this::loadProjects);

var defaultSortOrder = SortStrategy.NAME;
dataProvider = new ProjectListDataProvider(allAccessibleProjects);
dataProvider.setSort(defaultSortOrder.key, defaultSortOrder.order);

fastTrackAnnotatorsToProject();

Expand All @@ -172,6 +180,18 @@ public ProjectsOverviewPage()
queue(new ProjectRoleFilterPanel(MID_ROLE_FILTER,
() -> dataProvider.getFilterState().getRoles()));

DropDownChoice<SortStrategy> sortOrder = new DropDownChoice<>("sortOrder");
sortOrder.setModel(Model.of(defaultSortOrder));
sortOrder.setChoiceRenderer(new EnumChoiceRenderer<>(sortOrder));
sortOrder.setChoices(asList(SortStrategy.values()));
sortOrder.setNullValid(false);
sortOrder.add(new LambdaAjaxFormComponentUpdatingBehavior(CHANGE_EVENT, _target -> {
var s = sortOrder.getModelObject();
dataProvider.setSort(s.key, s.order);
_target.add(projectListContainer);
}));
queue(sortOrder);

nameFilter = new TextField<>("nameFilter",
PropertyModel.of(dataProvider.getFilterState(), "projectName"), String.class);
nameFilter.setOutputMarkupPlaceholderTag(true);
Expand Down Expand Up @@ -394,14 +414,16 @@ protected void populateItem(Item<ProjectEntry> aItem)
aItem.add(new TerseMarkdownLabel(MID_DESCRIPTION,
aItem.getModelObject().getShortDescription()));

addActionsDropdown(aItem);
aItem.add(projectLink);
aItem.add(createRoleBadges(aItem.getModelObject()));

Label createdLabel = new Label(MID_CREATED,
() -> project.getCreated() != null ? formatDate(project.getCreated())
: null);
addActionsDropdown(aItem);
aItem.add(projectLink);
createdLabel.add(visibleWhen(() -> createdLabel.getDefaultModelObject() != null));
aItem.add(createdLabel);
aItem.add(createRoleBadges(aItem.getModelObject()));

Label projectId = new Label(MID_ID, () -> project.getId());
projectId.add(visibleWhen(
() -> DEVELOPMENT.equals(getApplication().getConfigurationType())));
Expand Down Expand Up @@ -550,8 +572,23 @@ private List<ProjectEntry> loadProjects()
{
return projectService.listAccessibleProjectsWithPermissions(currentUser.getObject())
.entrySet().stream() //
.map(e -> new ProjectEntry(e.getKey(), e.getValue()))
.sorted(comparing(ProjectEntry::getName)) //
.map(e -> new ProjectEntry(e.getKey(), e.getValue())) //
.collect(toList());
}

private enum SortStrategy
{
NAME(ProjectListSortKeys.NAME, ASCENDING),
CREATED_OLDEST(ProjectListSortKeys.CREATED, ASCENDING),
CREATED_NEWEST(ProjectListSortKeys.CREATED, DESCENDING);

final ProjectListSortKeys key;
final SortOrder order;

SortStrategy(ProjectListSortKeys aKey, SortOrder aOrder)
{
key = aKey;
order = aOrder;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ noProjects.noFilterMatch=No project matches the selected filter criteria.
noProjects=You do not have access to any projects.
importProject=Import project
nameFilter.placeholder=Filter by name...
SortStrategy.CREATED_OLDEST=oldest first
SortStrategy.CREATED_NEWEST=newest first
SortStrategy.NAME=name

0 comments on commit 6e3a2fa

Please sign in to comment.