Several bugfixes, some new data for data model for the theme engines,

ported utils.ftl
Jens Pelzetter 2019-12-01 13:05:23 +01:00
parent c14e80f719
commit 15ac0bd916
7 changed files with 152 additions and 24 deletions

View File

@ -13,6 +13,7 @@ import org.librecms.pages.Pages;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors;
import javax.enterprise.context.RequestScoped; import javax.enterprise.context.RequestScoped;
import javax.inject.Inject; import javax.inject.Inject;
@ -23,7 +24,7 @@ import javax.transaction.Transactional;
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a> * @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/ */
@RequestScoped @RequestScoped
public class PageModelAdminPageController { class PageModelAdminPageController {
@Inject @Inject
private GlobalizationHelper globalizationHelper; private GlobalizationHelper globalizationHelper;
@ -32,19 +33,21 @@ public class PageModelAdminPageController {
private PageModelRepository pageModelRepository; private PageModelRepository pageModelRepository;
@Transactional(Transactional.TxType.REQUIRED) @Transactional(Transactional.TxType.REQUIRED)
public Map<String, Object> findDraftPageModelsByApplication( protected List<PageModelData> findDraftPageModelsByApplication(
final Pages pages final Pages pages
) { ) {
final List<PageModel> pageModels = pageModelRepository final List<PageModel> pageModels = pageModelRepository
.findDraftByApplication(pages); .findDraftByApplication(pages);
final Map<String, Object> result = new HashMap<>(); return pageModels.stream().map(this::buildPageModelData).collect(
for (final PageModel pageModel : pageModels) { Collectors.toList()
result.put("pageModelId", pageModel.getPageModelId()); );
final String title = globalizationHelper }
.getValueFromLocalizedString(pageModel.getTitle());
result.put("title", title); private PageModelData buildPageModelData(final PageModel fromPageModel) {
} final PageModelData result = new PageModelData();
result.setPageModelId(fromPageModel.getPageModelId());
result.setTitle(globalizationHelper.getValueFromLocalizedString(
fromPageModel.getTitle()));
return result; return result;
} }

View File

@ -0,0 +1,34 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.arsdigita.cms.ui.pages;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
class PageModelData {
private long pageModelId;
private String title;
public long getPageModelId() {
return pageModelId;
}
public void setPageModelId(long pageModelId) {
this.pageModelId = pageModelId;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}

View File

@ -57,10 +57,11 @@ import org.librecms.pages.PageManager;
import org.librecms.pages.PageRepository; import org.librecms.pages.PageRepository;
import org.librecms.pages.Pages; import org.librecms.pages.Pages;
import java.util.Map; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.TooManyListenersException; import java.util.TooManyListenersException;
/** /**
* *
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a> * @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
@ -68,19 +69,27 @@ import java.util.TooManyListenersException;
public class PagesAdminPage extends CMSApplicationPage { public class PagesAdminPage extends CMSApplicationPage {
private static final String INDEX_PAGE_MODEL_SELECT = "indexPageModelSelect"; private static final String INDEX_PAGE_MODEL_SELECT = "indexPageModelSelect";
private static final String ITEM_PAGE_MODEL_SELECT = "itemPageModelSelect"; private static final String ITEM_PAGE_MODEL_SELECT = "itemPageModelSelect";
private static final String INHERIT_PAGEMODEL = "--inherit--"; private static final String INHERIT_PAGEMODEL = "--inherit--";
private final ParameterSingleSelectionModel<String> selectedCategory; private final ParameterSingleSelectionModel<String> selectedCategory;
private final Tree categoryTree; private final Tree categoryTree;
private final Label nothingSelectedLabel; private final Label nothingSelectedLabel;
private final Form pageModelForm; private final Form pageModelForm;
private final SingleSelect indexPageModelSelect; private final SingleSelect indexPageModelSelect;
private final SingleSelect itemPageModelSelect; private final SingleSelect itemPageModelSelect;
private final SaveCancelSection saveCancelSection; private final SaveCancelSection saveCancelSection;
private Pages pagesInstance; private Pages pagesInstance;
private PagesContextBar pagesContextBar; private PagesContextBar pagesContextBar;
public PagesAdminPage() { public PagesAdminPage() {
@ -282,9 +291,16 @@ public class PagesAdminPage extends CMSApplicationPage {
// } // }
final PageModelAdminPageController controller = CdiUtil.createCdiUtil() final PageModelAdminPageController controller = CdiUtil.createCdiUtil()
.findBean(PageModelAdminPageController.class); .findBean(PageModelAdminPageController.class);
final Map<String, Object> options = controller final List<PageModelData> pageModels = controller
.findDraftPageModelsByApplication(pagesInstance); .findDraftPageModelsByApplication(pagesInstance);
for (final Map.Entry<St) for (final PageModelData pageModel : pageModels) {
target.addOption(
new Option(
Long.toString(pageModel.getPageModelId()),
new Text(pageModel.getTitle())
)
);
}
} }
private void categoryTreeStateChanged(final ChangeEvent event) { private void categoryTreeStateChanged(final ChangeEvent event) {

View File

@ -80,12 +80,24 @@ public class GreetingItemComponentRenderer
parameters.get(PARAMETER_CATEGORY).getClass().getName())); parameters.get(PARAMETER_CATEGORY).getClass().getName()));
} }
final Category category = categoryRepo final Optional<Category> catResult = categoryRepo.findById(
.findById(((CcmObject) parameters.get(PARAMETER_CATEGORY)) ((CcmObject) parameters.get(PARAMETER_CATEGORY)).getObjectId()
.getObjectId()) );
.orElseThrow(() -> new IllegalArgumentException(String.format( final Category category = catResult.orElseThrow(
"No category with ID %d in the database.", () -> new IllegalArgumentException(
((CcmObject) parameters.get(PARAMETER_CATEGORY)).getObjectId()))); String.format(
"No category with ID %d in the database.",
((CcmObject) parameters.get(PARAMETER_CATEGORY))
.getObjectId()
)
)
);
// final Category category = categoryRepo
// .findById(((CcmObject) parameters.get(PARAMETER_CATEGORY))
// .getObjectId())
// .orElseThrow(() -> new IllegalArgumentException(String.format(
// "No category with ID %d in the database.",
// ((CcmObject) parameters.get(PARAMETER_CATEGORY)).getObjectId())));
final Optional<CcmObject> indexObj = categoryManager final Optional<CcmObject> indexObj = categoryManager
.getIndexObject(category) .getIndexObject(category)

View File

@ -38,7 +38,12 @@ public class CmsPageRenderer extends AbstractPageRenderer {
public Map<String, Object> renderPage(final Map<String, Object> parameters) { public Map<String, Object> renderPage(final Map<String, Object> parameters) {
final Map<String, Object> result = new HashMap<>(); final Map<String, Object> result = new HashMap<>();
result.put("application", Pages.class.getName());
if (parameters.containsKey(PagesRouter.SITE_INFO)) {
result.put(
PagesRouter.SITE_INFO, parameters.get(PagesRouter.SITE_INFO)
);
}
return result; return result;
} }

View File

@ -75,6 +75,14 @@ import static org.librecms.pages.PagesConstants.*;
@Path("/") @Path("/")
public class PagesRouter { public class PagesRouter {
protected static final String SITE_INFO = "siteInfo";
protected static final String SITE_INFO_NAME = "name";
protected static final String SITE_INFO_DOMAIN = "domain";
protected static final String SITE_INFO_HOST = "host";
@Inject @Inject
private CategoryRepository categoryRepo; private CategoryRepository categoryRepo;
@ -636,6 +644,11 @@ public class PagesRouter {
final String domain = uriInfo.getBaseUri().getHost(); final String domain = uriInfo.getBaseUri().getHost();
final Pages pages = getPages(domain); final Pages pages = getPages(domain);
final Map<String, Object> siteInfo = new HashMap<>();
siteInfo.put(SITE_INFO_HOST, uriInfo.getBaseUri().getHost());
siteInfo.put(SITE_INFO_DOMAIN, pages.getSite().getDomainOfSite());
siteInfo.put(SITE_INFO_NAME, pages.getSite().getDisplayName());
parameters.put(SITE_INFO, siteInfo);
final Category category = getCategory(domain, pages, pagePath); final Category category = getCategory(domain, pages, pagePath);
final Locale locale = new Locale(language); final Locale locale = new Locale(language);

View File

@ -12,13 +12,58 @@
</#function> </#function>
<#--doc <#--doc
Not supported in 7.0.0 yet, will always return an empty string.
Get the title of the current page. Get the title of the current page.
This will only work of the current page is a navigation page with a category This will only work of the current page with a category tree
menu.
@return The title of the current page @return The title of the current page
--> -->
<#function getPageTitle> <#function getPageTitle>
<#return title> <#return "">
</#function> </#function>
<#--doc
Get the hostname from the sitebanner data.
@return The host name of the site.
-->
<#function getSiteHostName>
<#return siteInfo.hostName>
</#function>
<#--doc
Get the name of the site from the sitebanner data.
@return The name of the site.
-->
<#function getSiteName>
<#return siteInfo.siteName>
</#function>
<#--doc
A wrapper for the `_formatDateTime` function which adds missing numbers.
`_formatDateTime` uses Java APIs for formatting which don't work well with
incomplete dates. This function takes a date from the data model and checks
if a component (year, month, day, hour, minute, second) is missing. If the
the component is missing the function adds uses a default value of that
component.
@param style The date format style from the theme manifest to use.
@param date the date to format.
@return The formatted date.
-->
<#function formatDateTime style date>
<#assign year = date.year!0>
<#assign month = date.month!0>
<#assign day = date.day!0>
<#assign hour = date.hour!0>
<#assign minute = date.minute!0>
<#assign second = date.second!0>
<#return _formatDateTime(style, year, month, day, hour, minute, second)>
</#function>