Some work on for showing an MPA
parent
6dd855e1e2
commit
2c49a4fbc1
|
|
@ -0,0 +1,21 @@
|
||||||
|
<#macro details>
|
||||||
|
<h1>${CmsPagesCategorizedItemModel.title}</h1>
|
||||||
|
<p class="item-description">${CmsPagesCategorizedItemModel.description}</p>
|
||||||
|
|
||||||
|
<h2>${CmsPagesMultiPartArticleModel.currentSectionTitle}</h2>
|
||||||
|
<div>
|
||||||
|
<nav>
|
||||||
|
<ul class="flex-column float-end nav">
|
||||||
|
<#list CmsPagesMultiPartArticleModel.sectionTitles as section>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link"
|
||||||
|
href="${CmsPagesMultiPartArticleModel.sectionLinks[section?index]}">
|
||||||
|
${section}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
</#list>
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
|
${CmsPagesMultiPartArticleModel.currentSectionText}
|
||||||
|
</div>
|
||||||
|
</#macro>
|
||||||
|
|
@ -11,5 +11,5 @@ a.navbar-brand {
|
||||||
}
|
}
|
||||||
|
|
||||||
.item-description {
|
.item-description {
|
||||||
white-space: pre;
|
white-space: pre-wrap;
|
||||||
}
|
}
|
||||||
|
|
@ -18,11 +18,6 @@
|
||||||
*/
|
*/
|
||||||
package org.librecms.pages.models;
|
package org.librecms.pages.models;
|
||||||
|
|
||||||
import org.libreccm.l10n.GlobalizationHelper;
|
|
||||||
import org.librecms.contentsection.ContentItem;
|
|
||||||
import org.librecms.contenttypes.MultiPartArticle;
|
|
||||||
import org.librecms.contenttypes.MultiPartArticleSection;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
@ -35,6 +30,13 @@ import javax.transaction.Transactional;
|
||||||
import javax.ws.rs.WebApplicationException;
|
import javax.ws.rs.WebApplicationException;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
|
|
||||||
|
import org.libreccm.l10n.GlobalizationHelper;
|
||||||
|
import org.librecms.contentsection.ContentItem;
|
||||||
|
import org.librecms.contenttypes.MultiPartArticle;
|
||||||
|
import org.librecms.contenttypes.MultiPartArticleSection;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
|
@ -60,6 +62,8 @@ public class MultiPartArticleModel implements ProcessesContentItem {
|
||||||
|
|
||||||
private List<String> sectionTitles;
|
private List<String> sectionTitles;
|
||||||
|
|
||||||
|
private List<String> sectionLinks;
|
||||||
|
|
||||||
private String currentSectionTitle;
|
private String currentSectionTitle;
|
||||||
|
|
||||||
private String currentSectionText;
|
private String currentSectionText;
|
||||||
|
|
@ -91,6 +95,13 @@ public class MultiPartArticleModel implements ProcessesContentItem {
|
||||||
return Collections.unmodifiableList(sectionTitles);
|
return Collections.unmodifiableList(sectionTitles);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
|
public List<String> getSectionLinks() {
|
||||||
|
contentItemModel.init();
|
||||||
|
|
||||||
|
return Collections.unmodifiableList(sectionLinks);
|
||||||
|
}
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
public String getCurrentSectionTitle() {
|
public String getCurrentSectionTitle() {
|
||||||
contentItemModel.init();
|
contentItemModel.init();
|
||||||
|
|
@ -142,8 +153,10 @@ public class MultiPartArticleModel implements ProcessesContentItem {
|
||||||
)
|
)
|
||||||
.orElse(Collections.emptyList());
|
.orElse(Collections.emptyList());
|
||||||
|
|
||||||
|
sectionLinks = buildSectionLinks();
|
||||||
|
|
||||||
final int currentSection = readCurrentSection();
|
final int currentSection = readCurrentSection();
|
||||||
if (mpa.getSections().size() > currentSection) {
|
if (mpa.getSections().size() < currentSection) {
|
||||||
throw new WebApplicationException(
|
throw new WebApplicationException(
|
||||||
Response
|
Response
|
||||||
.status(Response.Status.NOT_FOUND)
|
.status(Response.Status.NOT_FOUND)
|
||||||
|
|
@ -212,4 +225,45 @@ public class MultiPartArticleModel implements ProcessesContentItem {
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
|
private List<String> buildSectionLinks() {
|
||||||
|
final String pathWithoutSections;
|
||||||
|
if (pageUrlModel.getPath().matches(".*/@sections/[0-9]*$")) {
|
||||||
|
final String path = pageUrlModel.getPath();
|
||||||
|
pathWithoutSections = path.substring(
|
||||||
|
0,
|
||||||
|
path.lastIndexOf("/@sections") + 1
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
pathWithoutSections = pageUrlModel.getPath();
|
||||||
|
}
|
||||||
|
|
||||||
|
final List<String> sectionLinksList = new ArrayList<>();
|
||||||
|
for (int i = 0; i < sectionTitles.size(); i++) {
|
||||||
|
sectionLinksList.add(
|
||||||
|
String.format(
|
||||||
|
"%s/@sections/%d?%s",
|
||||||
|
pathWithoutSections,
|
||||||
|
i,
|
||||||
|
pageUrlModel
|
||||||
|
.getQueryParameters()
|
||||||
|
.entrySet()
|
||||||
|
.stream()
|
||||||
|
.map(
|
||||||
|
entry -> String.format(
|
||||||
|
"%s=%s",
|
||||||
|
entry.getKey(),
|
||||||
|
entry.getValue()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.collect(
|
||||||
|
Collectors.joining("&")
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return sectionLinksList;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue