The sorting should always be in descending order for numbers when first clicking on a new search term, i. e. another Keyword type (area or regular).
This commit is contained in:
parent
6aaa4dd4f2
commit
1ed21f3b75
src/main/java/se/su/dsv/scipro/admin/panels/match
@ -10,10 +10,11 @@
|
|||||||
This page contains a list of all supervisors with number of research areas and keywords attached to them.
|
This page contains a list of all supervisors with number of research areas and keywords attached to them.
|
||||||
You may filter the list by searching for name of supervisor. Click on the supervisors name to see which research areas and keywords that is attached.
|
You may filter the list by searching for name of supervisor. Click on the supervisors name to see which research areas and keywords that is attached.
|
||||||
</div>
|
</div>
|
||||||
<form wicket:id="filterForm">
|
|
||||||
<label for="supervisorField">Filter using supervisor name:</label><br />
|
<label for="autoComplete">Filter using supervisor name:</label><br />
|
||||||
<input style="width:300px;" wicket:id="supervisorField" type="text" />
|
<input wicket:id="autoComplete" /><br />
|
||||||
<input type="submit" wicket:id="filterButton" value="Filter"/>
|
<form wicket:id="showAllForm">
|
||||||
|
<div><button wicket:id="showAllButton">Show all</button></div>
|
||||||
</form>
|
</form>
|
||||||
<table wicket:id="table" class="rounded-corner">
|
<table wicket:id="table" class="rounded-corner">
|
||||||
<thead>
|
<thead>
|
||||||
|
@ -9,21 +9,21 @@ import org.apache.wicket.ajax.markup.html.form.AjaxButton;
|
|||||||
import org.apache.wicket.markup.html.WebMarkupContainer;
|
import org.apache.wicket.markup.html.WebMarkupContainer;
|
||||||
import org.apache.wicket.markup.html.basic.Label;
|
import org.apache.wicket.markup.html.basic.Label;
|
||||||
import org.apache.wicket.markup.html.form.Form;
|
import org.apache.wicket.markup.html.form.Form;
|
||||||
import org.apache.wicket.markup.html.form.TextField;
|
|
||||||
import org.apache.wicket.markup.html.list.ListItem;
|
import org.apache.wicket.markup.html.list.ListItem;
|
||||||
import org.apache.wicket.markup.html.list.ListView;
|
import org.apache.wicket.markup.html.list.ListView;
|
||||||
import org.apache.wicket.markup.html.panel.EmptyPanel;
|
import org.apache.wicket.markup.html.panel.EmptyPanel;
|
||||||
import org.apache.wicket.markup.html.panel.Panel;
|
import org.apache.wicket.markup.html.panel.Panel;
|
||||||
import org.apache.wicket.model.LoadableDetachableModel;
|
import org.apache.wicket.model.LoadableDetachableModel;
|
||||||
import org.apache.wicket.model.Model;
|
|
||||||
import org.apache.wicket.spring.injection.annot.SpringBean;
|
import org.apache.wicket.spring.injection.annot.SpringBean;
|
||||||
import org.odlabs.wiquery.ui.dialog.Dialog;
|
import org.odlabs.wiquery.ui.dialog.Dialog;
|
||||||
|
|
||||||
|
import org.springframework.data.domain.Sort;
|
||||||
import se.su.dsv.scipro.data.dataobjects.Employee;
|
import se.su.dsv.scipro.data.dataobjects.Employee;
|
||||||
import se.su.dsv.scipro.match.dao.interfaces.KeywordTypeDao;
|
import se.su.dsv.scipro.match.dao.interfaces.KeywordTypeDao;
|
||||||
import se.su.dsv.scipro.match.dao.interfaces.SupervisorDao;
|
import se.su.dsv.scipro.match.dao.interfaces.SupervisorDao;
|
||||||
import se.su.dsv.scipro.match.dataobject.Keyword;
|
import se.su.dsv.scipro.match.dataobject.Keyword;
|
||||||
import se.su.dsv.scipro.match.dataobject.KeywordType;
|
import se.su.dsv.scipro.match.dataobject.KeywordType;
|
||||||
|
import se.su.dsv.scipro.reusable.EmployeeAutoComplete;
|
||||||
import se.su.dsv.scipro.springdata.services.SupervisorService;
|
import se.su.dsv.scipro.springdata.services.SupervisorService;
|
||||||
|
|
||||||
public class AdminSupervisorKeywordPanel extends Panel {
|
public class AdminSupervisorKeywordPanel extends Panel {
|
||||||
@ -31,7 +31,7 @@ public class AdminSupervisorKeywordPanel extends Panel {
|
|||||||
private static final long serialVersionUID = -6390936928562430893L;
|
private static final long serialVersionUID = -6390936928562430893L;
|
||||||
|
|
||||||
@SpringBean
|
@SpringBean
|
||||||
private SupervisorDao supervisorDao;
|
private SupervisorDao supervisorDao;
|
||||||
|
|
||||||
@SpringBean
|
@SpringBean
|
||||||
private SupervisorService supervisorService;
|
private SupervisorService supervisorService;
|
||||||
@ -39,57 +39,60 @@ public class AdminSupervisorKeywordPanel extends Panel {
|
|||||||
@SpringBean
|
@SpringBean
|
||||||
private KeywordTypeDao keywordTypeDao;
|
private KeywordTypeDao keywordTypeDao;
|
||||||
|
|
||||||
public AdminSupervisorKeywordPanel(String str) {
|
public AdminSupervisorKeywordPanel(String str) {
|
||||||
super(str);
|
super(str);
|
||||||
Dialog dialog = new Dialog("detailsDialog");
|
Dialog dialog = new Dialog("detailsDialog");
|
||||||
setUpDialog(dialog);
|
setUpDialog(dialog);
|
||||||
WebMarkupContainer tableContainer = new WebMarkupContainer("table");
|
final WebMarkupContainer tableContainer = new WebMarkupContainer("table");
|
||||||
TextField<String> supervisorField = new TextField<String>("supervisorField", new Model<String>());
|
final EmployeeAutoComplete autoCompleteObjectField = createDsvAutocompleteComponent(tableContainer);
|
||||||
StringBuffer supervisorName = new StringBuffer();
|
add(autoCompleteObjectField.setOutputMarkupId(true));
|
||||||
add(new FilterForm(tableContainer, supervisorField, supervisorName));
|
add(new Form<Void>("showAllForm").add(createShowAllButton(tableContainer, autoCompleteObjectField)));
|
||||||
setUpTable(dialog, tableContainer, supervisorName);
|
setUpTable(dialog, tableContainer, autoCompleteObjectField);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setUpDialog(Dialog dialog) {
|
private EmployeeAutoComplete createDsvAutocompleteComponent(final WebMarkupContainer tableContainer) {
|
||||||
dialog.setModal(true);
|
return new EmployeeAutoComplete("autoComplete") {
|
||||||
dialog.setAutoOpen(false);
|
private static final long serialVersionUID = 8758471618644888953L;
|
||||||
dialog.setWidth(500);
|
|
||||||
dialog.setHeight(400);
|
|
||||||
dialog.setTitle("Supervisor details");
|
|
||||||
dialog.add(new EmptyPanel("dialogContent"));
|
|
||||||
add(dialog.setOutputMarkupId(true));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void getSortOrder(StringBuffer sortDirection, StringBuffer orderBy__, String orderBy, final StringBuffer supervisorName) {
|
@Override
|
||||||
if(!supervisorName.toString().isEmpty()) {
|
public void action(AjaxRequestTarget pTarget, Employee newSelection) {
|
||||||
String addToSearch = "true";
|
pTarget.addComponent(tableContainer);
|
||||||
}
|
|
||||||
if ((sortDirection.toString().isEmpty() && !orderBy.equals("keywords.all.size")) || sortDirection.toString().equalsIgnoreCase("asc")) {
|
|
||||||
sortDirection.delete(0, sortDirection.length());
|
|
||||||
sortDirection.append("desc");
|
|
||||||
} else {
|
|
||||||
sortDirection.delete(0, sortDirection.length());
|
|
||||||
sortDirection.append("asc");
|
|
||||||
}
|
|
||||||
orderBy__.delete(0, orderBy__.length());
|
|
||||||
orderBy__.append(orderBy);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private List<Employee> addEmployeesToList(final StringBuffer supervisorName, List<Employee> employeeList) {
|
|
||||||
List<Employee> employeeListName = new ArrayList<Employee>();
|
|
||||||
for(Employee employee : employeeList) {
|
|
||||||
if(employee.getNameAsString().equals(supervisorName.toString())) {
|
|
||||||
employeeListName.add(employee);
|
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
if(!employeeListName.isEmpty()) {
|
|
||||||
return employeeListName;
|
|
||||||
}
|
|
||||||
return employeeList;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadEmployeeList(List<Employee> employeeList, StringBuffer orderBy, StringBuffer sortDirection) {
|
private AjaxButton createShowAllButton(final WebMarkupContainer tableContainer, final EmployeeAutoComplete autoCompleteObjectField) {
|
||||||
|
return new AjaxButton("showAllButton") { //button to click for performing overriden method
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
@Override
|
||||||
|
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
|
||||||
|
List<Employee> employeeList = new ArrayList<Employee>();
|
||||||
|
employeeList.addAll(supervisorService.findAllEmployees(new Sort(Sort.Direction.ASC, "user.lastName")));
|
||||||
|
tableContainer.get("supervisorList").setDefaultModelObject(employeeList);
|
||||||
|
autoCompleteObjectField.setDefaultModelObject(null);
|
||||||
|
autoCompleteObjectField.clearInput();
|
||||||
|
target.addComponent(tableContainer);
|
||||||
|
target.addComponent(autoCompleteObjectField);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setUpDialog(Dialog dialog) {
|
||||||
|
dialog.setModal(true);
|
||||||
|
dialog.setAutoOpen(false);
|
||||||
|
dialog.setWidth(500);
|
||||||
|
dialog.setHeight(400);
|
||||||
|
dialog.setTitle("Supervisor details");
|
||||||
|
dialog.add(new EmptyPanel("dialogContent"));
|
||||||
|
add(dialog.setOutputMarkupId(true));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void changeOrderBy(StringBuffer orderBy, String newOrderBy) {
|
||||||
|
orderBy.delete(0, orderBy.length());
|
||||||
|
orderBy.append(newOrderBy);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadEmployeeList(List<Employee> employeeList, StringBuffer orderBy, StringBuffer sortDirection, StringBuffer previousOrderBy) {
|
||||||
KeywordType keywordType = keywordTypeDao.findByType(KeywordTypeDao.TYPE.REGULAR);
|
KeywordType keywordType = keywordTypeDao.findByType(KeywordTypeDao.TYPE.REGULAR);
|
||||||
if(orderBy.toString().equals("keywords.all.size")) {
|
if(orderBy.toString().equals("keywords.all.size")) {
|
||||||
keywordType = keywordTypeDao.findByType(KeywordTypeDao.TYPE.REGULAR);
|
keywordType = keywordTypeDao.findByType(KeywordTypeDao.TYPE.REGULAR);
|
||||||
@ -97,24 +100,46 @@ if(!supervisorName.toString().isEmpty()) {
|
|||||||
keywordType = keywordTypeDao.findByType(KeywordTypeDao.TYPE.RESEARCH_AREA);
|
keywordType = keywordTypeDao.findByType(KeywordTypeDao.TYPE.RESEARCH_AREA);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!orderBy.toString().equalsIgnoreCase(previousOrderBy.toString())) { // the direction should always be desc for numbers when there is a new sort term
|
||||||
|
sortDirection.delete(0, sortDirection.length());
|
||||||
|
sortDirection.append("desc");
|
||||||
|
}
|
||||||
|
|
||||||
if(sortDirection.toString().equalsIgnoreCase("asc")) {
|
if(sortDirection.toString().equalsIgnoreCase("asc")) {
|
||||||
for(Employee employee : supervisorService.findSupervisorDescDirection(keywordType.getName())) {
|
for(Employee employee : supervisorService.findSupervisorBySQL(keywordType.getName(), "asc")) {
|
||||||
if(!employeeList.contains(employee)) {
|
if(!employeeList.contains(employee)) {
|
||||||
employeeList.add(employee);
|
employeeList.add(employee);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else if(sortDirection.toString().equalsIgnoreCase("desc")) {
|
||||||
for(Employee employee : supervisorService.findSupervisorDescDirection(keywordType.getName())) {
|
for(Employee employee : supervisorService.findSupervisorBySQL(keywordType.getName(), "desc")) {
|
||||||
if(!employeeList.contains(employee)) {
|
if(!employeeList.contains(employee)) {
|
||||||
employeeList.add(employee);
|
employeeList.add(employee);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
changePreviousOrderBy(previousOrderBy, orderBy);
|
||||||
|
if(sortDirection.toString().equalsIgnoreCase("asc")) {
|
||||||
|
changeSortDirection(sortDirection, "desc");
|
||||||
|
} else if(sortDirection.toString().equalsIgnoreCase("desc")) {
|
||||||
|
changeSortDirection(sortDirection, "asc");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setUpTable(final Dialog dialog, final WebMarkupContainer tableContainer, final StringBuffer supervisorName) {
|
private void changeSortDirection(StringBuffer sortDirection, String direction) {
|
||||||
|
sortDirection.delete(0, sortDirection.length());
|
||||||
|
sortDirection.append(direction);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void changePreviousOrderBy(StringBuffer previousOrderBy, StringBuffer orderBy) {
|
||||||
|
previousOrderBy.delete(0, previousOrderBy.length());
|
||||||
|
previousOrderBy.append(orderBy.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setUpTable(final Dialog dialog, final WebMarkupContainer tableContainer, final EmployeeAutoComplete autoCompleteObjectField) {
|
||||||
final StringBuffer sortDirection = new StringBuffer();
|
final StringBuffer sortDirection = new StringBuffer();
|
||||||
final StringBuffer orderBy = new StringBuffer();
|
final StringBuffer orderBy = new StringBuffer();
|
||||||
|
final StringBuffer previousOrderBy = new StringBuffer();
|
||||||
|
|
||||||
final ListView<Employee> dataView = new ListView<Employee>("supervisorList", new LoadableDetachableModel<List<Employee>>() {
|
final ListView<Employee> dataView = new ListView<Employee>("supervisorList", new LoadableDetachableModel<List<Employee>>() {
|
||||||
private static final long serialVersionUID = -2395796971679213814L;
|
private static final long serialVersionUID = -2395796971679213814L;
|
||||||
@ -122,25 +147,28 @@ if(!supervisorName.toString().isEmpty()) {
|
|||||||
@Override
|
@Override
|
||||||
protected List<Employee> load() {
|
protected List<Employee> load() {
|
||||||
List<Employee> employeeList = new ArrayList<Employee>();
|
List<Employee> employeeList = new ArrayList<Employee>();
|
||||||
if(!orderBy.toString().equals("areas.all.size") && !orderBy.toString().equals("keywords.all.size")) {
|
if(autoCompleteObjectField.getDefaultModelObject() != null) {
|
||||||
org.springframework.data.domain.Sort sorter;
|
employeeList.add((Employee) autoCompleteObjectField.getDefaultModelObject());
|
||||||
if (sortDirection.toString().isEmpty() || sortDirection.toString().equalsIgnoreCase("asc")) {
|
|
||||||
sorter = new org.springframework.data.domain.Sort(org.springframework.data.domain.Sort.Direction.ASC, "user.lastName");
|
|
||||||
employeeList.addAll(supervisorService.findAllEmployees(sorter));
|
|
||||||
} else {
|
|
||||||
sorter = new org.springframework.data.domain.Sort(org.springframework.data.domain.Sort.Direction.DESC, "user.lastName");
|
|
||||||
employeeList.addAll(supervisorService.findAllEmployees(sorter));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
loadEmployeeList(employeeList, orderBy, sortDirection);
|
|
||||||
}
|
|
||||||
if(supervisorName.toString().isEmpty()) {
|
|
||||||
return employeeList;
|
return employeeList;
|
||||||
|
} else if (orderBy.toString().isEmpty()) {
|
||||||
|
employeeList.addAll(supervisorService.findAllEmployees(new Sort(Sort.Direction.ASC, "user.lastName"))); // the direction should always be asc for characters when there is a new sort term
|
||||||
|
changeSortDirection(sortDirection, "desc");
|
||||||
|
previousOrderBy.append("user.lastName");
|
||||||
|
} else if (orderBy.toString().equals("user.lastName")) { // if there has been a previous search and the search term was different than the present search term or direction should be asc
|
||||||
|
if((!previousOrderBy.toString().isEmpty() && !previousOrderBy.toString().equals(orderBy.toString())) || sortDirection.toString().equalsIgnoreCase("asc")) {
|
||||||
|
employeeList.addAll(supervisorService.findAllEmployees(new Sort(Sort.Direction.ASC, "user.lastName")));
|
||||||
|
changeSortDirection(sortDirection, "desc");
|
||||||
|
} else if(sortDirection.toString().equalsIgnoreCase("desc")){
|
||||||
|
employeeList.addAll(supervisorService.findAllEmployees(new Sort(Sort.Direction.DESC, "user.lastName")));
|
||||||
|
changeSortDirection(sortDirection, "asc");
|
||||||
|
}
|
||||||
|
changePreviousOrderBy(previousOrderBy, orderBy);
|
||||||
|
} else {
|
||||||
|
loadEmployeeList(employeeList, orderBy, sortDirection, previousOrderBy);
|
||||||
}
|
}
|
||||||
return addEmployeesToList(supervisorName, employeeList);
|
return employeeList;
|
||||||
}
|
}
|
||||||
}) {
|
}) {
|
||||||
|
|
||||||
private static final long serialVersionUID = 3572766096237883198L;
|
private static final long serialVersionUID = 3572766096237883198L;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -149,9 +177,7 @@ if(!supervisorName.toString().isEmpty()) {
|
|||||||
List<Keyword> areaKeywords = supervisor.getKeywords().getFiltered(KeywordTypeDao.TYPE.RESEARCH_AREA.toDbName());
|
List<Keyword> areaKeywords = supervisor.getKeywords().getFiltered(KeywordTypeDao.TYPE.RESEARCH_AREA.toDbName());
|
||||||
List<Keyword> regularKeywords = supervisor.getKeywords().getFiltered(KeywordTypeDao.TYPE.REGULAR.toDbName());
|
List<Keyword> regularKeywords = supervisor.getKeywords().getFiltered(KeywordTypeDao.TYPE.REGULAR.toDbName());
|
||||||
final AjaxLink<Void> detailsLink = new AjaxLink<Void>("detailsLink") {
|
final AjaxLink<Void> detailsLink = new AjaxLink<Void>("detailsLink") {
|
||||||
|
|
||||||
private static final long serialVersionUID = 8902222410746133732L;
|
private static final long serialVersionUID = 8902222410746133732L;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(AjaxRequestTarget target) {
|
public void onClick(AjaxRequestTarget target) {
|
||||||
target.addComponent(dialog);
|
target.addComponent(dialog);
|
||||||
@ -172,15 +198,15 @@ if(!supervisorName.toString().isEmpty()) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
final AjaxLink<Void> nameSortLink = new AjaxLink<Void>("nameSortLink") {
|
final AjaxLink<Void> nameSortLink = new AjaxLink<Void>("nameSortLink") {
|
||||||
private static final long serialVersionUID = -6459164267551936706L;
|
private static final long serialVersionUID = -6459164267551936706L;
|
||||||
@Override
|
@Override
|
||||||
public void onClick(AjaxRequestTarget target) {
|
public void onClick(AjaxRequestTarget target) {
|
||||||
getSortOrder(sortDirection, orderBy, "user.lastName", supervisorName);
|
changeOrderBy(orderBy, "user.lastName");
|
||||||
target.addComponent(tableContainer);
|
target.addComponent(tableContainer);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
tableContainer.add(nameSortLink);
|
tableContainer.add(nameSortLink);
|
||||||
|
|
||||||
final AjaxLink<Void> numberOfAreasSortLink = new AjaxLink<Void>("numberOfAreasSortLink") {
|
final AjaxLink<Void> numberOfAreasSortLink = new AjaxLink<Void>("numberOfAreasSortLink") {
|
||||||
|
|
||||||
@ -188,7 +214,7 @@ if(!supervisorName.toString().isEmpty()) {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(AjaxRequestTarget target) {
|
public void onClick(AjaxRequestTarget target) {
|
||||||
getSortOrder(sortDirection, orderBy, "areas.all.size", supervisorName);
|
changeOrderBy(orderBy, "areas.all.size");
|
||||||
target.addComponent(tableContainer);
|
target.addComponent(tableContainer);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -200,35 +226,12 @@ if(!supervisorName.toString().isEmpty()) {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(AjaxRequestTarget target) {
|
public void onClick(AjaxRequestTarget target) {
|
||||||
getSortOrder(sortDirection, orderBy, "keywords.all.size", supervisorName);
|
changeOrderBy(orderBy, "keywords.all.size");
|
||||||
target.addComponent(tableContainer);
|
target.addComponent(tableContainer);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
tableContainer.add(numberOfRegularsSortLink);
|
tableContainer.add(numberOfRegularsSortLink);
|
||||||
tableContainer.add(dataView);
|
tableContainer.add(dataView);
|
||||||
add(tableContainer.setOutputMarkupId(true));
|
add(tableContainer.setOutputMarkupId(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
private class FilterForm extends Form<Void> {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 3488715734113880308L;
|
|
||||||
|
|
||||||
public FilterForm(final WebMarkupContainer tableContainer, final TextField<String> supervisorField, final StringBuffer supervisorName) {
|
|
||||||
super("filterForm");
|
|
||||||
AjaxButton filterButton = new AjaxButton("filterButton") {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = -8216928567709372986L;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
|
|
||||||
supervisorName.append(supervisorField.getModelObject());
|
|
||||||
target.addComponent(tableContainer);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
add(supervisorField);
|
|
||||||
add(filterButton);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user