diff --git a/src/main/java/org/olat/modules/video/VideoManager.java b/src/main/java/org/olat/modules/video/VideoManager.java index 6f37936e14625edb74a0837d193b19809699e4bf..b6cddd98240fb3a8ae179495c168cedc16a5dd73 100644 --- a/src/main/java/org/olat/modules/video/VideoManager.java +++ b/src/main/java/org/olat/modules/video/VideoManager.java @@ -84,6 +84,8 @@ public interface VideoManager { * @param newPosterFile the new poster file */ public void setPosterframeResizeUploadfile(OLATResource videoResource, VFSLeaf newPosterFile); + + public void deletePosterframe(OLATResource videoResource); /** * get all available Tracks of given videoResource diff --git a/src/main/java/org/olat/modules/video/manager/VideoManagerImpl.java b/src/main/java/org/olat/modules/video/manager/VideoManagerImpl.java index 81a9018d69b5eb4283f8b532ee484bdc08ef7626..14a1e981ba3306704ae43cdd2a3afbcb5daa76bd 100644 --- a/src/main/java/org/olat/modules/video/manager/VideoManagerImpl.java +++ b/src/main/java/org/olat/modules/video/manager/VideoManagerImpl.java @@ -191,7 +191,9 @@ public class VideoManagerImpl implements VideoManager { && posterRes.getHeight() >= videoMetadata.getHeight() && posterRes.getWidth() >= videoMetadata.getWidth()) { VFSLeaf oldPosterFile = getPosterframe(videoResource); - oldPosterFile.delete(); + if(oldPosterFile != null) { + oldPosterFile.delete(); + } VFSContainer masterContainer = getMasterContainer(videoResource); LocalFileImpl newPoster = (LocalFileImpl) masterContainer.createChildLeaf(FILENAME_POSTER_JPG); // to shrink image file, resolution ratio needs to be equal, otherwise crop from top left corner @@ -206,6 +208,16 @@ public class VideoManagerImpl implements VideoManager { } } + @Override + public void deletePosterframe(OLATResource videoResource) { + VFSLeaf oldPosterFile = getPosterframe(videoResource); + if(oldPosterFile != null) { + oldPosterFile.delete(); + } + RepositoryEntry repoEntry = repositoryManager.lookupRepositoryEntry(videoResource, true); + repositoryManager.deleteImage(repoEntry); + } + /** * get a specific subtitle-track of the videoresource */ diff --git a/src/main/java/org/olat/modules/video/ui/VideoPosterEditController.java b/src/main/java/org/olat/modules/video/ui/VideoPosterEditController.java index 049c38c7b64acbd222210f04c17e498c6254c7c3..d6265b8cdc4c1721b84de001d48ac6a9f3e4c702 100644 --- a/src/main/java/org/olat/modules/video/ui/VideoPosterEditController.java +++ b/src/main/java/org/olat/modules/video/ui/VideoPosterEditController.java @@ -32,7 +32,6 @@ import org.olat.core.gui.control.Controller; import org.olat.core.gui.control.Event; import org.olat.core.gui.control.WindowControl; import org.olat.core.gui.control.generic.closablewrapper.CloseableModalController; -import org.olat.core.helpers.Settings; import org.olat.core.util.vfs.VFSContainer; import org.olat.core.util.vfs.VFSLeaf; import org.olat.modules.video.VideoFormat; @@ -49,6 +48,7 @@ import org.springframework.beans.factory.annotation.Autowired; */ public class VideoPosterEditController extends FormBasicController { + private FormLink deleteImage; private FormLink uploadImage; private FormLink replaceImage; private FormLayoutContainer displayContainer; @@ -68,6 +68,7 @@ public class VideoPosterEditController extends FormBasicController { this.videoResource = videoResource; videoMetadata = videoManager.getVideoMetadata(videoResource); initForm(ureq); + updatePosterImage(ureq, videoResource); } @Override @@ -79,7 +80,6 @@ public class VideoPosterEditController extends FormBasicController { displayContainer.contextPut("hint", translate("video.config.poster.hint")); - updatePosterImage(ureq, videoResource); displayContainer.setLabel("video.config.poster", null); formLayout.add(displayContainer); @@ -93,6 +93,8 @@ public class VideoPosterEditController extends FormBasicController { uploadImage = uifactory.addFormLink("uploadImage", "video.config.poster.upload", null, buttonGroupLayout, Link.BUTTON); uploadImage.setIconLeftCSS("o_icon o_icon_upload o_icon-f"); + + deleteImage = uifactory.addFormLink("deleteImage", "delete", null, buttonGroupLayout, Link.BUTTON); } @Override @@ -103,9 +105,11 @@ public class VideoPosterEditController extends FormBasicController { @Override protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) { if (source == replaceImage) { - doReplaceVideo(ureq); + doReplacePoster(ureq); } else if (source == uploadImage) { - doUploadVideo(ureq); + doUploadPoster(ureq); + } else if (source == deleteImage) { + doDeletePoster(ureq); } } @Override @@ -142,7 +146,7 @@ public class VideoPosterEditController extends FormBasicController { cmc = null; } - private void doReplaceVideo(UserRequest ureq){ + private void doReplacePoster(UserRequest ureq){ posterSelectionForm = new VideoPosterSelectionForm(ureq, getWindowControl(), videoResource, videoMetadata); listenTo(posterSelectionForm); @@ -157,7 +161,7 @@ public class VideoPosterEditController extends FormBasicController { } } - private void doUploadVideo(UserRequest ureq){ + private void doUploadPoster(UserRequest ureq){ posterUploadForm = new VideoPosterUploadForm(ureq, getWindowControl(), videoResource); listenTo(posterUploadForm); @@ -167,17 +171,24 @@ public class VideoPosterEditController extends FormBasicController { listenTo(cmc); cmc.activate(); } + + private void doDeletePoster(UserRequest ureq){ + videoManager.deletePosterframe(videoResource); + updatePosterImage(ureq, videoResource); + } - private void updatePosterImage(UserRequest ureq, OLATResource video){ + private boolean updatePosterImage(UserRequest ureq, OLATResource video){ VFSLeaf posterFile = videoManager.getPosterframe(video); if(posterFile != null) { VFSContainer masterContainer = posterFile.getParentContainer(); VideoMediaMapper mediaMapper = new VideoMediaMapper(masterContainer); String mediaUrl = registerMapper(ureq, mediaMapper); - String serverUrl = Settings.createServerURI(); - displayContainer.contextPut("serverUrl", serverUrl); displayContainer.contextPut("mediaUrl", mediaUrl); - displayContainer.setDirty(true); + } else { + displayContainer.contextRemove("mediaUrl"); } + displayContainer.setDirty(true); + deleteImage.setVisible(posterFile != null); + return posterFile != null; } } \ No newline at end of file diff --git a/src/main/java/org/olat/modules/video/ui/_content/poster_config.html b/src/main/java/org/olat/modules/video/ui/_content/poster_config.html index 81c96a517d67d9efe9120e38a9491857c36c2ac3..e1baff74baeb3ff94738a3bcabdb655b45c536d0 100644 --- a/src/main/java/org/olat/modules/video/ui/_content/poster_config.html +++ b/src/main/java/org/olat/modules/video/ui/_content/poster_config.html @@ -1,2 +1,2 @@ <div class="o_note">$hint</div> -<div class="o_video_poster" style="background-image: url('$mediaUrl/poster.jpg')"></div> +<div class="o_video_poster" style="#if($r.isNotEmpty($mediaUrl)) background-image: url('$mediaUrl/poster.jpg') #end"></div>