Bugfixes for the edit steps of the multipart article

pull/10/head
Jens Pelzetter 2021-12-23 21:21:21 +01:00
parent 6b48c5deec
commit 568a9fa6bc
7 changed files with 232 additions and 121 deletions

View File

@ -18,6 +18,8 @@
*/
package org.librecms.ui.contenttypes.mpa;
import org.librecms.ui.contentsections.documents.CmsEditorLocaleVariantRow;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@ -39,6 +41,8 @@ public class MpaSectionModel {
private long sectionId;
private String sectionTitle;
private boolean pageBreak;
private int rank;
@ -49,7 +53,7 @@ public class MpaSectionModel {
private List<String> unusedTitleLocales;
private Map<String, String> textValues;
private List<CmsEditorLocaleVariantRow> textValues;
private Map<String, String> truncatedTextValues;
@ -71,6 +75,14 @@ public class MpaSectionModel {
this.sectionId = sectionId;
}
public String getSectionTitle() {
return sectionTitle;
}
protected void setSectionTitle(final String sectionTitle) {
this.sectionTitle = sectionTitle;
}
public boolean isPageBreak() {
return pageBreak;
}
@ -115,12 +127,12 @@ public class MpaSectionModel {
return !unusedTitleLocales.isEmpty();
}
public Map<String, String> getTextValues() {
return Collections.unmodifiableMap(textValues);
public List<CmsEditorLocaleVariantRow> getTextValues() {
return Collections.unmodifiableList(textValues);
}
protected void setTextValues(final Map<String, String> textValues) {
this.textValues = new HashMap<>(textValues);
protected void setTextValues(final List<CmsEditorLocaleVariantRow> textValues) {
this.textValues = new ArrayList<>(textValues);
}
public Map<String, String> getTruncatedTextValues() {

View File

@ -27,6 +27,7 @@ import org.librecms.contenttypes.MultiPartArticleSectionRepository;
import org.librecms.ui.contentsections.ContentSectionNotFoundException;
import org.librecms.ui.contentsections.ItemPermissionChecker;
import org.librecms.ui.contentsections.documents.AbstractMvcAuthoringStep;
import org.librecms.ui.contentsections.documents.CmsEditorLocaleVariantRow;
import org.librecms.ui.contentsections.documents.DocumentNotFoundException;
import org.librecms.ui.contentsections.documents.DocumentUi;
import org.librecms.ui.contentsections.documents.MvcAuthoringStepDef;
@ -38,6 +39,7 @@ import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.stream.Collectors;
import javax.enterprise.context.RequestScoped;
@ -92,6 +94,7 @@ public class MvcMpaSectionsStep extends AbstractMvcAuthoringStep {
@Inject
private MpaSectionsStepModel mpaSectionsStepModel;
@Inject
private MpaSectionModel mpaSectionModel;
@ -338,7 +341,9 @@ public class MvcMpaSectionsStep extends AbstractMvcAuthoringStep {
section.getTitle().putValue(locale, value);
sectionRepo.save(section);
return buildRedirectPathForStep();
return String.format(
"%s/%d", buildRedirectPathForStep(), section.getSectionId()
);
} else {
return documentUi.showAccessDenied(
getContentSection(),
@ -349,7 +354,7 @@ public class MvcMpaSectionsStep extends AbstractMvcAuthoringStep {
}
@POST
@Path("/{sectionId}/title/@remove")
@Path("/{sectionId}/title/@remove/{locale}")
@Transactional(Transactional.TxType.REQUIRED)
public String removeTitleValue(
@PathParam(MvcAuthoringSteps.SECTION_IDENTIFIER_PATH_PARAM)
@ -358,7 +363,7 @@ public class MvcMpaSectionsStep extends AbstractMvcAuthoringStep {
final String documentPath,
@PathParam("sectionId")
final String sectionIdParam,
@FormParam("locale")
@PathParam("locale")
final String localeParam
) {
try {
@ -385,7 +390,9 @@ public class MvcMpaSectionsStep extends AbstractMvcAuthoringStep {
section.getTitle().removeValue(locale);
sectionRepo.save(section);
return buildRedirectPathForStep();
return String.format(
"%s/%d", buildRedirectPathForStep(), section.getSectionId()
);
} else {
return documentUi.showAccessDenied(
getContentSection(),
@ -440,7 +447,9 @@ public class MvcMpaSectionsStep extends AbstractMvcAuthoringStep {
section.getText().putValue(locale, value);
sectionRepo.save(section);
return buildRedirectPathForStep();
return String.format(
"%s/%d", buildRedirectPathForStep(), section.getSectionId()
);
} else {
return documentUi.showAccessDenied(
getContentSection(),
@ -512,7 +521,9 @@ public class MvcMpaSectionsStep extends AbstractMvcAuthoringStep {
section.getText().putValue(locale, value);
sectionRepo.save(section);
return buildRedirectPathForStep();
return String.format(
"%s/%d", buildRedirectPathForStep(), section.getSectionId()
);
} else {
return documentUi.showAccessDenied(
getContentSection(),
@ -559,7 +570,9 @@ public class MvcMpaSectionsStep extends AbstractMvcAuthoringStep {
section.getText().removeValue(locale);
sectionRepo.save(section);
return buildRedirectPathForStep();
return String.format(
"%s/%d", buildRedirectPathForStep(), section.getSectionId()
);
} else {
return documentUi.showAccessDenied(
getContentSection(),
@ -601,10 +614,12 @@ public class MvcMpaSectionsStep extends AbstractMvcAuthoringStep {
}
final MultiPartArticleSection section = result.get();
section.setPageBreak(Boolean.parseBoolean(pageBreakParam));
section.setPageBreak(pageBreakParam != null);
sectionRepo.save(section);
return buildRedirectPathForStep();
return String.format(
"%s/%d", buildRedirectPathForStep(), section.getSectionId()
);
} else {
return documentUi.showAccessDenied(
getContentSection(),
@ -718,18 +733,19 @@ public class MvcMpaSectionsStep extends AbstractMvcAuthoringStep {
mpaSectionModel.setPageBreak(section.isPageBreak());
mpaSectionModel.setRank(section.getRank());
mpaSectionModel.setSectionId(section.getSectionId());
mpaSectionModel.setSectionTitle(
globalizationHelper.getValueFromLocalizedString(
section.getTitle()
)
);
mpaSectionModel.setTextValues(
section
.getText()
.getValues()
.entrySet()
.stream()
.collect(
Collectors.toMap(
entry -> entry.getKey().toString(),
Map.Entry::getValue
)
)
.map(this::buildVariantRow)
.collect(Collectors.toList())
);
mpaSectionModel.setTitleValues(
section
@ -805,4 +821,14 @@ public class MvcMpaSectionsStep extends AbstractMvcAuthoringStep {
return showStep(sectionIdentifier, documentPath);
}
private CmsEditorLocaleVariantRow buildVariantRow(
final Map.Entry<Locale, String> variant
) {
final CmsEditorLocaleVariantRow row = new CmsEditorLocaleVariantRow();
row.setLocale(variant.getKey().toString());
row.setWordCount(new StringTokenizer(variant.getValue()).countTokens());
return row;
}
}

View File

@ -16,11 +16,11 @@
</a>
<h2>#{CmsMpaMessageBundle.getMessage('sectionstep.textstep.header.edit',[CmsMpaSectionStep.articleTitle, CmsMpaSectionStep.titleValues.get(CmsMpaSectionStep.selectedLocale) , CmsMpaSectionStep.selectedLocale])}</h2>
<c:if test="#{CmsArticleTextBodyStep.canEdit}">
<c:if test="#{CmsMpaSectionsStep.canEdit}">
<librecms:cmsEditor
backUrl="#{mvc.basePath}/#{ContentSectionModel.sectionName}/documents/#{CmsSelectedDocumentModel.itemPath}/@mpa-sections/#{CmsMpaSectionStep.sectionId}"
baseUrl="#{mvc.basePath}"
canEdit="#{CmsMpaSectionStep.canEdit}"
canEdit="#{CmsMpaSectionsStep.canEdit}"
contentSection="#{ContentSectionModel.sectionName}"
editMethod="#{mvc.basePath}/#{ContentSectionModel.sectionName}/documents/#{CmsSelectedDocumentModel.itemPath}/@mpa-sections/edit"
editorId="cms-mpa-section-text-editor"

View File

@ -9,19 +9,49 @@
<ui:define name="authoringStep">
<div class="d-flex">
<div>
<a class="btn btn-secondary btn-sm mr-2"
href="#{mvc.basePath}/#{ContentSectionModel.sectionName}/documents/#{CmsSelectedDocumentModel.itemPath}/@mpa-sections">
<bootstrap:svgIcon icon="caret-left-fill" />
<span class="sr-only">#{CmsMpaMessageBundle['sectionstep.back']}</span>
</a>
<h2>#{CmsMpaMessageBundle.getMessage('sectionstep.header', CmsMpaSectionStep.articleTitle, CmsMpaSectionStep.titleValues.get(CmsMpaSectionStep.selectedLocale))}</h2>
</div>
<h2>#{CmsMpaMessageBundle['sectionstep.header']}</h2>
</div>
<dl>
<dt>#{CmsMpaMessageBundle['sectionstep.current_article']}</dt>
<dd>#{CmsMpaSectionStep.articleTitle}</dd>
<dt>#{CmsMpaMessageBundle['sectionstep.current_section']}</dt>
<dd>#{CmsMpaSectionStep.sectionTitle}</dd>
</dl>
<libreccm:localizedStringEditor
addButtonLabel="#{CmsMpaMessageBundle['sectionstep.title.add.label']}"
addDialogCancelLabel="#{CmsMpaMessageBundle['sectionstep.title.add.cancel']}"
addDialogLocaleSelectHelp="#{CmsMpaMessageBundle['sectionstep.title.add.locale.help']}"
addDialogLocaleSelectLabel="#{CmsMpaMessageBundle['sectionstep.title.add.locale.label']}"
addDialogSubmitLabel="#{CmsMpaMessageBundle['sectionstep.title.add.submit']}"
addDialogTitle="#{CmsMpaMessageBundle['sectionstep.title.add.dialog_title']}"
addDialogValueHelp="#{CmsMpaMessageBundle['sectionstep.title.add.value.help']}"
addDialogValueLabel="#{CmsMpaMessageBundle['sectionstep.title.add.value.label']}"
addMethod="#{mvc.basePath}/#{ContentSectionModel.sectionName}/documents/#{CmsSelectedDocumentModel.itemPath}/@mpa-sections/#{CmsMpaSectionStep.sectionId}/title/@add"
editButtonLabel="#{CmsMpaMessageBundle['sectionstep.title.edit.label']}"
editDialogCancelLabel="#{CmsMpaMessageBundle['sectionstep.title.edit.dialog.cancel']}"
editDialogSubmitLabel="#{CmsMpaMessageBundle['sectionstep.title.edit.dialog.submit']}"
editDialogTitle="#{CmsMpaMessageBundle['sectionstep.title.edit.dialog.title']}"
editDialogValueHelp="#{CmsMpaMessageBundle['sectionstep.title.edit.dialog.value.help']}"
editDialogValueLabel="#{CmsMpaMessageBundle['sectionstep.title.edit.dialog.value.label']}"
editMethod="#{mvc.basePath}/#{ContentSectionModel.sectionName}/documents/#{CmsSelectedDocumentModel.itemPath}/@mpa-sections/#{CmsMpaSectionStep.sectionId}/title/@edit"
editorId="section-title-editor"
emptyText="#{CmsMpaMessageBundle['sectionstep.title.empty']}"
hasUnusedLocales="#{CmsMpaSectionStep.hasUnusedTitleLocales}"
objectIdentifier="#{CmsMpaSectionStep.sectionId}"
removeButtonLabel="#{CmsMpaMessageBundle['sectionstep.title.edit.remove.label']}"
removeDialogCancelLabel="#{CmsMpaMessageBundle['sectionstep.title.edit.remove.dialog.cancel']}"
removeDialogSubmitLabel="#{CmsMpaMessageBundle['sectionstep.title.edit.remove.dialog.submit']}"
removeDialogText="#{CmsMpaMessageBundle['sectionstep.title.edit.remove.dialog.text']}"
removeDialogTitle="#{CmsMpaMessageBundle['sectionstep.title.edit.remove.dialog.title']}"
removeMethod="#{mvc.basePath}/#{ContentSectionModel.sectionName}/documents/#{CmsSelectedDocumentModel.itemPath}/@mpa-sections/#{CmsMpaSectionStep.sectionId}/title/@remove"
title="#{CmsMpaMessageBundle['sectionstep.title.label']}"
unusedLocales="#{CmsMpaSectionStep.unusedTitleLocales}"
@ -48,8 +78,8 @@
</div>
<div aria-describedby="pagebreak-edit-dialog-title"
aria-hidden="true"
class="modal-fade"
id="page-edit-dialog"
class="modal fade"
id="pagebreak-edit-dialog"
tabindex="-1">
<div class="modal-dialog">
<form action="#{mvc.basePath}/#{ContentSectionModel.sectionName}/documents/#{CmsSelectedDocumentModel.itemPath}/@mpa-sections/#{CmsMpaSectionStep.sectionId}/pagebreak"
@ -103,7 +133,8 @@
viewPageUrl="#{mvc.basePath}/#{ContentSectionModel.sectionName}/documents/#{CmsSelectedDocumentModel.itemPath}/@mpa-sections/#{CmsMpaSectionStep.sectionId}/text/@view"
/>
</div>
</ui:define>
</ui:composition>
</html>

View File

@ -117,7 +117,7 @@
</p>
</c:when>
<c:otherwise>
<table class="table">
<table class="table mt-3">
<thead>
<tr>
<th>#{CmsMpaMessageBundle['sectionsstep.sections.section.title']}</th>
@ -143,10 +143,6 @@
iconClass="text-success" />
<span class="sr-only">#{CmsMpaMessageBundle['sectionsstep.sections.section.pagebreak.yes']}</span>
</c:when>
<c:otherwise>
<span class="sr-only">#{CmsMpaMessageBundle['sectionsstep.sections.section.pagebreak.no']}</span>
<bootstrap:svgIcon icon="check" />
</c:otherwise>
</c:choose>
</td>
<td>
@ -160,12 +156,14 @@
<c:if test="#{CmsMpaSectionsStep.canEdit}">
<libreccm:deleteDialog
actionTarget="#{mvc.basePath}/#{ContentSectionModel.sectionName}/documents/#{CmsSelectedDocumentModel.itemPath}/@mpa-sections/#{section.sectionId}/@remove"
buttonLabelClass="sr-only"
buttonText="#{CmsMpaMessageBundle['sectionsstep.sections.section.remove.label']}"
cancelLabel="#{CmsMpaMessageBundle['sectionsstep.sections.section.remove.dialog.cancel']}"
confirmLabel="#{CmsMpaMessageBundle['sectionsstep.sections.section.remove.dialog.confirm']}"
dialogId="remove-section-dialog-#{section.sectionId}"
dialogTitle="#{CmsMpaMessageBundle['sectionsstep.sections.section.remove.dialog.title']}"
message="#{CmsMpaMessageBundle['sectionsstep.sections.section.remove.dialog.message']}"
/>
</c:if>
</td>

View File

@ -97,7 +97,7 @@ sectionsstep.sections.section.remove.dialog.confirm=Remove section
sectionsstep.sections.section.remove.dialog.title=Confirm removal of section
sectionsstep.sections.section.remove.dialog.message=Are you sure to remove the following section?
sectionstep.back=Back
sectionstep.header=Edit section {1} of multipart article {0}
sectionstep.header=Edit section of a multipart article
sectionstep.title.label=Title
sectionsection.pagebreak.title=Page break after section?
sectionsection.pagebreak.yes=Yes
@ -116,3 +116,25 @@ authoringsteps.sections.label=Sections
sectionsstep.sections.empty=This multipart article has no sections yet.
sectionsstep.error.initial_locale_missing=Initial locale is missing.
sectionsstep.error.title_missing=Title for the new section is missing.
sectionstep.current_article=Selection multipart article
sectionstep.current_section=Selected section
sectionstep.title.add.label=Add localized title
sectionstep.title.add.cancel=Cancel
sectionstep.title.add.locale.help=The locale of the new localized title.
sectionstep.title.add.locale.label=Locale
sectionstep.title.add.submit=Add localized title
sectionstep.title.add.dialog_title=Add localized title
sectionstep.title.add.value.help=The localized title.
sectionstep.title.add.value.label=Title
sectionstep.title.edit.label=Edit
sectionstep.title.edit.dialog.cancel=Cancel
sectionstep.title.edit.dialog.submit=Save
sectionstep.title.edit.dialog.title=Edit localized title
sectionstep.title.edit.dialog.value.help=The localized title.
sectionstep.title.edit.dialog.value.label=Title
sectionstep.title.empty=No localized title yet.
sectionstep.title.edit.remove.label=Remove
sectionstep.title.edit.remove.dialog.cancel=Cancel
sectionstep.title.edit.remove.dialog.submit=Remove localized title
sectionstep.title.edit.remove.dialog.text=Are you sure to remove to this localized title?
sectionstep.title.edit.remove.dialog.title=Remove localized title

View File

@ -97,7 +97,7 @@ sectionsstep.sections.section.remove.dialog.confirm=Abschnitt entfernen
sectionsstep.sections.section.remove.dialog.title=Entfernen des Abschnitts best\u00e4tigen
sectionsstep.sections.section.remove.dialog.message=Sind Sie sicher, dass Sie den folgenden Abschnitt entfernen wollen?
sectionstep.back=Zur\u00fcck
sectionstep.header=Abschnitt {1} des mehrteiligen Artikels {0} bearbeiten
sectionstep.header=Einen Abschnitt eines mehrteiligen Artikels bearbeiten
sectionstep.title.label=Titel
sectionsection.pagebreak.title=Seitenumbruch nach Abschnitt?
sectionsection.pagebreak.yes=Ja
@ -116,3 +116,25 @@ authoringsteps.sections.label=Abschnitte
sectionsstep.sections.empty=Diese mehrteilige Artikel hat noch keine Abschnitte.
sectionsstep.error.initial_locale_missing=Es wurde keine initiale Sprache f\u00fcr den neuen Abschnitt angegeben.
sectionsstep.error.title_missing=Der Titel f\u00fcr den neuen Abschnitt wurde nicht angegeben.
sectionstep.current_article=Ausgew\u00e4hlter mehrteiliger Artikel
sectionstep.current_section=Ausgew\u00e4hlter Abschnitt
sectionstep.title.add.label=Lokalisierten Titel hinzuf\u00fcgen
sectionstep.title.add.cancel=Abbrechen
sectionstep.title.add.locale.help=Die Sprache des neuen lokalisierten Titels.
sectionstep.title.add.locale.label=Sprache
sectionstep.title.add.submit=Lokalisierten Titel hinzuf\u00fcgen
sectionstep.title.add.dialog_title=Lokalisierten Titel hinzuf\u00fcgen
sectionstep.title.add.value.help=Der lokalisierte Titel
sectionstep.title.add.value.label=Titel
sectionstep.title.edit.label=Bearbeiten
sectionstep.title.edit.dialog.cancel=Abbrechen
sectionstep.title.edit.dialog.submit=Speichern
sectionstep.title.edit.dialog.title=Lokalisierten Titel bearbeiten
sectionstep.title.edit.dialog.value.help=Der lokalisierte Titel.
sectionstep.title.edit.dialog.value.label=Titel
sectionstep.title.empty=Es wurden noch keine lokalisierten Titel hinzugef\u00fcgt.
sectionstep.title.edit.remove.label=Entfernen
sectionstep.title.edit.remove.dialog.cancel=Abbrechen
sectionstep.title.edit.remove.dialog.submit=Lokalisierten Titel entfernen
sectionstep.title.edit.remove.dialog.text=Sind Sie sicher, dass Sie diesen lokaliserten Titel entfernen wollen?
sectionstep.title.edit.remove.dialog.title=Lokalisierten Titel entfernen