Some bugfixing

pull/10/head
Jens Pelzetter 2021-05-04 20:37:32 +02:00
parent e8b9d5940b
commit 1abf3d96a1
4 changed files with 81 additions and 91 deletions

View File

@ -87,6 +87,8 @@ public abstract class AbstractMvcAuthoringStep implements MvcAuthoringStep {
private ContentItem document; private ContentItem document;
private String documentPath; private String documentPath;
private String stepPath;
/** /**
* Inits the step. This method MUST be called by all resource methods (all * Inits the step. This method MUST be called by all resource methods (all
@ -128,8 +130,29 @@ public abstract class AbstractMvcAuthoringStep implements MvcAuthoringStep {
documentModel.setContentItem(document); documentModel.setContentItem(document);
this.documentPath = itemManager.getItemPath(document); this.documentPath = itemManager.getItemPath(document);
final Map<String, String> values = new HashMap<>();
values.put(
MvcAuthoringSteps.SECTION_IDENTIFIER_PATH_PARAM,
contentSection.getLabel()
);
values.put(
MvcAuthoringSteps.DOCUMENT_PATH_PATH_PARAM_NAME,
documentPath
);
stepPath = Optional
.ofNullable(getStepClass().getAnnotation(Path.class))
.map(Path::value)
.map(
path -> UriBuilder
.fromPath(path)
.buildFromMap(values)
.toString()
)
.orElse("");
models.put("activeDocumentTab", "editTab"); models.put("activeDocumentTab", "editTab");
models.put("stepPath", stepPath);
} }
@Override @Override
@ -229,52 +252,7 @@ public abstract class AbstractMvcAuthoringStep implements MvcAuthoringStep {
@Override @Override
public String getStepPath() { public String getStepPath() {
final ContentSection section = Optional return stepPath;
.ofNullable(contentSection)
.orElseThrow(
() -> new WebApplicationException(
String.format(
"Authoring Step %s was not initalized properly. "
+ "Did you forget to call %s#init()?",
getStepClass().getName(),
AbstractMvcAuthoringStep.class.getName()
)
)
);
final String docPath = Optional
.ofNullable(documentPath)
.map(this::withoutLeadingSlash)
.orElseThrow(
() -> new WebApplicationException(
String.format(
"Authoring Step %s was not initalized properly. "
+ "Did you forget to call %s#init()?",
getStepClass().getName(),
AbstractMvcAuthoringStep.class.getName()
)
)
);
final Map<String, String> values = new HashMap<>();
values.put(
MvcAuthoringSteps.SECTION_IDENTIFIER_PATH_PARAM,
section.getLabel()
);
values.put(
MvcAuthoringSteps.DOCUMENT_PATH_PATH_PARAM_NAME,
docPath
);
return Optional
.ofNullable(getStepClass().getAnnotation(Path.class))
.map(Path::value)
.map(
path -> UriBuilder
.fromPath(path)
.buildFromMap(values)
.toString()
)
.orElse("");
} }
@Override @Override

View File

@ -50,13 +50,15 @@ import javax.ws.rs.PathParam;
import org.librecms.ui.contentsections.documents.MvcAuthoringStepDef; import org.librecms.ui.contentsections.documents.MvcAuthoringStepDef;
import java.util.Collections;
/** /**
* Authoring step for editing the main text of an {@link Article}. * Authoring step for editing the main text of an {@link Article}.
* *
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a> * @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/ */
@RequestScoped @RequestScoped
@Path(MvcAuthoringSteps.PATH_PREFIX + "text") @Path(MvcAuthoringSteps.PATH_PREFIX + "article-text")
@Controller @Controller
@Named("CmsArticleTextBodyStep") @Named("CmsArticleTextBodyStep")
@MvcAuthoringStepDef( @MvcAuthoringStepDef(
@ -88,11 +90,15 @@ public class MvcArticleTextBodyStep extends AbstractMvcAuthoringStep {
@Inject @Inject
private ItemPermissionChecker itemPermissionChecker; private ItemPermissionChecker itemPermissionChecker;
private Map<String, String> textValues;
private List<String> unusedLocales;
@Override @Override
public Class<MvcArticleTextBodyStep> getStepClass() { public Class<MvcArticleTextBodyStep> getStepClass() {
return MvcArticleTextBodyStep.class; return MvcArticleTextBodyStep.class;
} }
@GET @GET
@Path("/") @Path("/")
@Transactional(Transactional.TxType.REQUIRED) @Transactional(Transactional.TxType.REQUIRED)
@ -111,6 +117,28 @@ public class MvcArticleTextBodyStep extends AbstractMvcAuthoringStep {
} }
if (itemPermissionChecker.canEditItem(getArticle())) { if (itemPermissionChecker.canEditItem(getArticle())) {
textValues = getArticle()
.getText()
.getValues()
.entrySet()
.stream()
.collect(
Collectors.toMap(
entry -> entry.getKey().toString(),
entry -> entry.getValue()
)
);
final Set<Locale> locales = getArticle()
.getText()
.getAvailableLocales();
unusedLocales = globalizationHelper
.getAvailableLocales()
.stream()
.filter(locale -> !locales.contains(locale))
.map(Locale::toString)
.collect(Collectors.toList());
return "org/librecms/ui/contenttypes/article/article-text.xhtml"; return "org/librecms/ui/contenttypes/article/article-text.xhtml";
} else { } else {
return documentUi.showAccessDenied( return documentUi.showAccessDenied(
@ -127,17 +155,7 @@ public class MvcArticleTextBodyStep extends AbstractMvcAuthoringStep {
* @return The localized values of the main text. * @return The localized values of the main text.
*/ */
public Map<String, String> getTextValues() { public Map<String, String> getTextValues() {
return getArticle() return Collections.unmodifiableMap(textValues);
.getText()
.getValues()
.entrySet()
.stream()
.collect(
Collectors.toMap(
entry -> entry.getKey().toString(),
entry -> entry.getValue()
)
);
} }
/** /**
@ -146,15 +164,7 @@ public class MvcArticleTextBodyStep extends AbstractMvcAuthoringStep {
* @return The locales for which the main text has not been defined yet. * @return The locales for which the main text has not been defined yet.
*/ */
public List<String> getUnusedLocales() { public List<String> getUnusedLocales() {
final Set<Locale> locales = getArticle() return Collections.unmodifiableList(unusedLocales);
.getText()
.getAvailableLocales();
return globalizationHelper
.getAvailableLocales()
.stream()
.filter(locale -> !locales.contains(locale))
.map(Locale::toString)
.collect(Collectors.toList());
} }
/** /**
@ -257,7 +267,7 @@ public class MvcArticleTextBodyStep extends AbstractMvcAuthoringStep {
@POST @POST
@Path("/@remove/{locale}") @Path("/@remove/{locale}")
@Transactional(Transactional.TxType.REQUIRED) @Transactional(Transactional.TxType.REQUIRED)
public String remvoeTextValue( public String removeTextValue(
@PathParam(MvcAuthoringSteps.SECTION_IDENTIFIER_PATH_PARAM) @PathParam(MvcAuthoringSteps.SECTION_IDENTIFIER_PATH_PARAM)
final String sectionIdentifier, final String sectionIdentifier,
@PathParam(MvcAuthoringSteps.DOCUMENT_PATH_PATH_PARAM_NAME) @PathParam(MvcAuthoringSteps.DOCUMENT_PATH_PATH_PARAM_NAME)

View File

@ -46,7 +46,7 @@
method="post"> method="post">
<input name="returnUrl" <input name="returnUrl"
type="hidden" type="hidden"
value="#{CmsArticlePropertiesStep.stepPath}" /> value="#{stepPath}" />
<button class="btn btn-primary" <button class="btn btn-primary"
type="submit"> type="submit">
@ -64,7 +64,7 @@
method="post"> method="post">
<input name="returnUrl" <input name="returnUrl"
type="hidden" type="hidden"
value="#{CmsArticlePropertiesStep.stepPath}" /> value="#{stepPath}" />
<button class="btn btn-secondary btn-sm" <button class="btn btn-secondary btn-sm"
type="submit"> type="submit">
#{CmsAdminMessages['contentsection.document.authoring.workflow.active_task.release']} #{CmsAdminMessages['contentsection.document.authoring.workflow.active_task.release']}
@ -75,7 +75,7 @@
method="post"> method="post">
<input name="returnUrl" <input name="returnUrl"
type="hidden" type="hidden"
value="#{CmsArticlePropertiesStep.stepPath}" /> value="#{stepPath}" />
<button class="btn btn-secondary btn-sm" <button class="btn btn-secondary btn-sm"
type="submit"> type="submit">
#{CmsAdminMessages['contentsection.document.authoring.workflow.active_task.finish']} #{CmsAdminMessages['contentsection.document.authoring.workflow.active_task.finish']}
@ -88,7 +88,7 @@
method="post"> method="post">
<input name="returnUrl" <input name="returnUrl"
type="hidden" type="hidden"
value="#{CmsArticlePropertiesStep.stepPath}" /> value="#{stepPath}" />
<button class="btn btn-secondary btn-sm" <button class="btn btn-secondary btn-sm"
type="submit"> type="submit">
#{CmsAdminMessages['contentsection.document.authoring.workflow.active_task.takeover']} #{CmsAdminMessages['contentsection.document.authoring.workflow.active_task.takeover']}
@ -101,7 +101,7 @@
method="post"> method="post">
<input name="returnUrl" <input name="returnUrl"
type="hidden" type="hidden"
value="#{CmsArticlePropertiesStep.stepPath}" /> value="#{stepPath}" />
<button class="btn btn-secondary btn-sm" <button class="btn btn-secondary btn-sm"
type="submit"> type="submit">
#{CmsAdminMessages['contentsection.document.authoring.workflow.active_task.lock']} #{CmsAdminMessages['contentsection.document.authoring.workflow.active_task.lock']}

View File

@ -5,23 +5,25 @@
xmlns:libreccm="http://xmlns.jcp.org/jsf/composite/components/libreccm" xmlns:libreccm="http://xmlns.jcp.org/jsf/composite/components/libreccm"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"> xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<ui:composition template="/WEB-INF/views/org/librecms/ui/contentsection/documents/authoringstep.xhtml"> <ui:composition template="/WEB-INF/views/org/librecms/ui/contentsection/documents/authoringstep.xhtml">
<h2>#{CmsArticleMessageBundle['textstep.header']}</h2> <ui:define name="authoringStep">
<h2>#{CmsArticleMessageBundle['textstep.header']}</h2>
<libreccm:localizedStringEditor
addMethod="#{mvc.basePath}/#{ContentSectionModel.sectionName}/documents/#{CmsSelectedDocumentModel.itemPath}/@authoringsteps/text/@add" <libreccm:localizedStringEditor
editMethod="#{mvc.basePath}/#{ContentSectionModel.sectionName}/documents/#{CmsSelectedDocumentModel.itemPath}/@authoringsteps/text/@edit" addMethod="#{mvc.basePath}/#{ContentSectionModel.sectionName}/documents/#{CmsSelectedDocumentModel.itemPath}/@article-text/add"
editorId="article-text-editor" editMethod="#{mvc.basePath}/#{ContentSectionModel.sectionName}/documents/#{CmsSelectedDocumentModel.itemPath}/@article-text/edit"
hasUnusedLocales="#{!CmsArticleTextBodyStep.unusedLocales.isEmpty()}" editorId="article-text-editor"
headingLevel="3" hasUnusedLocales="#{!CmsArticleTextBodyStep.unusedLocales.isEmpty()}"
objectIdentifier="#{CmsSelectedDocumentModel.itemPath}" headingLevel="3"
removeMethod="#{mvc.basePath}/#{ContentSectionModel.sectionName}/documents/#{CmsSelectedDocumentModel.itemPath}/@authoringsteps/text/@remove" objectIdentifier="#{CmsSelectedDocumentModel.itemPath}"
title="#{CmsArticleMessageBundle['text.editor.header']}" removeMethod="#{mvc.basePath}/#{ContentSectionModel.sectionName}/documents/#{CmsSelectedDocumentModel.itemPath}/@article-text/remove"
unusedLocales="#{CmsArticleTextBodyStep.unusedLocales}" title="#{CmsArticleMessageBundle['text.editor.header']}"
useTextarea="true" unusedLocales="#{CmsArticleTextBodyStep.unusedLocales}"
values="#{CmsArticleTextBodyStep.textValues}" useTextarea="true"
/> values="#{CmsArticleTextBodyStep.textValues}"
/>
</ui:define>
</ui:composition> </ui:composition>
</html> </html>