Several bugfixes, some new data for data model for the theme engines,
ported utils.ftlccm-docs
parent
742e0de0b7
commit
4ee3303429
|
|
@ -13,6 +13,7 @@ import org.librecms.pages.Pages;
|
|||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.inject.Inject;
|
||||
|
|
@ -23,7 +24,7 @@ import javax.transaction.Transactional;
|
|||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@RequestScoped
|
||||
public class PageModelAdminPageController {
|
||||
class PageModelAdminPageController {
|
||||
|
||||
@Inject
|
||||
private GlobalizationHelper globalizationHelper;
|
||||
|
|
@ -32,19 +33,21 @@ public class PageModelAdminPageController {
|
|||
private PageModelRepository pageModelRepository;
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public Map<String, Object> findDraftPageModelsByApplication(
|
||||
protected List<PageModelData> findDraftPageModelsByApplication(
|
||||
final Pages pages
|
||||
) {
|
||||
final List<PageModel> pageModels = pageModelRepository
|
||||
.findDraftByApplication(pages);
|
||||
final Map<String, Object> result = new HashMap<>();
|
||||
for (final PageModel pageModel : pageModels) {
|
||||
result.put("pageModelId", pageModel.getPageModelId());
|
||||
final String title = globalizationHelper
|
||||
.getValueFromLocalizedString(pageModel.getTitle());
|
||||
result.put("title", title);
|
||||
return pageModels.stream().map(this::buildPageModelData).collect(
|
||||
Collectors.toList()
|
||||
);
|
||||
}
|
||||
|
||||
private PageModelData buildPageModelData(final PageModel fromPageModel) {
|
||||
final PageModelData result = new PageModelData();
|
||||
result.setPageModelId(fromPageModel.getPageModelId());
|
||||
result.setTitle(globalizationHelper.getValueFromLocalizedString(
|
||||
fromPageModel.getTitle()));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -57,10 +57,11 @@ import org.librecms.pages.PageManager;
|
|||
import org.librecms.pages.PageRepository;
|
||||
import org.librecms.pages.Pages;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.TooManyListenersException;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
|
|
@ -68,19 +69,27 @@ import java.util.TooManyListenersException;
|
|||
public class PagesAdminPage extends CMSApplicationPage {
|
||||
|
||||
private static final String INDEX_PAGE_MODEL_SELECT = "indexPageModelSelect";
|
||||
|
||||
private static final String ITEM_PAGE_MODEL_SELECT = "itemPageModelSelect";
|
||||
|
||||
private static final String INHERIT_PAGEMODEL = "--inherit--";
|
||||
|
||||
private final ParameterSingleSelectionModel<String> selectedCategory;
|
||||
|
||||
private final Tree categoryTree;
|
||||
|
||||
private final Label nothingSelectedLabel;
|
||||
|
||||
private final Form pageModelForm;
|
||||
|
||||
private final SingleSelect indexPageModelSelect;
|
||||
|
||||
private final SingleSelect itemPageModelSelect;
|
||||
|
||||
private final SaveCancelSection saveCancelSection;
|
||||
|
||||
private Pages pagesInstance;
|
||||
|
||||
private PagesContextBar pagesContextBar;
|
||||
|
||||
public PagesAdminPage() {
|
||||
|
|
@ -282,9 +291,16 @@ public class PagesAdminPage extends CMSApplicationPage {
|
|||
// }
|
||||
final PageModelAdminPageController controller = CdiUtil.createCdiUtil()
|
||||
.findBean(PageModelAdminPageController.class);
|
||||
final Map<String, Object> options = controller
|
||||
final List<PageModelData> pageModels = controller
|
||||
.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) {
|
||||
|
|
|
|||
|
|
@ -80,12 +80,24 @@ public class GreetingItemComponentRenderer
|
|||
parameters.get(PARAMETER_CATEGORY).getClass().getName()));
|
||||
}
|
||||
|
||||
final Category category = categoryRepo
|
||||
.findById(((CcmObject) parameters.get(PARAMETER_CATEGORY))
|
||||
.getObjectId())
|
||||
.orElseThrow(() -> new IllegalArgumentException(String.format(
|
||||
final Optional<Category> catResult = categoryRepo.findById(
|
||||
((CcmObject) parameters.get(PARAMETER_CATEGORY)).getObjectId()
|
||||
);
|
||||
final Category category = catResult.orElseThrow(
|
||||
() -> new IllegalArgumentException(
|
||||
String.format(
|
||||
"No category with ID %d in the database.",
|
||||
((CcmObject) parameters.get(PARAMETER_CATEGORY)).getObjectId())));
|
||||
((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
|
||||
.getIndexObject(category)
|
||||
|
|
|
|||
|
|
@ -38,7 +38,12 @@ public class CmsPageRenderer extends AbstractPageRenderer {
|
|||
public Map<String, Object> renderPage(final Map<String, Object> parameters) {
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -75,6 +75,14 @@ import static org.librecms.pages.PagesConstants.*;
|
|||
@Path("/")
|
||||
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
|
||||
private CategoryRepository categoryRepo;
|
||||
|
||||
|
|
@ -636,6 +644,11 @@ public class PagesRouter {
|
|||
|
||||
final String domain = uriInfo.getBaseUri().getHost();
|
||||
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 Locale locale = new Locale(language);
|
||||
|
|
|
|||
|
|
@ -12,13 +12,58 @@
|
|||
</#function>
|
||||
|
||||
<#--doc
|
||||
|
||||
Not supported in 7.0.0 yet, will always return an empty string.
|
||||
|
||||
Get the title of the current page.
|
||||
|
||||
This will only work of the current page is a navigation page with a category
|
||||
menu.
|
||||
This will only work of the current page with a category tree
|
||||
|
||||
@return The title of the current page
|
||||
-->
|
||||
<#function getPageTitle>
|
||||
<#return title>
|
||||
<#return "">
|
||||
</#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>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue