added order up down functionality
This commit is contained in:
parent
60660ea844
commit
0dd604593c
src/main/java/se/su/dsv/scipro
datatables/checklist
springdata
repos
serviceimpls
services
@ -75,9 +75,11 @@ public class CheckListTemplateDataPanel extends Panel {
|
|||||||
protected void onClick(IModel<CheckListTemplate> clicked, AjaxRequestTarget target, boolean up) {
|
protected void onClick(IModel<CheckListTemplate> clicked, AjaxRequestTarget target, boolean up) {
|
||||||
System.out.println(up);
|
System.out.println(up);
|
||||||
if (up){
|
if (up){
|
||||||
|
checklistTemplateService.upChecklistTemplate(clicked.getObject());
|
||||||
|
target.addComponent(table);
|
||||||
} else {
|
} else {
|
||||||
|
checklistTemplateService.downChecklistTemplate(clicked.getObject());
|
||||||
|
target.addComponent(table);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -12,6 +12,6 @@ import se.su.dsv.scipro.data.dataobjects.CheckListTemplate;
|
|||||||
@Transactional(readOnly = true)
|
@Transactional(readOnly = true)
|
||||||
public interface ChecklistTemplateRepo extends JpaRepository<CheckListTemplate, Long>, QueryDslPredicateExecutor<CheckListTemplate> {
|
public interface ChecklistTemplateRepo extends JpaRepository<CheckListTemplate, Long>, QueryDslPredicateExecutor<CheckListTemplate> {
|
||||||
|
|
||||||
//nothing here yet
|
CheckListTemplate findByTemplateNumber(int templateNumber);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -59,6 +59,40 @@ public class ChecklistTemplateServiceImpl extends AbstractQueryService<CheckList
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional ( readOnly = false )
|
||||||
|
@Override
|
||||||
|
public void upChecklistTemplate(CheckListTemplate checkListTemplate) {
|
||||||
|
//if there is one above
|
||||||
|
if (checklistTemplateRepo.findByTemplateNumber(checkListTemplate.getTemplateNumber() + 1) !=null){
|
||||||
|
//find the one with value 1 higher
|
||||||
|
CheckListTemplate downChecklistTemplate = checklistTemplateRepo.findByTemplateNumber(checkListTemplate.getTemplateNumber() + 1);
|
||||||
|
//give that one the one to be upped's value
|
||||||
|
downChecklistTemplate.setTemplateNumber(checkListTemplate.getTemplateNumber());
|
||||||
|
//increase the value of the one to be upped with 1
|
||||||
|
checkListTemplate.setTemplateNumber(checkListTemplate.getTemplateNumber() + 1);
|
||||||
|
//save both
|
||||||
|
checklistTemplateRepo.save(downChecklistTemplate);
|
||||||
|
checklistTemplateRepo.save(checkListTemplate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional ( readOnly = false )
|
||||||
|
@Override
|
||||||
|
public void downChecklistTemplate(CheckListTemplate checkListTemplate) {
|
||||||
|
//if there is one below
|
||||||
|
if (checklistTemplateRepo.findByTemplateNumber(checkListTemplate.getTemplateNumber() -1) != null){
|
||||||
|
//find the one with value 1 lower
|
||||||
|
CheckListTemplate upChecklistTemplate = checklistTemplateRepo.findByTemplateNumber(checkListTemplate.getTemplateNumber() -1);
|
||||||
|
//give that one the one to be downed's value
|
||||||
|
upChecklistTemplate.setTemplateNumber(checkListTemplate.getTemplateNumber());
|
||||||
|
//decrease the value of the one to be downed with 1
|
||||||
|
checkListTemplate.setTemplateNumber(checkListTemplate.getTemplateNumber() -1);
|
||||||
|
//save both
|
||||||
|
checklistTemplateRepo.save(upChecklistTemplate);
|
||||||
|
checklistTemplateRepo.save(checkListTemplate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private BooleanExpression filterStringIsCreatorName(String filterString){
|
private BooleanExpression filterStringIsCreatorName(String filterString){
|
||||||
return QCheckListTemplate.checkListTemplate.creator.firstName.contains(filterString).or(QCheckListTemplate.checkListTemplate.creator.lastName.contains(filterString));
|
return QCheckListTemplate.checkListTemplate.creator.firstName.contains(filterString).or(QCheckListTemplate.checkListTemplate.creator.lastName.contains(filterString));
|
||||||
}
|
}
|
||||||
|
@ -14,4 +14,5 @@ public interface ChecklistTemplateService extends CrudService<CheckListTemplate,
|
|||||||
Page<CheckListTemplate> find(String filterString, Pageable pageable);
|
Page<CheckListTemplate> find(String filterString, Pageable pageable);
|
||||||
Long count(String filterString);
|
Long count(String filterString);
|
||||||
void upChecklistTemplate(CheckListTemplate checkListTemplate);
|
void upChecklistTemplate(CheckListTemplate checkListTemplate);
|
||||||
|
void downChecklistTemplate(CheckListTemplate checkListTemplate);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user