Index: lams_central/src/java/org/lamsfoundation/lams/web/qb/QbCollectionController.java =================================================================== diff -u -r33b937e6fb979aa7a58fd0f33d1ecf474150155b -r8d2337141f10b26a11e9730f9c44d53a96fcc062 --- lams_central/src/java/org/lamsfoundation/lams/web/qb/QbCollectionController.java (.../QbCollectionController.java) (revision 33b937e6fb979aa7a58fd0f33d1ecf474150155b) +++ lams_central/src/java/org/lamsfoundation/lams/web/qb/QbCollectionController.java (.../QbCollectionController.java) (revision 8d2337141f10b26a11e9730f9c44d53a96fcc062) @@ -34,7 +34,6 @@ import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; -import org.lamsfoundation.lams.qb.model.QbCollection; import org.lamsfoundation.lams.qb.model.QbQuestion; import org.lamsfoundation.lams.qb.service.IQbService; import org.lamsfoundation.lams.usermanagement.dto.UserDTO; @@ -71,19 +70,7 @@ @RequestMapping("/show") public String showUserCollections(Model model) throws Exception { Integer userId = getUserId(); - List collections = qbService.getUserCollections(userId); - for (QbCollection collection : collections) { - collection.setShareableWithOrganisations( - qbService.getShareableWithOrganisations(collection.getUid(), userId)); - } - - QbCollection privateCollection = qbService.getUserPrivateCollection(userId); - collections.add(privateCollection); - - QbCollection publicCollection = qbService.getPublicCollection(); - collections.add(publicCollection); - - model.addAttribute("collections", collections); + model.addAttribute("collections", qbService.getUserCollections(userId)); return "qb/collection"; } @@ -187,8 +174,9 @@ @RequestMapping("/addCollectionQuestions") @ResponseBody - public void addCollectionQuestions(@RequestParam long sourceCollectionUid, @RequestParam long targetCollectionUid, - @RequestParam boolean copy, @RequestParam String included, @RequestParam String excluded) + public void addCollectionQuestions(@RequestParam(required = false) Long sourceCollectionUid, + @RequestParam long targetCollectionUid, @RequestParam boolean copy, + @RequestParam(required = false) String included, @RequestParam(required = false) String excluded) throws IOException { if (StringUtils.isBlank(excluded)) { ArrayNode includedJSON = JsonUtil.readArray(included); Index: lams_central/src/java/org/lamsfoundation/lams/web/qb/QbStatsController.java =================================================================== diff -u -raccfdd9d97b1e9f4db2c48861a2f5ea1d065a3cb -r8d2337141f10b26a11e9730f9c44d53a96fcc062 --- lams_central/src/java/org/lamsfoundation/lams/web/qb/QbStatsController.java (.../QbStatsController.java) (revision accfdd9d97b1e9f4db2c48861a2f5ea1d065a3cb) +++ lams_central/src/java/org/lamsfoundation/lams/web/qb/QbStatsController.java (.../QbStatsController.java) (revision 8d2337141f10b26a11e9730f9c44d53a96fcc062) @@ -22,10 +22,18 @@ package org.lamsfoundation.lams.web.qb; +import java.util.Collection; + +import javax.servlet.http.HttpSession; + import org.apache.log4j.Logger; import org.lamsfoundation.lams.qb.dto.QbStatsDTO; +import org.lamsfoundation.lams.qb.model.QbCollection; import org.lamsfoundation.lams.qb.service.IQbService; +import org.lamsfoundation.lams.usermanagement.dto.UserDTO; import org.lamsfoundation.lams.util.MessageService; +import org.lamsfoundation.lams.web.session.SessionManager; +import org.lamsfoundation.lams.web.util.AttributeNames; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Controller; @@ -49,6 +57,18 @@ public String showStats(@RequestParam long qbQuestionUid, Model model) throws Exception { QbStatsDTO stats = qbService.getQbQuestionStats(qbQuestionUid); model.addAttribute("stats", stats); + + Integer userId = getUserId(); + Collection collections = qbService.getUserCollections(userId); + collections.removeAll(qbService.getQuestionCollections(qbQuestionUid)); + model.addAttribute("collections", collections); + return "qb/stats"; } + + private Integer getUserId() { + HttpSession ss = SessionManager.getSession(); + UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER); + return user != null ? user.getUserID() : null; + } } \ No newline at end of file Index: lams_central/web/qb/stats.jsp =================================================================== diff -u -r2cbaf1342c0f195d608134205e7f7d9765bf97b0 -r8d2337141f10b26a11e9730f9c44d53a96fcc062 --- lams_central/web/qb/stats.jsp (.../stats.jsp) (revision 2cbaf1342c0f195d608134205e7f7d9765bf97b0) +++ lams_central/web/qb/stats.jsp (.../stats.jsp) (revision 8d2337141f10b26a11e9730f9c44d53a96fcc062) @@ -3,6 +3,8 @@ <%@ taglib uri="tags-fmt" prefix="fmt"%> <%@ taglib uri="tags-core" prefix="c"%> + + @@ -41,10 +43,27 @@ drawChart('bar', 'chartDiv', ${stats.answersJSON}); $("time.timeago").timeago(); }); + + // add or copy questions to a collection + function addCollectionQuestions() { + var targetCollectionUid = $('#targetCollectionSelect').val(); + $.ajax({ + 'url' : 'qb/collection/addCollectionQuestions.do', + 'type' : 'POST', + 'dataType' : 'text', + 'data' : { + 'targetCollectionUid' : targetCollectionUid, + 'copy' : false, + 'included' : JSON.stringify([${question.uid}]) + }, + 'cache' : false + }).done(function(){ + document.location.reload(); + }); + } -
@@ -95,6 +114,20 @@
+ +
+ Transfer questions to + + +
+
+

