Skip to content

Commit

Permalink
Minio raus, Youtube-Videos ergänzen, bearbeiten und anzeigen
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernd Ritter committed May 3, 2024
1 parent f290b79 commit e6e7e4a
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 65 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ docs

*.log
onb-configuration.xml
.dev-environments
.env
20 changes: 1 addition & 19 deletions doc/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,6 @@ services:
networks:
- holarse-dev

storage:
image: minio/minio
container_name: minio
restart: always
command: server --console-address ":9001" /data
environment:
MINIO_ROOT_USER: minioadmin
MINIO_ROOT_PASSWORD: minioadmin
ports:
- 9000:9000
- 9001:9001
volumes:
- storage_data:/data
networks:
- holarse-dev

app:
image: tomcat:11.0-jdk21-openjdk
container_name: app
Expand All @@ -61,6 +45,7 @@ services:
environment:
- OCI_ACCESSKEYID=${OCI_ACCESSKEYID}
- OCI_SECRETKEYID=${OCI_SECRETKEYID}

cache:
image: memcached:latest
container_name: cache
Expand All @@ -85,9 +70,6 @@ volumes:
external: true
amq_journal_data:
external: true
storage_data:
external: true


networks:
holarse-dev:
Expand Down
48 changes: 16 additions & 32 deletions src/main/java/de/holarse/backend/view/YoutubeView.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,29 @@

import de.holarse.backend.db.Attachment;

