Started implementation of UI for managing Pages instances and Page instances.

pull/10/head
Jens Pelzetter 2021-11-18 20:32:49 +01:00
parent e842cbc9ff
commit 1ac439a428
4 changed files with 197 additions and 3 deletions

View File

@ -34,7 +34,7 @@ import javax.transaction.Transactional;
/** /**
* Model for table of content sections. * Model for table of content sections.
* *
* @see CmsController#getContentSections() * @see ContentSectionsController#getContentSections()
* *
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a> * @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/ */

View File

@ -18,11 +18,17 @@
*/ */
package org.librecms.ui; package org.librecms.ui;
import org.libreccm.categorization.Domain;
import org.libreccm.core.CoreConstants;
import org.libreccm.security.AuthorizationRequired; import org.libreccm.security.AuthorizationRequired;
import org.libreccm.security.RequiresPrivilege;
import javax.enterprise.context.RequestScoped; import javax.enterprise.context.RequestScoped;
import javax.mvc.Controller; import javax.mvc.Controller;
import javax.transaction.Transactional;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET; import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path; import javax.ws.rs.Path;
/** /**
@ -35,9 +41,9 @@ import javax.ws.rs.Path;
public class PagesController { public class PagesController {
/** /**
* ToDo: Show UI for managing pages. * Shows all available pages instances.
* *
* @return Placeholder * @return The template to use.
*/ */
@GET @GET
@Path("/") @Path("/")
@ -46,4 +52,39 @@ public class PagesController {
return "org/librecms/ui/cms/pages.xhtml"; return "org/librecms/ui/cms/pages.xhtml";
} }
/**
* Creates a new {@link Pages} instance.
*
* @param siteParam The site for which the {@link Pages} instance
* is created.
* @param primaryUrlParam The primary URL/path of the pages instance.
* @param categoryDomainParam The category {@link Domain} to link with the
* {@link Pages} instance.
*
* @return Redirect to the list of {@link Pages} instances.
*/
@POST
@Path("/@new")
@AuthorizationRequired
@RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
@Transactional(Transactional.TxType.REQUIRED)
public String createPagesInstance(
@FormParam("site") final String siteParam,
@FormParam("primaryUrl") final String primaryUrlParam,
@FormParam("categoryDomain") final String categoryDomainParam
) {
// ToDo
throw new UnsupportedOperationException();
}
//ToDo: Update Pages instance
//ToDo: Delete Pages instance
//ToDo: Show details for Pages instance
//ToDo: Show details for page
//ToDo: Create Page for category
//ToDo: Edit Page for category
//ToDo: Remove page from category
//ToDo: Add page property
//ToDo: Edit page property
//ToDo: Remove page property
} }

View File

@ -0,0 +1,85 @@
/*
* Copyright (C) 2021 LibreCCM Foundation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package org.librecms.ui;
import org.libreccm.security.AuthorizationRequired;
import org.librecms.pages.Pages;
import org.librecms.pages.PagesRepository;
import java.util.List;
import java.util.stream.Collectors;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.inject.Named;
import javax.transaction.Transactional;
/**
* Model for the table of pages instances.
*
* @see PagesController#getPages()
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@RequestScoped
@Named("CmsPagesTableModel")
public class PagesTableModel {
/**
* Repository for pages.
*/
@Inject
private PagesRepository pagesRepo;
/**
* Retrieves all available pages instances and builds a
* {@link PagesTableRow} for each pages instance.
*
* @return A list of {@link PagesTableRow}s.
*/
@AuthorizationRequired
@Transactional(Transactional.TxType.REQUIRED)
public List<PagesTableRow> getPages() {
return pagesRepo
.findAll()
.stream()
.map(this::buildTableRow)
.sorted()
.collect(Collectors.toList());
}
/**
* Helper method for building a {@link PagesTableRow} for a {@link Pages}
* instance.
*
* @param pages The pages instance to map to an {@link PagesTableRow}.
*
* @return A {@link PagesTableRow} for the pages instance.
*/
private PagesTableRow buildTableRow(final Pages pages) {
final PagesTableRow row = new PagesTableRow();
row.setPagesId(pages.getObjectId());
row.setPrimaryUrl(pages.getPrimaryUrl());
row.setSite(pages.getSite().getDomainOfSite());
return row;
}
}

View File

@ -0,0 +1,68 @@
/*
* Copyright (C) 2021 LibreCCM Foundation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package org.librecms.ui;
import java.util.Comparator;
/**
* Model for a row in the {@link PagesTableModel}.
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public class PagesTableRow implements Comparable<PagesTableRow>{
private long pagesId;
private String site;
private String primaryUrl;
public long getPagesId() {
return pagesId;
}
public void setPagesId(final long pagesId) {
this.pagesId = pagesId;
}
public String getSite() {
return site;
}
public void setSite(final String site) {
this.site = site;
}
public String getPrimaryUrl() {
return primaryUrl;
}
public void setPrimaryUrl(final String primaryUrl) {
this.primaryUrl = primaryUrl;
}
@Override
public int compareTo(final PagesTableRow other) {
return Comparator
.comparing(PagesTableRow::getPrimaryUrl, String::compareTo)
.thenComparing(PagesTableRow::getSite, String::compareTo)
.thenComparing(PagesTableRow::getPagesId)
.compare(this, other);
}
}