Options

Index: lams_common/src/java/org/lamsfoundation/lams/qb/dao/hibernate/QbDAO.java =================================================================== diff -u -r33b937e6fb979aa7a58fd0f33d1ecf474150155b -r8d2337141f10b26a11e9730f9c44d53a96fcc062 --- lams_common/src/java/org/lamsfoundation/lams/qb/dao/hibernate/QbDAO.java (.../QbDAO.java) (revision 33b937e6fb979aa7a58fd0f33d1ecf474150155b) +++ lams_common/src/java/org/lamsfoundation/lams/qb/dao/hibernate/QbDAO.java (.../QbDAO.java) (revision 8d2337141f10b26a11e9730f9c44d53a96fcc062) @@ -246,7 +246,7 @@ @Override public List getQuestionCollections(long qbQuestionUid) { return getSession().createNativeQuery(FIND_QUESTION_COLLECTIONS).setParameter("qbQuestionUid", qbQuestionUid) - .list(); + .addEntity(QbCollection.class).list(); } @SuppressWarnings("unchecked") Index: lams_common/src/java/org/lamsfoundation/lams/qb/service/IQbService.java =================================================================== diff -u -r33b937e6fb979aa7a58fd0f33d1ecf474150155b -r8d2337141f10b26a11e9730f9c44d53a96fcc062 --- lams_common/src/java/org/lamsfoundation/lams/qb/service/IQbService.java (.../IQbService.java) (revision 33b937e6fb979aa7a58fd0f33d1ecf474150155b) +++ lams_common/src/java/org/lamsfoundation/lams/qb/service/IQbService.java (.../IQbService.java) (revision 8d2337141f10b26a11e9730f9c44d53a96fcc062) @@ -59,13 +59,17 @@ List getUserCollections(int userId); + List getUserOwnCollections(int userId); + List getCollectionQuestions(long collectionUid); List getCollectionQuestions(long collectionUid, Integer offset, Integer limit, String orderBy, String orderDirection, String search); int countCollectionQuestions(long collectionUid, String search); + List getQuestionCollections(long qbQuestionUid); + QbCollection addCollection(int userId, String name); void removeCollection(long collectionUid); Index: lams_common/src/java/org/lamsfoundation/lams/qb/service/QbService.java =================================================================== diff -u -r33b937e6fb979aa7a58fd0f33d1ecf474150155b -r8d2337141f10b26a11e9730f9c44d53a96fcc062 --- lams_common/src/java/org/lamsfoundation/lams/qb/service/QbService.java (.../QbService.java) (revision 33b937e6fb979aa7a58fd0f33d1ecf474150155b) +++ lams_common/src/java/org/lamsfoundation/lams/qb/service/QbService.java (.../QbService.java) (revision 8d2337141f10b26a11e9730f9c44d53a96fcc062) @@ -271,7 +271,7 @@ @Override @SuppressWarnings("unchecked") - public List getUserCollections(int userId) { + public List getUserOwnCollections(int userId) { Map map = new HashMap<>(); map.put("userId", userId); map.put("personal", false); @@ -295,6 +295,11 @@ } @Override + public List getQuestionCollections(long qbQuestionUid) { + return qbDAO.getQuestionCollections(qbQuestionUid); + } + + @Override public QbCollection addCollection(int userId, String name) { QbCollection collection = new QbCollection(); collection.setName(name); @@ -380,7 +385,7 @@ @Override public boolean removeQuestionFromCollection(long collectionUid, long qbQuestionUid) { - Collection collections = qbDAO.getQuestionCollections(qbQuestionUid); + Collection collections = getQuestionCollections(qbQuestionUid); int size = collections.size(); if (size <= 1) { // if the question is in its last collection, try to remove it permanently @@ -429,6 +434,22 @@ return result; } + @Override + public List getUserCollections(int userId) { + List collections = getUserOwnCollections(userId); + for (QbCollection collection : collections) { + collection.setShareableWithOrganisations(getShareableWithOrganisations(collection.getUid(), userId)); + } + + QbCollection privateCollection = getUserPrivateCollection(userId); + collections.add(privateCollection); + + QbCollection publicCollection = getPublicCollection(); + collections.add(publicCollection); + + return collections; + } + public void setQbDAO(IQbDAO qbDAO) { this.qbDAO = qbDAO; }