From 7f4430b1b71c0f4fceb824a4f2f376800a38ef2e Mon Sep 17 00:00:00 2001
From: fkiefer <none@none>
Date: Mon, 20 Jun 2016 16:08:57 +0200
Subject: [PATCH] OO-2057 sorting of floating entries and binder entries

---
 .../ui/AbstractPageListController.java        | 37 +++++++++++++++++--
 .../ui/PageMetadataEditController.java        |  6 +--
 2 files changed, 37 insertions(+), 6 deletions(-)

diff --git a/src/main/java/org/olat/modules/portfolio/ui/AbstractPageListController.java b/src/main/java/org/olat/modules/portfolio/ui/AbstractPageListController.java
index 2c9f47e638b..01ebd11adf6 100644
--- a/src/main/java/org/olat/modules/portfolio/ui/AbstractPageListController.java
+++ b/src/main/java/org/olat/modules/portfolio/ui/AbstractPageListController.java
@@ -20,7 +20,10 @@
 package org.olat.modules.portfolio.ui;
 
 import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Map;
 
 import org.olat.core.gui.UserRequest;
 import org.olat.core.gui.components.Component;
@@ -53,6 +56,7 @@ import org.olat.modules.portfolio.Page;
 import org.olat.modules.portfolio.PortfolioService;
 import org.olat.modules.portfolio.Section;
 import org.olat.modules.portfolio.model.PageRow;
+import org.olat.modules.portfolio.model.SectionImpl;
 import org.olat.modules.portfolio.ui.BindersDataModel.PortfolioCols;
 import org.springframework.beans.factory.annotation.Autowired;
 
@@ -133,10 +137,30 @@ implements Activateable2, TooledController, FlexiTableComponentDelegate, FlexiTa
 	
 	protected void loadModel(List<Page> pages) {
 		List<PageRow> rows = new ArrayList<>(pages.size());
+		Map<Section, List<Page>> sortMap = new HashMap<>();
+		for (Page page : pages) {
+			if (sortMap.containsKey(page.getSection())) {
+				sortMap.get(page.getSection()).add(page);
+			} else if (page.getSection() == null) {
+				ArrayList<Page> pageList = new ArrayList<>();
+				pageList.add(page);
+				sortMap.put(new SectionImpl(), pageList);
+			} else {
+				ArrayList<Page> pageList = new ArrayList<>();
+				pageList.add(page);
+				sortMap.put(page.getSection(), pageList);
+			}
+		}		
+		List<Page> pax = new ArrayList<>();
+		
+		for (List<Page> p : sortMap.values()){
+			pax.addAll(p);
+		}
 		Section section = null;
-		for(Page page:pages) {
+		for (Page page : pax) {
+
 			boolean first = false;
-			if(section == null || !section.equals(page.getSection())) {
+			if (section == null || !section.equals(page.getSection())) {
 				first = true;
 				section = page.getSection();
 			}
@@ -149,7 +173,6 @@ implements Activateable2, TooledController, FlexiTableComponentDelegate, FlexiTa
 	
 	protected PageRow forgeRow(Page page, boolean firstOfSection) {
 		PageRow row = new PageRow(page, page.getSection(), firstOfSection);
-		
 		String openLinkId = "open_" + (++counter);
 		FormLink openLink = uifactory.addFormLink(openLinkId, "open.full", "open.full.page", null, flc, Link.BUTTON);
 		openLink.setIconRightCSS("o_icon o_icon_start");
@@ -217,4 +240,12 @@ implements Activateable2, TooledController, FlexiTableComponentDelegate, FlexiTa
 		String displayName = StringHelper.escapeHtml(page.getTitle());
 		stackPanel.pushController(displayName, pageCtrl);
 	}
+
+	private void view(Object... args) {
+		StringBuilder sb = new StringBuilder();
+		for (Object s : args) {
+			sb.append(" %20s");
+		}
+		System.out.println(String.format(sb.toString(), args));
+	}
 }
\ No newline at end of file
diff --git a/src/main/java/org/olat/modules/portfolio/ui/PageMetadataEditController.java b/src/main/java/org/olat/modules/portfolio/ui/PageMetadataEditController.java
index 8d405f6682d..7ba78442b49 100644
--- a/src/main/java/org/olat/modules/portfolio/ui/PageMetadataEditController.java
+++ b/src/main/java/org/olat/modules/portfolio/ui/PageMetadataEditController.java
@@ -127,7 +127,7 @@ public class PageMetadataEditController extends FormBasicController {
 		fileUpload.setPreview(ureq.getUserSession(), true);
 		fileUpload.addActionListener(FormEvent.ONCHANGE);
 		fileUpload.setDeleteEnabled(true);
-		fileUpload.setHelpText("background img of binder");
+		fileUpload.setHelpText("page.title");
 		fileUpload.limitToMimeType(imageMimeTypes, null, null);
 		fileUpload.setMaxUploadSizeKB(picUploadlimitKB, null, null);
 		if(page != null) {
@@ -243,7 +243,7 @@ public class PageMetadataEditController extends FormBasicController {
 			String title = titleEl.getValue();
 			String summary = summaryEl.getValue();
 			SectionRef selectSection = null;
-			if (sectionsEl.isOneSelected() && sectionsEl.isEnabled() && sectionsEl.isVisible()) {
+			if (sectionsEl!=null && sectionsEl.isOneSelected() && sectionsEl.isEnabled() && sectionsEl.isVisible()) {
 				String selectedKey = sectionsEl.getSelectedKey();
 				selectSection = new SectionKeyRef(new Long(selectedKey));
 			}
@@ -252,7 +252,7 @@ public class PageMetadataEditController extends FormBasicController {
 				imagePath = portfolioService.addPosterImageForPage(fileUpload.getUploadFile(),
 						fileUpload.getUploadFileName());
 			}
-			portfolioService.appendNewPage(getIdentity(), title, summary, imagePath, selectSection);
+			if (sectionsEl!=null)portfolioService.appendNewPage(getIdentity(), title, summary, imagePath, selectSection);
 		} else {
 			page.setTitle(titleEl.getValue());
 			page.setSummary(summaryEl.getValue());
-- 
GitLab