Skip to content

Commit

Permalink
rewrite flow of description + no i18n needed anymore for the slide items
Browse files Browse the repository at this point in the history
  • Loading branch information
Florent Mariotti committed Feb 27, 2025
1 parent 8e05449 commit c94a377
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

public enum SlideResourceType {
TITLE("title"),
DESCRIPTION("description"),
TEXT("text"),
IMAGE("image"),
VIDEO("video"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ public Slide createSlide(SlideResourceType type, SlideProperties properties) {
switch (type) {
case TITLE:
return new SlideTitle(properties.getTitle(), properties.getDescription(), properties.getOwnerName(),
properties.getModificationDate(), properties.getResourceData(), properties.getContentType(),
properties.getI18nHelper());
properties.getModificationDate(), properties.getResourceData(), properties.getContentType());
case DESCRIPTION:
return new SlideDescription(properties.getTitle(), properties.getDescription());
case TEXT:
return new SlideText(properties.getTitle(), properties.getDescription());
case FILE:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ private SlideProperties() {

private boolean isValidForTitle() {
return title != null && description != null && ownerName != null && modificationDate != null
&& resourceData != null && i18nHelper != null && contentType != null;
&& resourceData != null && contentType != null;
}

public boolean isValidForType(SlideResourceType type) {
Expand All @@ -36,6 +36,8 @@ public boolean isValidForType(SlideResourceType type) {
switch (type) {
case TITLE:
return isValidForTitle();
case DESCRIPTION:
return isValidForDescription();
case TEXT:
return isValidForText();
case FILE:
Expand All @@ -60,6 +62,10 @@ public I18nHelper getI18nHelper() {
return i18nHelper;
}

private boolean isValidForDescription() {
return title != null && description != null;
}

private boolean isValidForText() {
return title != null && description != null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,35 @@
package fr.cgi.magneto.model.slides;

import fr.cgi.magneto.core.constants.Slideshow;
import fr.cgi.magneto.helper.SlideHelper;
import org.apache.poi.sl.usermodel.TextParagraph;
import org.apache.poi.xslf.usermodel.XSLFSlide;
import org.apache.poi.xslf.usermodel.XSLFTextBox;
import org.apache.poi.xslf.usermodel.XSLFTextParagraph;
import org.apache.poi.xslf.usermodel.XSLFTextRun;

public class SlideDescription extends Slide {

public SlideDescription(String description) {
public SlideDescription(String description, String title) {
this.description = description;
this.title = title;
}

@Override
public Object createApacheSlide(XSLFSlide newSlide) {
return null;

SlideHelper.createTitle(newSlide, title,
Slideshow.DESCRIPTION_TITLE_HEIGHT, Slideshow.DESCRIPTION_TITLE_FONT_SIZE, TextParagraph.TextAlign.LEFT);

XSLFTextBox textBox = SlideHelper.createContent(newSlide);

XSLFTextParagraph paragraph = textBox.addNewTextParagraph();
paragraph.setTextAlign(TextParagraph.TextAlign.LEFT);
XSLFTextRun textRun = paragraph.addNewTextRun();
textRun.setText(description);
textRun.setFontSize(Slideshow.DESCRIPTION_FONT_SIZE);
textRun.setFontFamily(Slideshow.DEFAULT_FONT);

return newSlide;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package fr.cgi.magneto.model.slides;

import fr.cgi.magneto.core.constants.Slideshow;
import fr.cgi.magneto.helper.I18nHelper;
import fr.cgi.magneto.helper.SlideHelper;
import org.apache.poi.sl.usermodel.TextParagraph;
import org.apache.poi.xslf.usermodel.XSLFSlide;
Expand All @@ -16,16 +15,14 @@ public class SlideTitle extends Slide {
private final String modificationDate;
private final byte[] resourceData;
private final String contentType;
private final I18nHelper i18nHelper;

public SlideTitle(String title, String description, String ownerName, String modificationDate, byte[] resourceData,
String contentType, I18nHelper i18nHelper) {
String contentType) {
this.title = title;
this.description = description;
this.ownerName = ownerName;
this.modificationDate = modificationDate;
this.resourceData = resourceData;
this.i18nHelper = i18nHelper;
this.contentType = contentType;
}

Expand All @@ -40,13 +37,13 @@ public Object createApacheSlide(XSLFSlide newSlide) {
XSLFTextParagraph paragraph = textBox.addNewTextParagraph();
paragraph.setTextAlign(TextParagraph.TextAlign.CENTER);
XSLFTextRun textRun = paragraph.addNewTextRun();
textRun.setText(i18nHelper.translate("magneto.slideshow.created.by") + ownerName + ",");
textRun.setText(ownerName);
textRun.setFontSize(Slideshow.CONTENT_FONT_SIZE);

XSLFTextParagraph paragraph2 = textBox.addNewTextParagraph();
paragraph2.setTextAlign(TextParagraph.TextAlign.CENTER);
XSLFTextRun textRun2 = paragraph2.addNewTextRun();
textRun2.setText(i18nHelper.translate("magneto.slideshow.updated.the") + modificationDate);
textRun2.setText(modificationDate);
textRun2.setFontSize(Slideshow.CONTENT_FONT_SIZE);

SlideHelper.createImage(newSlide, resourceData, contentType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,16 +152,18 @@ private Future<XMLSlideShow> createFreeLayoutSlideObjects(Board board, UserInfos
Slide titleSlide = createTitleSlide(board, slideFactory, documents, i18nHelper);
XSLFSlide newTitleSlide = ppt.createSlide();
titleSlide.createApacheSlide(newTitleSlide);

// DESCRIPTION
Slide descriptionSlide = createDescriptionSlide(board, slideFactory, i18nHelper);
XSLFSlide newDescriptionSlide = ppt.createSlide();
descriptionSlide.createApacheSlide(newDescriptionSlide);

return serviceFactory.cardService().getAllCardsByBoard(board, user)
.map(fetchedCards -> {
// Créer une map des cartes récupérées pour un accès rapide
Map<String, Card> cardMap = fetchedCards.stream()
.collect(Collectors.toMap(Card::getId, card -> card));

//DESCRIPTION
XSLFSlide descriptionApacheSlide = createDescriptionSlide(board, i18nHelper);
ppt.createSlide().importContent(descriptionApacheSlide);

// Utiliser l'ordre des cartes du Board
for (Card boardCard : board.cards()) {
String cardId = boardCard.getId();
Expand Down Expand Up @@ -196,7 +198,6 @@ private Future<XMLSlideShow> createFreeLayoutSlideObjects(Board board, UserInfos
});
}


private Future<XMLSlideShow> createSectionLayoutSlideObjects(Board board, UserInfos user,
JsonObject slideShowData, List<Map<String, Object>> documents, I18nHelper i18nHelper) {
XMLSlideShow ppt = new XMLSlideShow();
Expand All @@ -209,6 +210,11 @@ private Future<XMLSlideShow> createSectionLayoutSlideObjects(Board board, UserIn
XSLFSlide newTitleSlide = ppt.createSlide();
titleSlide.createApacheSlide(newTitleSlide);

// DESCRIPTION
Slide descriptionSlide = createDescriptionSlide(board, slideFactory, i18nHelper);
XSLFSlide newDescriptionSlide = ppt.createSlide();
descriptionSlide.createApacheSlide(newDescriptionSlide);

return this.serviceFactory.sectionService().createSectionWithCards(board, user)
.map(sections -> {
for (Section section : sections) {
Expand Down Expand Up @@ -312,12 +318,20 @@ private Slide createTitleSlide(Board board, SlideFactory slideFactory, List<Map<
String contentType = documentData != null ? (String) documentData.get(Field.CONTENTTYPE) : "";

propertiesBuilder
.ownerName(board.getOwnerName())
.modificationDate(board.getModificationDate())
.ownerName(i18nHelper.translate("magneto.slideshow.created.by") + board.getOwnerName() + ",")
.modificationDate(i18nHelper.translate("magneto.slideshow.updated.the") + board.getModificationDate())
.resourceData(documentBuffer != null ? documentBuffer.getBytes() : null)
.contentType(contentType)
.i18nHelper(i18nHelper);
.contentType(contentType);

return slideFactory.createSlide(SlideResourceType.TITLE, propertiesBuilder.build());
}

private Slide createDescriptionSlide(Board board, SlideFactory slideFactory,
I18nHelper i18nHelper) {
SlideProperties.Builder propertiesBuilder = new SlideProperties.Builder()
.title(i18nHelper.translate("magneto.create.board.description"))
.description(board.getDescription());

return slideFactory.createSlide(SlideResourceType.DESCRIPTION, propertiesBuilder.build());
}
}

0 comments on commit c94a377

Please sign in to comment.