CategoryModel now provides link for category
parent
e7cebdd9ff
commit
b174fe4b75
|
|
@ -20,7 +20,6 @@ package org.librecms.pages.models;
|
|||
|
||||
import org.libreccm.categorization.Category;
|
||||
import org.libreccm.categorization.CategoryManager;
|
||||
import org.libreccm.categorization.CategoryRepository;
|
||||
import org.libreccm.categorization.Domain;
|
||||
import org.libreccm.categorization.DomainRepository;
|
||||
import org.libreccm.l10n.GlobalizationHelper;
|
||||
|
|
@ -28,6 +27,7 @@ import org.librecms.contentsection.ContentItemVersion;
|
|||
import org.librecms.pages.PagesService;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
|
@ -57,9 +57,6 @@ public class CategoryModel implements Serializable {
|
|||
@Inject
|
||||
private GlobalizationHelper globalizationHelper;
|
||||
|
||||
@Inject
|
||||
private PagesService pagesService;
|
||||
|
||||
private CategoryDomainData domain;
|
||||
|
||||
private CategoryData category;
|
||||
|
|
@ -73,8 +70,8 @@ public class CategoryModel implements Serializable {
|
|||
*/
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public void init(
|
||||
final Domain domain,
|
||||
final Category category,
|
||||
final Domain domain,
|
||||
final Category category,
|
||||
final ContentItemVersion version
|
||||
) {
|
||||
this.domain = new CategoryDomainData();
|
||||
|
|
@ -126,6 +123,11 @@ public class CategoryModel implements Serializable {
|
|||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public CategoryTreeNode getCategoryTree() {
|
||||
if (domain == null) {
|
||||
final CategoryTreeNode emptyNode = new CategoryTreeNode();
|
||||
emptyNode.setSubCategories(Collections.emptyList());
|
||||
return emptyNode;
|
||||
}
|
||||
final Domain currentDomain = domainRepository
|
||||
.findById(domain.getDomainId())
|
||||
.orElseThrow(
|
||||
|
|
@ -148,6 +150,13 @@ public class CategoryModel implements Serializable {
|
|||
) {
|
||||
final CategoryTreeNode node = new CategoryTreeNode();
|
||||
node.setCategoryPath(categoryManager.getCategoryPath(fromCategory));
|
||||
node.setCategoyLink(
|
||||
String.format(
|
||||
"/pages/%s/index.%s.html",
|
||||
node.getCategoryPath(),
|
||||
globalizationHelper.getNegotiatedLocale().toString()
|
||||
)
|
||||
);
|
||||
node.setDescription(
|
||||
globalizationHelper.getValueFromLocalizedString(
|
||||
fromCategory.getDescription())
|
||||
|
|
|
|||
|
|
@ -37,6 +37,8 @@ public class CategoryTreeNode {
|
|||
private String description;
|
||||
|
||||
private String categoryPath;
|
||||
|
||||
private String categoryLink;
|
||||
|
||||
private boolean visible;
|
||||
|
||||
|
|
@ -87,6 +89,14 @@ public class CategoryTreeNode {
|
|||
protected void setCategoryPath(final String categoryPath) {
|
||||
this.categoryPath = categoryPath;
|
||||
}
|
||||
|
||||
public String getCategoryLink() {
|
||||
return categoryLink;
|
||||
}
|
||||
|
||||
protected void setCategoyLink(final String categoryLink) {
|
||||
this.categoryLink = categoryLink;
|
||||
}
|
||||
|
||||
public List<CategoryTreeNode> getSubCategories() {
|
||||
return Collections.unmodifiableList(subCategories);
|
||||
|
|
|
|||
|
|
@ -123,7 +123,6 @@ public class PageUrlModel {
|
|||
|
||||
breadcrumbs = new ArrayList<>();
|
||||
breadcrumbs = buildBreadcrumbs(categoryModel.getCategoryTree());
|
||||
|
||||
}
|
||||
|
||||
public String getProtocol() {
|
||||
|
|
@ -151,9 +150,12 @@ public class PageUrlModel {
|
|||
}
|
||||
|
||||
public List<BreadcrumbData> getBreadcrumbs() {
|
||||
return Collections.unmodifiableList(breadcrumbs);
|
||||
return Optional
|
||||
.ofNullable(breadcrumbs)
|
||||
.map(Collections::unmodifiableList)
|
||||
.orElse(Collections.emptyList());
|
||||
}
|
||||
|
||||
|
||||
public String getPageName() {
|
||||
return pageName;
|
||||
}
|
||||
|
|
@ -228,13 +230,13 @@ public class PageUrlModel {
|
|||
Collectors.joining("&", "?", "")
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
private List<BreadcrumbData> buildBreadcrumbs(
|
||||
final CategoryTreeNode category
|
||||
) {
|
||||
return buildBreadcrumbs(category, new ArrayList<>());
|
||||
}
|
||||
|
||||
|
||||
private List<BreadcrumbData> buildBreadcrumbs(
|
||||
final CategoryTreeNode category,
|
||||
final List<BreadcrumbData> breadcrumbs
|
||||
|
|
@ -244,15 +246,15 @@ public class PageUrlModel {
|
|||
.stream()
|
||||
.filter(subCat -> subCat.isSelected())
|
||||
.findAny();
|
||||
|
||||
|
||||
if (selected.isPresent()) {
|
||||
final BreadcrumbData breadcrumb = new BreadcrumbData();
|
||||
breadcrumb.setPath(selected.get().getCategoryPath());
|
||||
breadcrumb.setTitle(selected.get().getTitle());
|
||||
|
||||
|
||||
buildBreadcrumbs(selected.get(), breadcrumbs);
|
||||
}
|
||||
|
||||
|
||||
return breadcrumbs;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue