Display MPA in default theme (as index item).

pull/20/head
Jens Pelzetter 2022-03-02 20:40:45 +01:00
parent 496d0ac462
commit 591bb6b1d2
3 changed files with 98 additions and 18 deletions

View File

@ -5,6 +5,7 @@
"build": "npm-run-all build:*",
"build:mkdir": "shx mkdir -p target/generated-resources/themes/librecms",
"build:theme": "shx cp -r src/main/resources/themes/librecms/* target/generated-resources/themes/librecms",
"build:icons": "shx cp node_modules/bootstrap-icons/bootstrap-icons.svg target/generated-resources/themes/librecms/images/",
"build:js": "webpack",
"build:css": "npm-run-all build:css:*",
"build:css:librecms": "sass src/main/scss/librecms.scss target/generated-resources/themes/librecms/styles/librecms.css",

View File

@ -8,14 +8,54 @@
<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>
<#if section?index == CmsPagesMultiPartArticleModel.currentSection>
<a aria-current="page"
class="active nav-link"
href="${CmsPagesMultiPartArticleModel.sectionLinks[section?index]}">
${section}
</a>
<#else>
<a class="nav-link"
href="${CmsPagesMultiPartArticleModel.sectionLinks[section?index]}">
${section}
</a>
</#if>
</li>
</#list>
</ul>
</nav>
${CmsPagesMultiPartArticleModel.currentSectionText}
<nav>
<ul class="pagination">
<#if CmsPagesMultiPartArticleModel.prevSectionLink != "">
<li class="list-item">
<a class="page-link"
href="${CmsPagesMultiPartArticleModel.prevSectionLink}">
<svg class="bi"
fill="current-color"
height="1em"
width="1em">
<use xlink:href="${themeUrl}/images/bootstrap-icons.svg#caret-left-fill" />
</svg>
<span class="visually-hidden">Previous</span>
</a>
</li>
</#if>
<#if CmsPagesMultiPartArticleModel.nextSectionLink != "">
<li class="list-item">
<a class="page-link"
href="${CmsPagesMultiPartArticleModel.nextSectionLink}">
<svg class="bi"
fill="current-color"
height="1em"
width="1em">
<use xlink:href="${themeUrl}/images/bootstrap-icons.svg#caret-right-fill" />
</svg>
<span class="visually-hidden">Next</span>
</a>
</li>
</#if>
</ul>
</nav>
</div>
</#macro>

View File

@ -18,6 +18,7 @@
*/
package org.librecms.pages.models;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
@ -35,9 +36,6 @@ import org.librecms.contentsection.ContentItem;
import org.librecms.contenttypes.MultiPartArticle;
import org.librecms.contenttypes.MultiPartArticleSection;
import java.net.URL;
import java.util.ArrayList;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
@ -67,6 +65,12 @@ public class MultiPartArticleModel implements ProcessesContentItem {
private List<String> sectionLinks;
private String prevSectionLink;
private String nextSectionLink;
private int currentSection;
private String currentSectionTitle;
private String currentSectionText;
@ -105,6 +109,27 @@ public class MultiPartArticleModel implements ProcessesContentItem {
return Collections.unmodifiableList(sectionLinks);
}
@Transactional(Transactional.TxType.REQUIRED)
public String getPrevSectionLink() {
contentItemModel.init();
return prevSectionLink;
}
@Transactional(Transactional.TxType.REQUIRED)
public String getNextSectionLink() {
contentItemModel.init();
return nextSectionLink;
}
@Transactional(Transactional.TxType.REQUIRED)
public int getCurrentSection() {
contentItemModel.init();
return currentSection;
}
@Transactional(Transactional.TxType.REQUIRED)
public String getCurrentSectionTitle() {
contentItemModel.init();
@ -156,9 +181,8 @@ public class MultiPartArticleModel implements ProcessesContentItem {
)
.orElse(Collections.emptyList());
sectionLinks = buildSectionLinks();
final int currentSection = readCurrentSection();
currentSection = readCurrentSection();
if (mpa.getSections().size() < currentSection) {
throw new WebApplicationException(
Response
@ -189,6 +213,7 @@ public class MultiPartArticleModel implements ProcessesContentItem {
.orElse("");
}
sectionLinks = buildSectionLinks();
sections = mpa
.getSections()
.stream()
@ -236,8 +261,26 @@ public class MultiPartArticleModel implements ProcessesContentItem {
final int size = sectionTitles.size();
final List<String> sectionLinksList = new ArrayList<>();
for (int i = 0; i < size; i++) {
sectionLinksList.add(
String.format(
sectionLinksList.add(buildSectionLink(i));
}
if (currentSection == 0) {
prevSectionLink = "";
} else {
prevSectionLink = buildSectionLink(currentSection - 1);
}
if (currentSection < sectionLinksList.size() - 1) {
nextSectionLink = buildSectionLink(currentSection + 1);
} else {
nextSectionLink = "";
}
return sectionLinksList;
}
private String buildSectionLink(final int section) {
return String.format(
"?%s&%s=%d",
pageUrlModel
.getQueryParameters()
@ -257,12 +300,8 @@ public class MultiPartArticleModel implements ProcessesContentItem {
)
.collect(Collectors.joining("&")),
MPA_SECTION_QUERY_PARAM,
i
)
);
}
return sectionLinksList;
section
);
}
}