Skip to content

Commit

Permalink
feat(media): add audio icon SVG and enhance SlideMedia with media typ…
Browse files Browse the repository at this point in the history
…e detection

feat(export): enhance media handling by copying media parts and relationships during slide export

media audio stable

media based on content-type

feat(slide): refactor media icon creation and positioning for improved layout

video stable
  • Loading branch information
ThomasSevagen committed Feb 26, 2025
1 parent c70879b commit 9504070
Show file tree
Hide file tree
Showing 16 changed files with 792 additions and 72 deletions.
8 changes: 7 additions & 1 deletion backend/pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
Expand Down Expand Up @@ -130,6 +131,11 @@
<artifactId>poi-ooxml</artifactId>
<version>${apachePoiVersion}</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-full</artifactId>
<version>${apachePoiVersion}</version>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
package fr.cgi.magneto.controller;

import java.io.ByteArrayOutputStream;
import java.io.IOException;

import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.openxml4j.opc.PackageRelationship;
import org.entcore.common.controller.ControllerHelper;
import org.entcore.common.user.UserUtils;

import fr.cgi.magneto.core.constants.Field;
import fr.cgi.magneto.helper.I18nHelper;
import fr.cgi.magneto.service.ExportService;
Expand All @@ -9,11 +19,6 @@
import fr.wseduc.webutils.I18n;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.http.HttpServerRequest;
import org.entcore.common.controller.ControllerHelper;
import org.entcore.common.user.UserUtils;

import java.io.ByteArrayOutputStream;
import java.io.IOException;

