Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SAK-49359 Portal add sub-sites dropdown #13288

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,15 @@
}

.portal-header-breadcrumb-separator, .portal-header-breadcrumb-item > a {
font-size: 16px;
color: var(--sakai-text-color-inverted) !important;
text-decoration: none;
&:hover {
text-decoration: underline;
}
}
.portal-header-breadcrumb-separator {
font-size: 14px;
}

#header-site-title {
.portal-header-site-title {
padding-bottom: 2px;

> a {
font-size: 20px;
}
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ public interface PortalSiteHelper
*/
SitePage lookupSitePage(String pageId, Site site);

List<Map<String, String>> getParentSites(Site s);

/**
* Produce a page and/or a tool list by iterating through the pages in a site.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ public void doSite(HttpServletRequest req, HttpServletResponse res, Session sess

// Does the tool allow us to buffer?
allowBuffer = allowBufferContent(req, site, siteTool);
log.debug("allowBuffer="+allowBuffer+" url="+req.getRequestURL());
log.debug("allowBuffer={} url={}", allowBuffer, req.getRequestURL());

if ( allowBuffer ) {
TCP = req.getContextPath() + req.getServletPath() + Web.makePath(parts, 1, 5);
Expand Down Expand Up @@ -590,7 +590,7 @@ public void doSite(HttpServletRequest req, HttpServletResponse res, Session sess
}

rcontext.put("siteId", siteId);
boolean showShortDescription = Boolean.valueOf(serverConfigurationService.getBoolean("portal.title.shortdescription.show", false));
boolean showShortDescription = serverConfigurationService.getBoolean("portal.title.shortdescription.show", false);

if (showShortDescription) {
rcontext.put("shortDescription", Web.escapeHtml(site.getShortDescription()));
Expand All @@ -604,6 +604,7 @@ public void doSite(HttpServletRequest req, HttpServletResponse res, Session sess
}else{
rcontext.put("siteTitle", portal.getSiteHelper().getUserSpecificSiteTitle(site, false, true, providers));
rcontext.put("siteUrl", site.getUrl());
rcontext.put("siteParents", portal.getSiteHelper().getParentSites(site));
rcontext.put("siteTitleTruncated", Validator.escapeHtml(portal.getSiteHelper().getUserSpecificSiteTitle(site, true, false, providers)));
rcontext.put("isUserSite", false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import java.net.URISyntaxException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
Expand Down Expand Up @@ -298,7 +299,7 @@ private String getSubPages(String userId, String siteId, List<SitePage> pageList
.collect(Collectors.joining());
}

private Map<String, Object> getSiteMap(Site site, String currentSiteId, String userId, boolean pinned, boolean hidden, boolean includePages) {
private Map<String, Object> getSiteMap(Site site, String currentSiteId, String userId, boolean pinned, boolean hidden, boolean includePages, Map<String, List<Map<String, String>>> parentToChildSites) {

Map<String, Object> siteMap = new HashMap<>();
siteMap.put("id", site.getId());
Expand All @@ -319,15 +320,38 @@ private Map<String, Object> getSiteMap(Site site, String currentSiteId, String u
if (Boolean.parseBoolean(site.getProperties().getProperty("subpagenav")) && !pageList.isEmpty()) {
siteMap.put("subPages", getSubPages(userId, site.getId(), pageList));
}
if (parentToChildSites != null) {
// Add the childSiteIds: these are the IDs of sites whose parent is the current site.
siteMap.put("childSites", parentToChildSites.get(site.getId()));
siteMap.put("parentSiteId", site.getProperties().getProperty(PROP_PARENT_ID));
}
}
return siteMap;
}

private List<Map<String, Object>> getSiteMaps(Collection<Site> sites, String currentSiteId, String userId, boolean pinned, boolean hidden, boolean includePages) {

// Precompute a mapping from parent site IDs to child site IDs.
Map<String, List<Map<String, String>>> parentToChildSites;
if (!Arrays.asList("false", "never").contains(serverConfigurationService.getString("portal.includesubsites"))) {
parentToChildSites = sites.stream()
.filter(site -> site.getProperties().getProperty(PROP_PARENT_ID) != null)
.collect(Collectors.groupingBy(
site -> site.getProperties().getProperty(PROP_PARENT_ID),
Collectors.mapping(site -> {
Map<String, String> siteInfo = new HashMap<>();
siteInfo.put("id", site.getId());
siteInfo.put("title", site.getTitle());
return siteInfo;
}, Collectors.toList())
));
} else {
parentToChildSites = null;
}

return sites.stream()
.map(site -> getSiteMap(site, currentSiteId, userId, pinned, hidden, includePages))
.collect(Collectors.toList());
.map(site -> getSiteMap(site, currentSiteId, userId, pinned, hidden, includePages, parentToChildSites))
.collect(Collectors.toList());
}

private Map<String, Object> getPageMap(SitePage page, boolean includeSubPage) {
Expand Down Expand Up @@ -409,7 +433,7 @@ public Map<String, Object> getContextSitesWithPages(HttpServletRequest req, Stri
if (loggedIn) {
// Put Home site in context
String userId = sessionManager.getCurrentSessionUserId();
contextSites.put("homeSite", getSiteMap(getSite(siteService.getUserSiteId(userId)), currentSiteId, userId,false, false, true));
contextSites.put("homeSite", getSiteMap(getSite(siteService.getUserSiteId(userId)), currentSiteId, userId,false, false, true, null));

List<String> excludedSiteIds = getExcludedSiteIds(userId);
// Get pinned sites, excluded sites never appear in the pinned list including current site
Expand Down Expand Up @@ -447,7 +471,7 @@ public Map<String, Object> getContextSitesWithPages(HttpServletRequest req, Stri

// If the current site is excluded it should appear in recent as hidden
if (excludedSiteIds.contains(currentSiteId)) {
recentSitesMaps.add(getSiteMap(getSite(currentSiteId), currentSiteId, userId, false, true, true));
recentSitesMaps.add(getSiteMap(getSite(currentSiteId), currentSiteId, userId, false, true, true, null));
}
contextSites.put("recentSites", recentSitesMaps);

Expand All @@ -461,7 +485,7 @@ public Map<String, Object> getContextSitesWithPages(HttpServletRequest req, Stri
//Get gateway site
Site gatewaySite = getSite(serverConfigurationService.getGatewaySiteId());
if (!gatewaySite.isEmpty()) {
contextSites.put("gatewaySite", getSiteMap(gatewaySite, currentSiteId, null,false, false, true));
contextSites.put("gatewaySite", getSiteMap(gatewaySite, currentSiteId, null,false, false, true, null));
}
}
return contextSites;
Expand Down Expand Up @@ -641,62 +665,50 @@ public Map<String, Object> convertSiteToMap(HttpServletRequest req, Site s, Stri
m.put("siteType", s.getType());
m.put("siteId", s.getId());

// TODO: This should come from the site neighbourhood.
if (includeSummary)
{
summarizeTool(m, s, "sakai.announce");
}
if (expandSite)
{
Map<String, Object> pageMap = pageListToMap(req, loggedIn, s, null, toolContextPath, prefix, doPages, resetTools, includeSummary);
m.put("sitePages", pageMap);
}

return m;
}

@Override
public List<Map<String, String>> getParentSites(Site s) {
ResourceProperties rp = s.getProperties();
String ourParent = rp.getProperty(PROP_PARENT_ID);
// We are not really a child unless the parent exists
// And we have a valid pwd
boolean isChild = false;

// Get the current site hierarchy
if (ourParent != null && isCurrentSite)
{
if (ourParent != null) {
List<Site> pwd = getPwd(s, ourParent);
if (pwd != null)
{
List<Map> l = new ArrayList<>();
// SAK-30477
// Skip current site size - 1
for (int i = 0; i < pwd.size() - 1; i++)
{
Site site = pwd.get(i);
log.debug("PWD[{}]={}{}", i, site.getId(), site.getTitle());
Map<String, Object> pm = new HashMap<>();
if (pwd != null && pwd.size() > 1) { // Ensure we have at least 2 sites
List<Map<String, String>> siteBreadcrumbs = new ArrayList<>();
// SAK-30477: Skip current site size - 1
for (Site site : pwd.subList(0, pwd.size() - 1)) {
log.debug("PWD: {}{}", site.getId(), site.getTitle());
Map<String, String> siteData = new HashMap<>();
List<String> providers = getProviderIDsForSite(site);

String parentSiteTitle = getUserSpecificSiteTitle(site, false, false, providers);
String parentSiteTitleTruncated = formattedText.makeShortenedText(parentSiteTitle, null, null, null);
pm.put("siteTitle", parentSiteTitle);
pm.put("siteTitleTrunc", parentSiteTitleTruncated);
pm.put("siteUrl", siteUrl + formattedText.escapeUrl(getSiteEffectiveId(site)));

l.add(pm);
isChild = true;
siteData.put("siteTitle", parentSiteTitle);
siteData.put("siteTitleTrunc", parentSiteTitleTruncated);
siteData.put("siteUrl", "/portal/site/" + formattedText.escapeUrl(getSiteEffectiveId(site)));
siteBreadcrumbs.add(siteData);
}
if (!siteBreadcrumbs.isEmpty()) {
return siteBreadcrumbs;
}
if ( l.size() > 0 ) m.put("pwd", l);
}
}

// If we are a child and have a non-zero length, pwd
// show breadcrumbs
if ( isChild ) {
m.put("isChild", Boolean.valueOf(isChild));
m.put("parentSite", ourParent);
}

if (includeSummary)
{
summarizeTool(m, s, "sakai.announce");
}
if (expandSite)
{
Map<String, Object> pageMap = pageListToMap(req, loggedIn, s, null, toolContextPath, prefix, doPages, resetTools, includeSummary);
m.put("sitePages", pageMap);
}

return m;
return null;
}

/**
* Gets the path of sites back to the root of the tree.
* @param s
Expand Down Expand Up @@ -974,13 +986,6 @@ else if ("always".equals(showHelpGlobal))

}

if ( addMoreToolsUrl != null ) {
theMap.put("pageNavAddMoreToolsUrl", addMoreToolsUrl);
theMap.put("pageNavCanAddMoreTools", true);
} else {
theMap.put("pageNavCanAddMoreTools", false);
}

if(manageOverviewUrl != null){
theMap.put("manageOverviewUrl", manageOverviewUrl);
theMap.put("canManageOverview", true);
Expand All @@ -999,17 +1004,6 @@ else if ("always".equals(showHelpGlobal))
}

theMap.put("pageNavTools", l);
theMap.put("pageMaxIfSingle", serverConfigurationService.getBoolean("portal.experimental.maximizesinglepage", false));
theMap.put("pageNavToolsCount", Integer.valueOf(l.size()));

String helpUrl = serverConfigurationService.getHelpUrl(null);
theMap.put("pageNavShowHelp", Boolean.valueOf(showHelp));
theMap.put("pageNavHelpUrl", helpUrl);
theMap.put("helpMenuClass", ICON_SAKAI + "help");
theMap.put("subsiteClass", ICON_SAKAI + "subsite");

// theMap.put("pageNavSitContentshead",
// Web.escapeHtml(rb.getString("sit_contentshead")));

// Display presence? Global property display.users.present may be always / never / true / false
// If true or false, the value may be overriden by the site property display-users-present
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,6 @@ protected void includePageNav(Map rcontext) throws IOException
rcontext.put("pageNavPublished", Boolean.valueOf(true));
rcontext.put("pageNavType", "type");
rcontext.put("pageNavIconUrl", "iconUrl");
rcontext.put("helpMenuClass", "HelpMenuClass");
// rcontext.put("pageNavSitToolsHead", "sit_toolshead");

List l = new ArrayList();
Expand Down Expand Up @@ -335,11 +334,6 @@ protected void includePageNav(Map rcontext) throws IOException
l.add(m);
rcontext.put("pageNavTools", l);

rcontext.put("pageNavShowHelp", Boolean.valueOf(true));
rcontext.put("pageNavHelpUrl", "helpUrl");
// rcontext.put("pageNavSitHelp", "sit_help");

rcontext.put("pageNavToolsCount", l.size());
rcontext.put("pageNavShowPresenceLoggedIn", Boolean.valueOf(true));
rcontext.put("pageNavPresenceUrl", "presenceUrl");
rcontext.put("sakaiPresenceTimeDelay", Integer.valueOf(3000));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<div class="portal-main-container container-fluid mt-2 d-flex flex-column">
<main id="$pageWrapperClass" class="portal-main-content #if( $numberTools > 1 || $homePage)Mrphs-multipleTools #end" role="main">
<h1 class="skip visually-hidden" tabindex="-1" id="tocontent">${rloader.sit_contentshead}</h1>
#parse("/vm/morpheus/includeSiteHierarchy.vm")
#parse("/vm/morpheus/snippets/roleSwitch-snippet.vm")
#parse("/vm/morpheus/snippets/siteStatus-snippet.vm")
#if ($pageTwoColumn)
<div class="row">
Expand Down
Loading
Loading