Media attachment part 1

pull/20/head
Jens Pelzetter 2022-03-09 20:18:49 +01:00
parent 8871eecea3
commit b89e15479d
7 changed files with 91 additions and 13 deletions

View File

@ -1,5 +1,13 @@
<#macro foo> <#macro "org.librecms.assets.AudioAsset" asset>
<p>foo</p> <pre>AudioAsset</pre>
</#macro>
<#macro "org.librecms.assets.ExternalAudioAsset" asset>
<pre>ExternalAudioAsset</pre>
</#macro>
<#macro "org.librecms.assets.ExternalVideoAsset" asset>
<pre>ExternalVideoAsset</pre>
</#macro> </#macro>
<#macro "org.librecms.assets.FileAsset" asset> <#macro "org.librecms.assets.FileAsset" asset>
@ -9,6 +17,11 @@
<#-- <p><code>A file asset</code></p> --> <#-- <p><code>A file asset</code></p> -->
</#macro> </#macro>
<#macro "org.librecms.assets.Image" asset>
<pre>Image</pre>
</#macro>
<#macro "org.librecms.assets.RelatedLink" asset> <#macro "org.librecms.assets.RelatedLink" asset>
<#if asset.externalLink> <#if asset.externalLink>
<div> <div>
@ -25,3 +38,7 @@
<a href="${asset.targetItemPath}">${asset.title}</a> <a href="${asset.targetItemPath}">${asset.title}</a>
</#if> </#if>
</#macro> </#macro>
<#macro "org.librecms.assets.VideoAsset" asset>
<pre>VideoAsset</pre>
</#macro>

View File

@ -1,7 +1,16 @@
<#import "../assets.html.ftl" as assets>
<#macro details> <#macro details>
<h1>${CmsPagesCategorizedItemModel.title}</h1> <h1>${CmsPagesCategorizedItemModel.title}</h1>
<p class="item-description">${CmsPagesCategorizedItemModel.description}</p> <p class="item-description">${CmsPagesCategorizedItemModel.description}</p>
<div class="float-end">
<#list CmsPagesCategorizedItemModel.mediaLists as mediaList>
<#list mediaList.attachments as media>
<@.vars["assets"][media.asset.type] media.asset />
</#list>
</#list>
</div>
<div> <div>
${CmsPagesArticleModel.text} ${CmsPagesArticleModel.text}
</div> </div>

View File

