added functionality to order checklistTemplates and they are now added in the correct order
This commit is contained in:
parent
09a747dddf
commit
6f1d713c3f
resources/db_update_scripts
src/main/java/se/su/dsv/scipro
admin/panels
checklists/panels
data
dao
dataobjects
@ -1 +1,2 @@
|
||||
ALTER TABLE `worker_data` ADD `lastSuccessfulRun` DATETIME NOT NULL DEFAULT '2011-11-28 13:33:37' AFTER `lastRun`;
|
||||
ALTER TABLE `worker_data` ADD `lastSuccessfulRun` DATETIME NOT NULL DEFAULT '2011-11-28 13:33:37' AFTER `lastRun`;
|
||||
ALTER TABLE `checklist_template` ADD `templateNumber` INT NOT NULL DEFAULT '999'
|
@ -34,12 +34,13 @@
|
||||
<th class="rounded-left-top">Name</th>
|
||||
<th>Categories</th>
|
||||
<th>Questions</th>
|
||||
<th></th>
|
||||
<th class="rounded-right-top">Delete</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<td colspan="4" class="rounded-foot"> </td>
|
||||
<td colspan="5" class="rounded-foot"> </td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
<tbody>
|
||||
@ -48,6 +49,15 @@
|
||||
wicket:id="templateName"></span></a></span></td>
|
||||
<td><span wicket:id="categories"></span></td>
|
||||
<td><span wicket:id="templateOuestion"></span></td>
|
||||
<td><div class="split-row">
|
||||
<a href="#" wicket:id="moveUpLink"><img
|
||||
wicket:id="upArrowImage" /></a>
|
||||
</div>
|
||||
<div class="split-row">
|
||||
<a href="#" wicket:id="moveDownLink"><img
|
||||
wicket:id="downArrowImage" alt="Down" title="Down" /></a>
|
||||
</div>
|
||||
</td>
|
||||
<td><a href="#" wicket:id="delete">
|
||||
<img wicket:id="deleteIcon" alt="Delete" title="Delete" />
|
||||
</a></td>
|
||||
|
@ -58,8 +58,11 @@ public class AdminListCheckListTemplatePanel extends Panel{
|
||||
private Form<CheckListTemplate> form;
|
||||
|
||||
private TextField<String> nameField;
|
||||
private AjaxLink newLink;
|
||||
private AjaxLink<Void> newLink;
|
||||
private WebMarkupContainer container;
|
||||
private int NO_NUMBER = 999;
|
||||
private ListView<CheckListTemplate> checkListTemplates;
|
||||
private int nrOfTemplates = 0;
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ -78,6 +81,8 @@ public class AdminListCheckListTemplatePanel extends Panel{
|
||||
dialog.add(tmpform);
|
||||
add(dialog);
|
||||
|
||||
templateNumberSetup();
|
||||
|
||||
|
||||
newLink = new AjaxLink<Void>("newLink") {
|
||||
|
||||
@ -118,6 +123,8 @@ public class AdminListCheckListTemplatePanel extends Panel{
|
||||
tmp.setName(nameField.getModelObject());
|
||||
|
||||
tmp.setCategories(categoryPanel.getSelectedCategories());
|
||||
List<CheckListTemplate> templates = checkListTemplateDao.findTemplates();
|
||||
tmp.setTemplateNumber(templates.size()-1);
|
||||
checkListTemplateDao.save(tmp);
|
||||
target.addComponent(container);
|
||||
dialog.close(target);
|
||||
@ -144,16 +151,6 @@ public class AdminListCheckListTemplatePanel extends Panel{
|
||||
};
|
||||
|
||||
add(newLink);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
final IModel<List<CheckListTemplate>> checkListTemplateModel = new LoadableDetachableModel<List<CheckListTemplate>>() {
|
||||
|
||||
@ -161,13 +158,15 @@ public class AdminListCheckListTemplatePanel extends Panel{
|
||||
|
||||
@Override
|
||||
protected List<CheckListTemplate> load() {
|
||||
return checkListTemplateDao.findAll();
|
||||
List<CheckListTemplate> templates = checkListTemplateDao.findTemplates();
|
||||
nrOfTemplates = templates.size();
|
||||
return templates;
|
||||
}
|
||||
};
|
||||
|
||||
container = new WebMarkupContainer("container");
|
||||
container.setOutputMarkupId(true);
|
||||
ListView<CheckListTemplate> checkListTemplates = new ListView<CheckListTemplate>("checkListTemplates", checkListTemplateModel) {
|
||||
checkListTemplates = new ListView<CheckListTemplate>("checkListTemplates", checkListTemplateModel) {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ -183,6 +182,38 @@ public class AdminListCheckListTemplatePanel extends Panel{
|
||||
MultiLineLabel categoriesLabel = new MultiLineLabel("categories", new Model<String>(labelMsg));
|
||||
|
||||
|
||||
AjaxLink<Void> moveUpLink = new AjaxLink<Void>("moveUpLink") {
|
||||
int itemPos = item.getModelObject().getTemplateNumber();
|
||||
private static final long serialVersionUID = 1529565679210978293L;
|
||||
@Override
|
||||
public void onClick(AjaxRequestTarget target) {
|
||||
swapTemplates(itemPos, itemPos - 1);
|
||||
target.addComponent(container);
|
||||
}
|
||||
};
|
||||
|
||||
AjaxLink<Void> moveDownLink = new AjaxLink<Void>("moveDownLink") {
|
||||
int itemPos = item.getModelObject().getTemplateNumber();
|
||||
private static final long serialVersionUID = 1529565679210978293L;
|
||||
@Override
|
||||
public void onClick(AjaxRequestTarget target) {
|
||||
swapTemplates(itemPos, itemPos + 1);
|
||||
target.addComponent(container);
|
||||
}
|
||||
};
|
||||
moveUpLink.add(new ImageObject("upArrowImage", ImageObject.THIRTYTWO + ImageObject.UPARROW));
|
||||
moveDownLink.add(new ImageObject("downArrowImage", ImageObject.THIRTYTWO + ImageObject.DOWNARROW));
|
||||
item.add(moveUpLink);
|
||||
item.add(moveDownLink);
|
||||
|
||||
if(item.getModelObject().getTemplateNumber() == 0){
|
||||
moveUpLink.setVisible(false);
|
||||
}else if(item.getModelObject().getTemplateNumber() == (nrOfTemplates-1)){
|
||||
moveDownLink.setVisible(false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
AjaxLink<Void> deleteLink = new AjaxLink<Void>("delete") {
|
||||
|
||||
@ -296,6 +327,28 @@ public class AdminListCheckListTemplatePanel extends Panel{
|
||||
|
||||
return labelMsg;
|
||||
}
|
||||
|
||||
private void templateNumberSetup(){
|
||||
List<CheckListTemplate> templates = checkListTemplateDao.findAll();
|
||||
for(CheckListTemplate t : templates){
|
||||
if(t.getTemplateNumber() == NO_NUMBER){
|
||||
t.setTemplateNumber(templates.indexOf(t));
|
||||
t = checkListTemplateDao.save(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void swapTemplates(int index1, int index2){
|
||||
List<CheckListTemplate> templates = checkListTemplateDao.findTemplates();
|
||||
if(index1 >= 0 && index2 < templates.size()){
|
||||
templates.get(index1).setTemplateNumber(index2);
|
||||
templates.get(index2).setTemplateNumber(index1);
|
||||
checkListTemplateDao.save(templates.get(index1));
|
||||
checkListTemplateDao.save(templates.get(index2));
|
||||
System.out.println("Swapped " + index1 + " and " + index2);
|
||||
checkListTemplates.detach();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -3,8 +3,13 @@
|
||||
xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd">
|
||||
<body>
|
||||
<wicket:panel>
|
||||
<a href=# wicket:id="addAllLink">Add Empirical Research Checklists</a>
|
||||
<a href="#" wicket:id="infoLink"><img src="images/icons/24/help2.png" alt="Partner info"/></a>
|
||||
<div wicket:id="listTemplatePanel"></div>
|
||||
<a href=# wicket:id="addAllLink">Add all</a>
|
||||
<div wicket:id="dialog">
|
||||
<div class="info-box rounded-box last span-10" wicket:id="info"></div>
|
||||
</div>
|
||||
</wicket:panel>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
||||
|
@ -1,27 +1,14 @@
|
||||
package se.su.dsv.scipro.checklists.panels;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.wicket.PageParameters;
|
||||
import org.apache.wicket.ajax.AjaxRequestTarget;
|
||||
import org.apache.wicket.ajax.markup.html.AjaxLink;
|
||||
import org.apache.wicket.markup.html.WebMarkupContainer;
|
||||
import org.apache.wicket.markup.html.basic.Label;
|
||||
import org.apache.wicket.markup.html.list.ListItem;
|
||||
import org.apache.wicket.markup.html.list.ListView;
|
||||
import org.apache.wicket.markup.html.panel.EmptyPanel;
|
||||
import org.apache.wicket.markup.html.panel.Panel;
|
||||
import org.apache.wicket.model.IModel;
|
||||
import org.apache.wicket.model.LoadableDetachableModel;
|
||||
import org.apache.wicket.model.PropertyModel;
|
||||
import org.apache.wicket.model.Model;
|
||||
import org.apache.wicket.spring.injection.annot.SpringBean;
|
||||
import org.odlabs.wiquery.ui.dialog.Dialog;
|
||||
|
||||
import se.su.dsv.scipro.data.dao.interfaces.CheckListDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.CheckListTemplateDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.ProjectDao;
|
||||
import se.su.dsv.scipro.data.dataobjects.CheckList;
|
||||
import se.su.dsv.scipro.data.dataobjects.CheckListTemplate;
|
||||
import se.su.dsv.scipro.data.dataobjects.Project;
|
||||
import se.su.dsv.scipro.data.enums.CheckListRole;
|
||||
import se.su.dsv.scipro.data.facade.ProjectFacade;
|
||||
@ -40,8 +27,11 @@ public class SupervisorAddChecklistPanel extends Panel{
|
||||
@SpringBean
|
||||
private ProjectFacade facade;
|
||||
|
||||
private Dialog dialog;
|
||||
|
||||
public SupervisorAddChecklistPanel(String id, final PageParameters pp, final Project project) {
|
||||
super(id);
|
||||
dialogSetup();
|
||||
|
||||
AjaxLink<Void> addAllLink = new AjaxLink<Void>("addAllLink"){
|
||||
|
||||
@ -60,7 +50,32 @@ public class SupervisorAddChecklistPanel extends Panel{
|
||||
|
||||
add(new ListCheckListTemplatePanel("listTemplatePanel", pp, CheckListRole.SUPERVISOR));
|
||||
add(addAllLink);
|
||||
}
|
||||
}
|
||||
|
||||
private void dialogSetup(){
|
||||
dialog = new Dialog("dialog");
|
||||
dialog.setModal(true);
|
||||
dialog.setAutoOpen(false);
|
||||
dialog.setWidth(500);
|
||||
dialog.setHeight(300);
|
||||
dialog.add(new Label("info", new Model<String>("test")));
|
||||
add(dialog);
|
||||
|
||||
AjaxLink<Void> infoLink = new AjaxLink<Void>("infoLink"){
|
||||
private static final long serialVersionUID = 1L;
|
||||
@Override
|
||||
public void onClick(AjaxRequestTarget target) {
|
||||
dialog.replace(new Label("info", new Model<String>("Delete those checklists wich are not relevant for your thesis project.\n" +
|
||||
"If you want other checklists then those avalible you can suggest them to thesissupport@dsv.su.se and they will be added to the pool. "+
|
||||
"You can add checklists manually from the templates avalible on the right side by clicking the link.")));
|
||||
|
||||
target.addComponent(dialog);
|
||||
dialog.setTitle("Checklist info");
|
||||
dialog.open(target);
|
||||
}
|
||||
};
|
||||
add(infoLink);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -12,9 +12,10 @@ public interface CheckListTemplateDao extends Dao<CheckListTemplate> {
|
||||
|
||||
public List<CheckListTemplate> findTemplatesByCategory(String category);
|
||||
|
||||
public List<CheckListTemplate> findTemplates();
|
||||
|
||||
/* New methods */
|
||||
List<CheckListTemplate> findTemplates(CheckListTemplateDao.Params params);
|
||||
public List<CheckListTemplate> findTemplates(CheckListTemplateDao.Params params);
|
||||
|
||||
/* New methods */
|
||||
long countTemplates(CheckListTemplateDao.Params params);
|
||||
|
@ -43,7 +43,8 @@ public class CheckListTemplateDaoJPAImp extends AbstractDaoJPAImp<CheckListTempl
|
||||
String q = "select distinct clt " +
|
||||
"from CheckListTemplate clt " +
|
||||
"join clt.categories c " +
|
||||
"where c.categoryName = :category";
|
||||
"where c.categoryName = :category "+
|
||||
"order by templateNumber";
|
||||
|
||||
TypedQuery<CheckListTemplate> query = em.createQuery(q, CheckListTemplate.class);
|
||||
|
||||
@ -58,6 +59,28 @@ public class CheckListTemplateDaoJPAImp extends AbstractDaoJPAImp<CheckListTempl
|
||||
});
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public List<CheckListTemplate> findTemplates() {
|
||||
return getJpaTemplate().execute(new JpaCallback<List<CheckListTemplate>>() {
|
||||
public List<CheckListTemplate> doInJpa(EntityManager em)
|
||||
throws PersistenceException {
|
||||
|
||||
String q = "select clt " +
|
||||
"from CheckListTemplate clt " +
|
||||
"order by templateNumber";
|
||||
|
||||
TypedQuery<CheckListTemplate> query = em.createQuery(q, CheckListTemplate.class);
|
||||
|
||||
try {
|
||||
return query.getResultList();
|
||||
} catch (NoResultException e) {
|
||||
return new ArrayList<CheckListTemplate>();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Transactional( readOnly=true )
|
||||
public List<CheckListTemplate> findTemplates(CheckListTemplateDao.Params params){
|
||||
return getJpaTemplate().execute(
|
||||
|
@ -19,7 +19,7 @@ import javax.persistence.Table;
|
||||
*/
|
||||
@Entity
|
||||
@Table(name="checklist_template")
|
||||
public class CheckListTemplate extends DomainObject {
|
||||
public class CheckListTemplate extends DomainObject implements Comparable<CheckListTemplate> {
|
||||
|
||||
private static final long serialVersionUID = 2959377496669050427L;
|
||||
|
||||
@ -30,6 +30,9 @@ public class CheckListTemplate extends DomainObject {
|
||||
@Column(nullable=false)
|
||||
private String name;
|
||||
|
||||
@Column
|
||||
private int templateNumber;
|
||||
|
||||
@Lob
|
||||
@ElementCollection
|
||||
private List<String> questions = new ArrayList<String>(1);
|
||||
@ -124,6 +127,14 @@ public class CheckListTemplate extends DomainObject {
|
||||
this.categories = categories;
|
||||
}
|
||||
|
||||
public int getTemplateNumber() {
|
||||
return templateNumber;
|
||||
}
|
||||
|
||||
public void setTemplateNumber(int templateNumber) {
|
||||
this.templateNumber = templateNumber;
|
||||
}
|
||||
|
||||
public void swapQuestions(int index1, int index2){
|
||||
String index2Question = new String(questions.get(index2));
|
||||
questions.set(index2, questions.get(index1));
|
||||
@ -162,6 +173,13 @@ public class CheckListTemplate extends DomainObject {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(CheckListTemplate other) {
|
||||
return this.templateNumber - other.templateNumber;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user