CCM NG/ccm-cms MultiPartArticle Sections Step now works

git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4876 8810af33-2d31-482b-a856-94f89814c4df
ccm-docs
jensp 2017-07-15 14:35:44 +00:00
parent 88daacb23b
commit 107bbfef3c
10 changed files with 202 additions and 67 deletions

View File

@ -18,7 +18,6 @@
*/
package com.arsdigita.cms.ui.authoring.multipartarticle;
import org.bouncycastle.asn1.cmp.ProtectedPart;
import org.librecms.contentsection.ContentItemRepository;
import org.librecms.contenttypes.MultiPartArticle;
import org.librecms.contenttypes.MultiPartArticleSection;
@ -26,6 +25,7 @@ import org.librecms.contenttypes.MultiPartArticleSectionManager;
import org.librecms.contenttypes.MultiPartArticleSectionRepository;
import java.util.List;
import java.util.stream.Collectors;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
@ -58,12 +58,19 @@ class MultiPartArticleSectionStepController {
.format("No MultiPartArticle with ID %d in the database.",
forArticle.getObjectId())));
return article.getSections();
//Ensure that the sections are loaded
return article
.getSections()
.stream()
.sorted((section1, section2) -> {
return Integer.compare(section1.getRank(), section2.getRank());
})
.collect(Collectors.toList());
}
@Transactional(Transactional.TxType.REQUIRED)
protected MultiPartArticleSection addSection(
final MultiPartArticle article) {
protected void addSection(final MultiPartArticle article,
final MultiPartArticleSection section) {
final MultiPartArticle theArticle = itemRepo
.findById(article.getObjectId(),
@ -72,10 +79,7 @@ class MultiPartArticleSectionStepController {
"No MultiPartArticle with ID %d in the database.",
article.getObjectId())));
final MultiPartArticleSection section = new MultiPartArticleSection();
sectionManager.addSectionToMultiPartArticle(section, theArticle);
return section;
}
@Transactional(Transactional.TxType.REQUIRED)
@ -119,4 +123,19 @@ class MultiPartArticleSectionStepController {
sectionManager.moveToFirst(theArticle, theSection);
}
@Transactional(Transactional.TxType.REQUIRED)
protected void moveAfter(final MultiPartArticle article,
final MultiPartArticleSection section,
final MultiPartArticleSection after) {
final MultiPartArticle theArticle = itemRepo
.findById(article.getObjectId(),
MultiPartArticle.class)
.orElseThrow(() -> new IllegalArgumentException(String.format(
"No MultiPartArticle with ID %d in the database.",
article.getObjectId())));
sectionManager.moveSectionAfter(theArticle, section, after);
}
}

View File

