Several improvements for path handling and asset creation and editing.

pull/10/head
Jens Pelzetter 2021-05-15 17:53:26 +02:00
parent 6b125c532f
commit 101f802d9c
21 changed files with 364 additions and 267 deletions

View File

@ -22,6 +22,9 @@ import com.arsdigita.cms.ui.assets.forms.PostalAddressForm;
import org.hibernate.envers.Audited;
import org.librecms.contentsection.Asset;
import org.librecms.ui.contentsections.assets.MvcAssetEditKit;
import org.librecms.ui.contentsections.assets.PostalAddressCreateStep;
import org.librecms.ui.contentsections.assets.PostalAddressEditStep;
import java.util.Objects;
@ -29,8 +32,9 @@ import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import static org.librecms.CmsConstants.*;
import static org.librecms.assets.AssetConstants.*;
import static org.librecms.CmsConstants.DB_SCHEMA;
import static org.librecms.assets.AssetConstants.ASSETS_BUNDLE;
/**
* A reuable postal address.
@ -40,11 +44,17 @@ import static org.librecms.assets.AssetConstants.*;
@Entity
@Audited
@Table(name = "POSTAL_ADDRESSES", schema = DB_SCHEMA)
@AssetType(assetForm = PostalAddressForm.class,
@AssetType(
assetForm = PostalAddressForm.class,
labelBundle = ASSETS_BUNDLE,
labelKey = "postaladdress.label",
descriptionBundle = ASSETS_BUNDLE,
descriptionKey = "postaladdress.description")
descriptionKey = "postaladdress.description"
)
@MvcAssetEditKit(
createStep = PostalAddressCreateStep.class,
editStep = PostalAddressEditStep.class
)
public class PostalAddress extends Asset {
private static final long serialVersionUID = 1L;

View File

@ -501,8 +501,10 @@ public class FolderManager {
Folder current = folder;
while (getParentFolder(current).isPresent()) {
current = getParentFolder(current).get();
if (getParentFolder(current).isPresent()) {
tokens.add(current.getName());
}
}
Collections.reverse(tokens);
final String path = String.join("/", tokens);

View File

@ -665,11 +665,11 @@ public class AssetFolderController {
row.setFolderPath(
folderManager
.getFolderPath(folder)
.substring(
folderManager
.getFolderPath(section.getRootAssetsFolder())
.length()
)
// .substring(
// folderManager
// .getFolderPath(section.getRootAssetsFolder())
// .length()
// )
);
row.setName(entry.getDisplayName());
row.setTitle(

View File

@ -22,6 +22,7 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.libreccm.ui.IsAuthenticatedFilter;
import org.librecms.ui.contentsections.assets.AssetEditStepsValidator;
import org.librecms.ui.contentsections.assets.AssetController;
import org.librecms.ui.contentsections.assets.MvcAssetEditSteps;
import org.librecms.ui.contentsections.documents.AuthoringStepsValidator;
import org.librecms.ui.contentsections.documents.DocumentController;
@ -69,6 +70,7 @@ public class ContentSectionApplication extends Application {
public Set<Class<?>> getClasses() {
final Set<Class<?>> classes = new HashSet<>();
classes.add(AssetController.class);
classes.add(AssetFolderController.class);
classes.add(CategoriesController.class);
classes.add(ConfigurationController.class);

View File

@ -799,11 +799,11 @@ public class DocumentFolderController {
row.setFolderPath(
folderManager
.getFolderPath(folder)
.substring(
folderManager
.getFolderPath(section.getRootDocumentsFolder())
.length()
)
// .substring(
// folderManager
// .getFolderPath(section.getRootDocumentsFolder())
// .length()
// )
);
row.setLanguages(Collections.emptySortedSet());
row.setLastEditPublished(false);

View File

@ -137,7 +137,7 @@ public abstract class AbstractMvcAssetCreateStep<T extends Asset>
if (folder.getParentFolder() == null) {
return "";
} else {
return folderManager.getFolderPath(folder);
return folderManager.getFolderPath(folder).substring(1);
}
}

View File

@ -19,7 +19,6 @@
package org.librecms.ui.contentsections.assets;
import org.libreccm.l10n.GlobalizationHelper;
import org.libreccm.security.AuthorizationRequired;
import org.librecms.contentsection.Asset;
import org.librecms.contentsection.AssetManager;
import org.librecms.contentsection.AssetRepository;
@ -28,7 +27,6 @@ import org.librecms.ui.contentsections.AssetPermissionsChecker;
import org.librecms.ui.contentsections.ContentSectionModel;
import org.librecms.ui.contentsections.ContentSectionsUi;
import org.librecms.ui.contentsections.ContentSectionNotFoundException;
import org.librecms.ui.contentsections.documents.MvcAuthoringSteps;
import java.util.HashMap;
import java.util.Map;
@ -37,10 +35,6 @@ import java.util.Optional;
import javax.inject.Inject;
import javax.mvc.Models;
import javax.servlet.http.HttpServletRequest;
import javax.transaction.Transactional;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.WebApplicationException;
@ -82,10 +76,10 @@ public abstract class AbstractMvcAssetEditStep implements MvcAssetEditStep {
@Inject
private SelectedAssetModel assetModel;
@PathParam(MvcAuthoringSteps.SECTION_IDENTIFIER_PATH_PARAM)
@PathParam(MvcAssetEditSteps.SECTION_IDENTIFIER_PATH_PARAM)
private String sectionIdentifier;
@PathParam(MvcAuthoringSteps.DOCUMENT_PATH_PATH_PARAM_NAME)
@PathParam(MvcAssetEditSteps.ASSET_PATH_PATH_PARAM_NAME)
private String assetPathParam;
private ContentSection contentSection;

View File

@ -60,7 +60,7 @@ import javax.ws.rs.core.MediaType;
@RequestScoped
@Path("/{sectionIdentifier}/assets")
@Controller
public class AssetsController {
public class AssetController {
@Inject
private AssetEditStepsValidator stepsValidator;
@ -183,7 +183,7 @@ public class AssetsController {
@Transactional(Transactional.TxType.REQUIRED)
public String showCreateStepPost(
@PathParam("sectionIdentifier") final String sectionIdentifier,
@FormParam("documentType") final String assetType
@FormParam("assetType") final String assetType
) {
return String.format(
"redirect:/%s/assets/@create/%s",
@ -199,7 +199,7 @@ public class AssetsController {
public String showCreateStep(
@PathParam("sectionIdentifier") final String sectionIdentifier,
@PathParam("folderPath") final String folderPath,
@FormParam("assetType") final String assetType
@PathParam("assetType") final String assetType
) {
final CreateStepResult result = findCreateStep(
sectionIdentifier,
@ -224,7 +224,7 @@ public class AssetsController {
@FormParam("assetType") final String assetType
) {
return String.format(
"redirect:/%s/documents/%s/@create/%s",
"redirect:/%s/assets/%s/@create/%s",
sectionIdentifier,
folderPath,
assetType
@ -275,7 +275,7 @@ public class AssetsController {
}
@GET
@Path("/{assetPath:(.+)?")
@Path("/{assetPath:(.+)?}")
@AuthorizationRequired
@Transactional(Transactional.TxType.REQUIRED)
public String editAsset(
@ -345,7 +345,7 @@ public class AssetsController {
* @param section The content section.
* @param folderPath The folder path.
*
* @return The template of the "document folder not found" page.
* @return The template of the "asset folder not found" page.
*/
private String showAssetFolderNotFound(
final ContentSection section, final String folderPath

View File

@ -58,7 +58,7 @@ public class AssetUi {
models.put("section", section.getLabel());
models.put("assetPath", assetPath);
models.put(step, step);
return "org/librecms/ui/contentsections/assets/access-denied.xhtml";
return "org/librecms/ui/contentsection/assets/access-denied.xhtml";
}
public String showAssetNotFound(
@ -66,7 +66,7 @@ public class AssetUi {
) {
models.put("section", section.getLabel());
models.put("assetPath", assetPath);
return "/org/librecms/ui/contentsections/assets/asset-not-found.xhtml";
return "/org/librecms/ui/contentsection/assets/asset-not-found.xhtml";
}
}

View File

@ -0,0 +1,39 @@
/*
* 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.contentsections.assets;
import java.util.HashSet;
import java.util.Set;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public class CmsAssetEditSteps implements MvcAssetEditSteps {
@Override
public Set<Class<?>> getClasses() {
final Set<Class<?>> classes = new HashSet<>();
classes.add(PostalAddressEditStep.class);
return classes;
}
}

View File

@ -25,8 +25,11 @@ import org.librecms.contentsection.AssetManager;
import org.librecms.contentsection.AssetRepository;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import javax.enterprise.context.RequestScoped;
@ -76,7 +79,7 @@ public class PostalAddressCreateStep
@Override
public String showCreateStep() {
return "/org/librecms/ui/assets/postaladdress/create-postaladdress.xhtml";
return "org/librecms/ui/contentsection/assets/postaladdress/create-postaladdress.xhtml";
}
@AuthorizationRequired
@ -220,17 +223,29 @@ public class PostalAddressCreateStep
}
public Map<String, String> getCountries() {
return Arrays
final Set<Locale> countries = Arrays
.stream(Locale.getISOCountries())
.map(country -> new Locale(country))
.map(country -> new Locale("", country))
.collect(Collectors.toCollection(LinkedHashSet::new));
final Map<String, String> countriesMap = countries
.stream()
.collect(
Collectors.toMap(
Locale::toString,
Locale::getCountry,
locale -> locale.getDisplayCountry(
globalizationHelper.getNegotiatedLocale()
)
),
(value1, value2) -> value1,
LinkedHashMap::new
)
);
final Map<String, String> values = new LinkedHashMap<>();
values.put("", "");
values.putAll(countriesMap);
return values;
}
}

View File

@ -29,6 +29,8 @@ import org.librecms.ui.contentsections.ContentSectionNotFoundException;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@ -92,11 +94,41 @@ public class PostalAddressEditStep extends AbstractMvcAssetEditStep {
private List<String> unusedTitleLocales;
private Map<String, String> countries;
@Override
public Class<? extends MvcAssetEditStep> getStepClass() {
return PostalAddressEditStep.class;
}
@Override
protected void init() throws ContentSectionNotFoundException,
AssetNotFoundException {
super.init();
final Set<Locale> countryLocales = Arrays
.stream(Locale.getISOCountries())
.map(country -> new Locale("", country))
.collect(Collectors.toCollection(LinkedHashSet::new));
final Map<String, String> countriesMap = countryLocales
.stream()
.collect(
Collectors.toMap(
Locale::getCountry,
locale -> locale.getDisplayCountry(
globalizationHelper.getNegotiatedLocale()
),
(value1, value2) -> value1,
LinkedHashMap::new
)
);
countries = new LinkedHashMap<>();
countries.put("", "");
countries.putAll(countriesMap);
}
@GET
@Path("/")
@AuthorizationRequired
@ -139,7 +171,7 @@ public class PostalAddressEditStep extends AbstractMvcAssetEditStep {
.map(Locale::toString)
.collect(Collectors.toList());
return "org/librecms/ui/assets/postaladdress/edit-postaladdress.xhtml";
return "org/librecms/ui/contentsection/assets/postaladdress/edit-postaladdress.xhtml";
} else {
return assetUi.showAccessDenied(
getContentSection(),
@ -326,8 +358,7 @@ public class PostalAddressEditStep extends AbstractMvcAssetEditStep {
}
public String getCountry() {
return new Locale(getPostalAddress()
.getIsoCountryCode())
return new Locale("", getPostalAddress().getIsoCountryCode())
.getDisplayCountry(globalizationHelper.getNegotiatedLocale());
}
@ -374,17 +405,7 @@ public class PostalAddressEditStep extends AbstractMvcAssetEditStep {
}
public Map<String, String> getCountries() {
return Arrays
.stream(Locale.getISOCountries())
.map(country -> new Locale(country))
.collect(
Collectors.toMap(
Locale::toString,
locale -> locale.getDisplayCountry(
globalizationHelper.getNegotiatedLocale()
)
)
);
return countries;
}
}

View File

@ -206,7 +206,7 @@ public abstract class AbstractMvcDocumentCreateStep<T extends ContentItem>
if (folder.getParentFolder() == null) {
return "";
} else {
return folderManager.getFolderPath(folder);
return folderManager.getFolderPath(folder).substring(1);
}
}

View File

@ -34,7 +34,6 @@ import org.librecms.lifecycle.LifecycleDefinition;
import org.librecms.lifecycle.Phase;
import org.librecms.ui.contentsections.ContentSectionModel;
import org.librecms.ui.contentsections.ContentSectionsUi;
import org.librecms.ui.contentsections.DocumentFolderController;
import org.librecms.ui.contentsections.ItemPermissionChecker;
import java.time.ZoneId;
@ -257,7 +256,7 @@ public class DocumentController {
public String showCreateStep(
@PathParam("sectionIdentifier") final String sectionIdentifier,
@PathParam("folderPath") final String folderPath,
@FormParam("documentType") final String documentType
@PathParam("documentType") final String documentType
) {
final CreateStepResult result = findCreateStep(
sectionIdentifier,
@ -273,7 +272,7 @@ public class DocumentController {
}
@POST
@Path("/{folderPath:(.+)?}/@create/{documentType}")
@Path("/{folderPath:(.+)?}/@create")
@AuthorizationRequired
@Transactional(Transactional.TxType.REQUIRED)
public String showCreateStepPost(

View File

@ -107,6 +107,11 @@
default="Failed to load variant."
required="false"
type="String" />
<cc:attribute name="mode"
default="full"
shortDescription="The editor mode. Use 'full' to enable all options including adding images etc. Use 'textonly' for a minimal version that only supports text editing, but does not allow insertation of images etc."
required="false"
type="String" />
<cc:attribute name="objectIdentifier"
required="true"
shortDescription="Identifier of the object to which the localized string belongs"

View File

@ -275,8 +275,8 @@
<c:when test="#{row.folder and (row.permissions.grantedEdit or row.permissions.grantedPreview)}">
<a href="#{mvc.basePath}/#{ContentSectionModel.sectionName}/assetfolders/#{row.folderPath}">#{row.name}</a>
</c:when>
<c:when test="#{row.permissions.grantedApprove or row.permissions.grantedCategorize or row.permissions.grantedEdit or row.permissions.grantedPreview or row.permissions.grantedPublish}">
<a href="#">#{row.name}</a>
<c:when test="#{row.permissions.grantedEdit or row.permissions.grantedUse or row.permissions.grantedView}">
<a href="#{mvc.basePath}/#{ContentSectionModel.sectionName}/assets/#{AssetFolderModel.pathWithTrailingSlash}#{row.name}">#{row.name}</a>
</c:when>
<c:otherwise>
<span>#{row.name}</span>

View File

@ -83,10 +83,11 @@
label="#{CmsAssetsStepsDefaultMessagesBundle['createform.postaladdress.country.label']}"
name="isoCountryCode"
options="#{CmsPostalAddressCreateStep.countries}"
required="false"
/>
<a class="btn btn-warning"
href="#{mvc.basePath}/#{CmsPostalAddressCreateStep.contentSectionLabel}/assetsfolders/#{CmsPostalAddressCreateStep.folderPath}">
href="#{mvc.basePath}/#{CmsPostalAddressCreateStep.contentSectionLabel}/assetfolders/#{CmsPostalAddressCreateStep.folderPath}">
#{CmsAssetsStepsDefaultMessagesBundle['createform.cancel']}
</a>
<button class="btn btn-success"

View File

@ -5,7 +5,10 @@
xmlns:libreccm="http://xmlns.jcp.org/jsf/composite/components/libreccm"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<ui:composition template="/WEB-INF/views/org/librecms/ui/contentsections/assets/editstep.xhtml">
<ui:composition template="/WEB-INF/views/org/librecms/ui/contentsection/assets/editstep.xhtml">
<ui:define name="editStep">
<div class="container">
<h2>#{CmsAssetsStepsDefaultMessagesBundle.getMessage('postaladdress.editstep.header', [CmsPostalAddressEditStep.name])}</h2>
<h3>#{CmsAssetsStepsDefaultMessagesBundle['editstep.name.header']}</h3>
@ -31,7 +34,7 @@
id="name-edit-dialog"
tabindex="-1">
<div class="modal-dialog">
<form action="#{mvc.basePath}/#{ContentSectionModel.sectionName}/assets/#{CmsSelectedAssetModel.assetPath}/@edit-postaladdress/name"
<form action="#{mvc.basePath}/#{ContentSectionModel.sectionName}/assets/#{CmsSelectedAssetModel.assetPath}/@postaladdress-edit/name"
class="modal-content"
method="post">
<div class="modal-header">
@ -198,7 +201,7 @@
<dl>
<div>
<dt>#{CmsAssetsStepsDefaultMessagesBundle['postaladdress.editstep.properties.address.label']}</dt>
<dd>#{CmsPostalAddressEditStep.address}</dd>
<dd><pre>#{CmsPostalAddressEditStep.address}</pre></dd>
</div>
<div>
<dt>#{CmsAssetsStepsDefaultMessagesBundle['postaladdress.editstep.properties.postal_code.label']}</dt>
@ -217,6 +220,8 @@
<dd>#{CmsPostalAddressEditStep.country}</dd>
</div>
</dl>
</div>
</ui:define>
</ui:composition>

View File

@ -63,3 +63,5 @@ postaladdress.editstep.properties.state.label=State
postaladdress.editstep.properties.edit.country.help=The country part of the address.
postaladdress.editstep.properties.country.label=Country
postaladdress.editstep.properties.edit.submit=Save
postal_address.label=Postal address
editstep.name.close=Cancel

View File

@ -63,3 +63,5 @@ postaladdress.editstep.properties.state.label=Bundesstaat
postaladdress.editstep.properties.edit.country.help=Das Land, in dem sich die Adresse befindet.
postaladdress.editstep.properties.country.label=Land
postaladdress.editstep.properties.edit.submit=Speichern
postal_address.label=Postanschrift
editstep.name.close=Abbrechen

View File

@ -52,7 +52,7 @@
id="#{cc.attrs.inputId}"
multiple="#{cc.attrs.multiple ? 'multiple' : null}"
name="#{cc.attrs.name}"
required="#{cc.attrs.required}"
required="#{cc.attrs.required ? 'required' : ''}"
size="#{not empty cc.attrs.size ? cc.attrs.size : null}">
<c:forEach items="#{cc.attrs.options.entrySet()}" var="option">
<option selected="#{cc.attrs.selectedOptions.contains(option.key) ? 'selected' : null}"