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