@ -61,6 +61,8 @@ public class CmsConstants {
public static final String FORM_ENCTYPE_MULTIPART = "multipart/form-data"; public static final String FORM_ENCTYPE_MULTIPART = "multipart/form-data";
public static final String MEDIA_LIST_PREFIX = ".media-";
/** /**
* Constant string used as key for creating service package as a legacy * Constant string used as key for creating service package as a legacy
* application. * application.

View File

@ -21,6 +21,7 @@ package org.librecms.pages.models;
import org.libreccm.categorization.CategoryRepository; import org.libreccm.categorization.CategoryRepository;
import org.libreccm.core.CcmObject; import org.libreccm.core.CcmObject;
import org.libreccm.l10n.GlobalizationHelper; import org.libreccm.l10n.GlobalizationHelper;
import org.librecms.CmsConstants;
import org.librecms.contentsection.Asset; import org.librecms.contentsection.Asset;
import org.librecms.contentsection.AttachmentList; import org.librecms.contentsection.AttachmentList;
import org.librecms.contentsection.ContentItem; import org.librecms.contentsection.ContentItem;
@ -283,6 +284,14 @@ public class ContentItemModel {
.orElse(Collections.emptyList()); .orElse(Collections.emptyList());
} }
@Transactional(Transactional.TxType.REQUIRED)
public List<AttachmentListModel> getMediaLists() {
init();
return contentItem
.map(ContentItemModelData::getMediaLists)
.orElse(Collections.emptyList());
}
/** /**
* Gets the version of the current item (see {@link ContentItem#version}. * Gets the version of the current item (see {@link ContentItem#version}.
* *
@ -510,6 +519,24 @@ public class ContentItemModel {
item item
.getAttachments() .getAttachments()
.stream() .stream()
.filter(
list -> !list.getName().startsWith(
CmsConstants.MEDIA_LIST_PREFIX
)
)
.map(this::buildAttachmentListModel)
.sorted()
.collect(Collectors.toList())
);
data.setMediaLists(
item
.getAttachments()
.stream()
.filter(
list -> list.getName().startsWith(
CmsConstants.MEDIA_LIST_PREFIX
)
)
.map(this::buildAttachmentListModel) .map(this::buildAttachmentListModel)
.sorted() .sorted()
.collect(Collectors.toList()) .collect(Collectors.toList())
@ -613,6 +640,8 @@ public class ContentItemModel {
private List<AttachmentListModel> attachmentLists; private List<AttachmentListModel> attachmentLists;
private List<AttachmentListModel> mediaLists;
public long getObjectId() { public long getObjectId() {
return objectId; return objectId;
} }
@ -716,10 +745,19 @@ public class ContentItemModel {
} }
public void setAttachmentLists( public void setAttachmentLists(
final List<AttachmentListModel> attachmentLists) { final List<AttachmentListModel> attachmentLists
) {
this.attachmentLists = new ArrayList<>(attachmentLists); this.attachmentLists = new ArrayList<>(attachmentLists);
} }
public List<AttachmentListModel> getMediaLists() {
return Collections.unmodifiableList(mediaLists);
}
public void setMediaLists(final List<AttachmentListModel> mediaLists) {
this.mediaLists = new ArrayList<>(mediaLists);
}
} }
} }

View File

@ -50,9 +50,12 @@ public class ImageModelBuilder
protected void addProperties(final Image image, final ImageModel model) { protected void addProperties(final Image image, final ImageModel model) {
super.addProperties(image, model); super.addProperties(image, model);
model.setHeight(image.getHeight()); model.setHeight(image.getHeight());
if (image.getLegalMetadata() != null) {
model.setLegalMetadata( model.setLegalMetadata(
legalMetadataModelBuilder.buildAssetModel(image.getLegalMetadata()) legalMetadataModelBuilder.buildAssetModel(
image.getLegalMetadata())
); );
}
model.setWidth(image.getWidth()); model.setWidth(image.getWidth());
} }

View File

@ -23,6 +23,7 @@ import org.libreccm.api.IdentifierParser;
import org.libreccm.l10n.GlobalizationHelper; import org.libreccm.l10n.GlobalizationHelper;
import org.libreccm.security.PermissionChecker; import org.libreccm.security.PermissionChecker;
import org.libreccm.ui.BaseUrl; import org.libreccm.ui.BaseUrl;
import org.librecms.CmsConstants;
import org.librecms.assets.AssetTypesManager; import org.librecms.assets.AssetTypesManager;
import org.librecms.contentsection.Asset; import org.librecms.contentsection.Asset;
import org.librecms.contentsection.AssetManager; import org.librecms.contentsection.AssetManager;
@ -63,6 +64,8 @@ import javax.ws.rs.Path;
import javax.ws.rs.PathParam; import javax.ws.rs.PathParam;
import javax.ws.rs.core.Context; import javax.ws.rs.core.Context;
import static org.librecms.CmsConstants.MEDIA_LIST_PREFIX;
/** /**
* *
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a> * @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
@ -83,8 +86,6 @@ public class MediaStep extends AbstractMvcAuthoringStep {
*/ */
static final String PATH_FRAGMENT = "media"; static final String PATH_FRAGMENT = "media";
protected static final String MEDIA_LIST_PREFIX = ".media-";
/** /**
* {@link AssetManager} instance of managing {@link Asset}s. * {@link AssetManager} instance of managing {@link Asset}s.
*/ */
@ -186,7 +187,11 @@ public class MediaStep extends AbstractMvcAuthoringStep {
getDocument() getDocument()
.getAttachments() .getAttachments()
.stream() .stream()
.filter(list -> list.getName().startsWith(MEDIA_LIST_PREFIX)) .filter(
list -> list.getName().startsWith(
CmsConstants.MEDIA_LIST_PREFIX
)
)
.map(this::buildMediaListDto) .map(this::buildMediaListDto)
.collect(Collectors.toList()) .collect(Collectors.toList())
); );

View File

@ -18,6 +18,7 @@
*/ */
package org.librecms.ui.contentsections.documents.media; package org.librecms.ui.contentsections.documents.media;
import org.librecms.CmsConstants;
import org.librecms.contentsection.AttachmentList; import org.librecms.contentsection.AttachmentList;
import org.librecms.contentsection.AttachmentListRepository; import org.librecms.contentsection.AttachmentListRepository;
import org.librecms.contentsection.ContentItem; import org.librecms.contentsection.ContentItem;
@ -102,7 +103,10 @@ public class MediaStepService {
.getAttachments() .getAttachments()
.stream() .stream()
.filter( .filter(
list -> list.getName().startsWith(MediaStep.MEDIA_LIST_PREFIX)) list -> list.getName().startsWith(
CmsConstants.MEDIA_LIST_PREFIX
)
)
.collect(Collectors.toList()); .collect(Collectors.toList());
final List<String> attachmentListsOrder = order final List<String> attachmentListsOrder = order
.getMediaListsOrder(); .getMediaListsOrder();
@ -147,7 +151,7 @@ public class MediaStepService {
.stream() .stream()
.filter( .filter(
list -> list.getName().startsWith( list -> list.getName().startsWith(
MediaStep.MEDIA_LIST_PREFIX CmsConstants.MEDIA_LIST_PREFIX
) )
) )
.filter(list -> attachmentsOrder.getKey().equals(list.getUuid())) .filter(list -> attachmentsOrder.getKey().equals(list.getUuid()))