public class ExportController extends ControllerHelper {
private final ExportService exportService;
Expand All @@ -38,6 +43,21 @@ public void exportBoardToPPTX(HttpServerRequest request) {
.putHeader("Content-Disposition", "attachment; filename=\"board.pptx\"");

ByteArrayOutputStream out = new ByteArrayOutputStream();
System.out.println("Parties du package avant sauvegarde :");
OPCPackage opcPackage = ppt.getPackage();
try {
for (PackagePart part : opcPackage.getParts()) {
System.out.println(part.getPartName());
}
} catch (InvalidFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

System.out.println("\nRelations du package :");
for (PackageRelationship rel : opcPackage.getRelationships()) {
System.out.println(rel.getRelationshipType() + " : " + rel.getTargetURI());
}
ppt.write(out);
request.response().end(Buffer.buffer(out.toByteArray()));
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ public class Slideshow {
public static final int MARGIN_LEFT = 140;
public static final int MARGIN_TOP_TITLE = 40;
public static final int WIDTH = 1000;
public static final int SLIDE_HEIGHT = 720;
public static final int SLIDE_WIDTH = 1280;

// Constantes pour les titres
public static final int TITLE_HEIGHT = 70;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public Slide createSlide(SlideResourceType type, SlideProperties properties) {
case VIDEO:
case AUDIO:
return new SlideMedia(properties.getTitle(), properties.getCaption(),
properties.getResourceData(), properties.getExtension());
properties.getResourceData(), properties.getContentType());
case BOARD:
return new SlideBoard(
properties.getTitle(), properties.getDescription(),
Expand Down
619 changes: 609 additions & 10 deletions backend/src/main/java/fr/cgi/magneto/helper/SlideHelper.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ public class SlideProperties {
private String content;
private String resourceUrl;
private String resourceId;
private String extension;
private String fileName;
private byte[] resourceData;
private String contentType;

private String ownerName;
private String modificationDate;
Expand Down Expand Up @@ -59,8 +59,8 @@ public Builder resourceId(String resourceId) {
return this;
}

public Builder extension(String extension) {
properties.extension = extension;
public Builder contentType(String contentType) {
properties.contentType = contentType;
return this;
}

Expand Down Expand Up @@ -143,7 +143,7 @@ private boolean isValidForLink() {
}

private boolean isValidForMedia() {
return title != null && caption != null && extension != null && resourceData != null;
return title != null && caption != null && contentType != null && resourceData != null;
}

private boolean isValidForBoard() {
Expand Down Expand Up @@ -180,8 +180,8 @@ public String getResourceId() {
return resourceId;
}

public String getExtension() {
return extension;
public String getContentType() {
return contentType;
}

public String getFileName() {
Expand Down
3 changes: 2 additions & 1 deletion backend/src/main/java/fr/cgi/magneto/model/slides/Slide.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package fr.cgi.magneto.model.slides;

import org.apache.poi.xslf.usermodel.XSLFSlide;

public abstract class Slide {
protected String title;
protected String description = "";

public abstract Object createApacheSlide();
public abstract Object createApacheSlide(XSLFSlide newSlide);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package fr.cgi.magneto.model.slides;

import org.apache.poi.xslf.usermodel.XSLFSlide;

public class SlideBoard extends Slide {
private final String ownerName;
private final String modificationDate;
Expand All @@ -19,7 +21,7 @@ public SlideBoard(String title, String description, String ownerName, String mod
}

@Override
public Object createApacheSlide() {
public Object createApacheSlide(XSLFSlide newSlide) {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package fr.cgi.magneto.model.slides;

import org.apache.poi.xslf.usermodel.XSLFSlide;

public class SlideDescription extends Slide {

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

@Override
public Object createApacheSlide() {
public Object createApacheSlide(XSLFSlide newSlide) {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package fr.cgi.magneto.model.slides;

import org.apache.poi.xslf.usermodel.XSLFSlide;

public class SlideFile extends Slide {
private final String fileName;
private final String desc;
Expand All @@ -10,7 +12,7 @@ public SlideFile(String fileName, String desc) {
}

@Override
public Object createApacheSlide() {
public Object createApacheSlide(XSLFSlide newSlide) {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package fr.cgi.magneto.model.slides;

import org.apache.poi.xslf.usermodel.XSLFSlide;

public class SlideLink extends Slide {
private final String link;

Expand All @@ -8,7 +10,7 @@ public SlideLink(String link) {
}

@Override
public Object createApacheSlide() {
public Object createApacheSlide(XSLFSlide newSlide) {
return null;
}
}
75 changes: 64 additions & 11 deletions backend/src/main/java/fr/cgi/magneto/model/slides/SlideMedia.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,81 @@

public class SlideMedia extends Slide {

public enum MediaType {
IMAGE,
AUDIO,
VIDEO
}

private byte[] resourceData;
private final String fileExtension;
private final String fileContentType;
private final String caption;
private final MediaType mediaType;

public SlideMedia(String title, String caption, byte[] resourceData,
String fileExtension) {
String fileContentType) {
this.title = title;
this.caption = caption;
this.resourceData = resourceData;
this.fileExtension = fileExtension;
this.fileContentType = fileContentType;
this.mediaType = determineMediaType(fileContentType);

// Log des informations dans le constructeur
System.out.println("SlideMedia - Construction:");
System.out.println("Title: " + title);
System.out.println("Caption: " + caption);
System.out.println("File extension: " + fileContentType);
System.out.println(
"Resource data present: " + (resourceData != null ? "Yes (" + resourceData.length + " bytes)" : "No"));
System.out.println("Determined media type: " + mediaType);
}

@Override
public Object createApacheSlide() {
private MediaType determineMediaType(String contentType) {
String type = contentType.toLowerCase();
MediaType mediaType;

if (type.startsWith("audio/")) {
mediaType = MediaType.AUDIO;
} else if (type.startsWith("video/")) {
mediaType = MediaType.VIDEO;
} else {
mediaType = MediaType.IMAGE;
}

XMLSlideShow ppt = new XMLSlideShow();
XSLFSlide slide = ppt.createSlide();
// Log du type de média déterminé
System.out.println("determineMediaType - Content Type: " + contentType + " -> Type: " + mediaType);

return mediaType;
}

@Override
public Object createApacheSlide(XSLFSlide newSlide) {
// Log au début de la création de la slide
System.out.println("\nStarting createApacheSlide:");
System.out.println("Title: " + title);
System.out.println("Media type: " + mediaType);
System.out.println("Resource data size: " + (resourceData != null ? resourceData.length : "null") + " bytes");
System.out.println("File extension: " + fileContentType);

SlideHelper.createTitle(slide, title, Slideshow.TITLE_HEIGHT, Slideshow.TITLE_FONT_SIZE, TextParagraph.TextAlign.LEFT);
SlideHelper.createImage(slide, resourceData, fileExtension, Slideshow.CONTENT_MARGIN_TOP, Slideshow.IMAGE_CONTENT_HEIGHT);
SlideHelper.createLegend(slide, caption);
SlideHelper.createTitle(newSlide, title, Slideshow.TITLE_HEIGHT, Slideshow.TITLE_FONT_SIZE,
TextParagraph.TextAlign.LEFT);
switch (mediaType) {
case AUDIO:
System.out.println("Creating audio slide...");
SlideHelper.createAudio(newSlide, resourceData, fileContentType);
break;
case VIDEO:
System.out.println("Creating video slide...");
SlideHelper.createVideo(newSlide, resourceData, fileContentType);
break;
default:
System.out.println("Creating image slide...");
SlideHelper.createImage(newSlide, resourceData, fileContentType, Slideshow.CONTENT_MARGIN_TOP,
Slideshow.IMAGE_CONTENT_HEIGHT);
}
SlideHelper.createLegend(newSlide, caption);

return slide;
System.out.println("Slide creation completed.");
return newSlide;
}
}
11 changes: 5 additions & 6 deletions backend/src/main/java/fr/cgi/magneto/model/slides/SlideText.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,16 @@ public SlideText(String title, String description) {
}

@Override
public Object createApacheSlide() {
XMLSlideShow ppt = new XMLSlideShow();
XSLFSlide slide = ppt.createSlide();
public Object createApacheSlide(XSLFSlide newSlide) {

SlideHelper.createTitle(slide, title, Slideshow.TITLE_HEIGHT, Slideshow.TITLE_FONT_SIZE, TextParagraph.TextAlign.LEFT);
XSLFTextBox contentBox = SlideHelper.createContent(slide);
SlideHelper.createTitle(newSlide, title, Slideshow.TITLE_HEIGHT, Slideshow.TITLE_FONT_SIZE,
TextParagraph.TextAlign.LEFT);
XSLFTextBox contentBox = SlideHelper.createContent(newSlide);

Document doc = Jsoup.parse(description);
processHtmlContent(contentBox, doc.body());

return slide;
return newSlide;
}

private void processHtmlContent(XSLFTextBox textBox, Element element) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package fr.cgi.magneto.model.slides;

import org.apache.poi.xslf.usermodel.XSLFSlide;

public class SlideTitle extends Slide {
private final String title;

Expand All @@ -8,7 +10,7 @@ public SlideTitle(String title) {
}

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

0 comments on commit 9504070

Please sign in to comment.