public class YoutubeView {
public class YoutubeView extends AttachmentView {

private Integer id;
private String url;
private String description;
private Integer weight;

public static YoutubeView of(final Attachment attachment) {
final YoutubeView view = new YoutubeView();
view.setId(attachment.getId());
view.setUrl(attachment.getData());
view.setDescription(attachment.getDescription());
view.setWeight(attachment.getWeight());
final static transient String YOUTUBE_NOCOOKIE_URL="https://www.youtube-nocookie.com/embed/%s?origin=https://holarse.de";

return view;
}

public Integer getWeight() {
return weight;
}
private String url;

public void setWeight(Integer weight) {
this.weight = weight;
public YoutubeView() {
super();
}

public Integer getId() {
return id;
public YoutubeView(final AttachmentView av) {
super();
setId(av.getId());
setData(av.getData());
setWeight(av.getWeight());
setDescription(av.getDescription());
setMarkAsDeleted(av.isMarkAsDeleted());
}

public void setId(Integer id) {
this.id = id;
public static YoutubeView of(final Attachment attachment) {
final YoutubeView view = new YoutubeView(AttachmentView.of(attachment));
view.setUrl(String.format(YOUTUBE_NOCOOKIE_URL, attachment.getData()));
return view;
}

public String getUrl() {
Expand All @@ -42,12 +34,4 @@ public String getUrl() {
public void setUrl(String url) {
this.url = url;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}
}
39 changes: 36 additions & 3 deletions src/main/java/de/holarse/web/controller/WikiController.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,14 @@ public ModelAndView edit(@PathVariable final Integer nodeId, final ModelAndView

// Attachments
final List<Attachment> websiteLinks = attachmentService.getAttachments(article, attachmentGroupRepository.findByCode(AttachmentGroupType.website.name()));
logger.debug("Links: {}", websiteLinks);
form.setWebsiteLinks(websiteLinks.stream().map(AttachmentView::of).toList());

form.setTags(tags.stream().map(t -> t.getName()).collect(Collectors.joining(", ")));

final List<Attachment> videos = attachmentService.getAttachments(article, attachmentGroupRepository.findByCode(AttachmentGroupType.video.name()));
form.setVideos(videos.stream().map(YoutubeView::of).toList());
final List<Attachment> screenshots = attachmentService.getAttachments(article, attachmentGroupRepository.findByCode(AttachmentGroupType.image.name()));
form.setScreenshots(screenshots.stream().map(ScreenshotView::of).map(ssv -> objectStorageService.patchUrl(ssv)).toList());

form.setTags(tags.stream().map(Tag::getName).collect(Collectors.joining(", ")));
form.setSettings(SettingsView.of(article.getNodeStatus()));

logger.debug("WebsiteLinks: {}", form.getWebsiteLinks());
Expand All @@ -211,6 +215,7 @@ public ModelAndView update(@PathVariable final int nodeId, @ModelAttribute("form

final AttachmentType attScreenshot = attachmentTypeRepository.findByCode("screenshot");
final AttachmentType attLink = attachmentTypeRepository.findByCode("link");
final AttachmentType attVideo = attachmentTypeRepository.findByCode("youtube");

List<Attachment> addedScreenShots = new ArrayList<>();
final List<FileUploadForm> screenshots = fileUploadService.readFileUpload(form);
Expand Down Expand Up @@ -281,6 +286,34 @@ public ModelAndView update(@PathVariable final int nodeId, @ModelAttribute("form
attachmentRepository.saveAllAndFlush(createdAndUpdatedAttachments);
logger.debug("Saved attachments (links)");

//
// Videos
//
logger.debug("Video-Attachments: {}", form.getVideos());
final Map<Boolean, List<YoutubeView>> videoMaps = form.getVideos().stream().collect(Collectors.partitioningBy(AttachmentView::isMarkAsDeleted));
// Die zu Löschenden verarbeiten
attachmentRepository.deleteAllById(videoMaps.get(Boolean.TRUE).stream().map(AttachmentView::getId).toList());

final List<Attachment> createdAndUpdatedVideos = new ArrayList<>();
// Die neuen Entities umwandeln und speichern
createdAndUpdatedVideos.addAll(videoMaps.get(Boolean.FALSE).stream()
.filter(av -> av.getId() == null)
.filter(av -> StringUtils.isNotBlank(av.getData()))
.map(av -> Attachment.build(av, nodeId, attVideo))
.toList());
// Die bestehenden finden und updaten
for (final AttachmentView av : videoMaps.get(Boolean.FALSE).stream().filter(av -> av.getId() != null).toList()) {
final Attachment att = attachmentRepository.findById(av.getId()).orElseThrow(EntityNotFoundException::new);
att.setWeight(av.getWeight());
att.setData(av.getData());
att.setDescription(av.getDescription());

createdAndUpdatedVideos.add(att);
}
attachmentRepository.saveAllAndFlush(createdAndUpdatedVideos);
logger.debug("Saved attachments (videos)");

// Neue Screenshots
attachmentRepository.saveAllAndFlush(addedScreenShots);
logger.debug("Saved attachments (screenshots");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import de.holarse.backend.view.AttachmentView;
import de.holarse.backend.view.ScreenshotView;
import de.holarse.backend.view.SettingsView;
import de.holarse.backend.view.YoutubeView;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;

Expand All @@ -18,6 +19,7 @@ public abstract class AbstractNodeForm {

private List<AttachmentView> websiteLinks = new ArrayList<>();
private List<ScreenshotView> screenshots = new ArrayList<>();
private List<YoutubeView> videos = new ArrayList<>();

private SettingsView settings = new SettingsView();

Expand Down Expand Up @@ -56,4 +58,11 @@ public void setSettings(SettingsView settings) {
public void setScreenshots(List<ScreenshotView> screenshots) { this.screenshots = screenshots ;}
public List<ScreenshotView> getScreenshots() { return screenshots; };

public List<YoutubeView> getVideos() {
return videos;
}

public void setVideos(List<YoutubeView> videos) {
this.videos = videos;
}
}
61 changes: 51 additions & 10 deletions src/main/webapp/WEB-INF/templates/sites/shared/articles/form.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#article-edit-tab-links" role="tab">Links</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#article-edit-tab-videos" role="tab">Videos</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#article-edit-tab-screenshots" role="tab">Screenshots</a>
</li>
Expand Down Expand Up @@ -146,15 +149,56 @@
<input data-th-name="websiteLinks[ + |${#lists.size(form.websiteLinks)}| + ].markAsDeleted" value="0" type="text" hidden>

<label class="col-sm-3 col-form-label g-mb-10" data-th-for="form.websiteLinks[][description]">Beschreibung</label>
<input data-th-name="websiteLinks[ + |${#lists.size(form.websiteLinks)}| + ].description" class="form-control form-control-md rounded-0" type="text" placeholder="Link zum Projekt/Webseite">
<input data-th-name="websiteLinks[ + |${#lists.size(form.websiteLinks)}| + ].description" class="form-control form-control-md rounded-0" type="text" placeholder="Beschreibung des Links">

<label class="col-sm-3 col-form-label g-mb-10" data-th-for="form.websiteLinks[][data]">URL</label>
<input data-th-name="websiteLinks[ + |${#lists.size(form.websiteLinks)}| + ].data" class="form-control form-control-md rounded-0" type="text" placeholder="Link zum Projekt/Webseite">
<input data-th-name="websiteLinks[ + |${#lists.size(form.websiteLinks)}| + ].data" class="form-control form-control-md rounded-0" type="text" placeholder="Link zum Projekt/Webseite">

</div>

</div>

<!-- Tab Videos -->
<div class="tab-pane fade show" id="article-edit-tab-videos" role="tabpanel">

<ul data-th-each="video,iter : *{videos}">
<!-- Website Link -->
<div class="form-group row g-mb-20 block-title block-title7">

<label class="col-sm-1 col-form-label g-mb-1" th:text="Link + ' #' + |${iter.count}|"></label>
<input data-th-field="*{videos[__${iter.index}__].id}" type="hidden">

<input data-th-field="*{videos[__${iter.index}__].weight}" type="hidden">
<input data-th-field="*{videos[__${iter.index}__].markAsDeleted}" type="hidden">

<div class="col-sm-11">
<label class="col-sm-3 col-form-label g-mb-10" th:for="${'videos[__${iter.index}__].description'}">Beschreibung</label>
<input data-th-field="*{videos[__${iter.index}__].description}" class="form-control form-control-md rounded-0" type="text" placeholder="Beschreibung">

<label class="col-sm-3 col-form-label g-mb-10" th:for="${'videos[__${iter.index}__].data'}">URL</label>
<input data-th-field="*{videos[__${iter.index}__].data}" class="form-control form-control-md rounded-0" type="text" placeholder="Link zum Video">
</div>
</div>
<!-- End Website Link -->
</ul>
<!-- Neuer Eintrag -->
<div class="form-group g-mb-20 block-title block-title7">

<span>Neuer Link</span>
<input data-th-name="videos[ + |${#lists.size(form.videos)}| + ].id" type="text" hidden>
<input data-th-name="videos[ + |${#lists.size(form.videos)}| + ].weight" value="0" type="text" hidden>
<input data-th-name="videos[ + |${#lists.size(form.videos)}| + ].markAsDeleted" value="0" type="text" hidden>

<label class="col-sm-3 col-form-label g-mb-10" data-th-for="form.videos[][description]">Beschreibung</label>
<input data-th-name="videos[ + |${#lists.size(form.videos)}| + ].description" class="form-control form-control-md rounded-0" type="text" placeholder="Beschreibung des Links">

<label class="col-sm-3 col-form-label g-mb-10" data-th-for="form.videos[][data]">URL</label>
<input data-th-name="videos[ + |${#lists.size(form.videos)}| + ].data" class="form-control form-control-md rounded-0" type="text" placeholder="Link zum Projekt/Webseite">

</div>

</div>

<!-- Tab Screenshots -->
<div class="tab-pane fade show" id="article-edit-tab-screenshots" role="tabpanel">

Expand All @@ -163,16 +207,13 @@
<!-- Existing Screenshot-Item -->
<div class="form-group row g-mb-20 block-title block-title7">

<label class="col-sm-1 col-form-label g-mb-1" data-th-text="Link + ' #' + |${iter.count}|"></label>
<input data-th-field="*{screenshot[__${iter.index}__].id}" type="hidden">
<label class="col-sm-1 col-form-label g-mb-1" data-th-text="Bild + ' #' + |${iter.count}|"></label>
<img class="img-fluid img-thumbnail rounded-circle" data-th-src="*{screenshots[__${iter.index}__].data}" alt="">

<input data-th-field="*{screenshot[__${iter.index}__].weight}" type="hidden">
<input data-th-field="*{screenshot[__${iter.index}__].markAsDeleted}" type="hidden">
<input data-th-field="*{screenshots[__${iter.index}__].id}" type="hidden">
<input data-th-field="*{screenshots[__${iter.index}__].weight}" type="hidden">
<input data-th-field="*{screenshots[__${iter.index}__].markAsDeleted}" type="hidden">

<div class="col-sm-11">
<label class="col-sm-3 col-form-label g-mb-10" data-th-for="${'screenshot[__${iter.index}__].description'}">Beschreibung</label>
<input data-th-field="*{screenshot[__${iter.index}__].description}" class="form-control form-control-md rounded-0" type="text" placeholder="Beschreibung zum Bild">
</div>
</div>
<!-- End Screenshots -->
</ul>
Expand Down
7 changes: 7 additions & 0 deletions src/main/webapp/WEB-INF/templates/sites/shared/videos.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div data-th-fragment="render(videos)">
<div class="list-group" data-th-each="video : ${videos}">
<div class="embed-responsive embed-responsive-16by9 g-mb-30">
<iframe width="100%" data-th-src="@{${video.url}}" frameborder="0" allowfullscreen=""></iframe>
</div>
</div>
</div>
2 changes: 2 additions & 0 deletions src/main/webapp/WEB-INF/templates/sites/wiki/show.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ <h4 class="g-font-weight-200" data-th-text="${altTitle}"></h4>
</section>

<p th:replace="~{sites/shared/screenshots :: render(screenshots=${view.screenshots})}"></p>

<p th:replace="~{sites/shared/videos :: render(videos=${view.youtubeVideos})}"></p>
</div>
</div>
<div class="col-sm-2">
Expand Down

0 comments on commit e6e7e4a

Please sign in to comment.