@ -129,7 +129,8 @@ public class MultiPartArticleSectionsStep extends ResettableContainer {
moveSectionModel = new SectionSelectionModel<>(moveSectionParam);
sectionTable = new SectionTable(selectedArticleModel,
moveSectionModel);
moveSectionModel,
selectedLanguageParam);
sectionTable.setClassAttr(DATA_TABLE);
// selected section is based on the selection in the SectionTable
@ -149,6 +150,27 @@ public class MultiPartArticleSectionsStep extends ResettableContainer {
moveSectionLabel = new Label(new GlobalizedMessage(
"cms.contenttypes.ui.mparticle.section.title",
CmsConstants.CMS_BUNDLE));
moveSectionLabel.addPrintListener(event -> {
final PageState state = event.getPageState();
final Label target = (Label) event.getTarget();
if (moveSectionModel.getSelectedKey(state) != null) {
final Locale selectedLocale = SelectedLanguageUtil
.selectedLocale(state, selectedLanguageParam);
final Object[] parameterObj = {
moveSectionModel
.getSelectedSection(state)
.getTitle()
.getValue(selectedLocale)
};
target.setLabel(new GlobalizedMessage(
"cms.contenttypes.ui.mparticle.move_section_name",
CmsConstants.CMS_BUNDLE,
parameterObj));
}
});
panel.add(moveSectionLabel, ColumnPanel.FULL_WIDTH | ColumnPanel.LEFT);
beginLink = new ActionLink(new GlobalizedMessage(
@ -181,21 +203,22 @@ public class MultiPartArticleSectionsStep extends ResettableContainer {
beginLink.setVisible(state, true);
moveSectionLabel.setVisible(state, true);
final Locale selectedLocale = SelectedLanguageUtil
.selectedLocale(state, selectedLanguageParam);
final Object[] parameterObj = {
moveSectionModel
.getSelectedSection(state)
.getTitle()
.getValue(selectedLocale)
};
moveSectionLabel
.setLabel(new GlobalizedMessage(
"cms.contenttypes.ui.mparticle.move_section_name",
CmsConstants.CMS_BUNDLE,
parameterObj));
// final Locale selectedLocale = SelectedLanguageUtil
// .selectedLocale(state, selectedLanguageParam);
//
// final Object[] parameterObj = {
// moveSectionModel
// .getSelectedSection(state)
// .getTitle()
// .getValue(selectedLocale)
// };
//
// moveSectionLabel
// .setLabel(new GlobalizedMessage(
// "cms.contenttypes.ui.mparticle.move_section_name",
// CmsConstants.CMS_BUNDLE,
// parameterObj),
// state);
}
});

View File

@ -58,7 +58,6 @@ import java.util.Locale;
*/
public class SectionEditForm extends Form {
public static final String TITLE = "title";
public static final String TEXT = "text";
public static final String IMAGE = "image";
@ -177,7 +176,6 @@ public class SectionEditForm extends Form {
return section;
}
/**
* Initialise the form. If there is a selected section, ie. this is an
* 'edit' step rather than a 'create new' step, load the data into the form
@ -278,7 +276,7 @@ public class SectionEditForm extends Form {
final MultiPartArticleSection section;
if (selectedSectionModel.getSelectedKey(state) == null) {
section = new MultiPartArticleSection();
controller.addSection(article);
} else {
section = selectedSectionModel.getSelectedSection(state);
}
@ -306,6 +304,17 @@ public class SectionEditForm extends Form {
section.getText().addValue(selectedLocale, text);
sectionRepo.save(section);
if (selectedSectionModel.getSelectedKey(state) == null) {
controller.addSection(article, section);
}
if (sectionsStep != null) {
sectionsStep
.onlyShowComponent(state,
MultiPartArticleSectionsStep.SECTION_TABLE
+ sectionsStep.getTypeIDStr());
}
}
}

View File

@ -26,6 +26,7 @@ import com.arsdigita.bebop.Table;
import com.arsdigita.bebop.Text;
import com.arsdigita.bebop.event.TableActionEvent;
import com.arsdigita.bebop.event.TableActionListener;
import com.arsdigita.bebop.parameters.StringParameter;
import com.arsdigita.bebop.table.TableCellRenderer;
import com.arsdigita.bebop.table.TableColumn;
import com.arsdigita.bebop.table.TableColumnModel;
@ -61,18 +62,22 @@ public class SectionTable extends Table {
* Index of the title column
*/
public static final int COL_INDEX_TITLE = 0;
/**
* Index of the page break column
*/
public static final int COL_PAGE_BREAK = 1;
/**
* Index of the edit column.
*/
public static final int COL_INDEX_EDIT = 1;
public static final int COL_INDEX_EDIT = 2;
/**
* Index of the move column
*/
public static final int COL_INDEX_MOVE = 2;
public static final int COL_INDEX_MOVE = 3;
/**
* Index of the delete column
*/
public static final int COL_INDEX_DELETE = 3;
public static final int COL_INDEX_DELETE = 4;
private ItemSelectionModel selectedArticleModel;
private SectionSelectionModel<? extends MultiPartArticleSection> selectedSectionModel;
@ -81,14 +86,16 @@ public class SectionTable extends Table {
/**
* Constructor. Create an instance of this class.
*
* @param selectedArticleModel a selection model that returns the
* MultiPartArticle which holds the sections to
* display.
* @param selectedArticleModel a selection model that returns the
* MultiPartArticle which holds the sections to
* display.
* @param moveSectionModel
* @param selectedLanguageParam
*/
public SectionTable(
final ItemSelectionModel selectedArticleModel,
final SectionSelectionModel<? extends MultiPartArticleSection> moveSectionModel) {
final SectionSelectionModel<? extends MultiPartArticleSection> moveSectionModel,
final StringParameter selectedLanguageParam) {
super();
this.selectedArticleModel = selectedArticleModel;
@ -100,6 +107,11 @@ public class SectionTable extends Table {
new Label(new GlobalizedMessage(
"cms.contenttypes.ui.mparticle.section_table.header_section",
CmsConstants.CMS_BUNDLE))));
model.add(new TableColumn(
COL_PAGE_BREAK,
new Label(new GlobalizedMessage(
"cms.contenttypes.ui.mparticle.section_table.header_page_break",
CmsConstants.CMS_BUNDLE))));
model.add(new TableColumn(
COL_INDEX_EDIT,
new Label(new GlobalizedMessage(
@ -116,12 +128,14 @@ public class SectionTable extends Table {
"cms.contenttypes.ui.mparticle.section_table.header_delete",
CmsConstants.CMS_BUNDLE))));
model.get(1).setCellRenderer(new SectionTableCellRenderer(true));
model.get(2).setCellRenderer(new SectionTableCellRenderer(true));
model.get(3).setCellRenderer(new SectionTableCellRenderer(true));
model.get(COL_INDEX_EDIT).setCellRenderer(new SectionTableCellRenderer(true));
model.get(COL_INDEX_MOVE).setCellRenderer(new SectionTableCellRenderer(true));
model.get(COL_INDEX_DELETE).setCellRenderer(new SectionTableCellRenderer(true));
super.setModelBuilder(
new SectionTableModelBuilder(selectedArticleModel, moveSectionModel));
new SectionTableModelBuilder(selectedArticleModel,
moveSectionModel,
selectedLanguageParam));
super.addTableActionListener(new TableActionListener() {
@ -175,16 +189,18 @@ public class SectionTable extends Table {
+ "the database.",
destId)));
// if sect is lower in rank than the dest
// then move below is default behavior
int rank = destSection.getRank();
if (section.getRank() > rank) {
// otherwise, add one to get "move below"
rank++;
}
controller.moveAfter(article, section, destSection);
section.setRank(rank);
sectionRepo.save(section);
// // if sect is lower in rank than the dest
// // then move below is default behavior
// int rank = destSection.getRank();
// if (section.getRank() > rank) {
// // otherwise, add one to get "move below"
// rank++;
// }
//
// section.setRank(rank);
// sectionRepo.save(section);
moveSectionModel.setSelectedKey(state, null);
}
}

View File

@ -21,8 +21,10 @@ package com.arsdigita.cms.ui.authoring.multipartarticle;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.Table;
import com.arsdigita.bebop.parameters.StringParameter;
import com.arsdigita.bebop.table.TableColumnModel;
import com.arsdigita.bebop.table.TableModel;
import com.arsdigita.cms.ui.authoring.SelectedLanguageUtil;
import com.arsdigita.globalization.GlobalizedMessage;
import org.libreccm.cdi.utils.CdiUtil;
@ -38,6 +40,7 @@ class SectionTableModel implements TableModel {
private final TableColumnModel columnModel;
private final SectionTable sectionTable;
private final PageState pageState;
private final StringParameter selectedLanguageParam;
private final SectionSelectionModel<? extends MultiPartArticleSection> moveSectionModel;
private final Iterator<MultiPartArticleSection> iterator;
@ -54,10 +57,12 @@ class SectionTableModel implements TableModel {
public SectionTableModel(
final Table sectionTable,
final PageState pageState,
final StringParameter selectedLanguageParam,
final MultiPartArticle article,
final SectionSelectionModel<? extends MultiPartArticleSection> moveSectionModel) {
this.pageState = pageState;
this.selectedLanguageParam = selectedLanguageParam;
this.sectionTable = (SectionTable) sectionTable;
this.moveSectionModel = moveSectionModel;
@ -104,9 +109,23 @@ class SectionTableModel implements TableModel {
if (columnModel == null) {
return null;
}
switch (columnIndex) {
case SectionTable.COL_INDEX_TITLE:
return currentSection.getTitle();
return currentSection
.getTitle()
.getValue(SelectedLanguageUtil
.selectedLocale(pageState, selectedLanguageParam));
case SectionTable.COL_PAGE_BREAK:
if (currentSection.isPageBreak()) {
return new Label(
new GlobalizedMessage("cms.ui.yes",
CmsConstants.CMS_BUNDLE));
} else {
return new Label(
new GlobalizedMessage("cms.ui.no",
CmsConstants.CMS_BUNDLE));
}
case SectionTable.COL_INDEX_EDIT:
return new Label(new GlobalizedMessage(
"cms.contenttypes.ui.mparticle.section_table.link_edit",

View File

@ -20,6 +20,7 @@ package com.arsdigita.cms.ui.authoring.multipartarticle;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.Table;
import com.arsdigita.bebop.parameters.StringParameter;
import com.arsdigita.bebop.table.TableModel;
import com.arsdigita.bebop.table.TableModelBuilder;
import com.arsdigita.cms.ItemSelectionModel;
@ -36,6 +37,8 @@ class SectionTableModelBuilder extends LockableImpl implements TableModelBuilder
private final ItemSelectionModel selectedArticleModel;
private final SectionSelectionModel<? extends MultiPartArticleSection> moveSectionModel;
private final StringParameter selectedLanguageParam;
/**
* Private class constructor.
*
@ -44,10 +47,12 @@ class SectionTableModelBuilder extends LockableImpl implements TableModelBuilder
*/
public SectionTableModelBuilder(
final ItemSelectionModel selectedArticleModel,
final SectionSelectionModel<? extends MultiPartArticleSection> moveSectionModel) {
final SectionSelectionModel<? extends MultiPartArticleSection> moveSectionModel,
final StringParameter selectedLanguageParam) {
this.selectedArticleModel = selectedArticleModel;
this.moveSectionModel = moveSectionModel;
this.selectedLanguageParam = selectedLanguageParam;
}
/**
@ -67,6 +72,7 @@ class SectionTableModelBuilder extends LockableImpl implements TableModelBuilder
.getSelectedObject(state);
return new SectionTableModel(table,
state,
selectedLanguageParam,
article,
moveSectionModel);
}

View File

@ -21,11 +21,11 @@ package org.librecms.contenttypes;
import org.librecms.contentsection.ContentItemRepository;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.transaction.Transactional;
/**
@ -41,13 +41,13 @@ public class MultiPartArticleSectionManager {
@Inject
private MultiPartArticleSectionRepository sectionRepo;
@Transactional(Transactional.TxType.REQUIRED)
public void addSectionToMultiPartArticle(
final MultiPartArticleSection section,
final MultiPartArticle article) {
article.addSection(section);
section.setRank(article.getSections().size() - 1);
itemRepo.save(article);
sectionRepo.save(section);
}
@ -67,23 +67,63 @@ public class MultiPartArticleSectionManager {
final MultiPartArticleSection section) {
final List<MultiPartArticleSection> sections = article
.getSections()
.stream()
.sorted((section1, section2) -> Integer.compare(section1.getRank(),
section2.getRank()))
.collect(Collectors.toList());
.getSections()
.stream()
.sorted((section1, section2) -> Integer.compare(section1.getRank(),
section2.getRank()))
.collect(Collectors.toList());
final int oldRank = section.getRank();
section.setRank(1);
section.setRank(0);
sections
.stream()
.filter(current -> !current.equals(section))
.forEach(current -> current.setRank(current.getRank() + 1));
sections
.forEach(current -> sectionRepo.save(section));
.forEach(current -> sectionRepo.save(current));
}
@Transactional(Transactional.TxType.REQUIRED)
public void moveSectionAfter(final MultiPartArticle article,
final MultiPartArticleSection section,
final MultiPartArticleSection after) {
Objects.requireNonNull(article);
Objects.requireNonNull(section);
Objects.requireNonNull(after);
final List<MultiPartArticleSection> sections = article
.getSections()
.stream()
.sorted((section1, section2) -> {
return Integer.compare(section1.getRank(), section2.getRank());
})
.collect(Collectors.toList());
if (!sections.contains(section)) {
throw new IllegalArgumentException(String.format(
"MultiPartArticleSection %d is not a section of multipart article %d.",
section.getSectionId(),
article.getObjectId()));
}
if (!sections.contains(after)) {
throw new IllegalArgumentException(String.format(
"MultiPartArticleSection %d is not a section of multipart article %d.",
after.getSectionId(),
article.getObjectId()));
}
final int afterIndex = sections.indexOf(after);
for (int i = afterIndex + 1; i < sections.size(); i++) {
final MultiPartArticleSection current = sections.get(i);
current.setRank(current.getRank() + 1);
sectionRepo.save(current);
}
section.setRank(afterIndex + 1);
sectionRepo.save(section);
}
}

View File

@ -369,7 +369,7 @@ cms.contenttypes.ui.mparticle.section.text=Text
cms.contenttypes.ui.mparticle.section.create_break=Create page break after this section
cms.contenttypes.ui.mparticle.no_sections_yet=No sections yet
cms.contenttypes.ui.mparticle.move_to_beginning=Move to beginning
cms.contenttypes.ui.mparticle.move_section_name=Name of section
cms.contenttypes.ui.mparticle.move_section_name=Move section "{0}"
cms.contenttypes.ui.mparticle.add_section=Add section
cms.contenttypes.ui.mparticle.edit_section=Edit section
cms.contenttypes.ui.mparticle.delete_section=Delete section
@ -377,3 +377,4 @@ cms.contenttypes.ui.mparticle.view_all_sections=View all sections
cms.contenttypes.ui.mparticle.add_new_section=Add new section
cms.contenttypes.ui.mparticle.no_launch_date=Launch date is required
cms.contenttypes.ui.mparticle.an_item_with_name_already_exists=An item with this name already exists
cms.contenttypes.ui.mparticle.section_table.header_page_break=Page break

View File

@ -366,7 +366,7 @@ cms.contenttypes.ui.mparticle.section.text=Text
cms.contenttypes.ui.mparticle.section.create_break=Seitenumbruch nach diesem Abschnitt einf\u00fcgen
cms.contenttypes.ui.mparticle.no_sections_yet=Keine Abschnitte vorhanden
cms.contenttypes.ui.mparticle.move_to_beginning=An die erste Position verschieben
cms.contenttypes.ui.mparticle.move_section_name=Name des Abschnitts
cms.contenttypes.ui.mparticle.move_section_name=Abschnitt "{0}" verschieben
cms.contenttypes.ui.mparticle.add_section=Abschnitt hinzuf\u00fcgen
cms.contenttypes.ui.mparticle.edit_section=Abschnitt hinzuf\u00fcgen
cms.contenttypes.ui.mparticle.delete_section=Abschnitt l\u00f6schen
@ -374,3 +374,4 @@ cms.contenttypes.ui.mparticle.view_all_sections=Alle Abschnitte ansehen
cms.contenttypes.ui.mparticle.add_new_section=Neuen Abschnitt hinzuf\u00fcgen
cms.contenttypes.ui.mparticle.no_launch_date=Es wurde kein Ver\u00f6ffentlichungsdatum angegeben
cms.contenttypes.ui.mparticle.an_item_with_name_already_exists=Ein Dokument mit diesem Namen existiert bereits.
cms.contenttypes.ui.mparticle.section_table.header_page_break=Seitenumbruch

View File

@ -325,7 +325,7 @@ cms.contenttypes.ui.mparticle.section.text=Text
cms.contenttypes.ui.mparticle.section.create_break=Create page break after this section
cms.contenttypes.ui.mparticle.no_sections_yet=No sections yet
cms.contenttypes.ui.mparticle.move_to_beginning=Move to beginning
cms.contenttypes.ui.mparticle.move_section_name=Name of section
cms.contenttypes.ui.mparticle.move_section_name=Move section "{0}"
cms.contenttypes.ui.mparticle.add_section=Add section
cms.contenttypes.ui.mparticle.edit_section=Edit section
cms.contenttypes.ui.mparticle.delete_section=Delete section
@ -333,3 +333,4 @@ cms.contenttypes.ui.mparticle.view_all_sections=View all sections
cms.contenttypes.ui.mparticle.add_new_section=Add new section
cms.contenttypes.ui.mparticle.no_launch_date=Launch date is required
cms.contenttypes.ui.mparticle.an_item_with_name_already_exists=An item with this name already exists
cms.contenttypes.ui.mparticle.section_table.header_page_break=Page break