Skip to content

Commit

Permalink
SAK-31274 - Order by term the hidden sites page (sakaiproject#5419)
Browse files Browse the repository at this point in the history
* SAK-31274 - Moving getPortalTermOrder to util so other methods can use
it

* SAK-31274 - Order by term the hidden sites page
  • Loading branch information
jonespm authored Mar 23, 2018
1 parent 751ac5a commit 6afa6d9
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.sakaiproject.exception.IdUnusedException;
import org.sakaiproject.portal.api.Portal;
import org.sakaiproject.portal.api.SiteNeighbourhoodService;
import org.sakaiproject.portal.util.PortalUtils;
import org.sakaiproject.site.api.Site;
import org.sakaiproject.site.api.SiteService;
import org.sakaiproject.site.api.ToolConfiguration;
Expand All @@ -50,9 +51,6 @@
import org.sakaiproject.user.api.PreferencesService;

import org.sakaiproject.util.ResourceLoader;
import org.sakaiproject.coursemanagement.api.AcademicSession;
import org.sakaiproject.coursemanagement.api.CourseManagementService;
import org.sakaiproject.component.cover.ComponentManager;

import org.sakaiproject.util.Web;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -65,7 +63,6 @@ public class MoreSiteViewImpl extends AbstractSiteViewImpl
{
/** messages. */
private static ResourceLoader rb = new ResourceLoader("sitenav");
private CourseManagementService courseManagementService = (CourseManagementService) ComponentManager.get(CourseManagementService.class);

/**
* @param siteHelper
Expand Down Expand Up @@ -371,56 +368,8 @@ public int compare(Map first, Map second)

}

String[] termOrder = serverConfigurationService
.getStrings("portal.term.order");
List<String> tabsMoreSortedTermList = new ArrayList<String>();

// Order term column headers according to order specified in
// portal.term.order
// Filter out terms for which user is not a member of any sites

// SAK-19464 - Set tab order
// Property portal.term.order
// Course sites (sorted in order by getAcademicSessions START_DATE ASC)
// Rest of terms in alphabetic order
if (termOrder != null)
{
for (int i = 0; i < termOrder.length; i++)
{

if (tabsMoreTerms.containsKey(termOrder[i]))
{

tabsMoreSortedTermList.add(termOrder[i]);

}

}
}


if (courseManagementService != null) {
Collection<AcademicSession> sessions = courseManagementService.getAcademicSessions();
for (AcademicSession s: sessions) {
String title = s.getTitle();
if (tabsMoreTerms.containsKey(title)) {
if (!tabsMoreSortedTermList.contains(title)) {
tabsMoreSortedTermList.add(title);
}
}
}
}

Iterator i = tabsMoreTerms.keySet().iterator();
while (i.hasNext())
{
String term = (String) i.next();
if (!tabsMoreSortedTermList.contains(term))
{
tabsMoreSortedTermList.add(term);

}
}
//Get a list of sorted terms
List<String> tabsMoreSortedTermList = PortalUtils.getPortalTermOrder(tabsMoreTerms.keySet());

SitePanesArrangement sitesByPane = arrangeSitesIntoPanes(tabsMoreTerms);
renderContextMap.put("tabsMoreTermsLeftPane", sitesByPane.sitesInLeftPane);
Expand Down
4 changes: 4 additions & 0 deletions portal/portal-util/util/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
<packaging>jar</packaging>

<dependencies>
<dependency>
<groupId>org.sakaiproject.edu-services.course-management</groupId>
<artifactId>coursemanagement-api</artifactId>
</dependency>
<dependency>
<groupId>org.sakaiproject.kernel</groupId>
<artifactId>sakai-kernel-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,22 @@
package org.sakaiproject.portal.util;

import java.time.Instant;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import org.sakaiproject.component.cover.ComponentManager;
import org.sakaiproject.component.cover.ServerConfigurationService;
import org.sakaiproject.coursemanagement.api.AcademicSession;
import org.sakaiproject.coursemanagement.api.CourseManagementService;

public class PortalUtils
{

private static CourseManagementService courseManagementService = (CourseManagementService) ComponentManager.get(CourseManagementService.class);

/**
* Returns an absolute URL for "/library" servlet with CDN path as necessary
*/
Expand Down Expand Up @@ -143,5 +153,68 @@ public static String includeLatestJQuery(String where)
public static String getLatestJQueryPath() {
return getWebjarsPath() + "jquery/1.12.4/jquery.min.js";
}

/*
* getPortalTermOrder - Gets the term order as sorted by the portal. Will take into consideration portal.term.order
* and the values returned by the CM service
* Set tabsMoreTerms, a Set containing all terms to include (optional).
* If provided it will both filter by this list and add anything in this list that isn't found in the CM table.
*
* Returns a sorted term List
*/
public static List<String> getPortalTermOrder(Set <String> tabsMoreTerms) {
String[] termOrder = ServerConfigurationService.getStrings("portal.term.order");
List<String> tabsMoreSortedTermList = new ArrayList<String>();

// Order term column headers according to order specified in
// portal.term.order
// Filter out terms for which user is not a member of any sites

// SAK-19464 - Set tab order
// Property portal.term.order
// Course sites (sorted in order by getAcademicSessions START_DATE ASC)
// Rest of terms in alphabetic order
if (termOrder != null && tabsMoreTerms != null)
{
for (int i = 0; i < termOrder.length; i++)
{
if (tabsMoreTerms.contains(termOrder[i]))
{
tabsMoreSortedTermList.add(termOrder[i]);
}
}
}

if (courseManagementService != null) {
Collection<AcademicSession> sessions = courseManagementService.getAcademicSessions();
for (AcademicSession s: sessions) {
String title = s.getTitle();
//Add this if the user doesn't specify to filter terms
if (tabsMoreTerms == null) {
tabsMoreSortedTermList.add(title);
}
else if (tabsMoreTerms.contains(title)) {
if (!tabsMoreSortedTermList.contains(title)) {
tabsMoreSortedTermList.add(title);
}
}
}
}

if (tabsMoreTerms != null) {
Iterator<String> i = tabsMoreTerms.iterator();
while (i.hasNext())
{
String term = (String) i.next();
if (!tabsMoreSortedTermList.contains(term))
{
tabsMoreSortedTermList.add(term);

}
}
}

return tabsMoreSortedTermList;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,14 @@
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

import org.apache.commons.lang3.math.NumberUtils;
import org.sakaiproject.component.cover.ComponentManager;
import org.sakaiproject.component.cover.ServerConfigurationService;
import org.sakaiproject.entity.api.ResourceProperties;
import org.sakaiproject.entity.api.ResourcePropertiesEdit;
import org.sakaiproject.event.cover.NotificationService;
import org.sakaiproject.exception.IdUnusedException;
import org.sakaiproject.portal.util.PortalUtils;
import org.sakaiproject.site.api.Site;
import org.sakaiproject.site.api.SiteService.SelectionType;
import org.sakaiproject.site.api.SiteService.SortType;
Expand Down Expand Up @@ -2566,11 +2567,12 @@ public int compare(DecoratedNotificationPreference first, DecoratedNotificationP
public class TermSites
{
private List<Term> terms;
private List <String> termOrder;

public class Term implements Comparable<Term> {
private String label;
private List<Site> sites;

public Term(String label, List<Site> sites) {
if (sites.isEmpty()) {
throw new RuntimeException("List of sites can't be empty");
Expand All @@ -2593,10 +2595,14 @@ public String getType() {
}

public int compareTo(Term other) {
if (termOrder != null && (termOrder.contains(this.label) || termOrder.contains(other.label))) {
return(NumberUtils.compare(termOrder.indexOf(this.label), termOrder.indexOf(other.label)));
}

String myType = this.getType();
String theirType = other.getType();

// Course sites win out over non-course-sites
// Otherwise if not found in a term course sites win out over non-course-sites
if (myType == null) {
return 1;
} else if (theirType == null) {
Expand Down Expand Up @@ -2642,6 +2648,8 @@ public TermSites(List<Site> sites) {
terms.add(new Term(name, termsToSites.get(name)));
}

termOrder = PortalUtils.getPortalTermOrder(null);

Collections.sort(terms);
}

Expand Down

0 comments on commit 6afa6d9

Please sign in to comment.