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
parent
4e14799253
commit
3fcfab137b
|
|
@ -18,7 +18,6 @@
|
||||||
*/
|
*/
|
||||||
package com.arsdigita.cms.ui.authoring.multipartarticle;
|
package com.arsdigita.cms.ui.authoring.multipartarticle;
|
||||||
|
|
||||||
import org.bouncycastle.asn1.cmp.ProtectedPart;
|
|
||||||
import org.librecms.contentsection.ContentItemRepository;
|
import org.librecms.contentsection.ContentItemRepository;
|
||||||
import org.librecms.contenttypes.MultiPartArticle;
|
import org.librecms.contenttypes.MultiPartArticle;
|
||||||
import org.librecms.contenttypes.MultiPartArticleSection;
|
import org.librecms.contenttypes.MultiPartArticleSection;
|
||||||
|
|
@ -26,6 +25,7 @@ import org.librecms.contenttypes.MultiPartArticleSectionManager;
|
||||||
import org.librecms.contenttypes.MultiPartArticleSectionRepository;
|
import org.librecms.contenttypes.MultiPartArticleSectionRepository;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import javax.enterprise.context.RequestScoped;
|
import javax.enterprise.context.RequestScoped;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
@ -58,12 +58,19 @@ class MultiPartArticleSectionStepController {
|
||||||
.format("No MultiPartArticle with ID %d in the database.",
|
.format("No MultiPartArticle with ID %d in the database.",
|
||||||
forArticle.getObjectId())));
|
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)
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
protected MultiPartArticleSection addSection(
|
protected void addSection(final MultiPartArticle article,
|
||||||
final MultiPartArticle article) {
|
final MultiPartArticleSection section) {
|
||||||
|
|
||||||
final MultiPartArticle theArticle = itemRepo
|
final MultiPartArticle theArticle = itemRepo
|
||||||
.findById(article.getObjectId(),
|
.findById(article.getObjectId(),
|
||||||
|
|
@ -72,10 +79,7 @@ class MultiPartArticleSectionStepController {
|
||||||
"No MultiPartArticle with ID %d in the database.",
|
"No MultiPartArticle with ID %d in the database.",
|
||||||
article.getObjectId())));
|
article.getObjectId())));
|
||||||
|
|
||||||
final MultiPartArticleSection section = new MultiPartArticleSection();
|
|
||||||
sectionManager.addSectionToMultiPartArticle(section, theArticle);
|
sectionManager.addSectionToMultiPartArticle(section, theArticle);
|
||||||
|
|
||||||
return section;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
|
|
@ -119,4 +123,19 @@ class MultiPartArticleSectionStepController {
|
||||||
sectionManager.moveToFirst(theArticle, theSection);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -129,7 +129,8 @@ public class MultiPartArticleSectionsStep extends ResettableContainer {
|
||||||
moveSectionModel = new SectionSelectionModel<>(moveSectionParam);
|
moveSectionModel = new SectionSelectionModel<>(moveSectionParam);
|
||||||
|
|
||||||
sectionTable = new SectionTable(selectedArticleModel,
|
sectionTable = new SectionTable(selectedArticleModel,
|
||||||
moveSectionModel);
|
moveSectionModel,
|
||||||
|
selectedLanguageParam);
|
||||||
sectionTable.setClassAttr(DATA_TABLE);
|
sectionTable.setClassAttr(DATA_TABLE);
|
||||||
|
|
||||||
// selected section is based on the selection in the SectionTable
|
// selected section is based on the selection in the SectionTable
|
||||||
|
|
@ -149,6 +150,27 @@ public class MultiPartArticleSectionsStep extends ResettableContainer {
|
||||||
moveSectionLabel = new Label(new GlobalizedMessage(
|
moveSectionLabel = new Label(new GlobalizedMessage(
|
||||||
"cms.contenttypes.ui.mparticle.section.title",
|
"cms.contenttypes.ui.mparticle.section.title",
|
||||||
CmsConstants.CMS_BUNDLE));
|
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);
|
panel.add(moveSectionLabel, ColumnPanel.FULL_WIDTH | ColumnPanel.LEFT);
|
||||||
|
|
||||||
beginLink = new ActionLink(new GlobalizedMessage(
|
beginLink = new ActionLink(new GlobalizedMessage(
|
||||||
|
|
@ -181,21 +203,22 @@ public class MultiPartArticleSectionsStep extends ResettableContainer {
|
||||||
beginLink.setVisible(state, true);
|
beginLink.setVisible(state, true);
|
||||||
moveSectionLabel.setVisible(state, true);
|
moveSectionLabel.setVisible(state, true);
|
||||||
|
|
||||||
final Locale selectedLocale = SelectedLanguageUtil
|
// final Locale selectedLocale = SelectedLanguageUtil
|
||||||
.selectedLocale(state, selectedLanguageParam);
|
// .selectedLocale(state, selectedLanguageParam);
|
||||||
|
//
|
||||||
final Object[] parameterObj = {
|
// final Object[] parameterObj = {
|
||||||
moveSectionModel
|
// moveSectionModel
|
||||||
.getSelectedSection(state)
|
// .getSelectedSection(state)
|
||||||
.getTitle()
|
// .getTitle()
|
||||||
.getValue(selectedLocale)
|
// .getValue(selectedLocale)
|
||||||
};
|
// };
|
||||||
|
//
|
||||||
moveSectionLabel
|
// moveSectionLabel
|
||||||
.setLabel(new GlobalizedMessage(
|
// .setLabel(new GlobalizedMessage(
|
||||||
"cms.contenttypes.ui.mparticle.move_section_name",
|
// "cms.contenttypes.ui.mparticle.move_section_name",
|
||||||
CmsConstants.CMS_BUNDLE,
|
// CmsConstants.CMS_BUNDLE,
|
||||||
parameterObj));
|
// parameterObj),
|
||||||
|
// state);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,6 @@ import java.util.Locale;
|
||||||
*/
|
*/
|
||||||
public class SectionEditForm extends Form {
|
public class SectionEditForm extends Form {
|
||||||
|
|
||||||
|
|
||||||
public static final String TITLE = "title";
|
public static final String TITLE = "title";
|
||||||
public static final String TEXT = "text";
|
public static final String TEXT = "text";
|
||||||
public static final String IMAGE = "image";
|
public static final String IMAGE = "image";
|
||||||
|
|
@ -177,7 +176,6 @@ public class SectionEditForm extends Form {
|
||||||
return section;
|
return section;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialise the form. If there is a selected section, ie. this is an
|
* 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
|
* '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;
|
final MultiPartArticleSection section;
|
||||||
if (selectedSectionModel.getSelectedKey(state) == null) {
|
if (selectedSectionModel.getSelectedKey(state) == null) {
|
||||||
section = new MultiPartArticleSection();
|
section = new MultiPartArticleSection();
|
||||||
controller.addSection(article);
|
|
||||||
} else {
|
} else {
|
||||||
section = selectedSectionModel.getSelectedSection(state);
|
section = selectedSectionModel.getSelectedSection(state);
|
||||||
}
|
}
|
||||||
|
|
@ -306,6 +304,17 @@ public class SectionEditForm extends Form {
|
||||||
section.getText().addValue(selectedLocale, text);
|
section.getText().addValue(selectedLocale, text);
|
||||||
|
|
||||||
sectionRepo.save(section);
|
sectionRepo.save(section);
|
||||||
|
|
||||||
|
if (selectedSectionModel.getSelectedKey(state) == null) {
|
||||||
|
controller.addSection(article, section);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sectionsStep != null) {
|
||||||
|
sectionsStep
|
||||||
|
.onlyShowComponent(state,
|
||||||
|
MultiPartArticleSectionsStep.SECTION_TABLE
|
||||||
|
+ sectionsStep.getTypeIDStr());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ import com.arsdigita.bebop.Table;
|
||||||
import com.arsdigita.bebop.Text;
|
import com.arsdigita.bebop.Text;
|
||||||
import com.arsdigita.bebop.event.TableActionEvent;
|
import com.arsdigita.bebop.event.TableActionEvent;
|
||||||
import com.arsdigita.bebop.event.TableActionListener;
|
import com.arsdigita.bebop.event.TableActionListener;
|
||||||
|
import com.arsdigita.bebop.parameters.StringParameter;
|
||||||
import com.arsdigita.bebop.table.TableCellRenderer;
|
import com.arsdigita.bebop.table.TableCellRenderer;
|
||||||
import com.arsdigita.bebop.table.TableColumn;
|
import com.arsdigita.bebop.table.TableColumn;
|
||||||
import com.arsdigita.bebop.table.TableColumnModel;
|
import com.arsdigita.bebop.table.TableColumnModel;
|
||||||
|
|
@ -61,18 +62,22 @@ public class SectionTable extends Table {
|
||||||
* Index of the title column
|
* Index of the title column
|
||||||
*/
|
*/
|
||||||
public static final int COL_INDEX_TITLE = 0;
|
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.
|
* 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
|
* 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
|
* 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 ItemSelectionModel selectedArticleModel;
|
||||||
private SectionSelectionModel<? extends MultiPartArticleSection> selectedSectionModel;
|
private SectionSelectionModel<? extends MultiPartArticleSection> selectedSectionModel;
|
||||||
|
|
@ -81,14 +86,16 @@ public class SectionTable extends Table {
|
||||||
/**
|
/**
|
||||||
* Constructor. Create an instance of this class.
|
* Constructor. Create an instance of this class.
|
||||||
*
|
*
|
||||||
* @param selectedArticleModel a selection model that returns the
|
* @param selectedArticleModel a selection model that returns the
|
||||||
* MultiPartArticle which holds the sections to
|
* MultiPartArticle which holds the sections to
|
||||||
* display.
|
* display.
|
||||||
* @param moveSectionModel
|
* @param moveSectionModel
|
||||||
|
* @param selectedLanguageParam
|
||||||
*/
|
*/
|
||||||
public SectionTable(
|
public SectionTable(
|
||||||
final ItemSelectionModel selectedArticleModel,
|
final ItemSelectionModel selectedArticleModel,
|
||||||
final SectionSelectionModel<? extends MultiPartArticleSection> moveSectionModel) {
|
final SectionSelectionModel<? extends MultiPartArticleSection> moveSectionModel,
|
||||||
|
final StringParameter selectedLanguageParam) {
|
||||||
|
|
||||||
super();
|
super();
|
||||||
this.selectedArticleModel = selectedArticleModel;
|
this.selectedArticleModel = selectedArticleModel;
|
||||||
|
|
@ -100,6 +107,11 @@ public class SectionTable extends Table {
|
||||||
new Label(new GlobalizedMessage(
|
new Label(new GlobalizedMessage(
|
||||||
"cms.contenttypes.ui.mparticle.section_table.header_section",
|
"cms.contenttypes.ui.mparticle.section_table.header_section",
|
||||||
CmsConstants.CMS_BUNDLE))));
|
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(
|
model.add(new TableColumn(
|
||||||
COL_INDEX_EDIT,
|
COL_INDEX_EDIT,
|
||||||
new Label(new GlobalizedMessage(
|
new Label(new GlobalizedMessage(
|
||||||
|
|
@ -116,12 +128,14 @@ public class SectionTable extends Table {
|
||||||
"cms.contenttypes.ui.mparticle.section_table.header_delete",
|
"cms.contenttypes.ui.mparticle.section_table.header_delete",
|
||||||
CmsConstants.CMS_BUNDLE))));
|
CmsConstants.CMS_BUNDLE))));
|
||||||
|
|
||||||
model.get(1).setCellRenderer(new SectionTableCellRenderer(true));
|
model.get(COL_INDEX_EDIT).setCellRenderer(new SectionTableCellRenderer(true));
|
||||||
model.get(2).setCellRenderer(new SectionTableCellRenderer(true));
|
model.get(COL_INDEX_MOVE).setCellRenderer(new SectionTableCellRenderer(true));
|
||||||
model.get(3).setCellRenderer(new SectionTableCellRenderer(true));
|
model.get(COL_INDEX_DELETE).setCellRenderer(new SectionTableCellRenderer(true));
|
||||||
|
|
||||||
super.setModelBuilder(
|
super.setModelBuilder(
|
||||||
new SectionTableModelBuilder(selectedArticleModel, moveSectionModel));
|
new SectionTableModelBuilder(selectedArticleModel,
|
||||||
|
moveSectionModel,
|
||||||
|
selectedLanguageParam));
|
||||||
|
|
||||||
super.addTableActionListener(new TableActionListener() {
|
super.addTableActionListener(new TableActionListener() {
|
||||||
|
|
||||||
|
|
@ -175,16 +189,18 @@ public class SectionTable extends Table {
|
||||||
+ "the database.",
|
+ "the database.",
|
||||||
destId)));
|
destId)));
|
||||||
|
|
||||||
// if sect is lower in rank than the dest
|
controller.moveAfter(article, section, destSection);
|
||||||
// then move below is default behavior
|
|
||||||
int rank = destSection.getRank();
|
// // if sect is lower in rank than the dest
|
||||||
if (section.getRank() > rank) {
|
// // then move below is default behavior
|
||||||
// otherwise, add one to get "move below"
|
// int rank = destSection.getRank();
|
||||||
rank++;
|
// if (section.getRank() > rank) {
|
||||||
}
|
// // otherwise, add one to get "move below"
|
||||||
|
// rank++;
|
||||||
section.setRank(rank);
|
// }
|
||||||
sectionRepo.save(section);
|
//
|
||||||
|
// section.setRank(rank);
|
||||||
|
// sectionRepo.save(section);
|
||||||
moveSectionModel.setSelectedKey(state, null);
|
moveSectionModel.setSelectedKey(state, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,10 @@ package com.arsdigita.cms.ui.authoring.multipartarticle;
|
||||||
import com.arsdigita.bebop.Label;
|
import com.arsdigita.bebop.Label;
|
||||||
import com.arsdigita.bebop.PageState;
|
import com.arsdigita.bebop.PageState;
|
||||||
import com.arsdigita.bebop.Table;
|
import com.arsdigita.bebop.Table;
|
||||||
|
import com.arsdigita.bebop.parameters.StringParameter;
|
||||||
import com.arsdigita.bebop.table.TableColumnModel;
|
import com.arsdigita.bebop.table.TableColumnModel;
|
||||||
import com.arsdigita.bebop.table.TableModel;
|
import com.arsdigita.bebop.table.TableModel;
|
||||||
|
import com.arsdigita.cms.ui.authoring.SelectedLanguageUtil;
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
import com.arsdigita.globalization.GlobalizedMessage;
|
||||||
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
import org.libreccm.cdi.utils.CdiUtil;
|
||||||
|
|
@ -38,6 +40,7 @@ class SectionTableModel implements TableModel {
|
||||||
private final TableColumnModel columnModel;
|
private final TableColumnModel columnModel;
|
||||||
private final SectionTable sectionTable;
|
private final SectionTable sectionTable;
|
||||||
private final PageState pageState;
|
private final PageState pageState;
|
||||||
|
private final StringParameter selectedLanguageParam;
|
||||||
private final SectionSelectionModel<? extends MultiPartArticleSection> moveSectionModel;
|
private final SectionSelectionModel<? extends MultiPartArticleSection> moveSectionModel;
|
||||||
|
|
||||||
private final Iterator<MultiPartArticleSection> iterator;
|
private final Iterator<MultiPartArticleSection> iterator;
|
||||||
|
|
@ -54,10 +57,12 @@ class SectionTableModel implements TableModel {
|
||||||
public SectionTableModel(
|
public SectionTableModel(
|
||||||
final Table sectionTable,
|
final Table sectionTable,
|
||||||
final PageState pageState,
|
final PageState pageState,
|
||||||
|
final StringParameter selectedLanguageParam,
|
||||||
final MultiPartArticle article,
|
final MultiPartArticle article,
|
||||||
final SectionSelectionModel<? extends MultiPartArticleSection> moveSectionModel) {
|
final SectionSelectionModel<? extends MultiPartArticleSection> moveSectionModel) {
|
||||||
|
|
||||||
this.pageState = pageState;
|
this.pageState = pageState;
|
||||||
|
this.selectedLanguageParam = selectedLanguageParam;
|
||||||
this.sectionTable = (SectionTable) sectionTable;
|
this.sectionTable = (SectionTable) sectionTable;
|
||||||
this.moveSectionModel = moveSectionModel;
|
this.moveSectionModel = moveSectionModel;
|
||||||
|
|
||||||
|
|
@ -104,9 +109,23 @@ class SectionTableModel implements TableModel {
|
||||||
if (columnModel == null) {
|
if (columnModel == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (columnIndex) {
|
switch (columnIndex) {
|
||||||
case SectionTable.COL_INDEX_TITLE:
|
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:
|
case SectionTable.COL_INDEX_EDIT:
|
||||||
return new Label(new GlobalizedMessage(
|
return new Label(new GlobalizedMessage(
|
||||||
"cms.contenttypes.ui.mparticle.section_table.link_edit",
|
"cms.contenttypes.ui.mparticle.section_table.link_edit",
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ package com.arsdigita.cms.ui.authoring.multipartarticle;
|
||||||
|
|
||||||
import com.arsdigita.bebop.PageState;
|
import com.arsdigita.bebop.PageState;
|
||||||
import com.arsdigita.bebop.Table;
|
import com.arsdigita.bebop.Table;
|
||||||
|
import com.arsdigita.bebop.parameters.StringParameter;
|
||||||
import com.arsdigita.bebop.table.TableModel;
|
import com.arsdigita.bebop.table.TableModel;
|
||||||
import com.arsdigita.bebop.table.TableModelBuilder;
|
import com.arsdigita.bebop.table.TableModelBuilder;
|
||||||
import com.arsdigita.cms.ItemSelectionModel;
|
import com.arsdigita.cms.ItemSelectionModel;
|
||||||
|
|
@ -36,6 +37,8 @@ class SectionTableModelBuilder extends LockableImpl implements TableModelBuilder
|
||||||
private final ItemSelectionModel selectedArticleModel;
|
private final ItemSelectionModel selectedArticleModel;
|
||||||
private final SectionSelectionModel<? extends MultiPartArticleSection> moveSectionModel;
|
private final SectionSelectionModel<? extends MultiPartArticleSection> moveSectionModel;
|
||||||
|
|
||||||
|
private final StringParameter selectedLanguageParam;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Private class constructor.
|
* Private class constructor.
|
||||||
*
|
*
|
||||||
|
|
@ -44,10 +47,12 @@ class SectionTableModelBuilder extends LockableImpl implements TableModelBuilder
|
||||||
*/
|
*/
|
||||||
public SectionTableModelBuilder(
|
public SectionTableModelBuilder(
|
||||||
final ItemSelectionModel selectedArticleModel,
|
final ItemSelectionModel selectedArticleModel,
|
||||||
final SectionSelectionModel<? extends MultiPartArticleSection> moveSectionModel) {
|
final SectionSelectionModel<? extends MultiPartArticleSection> moveSectionModel,
|
||||||
|
final StringParameter selectedLanguageParam) {
|
||||||
|
|
||||||
this.selectedArticleModel = selectedArticleModel;
|
this.selectedArticleModel = selectedArticleModel;
|
||||||
this.moveSectionModel = moveSectionModel;
|
this.moveSectionModel = moveSectionModel;
|
||||||
|
this.selectedLanguageParam = selectedLanguageParam;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -67,6 +72,7 @@ class SectionTableModelBuilder extends LockableImpl implements TableModelBuilder
|
||||||
.getSelectedObject(state);
|
.getSelectedObject(state);
|
||||||
return new SectionTableModel(table,
|
return new SectionTableModel(table,
|
||||||
state,
|
state,
|
||||||
|
selectedLanguageParam,
|
||||||
article,
|
article,
|
||||||
moveSectionModel);
|
moveSectionModel);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,11 +21,11 @@ package org.librecms.contenttypes;
|
||||||
import org.librecms.contentsection.ContentItemRepository;
|
import org.librecms.contentsection.ContentItemRepository;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import javax.enterprise.context.RequestScoped;
|
import javax.enterprise.context.RequestScoped;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.persistence.EntityManager;
|
|
||||||
import javax.transaction.Transactional;
|
import javax.transaction.Transactional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -37,17 +37,17 @@ public class MultiPartArticleSectionManager {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private ContentItemRepository itemRepo;
|
private ContentItemRepository itemRepo;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private MultiPartArticleSectionRepository sectionRepo;
|
private MultiPartArticleSectionRepository sectionRepo;
|
||||||
|
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
public void addSectionToMultiPartArticle(
|
public void addSectionToMultiPartArticle(
|
||||||
final MultiPartArticleSection section,
|
final MultiPartArticleSection section,
|
||||||
final MultiPartArticle article) {
|
final MultiPartArticle article) {
|
||||||
|
|
||||||
article.addSection(section);
|
article.addSection(section);
|
||||||
|
section.setRank(article.getSections().size() - 1);
|
||||||
itemRepo.save(article);
|
itemRepo.save(article);
|
||||||
sectionRepo.save(section);
|
sectionRepo.save(section);
|
||||||
}
|
}
|
||||||
|
|
@ -65,25 +65,65 @@ public class MultiPartArticleSectionManager {
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
public void moveToFirst(final MultiPartArticle article,
|
public void moveToFirst(final MultiPartArticle article,
|
||||||
final MultiPartArticleSection section) {
|
final MultiPartArticleSection section) {
|
||||||
|
|
||||||
final List<MultiPartArticleSection> sections = article
|
final List<MultiPartArticleSection> sections = article
|
||||||
.getSections()
|
.getSections()
|
||||||
.stream()
|
.stream()
|
||||||
.sorted((section1, section2) -> Integer.compare(section1.getRank(),
|
.sorted((section1, section2) -> Integer.compare(section1.getRank(),
|
||||||
section2.getRank()))
|
section2.getRank()))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
final int oldRank = section.getRank();
|
final int oldRank = section.getRank();
|
||||||
|
|
||||||
section.setRank(1);
|
section.setRank(0);
|
||||||
sections
|
sections
|
||||||
.stream()
|
.stream()
|
||||||
.filter(current -> !current.equals(section))
|
.filter(current -> !current.equals(section))
|
||||||
.forEach(current -> current.setRank(current.getRank() + 1));
|
.forEach(current -> current.setRank(current.getRank() + 1));
|
||||||
|
|
||||||
sections
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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.section.create_break=Create page break after this section
|
||||||
cms.contenttypes.ui.mparticle.no_sections_yet=No sections yet
|
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_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.add_section=Add section
|
||||||
cms.contenttypes.ui.mparticle.edit_section=Edit section
|
cms.contenttypes.ui.mparticle.edit_section=Edit section
|
||||||
cms.contenttypes.ui.mparticle.delete_section=Delete 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.add_new_section=Add new section
|
||||||
cms.contenttypes.ui.mparticle.no_launch_date=Launch date is required
|
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.an_item_with_name_already_exists=An item with this name already exists
|
||||||
|
cms.contenttypes.ui.mparticle.section_table.header_page_break=Page break
|
||||||
|
|
|
||||||
|
|
@ -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.section.create_break=Seitenumbruch nach diesem Abschnitt einf\u00fcgen
|
||||||
cms.contenttypes.ui.mparticle.no_sections_yet=Keine Abschnitte vorhanden
|
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_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.add_section=Abschnitt hinzuf\u00fcgen
|
||||||
cms.contenttypes.ui.mparticle.edit_section=Abschnitt hinzuf\u00fcgen
|
cms.contenttypes.ui.mparticle.edit_section=Abschnitt hinzuf\u00fcgen
|
||||||
cms.contenttypes.ui.mparticle.delete_section=Abschnitt l\u00f6schen
|
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.add_new_section=Neuen Abschnitt hinzuf\u00fcgen
|
||||||
cms.contenttypes.ui.mparticle.no_launch_date=Es wurde kein Ver\u00f6ffentlichungsdatum angegeben
|
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.an_item_with_name_already_exists=Ein Dokument mit diesem Namen existiert bereits.
|
||||||
|
cms.contenttypes.ui.mparticle.section_table.header_page_break=Seitenumbruch
|
||||||
|
|
|
||||||
|
|
@ -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.section.create_break=Create page break after this section
|
||||||
cms.contenttypes.ui.mparticle.no_sections_yet=No sections yet
|
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_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.add_section=Add section
|
||||||
cms.contenttypes.ui.mparticle.edit_section=Edit section
|
cms.contenttypes.ui.mparticle.edit_section=Edit section
|
||||||
cms.contenttypes.ui.mparticle.delete_section=Delete 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.add_new_section=Add new section
|
||||||
cms.contenttypes.ui.mparticle.no_launch_date=Launch date is required
|
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.an_item_with_name_already_exists=An item with this name already exists
|
||||||
|
cms.contenttypes.ui.mparticle.section_table.header_page_break=Page break
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue