Index: lams_central/src/java/org/lamsfoundation/lams/web/qb/QbCollectionController.java =================================================================== diff -u -r0952bdcd231fe03cb52b8d821bc6cc1882b7c369 -r70353119b16530e4ef2f9c82bdaba7ca825feeb0 --- lams_central/src/java/org/lamsfoundation/lams/web/qb/QbCollectionController.java (.../QbCollectionController.java) (revision 0952bdcd231fe03cb52b8d821bc6cc1882b7c369) +++ lams_central/src/java/org/lamsfoundation/lams/web/qb/QbCollectionController.java (.../QbCollectionController.java) (revision 70353119b16530e4ef2f9c82bdaba7ca825feeb0) @@ -22,13 +22,17 @@ package org.lamsfoundation.lams.web.qb; +import java.util.Collection; import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; 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; @@ -62,10 +66,26 @@ @RequestMapping("/show") public String showUserCollections(Model model) throws Exception { Integer userId = getUserId(); - model.addAttribute("collections", qbService.getUserCollections(userId)); + + Collection collections = qbService.getUserCollections(userId); + model.addAttribute("collections", collections); + + Map questionCount = collections.stream().collect( + Collectors.toMap(QbCollection::getUid, c -> qbService.getCountCollectionQuestions(c.getUid(), null))); + model.addAttribute("questionCount", questionCount); + return "qb/collectionList"; } + @RequestMapping("/showOne") + public String showOneCollection(@RequestParam long collectionUid, Model model) throws Exception { + model.addAttribute("collection", qbService.getCollection(collectionUid)); + model.addAttribute("availableOrganisations", + qbService.getShareableWithOrganisations(collectionUid, getUserId())); + model.addAttribute("questionCount", qbService.getCountCollectionQuestions(collectionUid, null)); + return "qb/collection"; + } + @RequestMapping("/getCollectionGridData") @ResponseBody public String getCollectionGridData(@RequestParam long collectionUid, HttpServletRequest request, @@ -82,7 +102,7 @@ int offset = (page - 1) * rowLimit; List questions = qbService.getCollectionQuestions(collectionUid, offset, rowLimit, sortBy, sortOrder, searchString); - int total = qbService.countCollectionQuestions(collectionUid, searchString); + int total = qbService.getCountCollectionQuestions(collectionUid, searchString); int maxPages = total / rowLimit + 1; return QbCollectionController.toGridXML(questions, page, maxPages); } Fisheye: Tag 14dec0981582e0cecba5de70a09f2aa2ef1be35d refers to a dead (removed) revision in file `lams_central/web/qb/collection.jsp'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_central/web/qb/collectionList.jsp =================================================================== diff -u -r0952bdcd231fe03cb52b8d821bc6cc1882b7c369 -r70353119b16530e4ef2f9c82bdaba7ca825feeb0 --- lams_central/web/qb/collectionList.jsp (.../collectionList.jsp) (revision 0952bdcd231fe03cb52b8d821bc6cc1882b7c369) +++ lams_central/web/qb/collectionList.jsp (.../collectionList.jsp) (revision 70353119b16530e4ef2f9c82bdaba7ca825feeb0) @@ -6,7 +6,7 @@ - Question collections + Collection management @@ -28,21 +28,24 @@ float: right; } - .row { - margin-top: 10px; + .ui-jqgrid-title { + display: inline-block; + width: 100%; + height: 30px; } - .row > div:first-child, .row > div:last-child { - text-align: left; - padding-left: 0; + .edit-button { + position: absolute; + right: 50px; } - - .row > div { - text-align: right; + + .grid-question-count { + margin-left: 10px; } - .header-column { - font-weight: bold; + .grid-collection-private { + margin-left: 10px; + color: red; } @@ -92,8 +95,8 @@ loadError: function(xhr,st,err) { collectionGrid.clearGridData(); alert("Error!"); - } - }).jqGrid('filterToolbar'); + } + }).jqGrid('filterToolbar'); }); }); @@ -129,123 +132,29 @@ }); } } - - // remove a collection - function removeCollection(button) { - var grid = $(button).closest('.container-fluid').siblings(".ui-jqgrid").find('.collection-grid'), - collectionUid = grid.data('collectionUid'), - name = grid.data('collectionName'); - - if (confirm('Are you sure you want to remove "' + name + '" collection?')) { - $.ajax({ - 'url' : 'qb/collection/removeCollection.do', - 'type' : 'POST', - 'dataType' : 'text', - 'data' : { - 'collectionUid' : collectionUid - }, - 'cache' : false - }).done(function(){ - document.location.reload(); - }); - } - } - - // share a collection with authors of an organisation - function shareCollection(button) { - var grid = $(button).closest('.container-fluid').siblings(".ui-jqgrid").find('.collection-grid'), - collectionUid = grid.data('collectionUid'), - organisationId = $(button).closest('.container-fluid').find('.targetOrganisationSelect').val(); - - $.ajax({ - 'url' : 'qb/collection/shareCollection.do', - 'type' : 'POST', - 'dataType' : 'text', - 'data' : { - 'collectionUid' : collectionUid, - 'organisationId': organisationId - }, - 'cache' : false - }).done(function(){ - document.location.reload(); - }); - } - - // stop sharing a collection with authors of an organisation - function unshareCollection(button, organisationId) { - var grid = $(button).closest('.container-fluid').siblings(".ui-jqgrid").find('.collection-grid'), - collectionUid = grid.data('collectionUid'); - - $.ajax({ - 'url' : 'qb/collection/unshareCollection.do', - 'type' : 'POST', - 'dataType' : 'text', - 'data' : { - 'collectionUid' : collectionUid, - 'organisationId': organisationId - }, - 'cache' : false - }).done(function(){ - document.location.reload(); - }); - } - +
- <%-- jqGrid placeholder with some useful attributes --%> -
- -
- <%-- Do not display links for collection manipulation for public and private collections --%> - -
-
- -
-
- Share collection with -
-
- -
-
- -
-
- - -
-
-
- Shared with organisations -
-
-
- -
-
-
- -
-
- -
-
-
-
+ + + (${questionCount[collection.uid]} questions) + + Private -
+ + + + <%-- jqGrid placeholder with some useful attributes --%> + +
+
Index: lams_common/src/java/org/lamsfoundation/lams/qb/dao/IQbDAO.java =================================================================== diff -u -r33b937e6fb979aa7a58fd0f33d1ecf474150155b -r70353119b16530e4ef2f9c82bdaba7ca825feeb0 --- lams_common/src/java/org/lamsfoundation/lams/qb/dao/IQbDAO.java (.../IQbDAO.java) (revision 33b937e6fb979aa7a58fd0f33d1ecf474150155b) +++ lams_common/src/java/org/lamsfoundation/lams/qb/dao/IQbDAO.java (.../IQbDAO.java) (revision 70353119b16530e4ef2f9c82bdaba7ca825feeb0) @@ -52,7 +52,7 @@ List getQuestionCollections(long qbQuestionUid); - int countCollectionQuestions(long collectionUid, String search); + int getCountCollectionQuestions(long collectionUid, String search); void addCollectionQuestion(long collectionUid, long qbQuestionUid); Index: lams_common/src/java/org/lamsfoundation/lams/qb/dao/hibernate/QbDAO.java =================================================================== diff -u -r8d2337141f10b26a11e9730f9c44d53a96fcc062 -r70353119b16530e4ef2f9c82bdaba7ca825feeb0 --- lams_common/src/java/org/lamsfoundation/lams/qb/dao/hibernate/QbDAO.java (.../QbDAO.java) (revision 8d2337141f10b26a11e9730f9c44d53a96fcc062) +++ lams_common/src/java/org/lamsfoundation/lams/qb/dao/hibernate/QbDAO.java (.../QbDAO.java) (revision 70353119b16530e4ef2f9c82bdaba7ca825feeb0) @@ -264,7 +264,7 @@ } @Override - public int countCollectionQuestions(long collectionUid, String search) { + public int getCountCollectionQuestions(long collectionUid, String search) { Query query = prepareCollectionQuestionsQuery(collectionUid, null, null, search, true); return ((BigInteger) query.getSingleResult()).intValue(); } Index: lams_common/src/java/org/lamsfoundation/lams/qb/model/QbCollection.java =================================================================== diff -u -r374f47ea57a62a77e6faf1bb9713de1f9f53c1be -r70353119b16530e4ef2f9c82bdaba7ca825feeb0 --- lams_common/src/java/org/lamsfoundation/lams/qb/model/QbCollection.java (.../QbCollection.java) (revision 374f47ea57a62a77e6faf1bb9713de1f9f53c1be) +++ lams_common/src/java/org/lamsfoundation/lams/qb/model/QbCollection.java (.../QbCollection.java) (revision 70353119b16530e4ef2f9c82bdaba7ca825feeb0) @@ -14,7 +14,6 @@ import javax.persistence.ManyToMany; import javax.persistence.OrderBy; import javax.persistence.Table; -import javax.persistence.Transient; import org.apache.commons.lang.builder.EqualsBuilder; import org.apache.commons.lang.builder.HashCodeBuilder; @@ -51,9 +50,6 @@ @OrderBy("name") private List organisations = new ArrayList<>(); - @Transient - private List shareableWithOrganisations = new ArrayList<>(); - public Long getUid() { return uid; } @@ -90,14 +86,6 @@ this.organisations = organisations; } - public List getShareableWithOrganisations() { - return shareableWithOrganisations; - } - - public void setShareableWithOrganisations(List shareableWithOrganisations) { - this.shareableWithOrganisations = shareableWithOrganisations; - } - @Override public boolean equals(Object o) { QbCollection other = (QbCollection) o; Index: lams_common/src/java/org/lamsfoundation/lams/qb/service/IQbService.java =================================================================== diff -u -r0952bdcd231fe03cb52b8d821bc6cc1882b7c369 -r70353119b16530e4ef2f9c82bdaba7ca825feeb0 --- lams_common/src/java/org/lamsfoundation/lams/qb/service/IQbService.java (.../IQbService.java) (revision 0952bdcd231fe03cb52b8d821bc6cc1882b7c369) +++ lams_common/src/java/org/lamsfoundation/lams/qb/service/IQbService.java (.../IQbService.java) (revision 70353119b16530e4ef2f9c82bdaba7ca825feeb0) @@ -66,7 +66,7 @@ List getCollectionQuestions(long collectionUid, Integer offset, Integer limit, String orderBy, String orderDirection, String search); - int countCollectionQuestions(long collectionUid, String search); + int getCountCollectionQuestions(long collectionUid, String search); List getQuestionCollections(long qbQuestionUid); @@ -92,4 +92,6 @@ boolean removeQuestion(long qbQuestionUid); boolean removeQuestionPossible(long qbQuestionUid); + + QbCollection getCollection(long collectionUid); } \ No newline at end of file Index: lams_common/src/java/org/lamsfoundation/lams/qb/service/QbService.java =================================================================== diff -u -r0952bdcd231fe03cb52b8d821bc6cc1882b7c369 -r70353119b16530e4ef2f9c82bdaba7ca825feeb0 --- lams_common/src/java/org/lamsfoundation/lams/qb/service/QbService.java (.../QbService.java) (revision 0952bdcd231fe03cb52b8d821bc6cc1882b7c369) +++ lams_common/src/java/org/lamsfoundation/lams/qb/service/QbService.java (.../QbService.java) (revision 70353119b16530e4ef2f9c82bdaba7ca825feeb0) @@ -85,7 +85,7 @@ @Override public QbStatsDTO getQbQuestionStats(long qbQuestionUid) { QbStatsDTO stats = new QbStatsDTO(); - QbQuestion qbQuestion = (QbQuestion) qbDAO.find(QbQuestion.class, qbQuestionUid); + QbQuestion qbQuestion = qbDAO.find(QbQuestion.class, qbQuestionUid); List qbOptions = qbQuestion.getQbOptions(); stats.setQuestion(qbQuestion); Map burningQuestions = qbDAO.getBurningQuestions(qbQuestionUid); @@ -136,17 +136,15 @@ return stats; } - @SuppressWarnings("unchecked") @Override public QbStatsActivityDTO getActivityStatsByContentId(Long toolContentId, Long qbQuestionUid) { - Activity activity = ((List) qbDAO.findByProperty(ToolActivity.class, "toolContentId", toolContentId)) - .get(0); + Activity activity = qbDAO.findByProperty(ToolActivity.class, "toolContentId", toolContentId).get(0); return getActivityStats(activity.getActivityId(), qbQuestionUid); } @Override public QbStatsActivityDTO getActivityStats(Long activityId, Long qbQuestionUid) { - QbQuestion qbQuestion = (QbQuestion) qbDAO.find(QbQuestion.class, qbQuestionUid); + QbQuestion qbQuestion = qbDAO.find(QbQuestion.class, qbQuestionUid); Set correctOptionUids = new HashSet<>(); for (QbOption option : qbQuestion.getQbOptions()) { if (option.isCorrect()) { @@ -159,7 +157,7 @@ @Override public QbStatsActivityDTO getActivityStats(Long activityId, Long qbQuestionUid, Collection correctOptionUids) { - ToolActivity activity = (ToolActivity) qbDAO.find(ToolActivity.class, activityId); + ToolActivity activity = qbDAO.find(ToolActivity.class, activityId); LearningDesign learningDesign = activity.getLearningDesign(); Lesson lesson = learningDesign.getLessons().iterator().next(); Long lessonId = lesson.getLessonId(); @@ -246,11 +244,10 @@ @Override public QbCollection getPublicCollection() { - return (QbCollection) qbDAO.find(QbCollection.class, 1L); + return qbDAO.find(QbCollection.class, 1L); } @Override - @SuppressWarnings("unchecked") public QbCollection getUserPrivateCollection(int userId) { Map map = new HashMap<>(); map.put("userId", userId); @@ -270,7 +267,6 @@ } @Override - @SuppressWarnings("unchecked") public List getUserOwnCollections(int userId) { Map map = new HashMap<>(); map.put("userId", userId); @@ -290,8 +286,8 @@ } @Override - public int countCollectionQuestions(long collectionUid, String search) { - return qbDAO.countCollectionQuestions(collectionUid, search); + public int getCountCollectionQuestions(long collectionUid, String search) { + return qbDAO.getCountCollectionQuestions(collectionUid, search); } @Override @@ -310,7 +306,10 @@ @Override public void removeCollection(long collectionUid) { - QbCollection collection = (QbCollection) qbDAO.find(QbCollection.class, collectionUid); + if (getCountCollectionQuestions(collectionUid, null) > 0) { + throw new InvalidParameterException("Can not remove a collection with questions"); + } + QbCollection collection = qbDAO.find(QbCollection.class, collectionUid); if (collection.getUserId() == null || collection.isPersonal()) { throw new InvalidParameterException("Attempt to remove a private or the public question bank collection"); } @@ -337,19 +336,19 @@ @Override public Organisation shareCollection(long collectionUid, int organisationId) { - QbCollection collection = (QbCollection) qbDAO.find(QbCollection.class, collectionUid); + QbCollection collection = qbDAO.find(QbCollection.class, collectionUid); if (collection.getUserId() == null || collection.isPersonal()) { throw new InvalidParameterException("Attempt to share a private or the public question bank collection"); } - Organisation organisation = (Organisation) qbDAO.find(Organisation.class, organisationId); + Organisation organisation = qbDAO.find(Organisation.class, organisationId); collection.getOrganisations().add(organisation); qbDAO.update(collection); return organisation; } @Override public void unshareCollection(long collectionUid, int organisationId) { - QbCollection collection = (QbCollection) qbDAO.find(QbCollection.class, collectionUid); + QbCollection collection = qbDAO.find(QbCollection.class, collectionUid); if (collection.getUserId() == null || collection.isPersonal()) { throw new InvalidParameterException("Attempt to unshare a private or the public question bank collection"); } @@ -416,7 +415,7 @@ @Override public List getShareableWithOrganisations(long collectionUid, int userId) { - QbCollection collection = (QbCollection) qbDAO.find(QbCollection.class, collectionUid); + QbCollection collection = qbDAO.find(QbCollection.class, collectionUid); if (collection.getUserId() == null || collection.isPersonal()) { return null; } @@ -432,7 +431,7 @@ } } if (organisationId != null && roleEntry.getValue().contains(Role.ROLE_AUTHOR)) { - Organisation organisation = (Organisation) qbDAO.find(Organisation.class, organisationId); + Organisation organisation = qbDAO.find(Organisation.class, organisationId); result.add(organisation); } } @@ -443,9 +442,6 @@ @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); @@ -456,6 +452,11 @@ return collections; } + @Override + public QbCollection getCollection(long collectionUid) { + return qbDAO.find(QbCollection.class, collectionUid); + } + public void setQbDAO(IQbDAO qbDAO) { this.qbDAO = qbDAO; }