Implemented adding file attachments (not tested yet)

pull/10/head
Jens Pelzetter 2021-07-27 20:30:48 +02:00
parent 16bdc50f0e
commit 9a9e5dc767
4 changed files with 167 additions and 17 deletions

View File

@ -0,0 +1,88 @@
/*
* Copyright (C) 2021 LibreCCM Foundation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package org.librecms.ui.contentsections.documents.relatedinfo;
import javax.enterprise.context.RequestScoped;
import javax.inject.Named;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@RequestScoped
@Named("CmsFileDetailsModel")
public class FileDetailsModel {
private String baseUrl;
/**
* The identifier of the {@link AttachmentList} of the link.
*/
private String listIdentifier;
/**
* The UUID of the link.
*/
private String uuid;
private String name;
private String sectionName;
public String getBaseUrl() {
return baseUrl;
}
public void setBaseUrl(final String baseUrl) {
this.baseUrl = baseUrl;
}
public String getListIdentifier() {
return listIdentifier;
}
public void setListIdentifier(final String listIdentifier) {
this.listIdentifier = listIdentifier;
}
public String getUuid() {
return uuid;
}
public void setUuid(final String uuid) {
this.uuid = uuid;
}
public String getName() {
return name;
}
public void setName(final String name) {
this.name = name;
}
public String getSectionName() {
return sectionName;
}
public void setSectionName(final String sectionName) {
this.sectionName = sectionName;
}
}

View File

@ -27,6 +27,7 @@ import org.libreccm.security.PermissionChecker;
import org.libreccm.ui.BaseUrl; import org.libreccm.ui.BaseUrl;
import org.librecms.assets.AssetTypesManager; import org.librecms.assets.AssetTypesManager;
import org.librecms.assets.Bookmark; import org.librecms.assets.Bookmark;
import org.librecms.assets.FileAsset;
import org.librecms.assets.RelatedLink; import org.librecms.assets.RelatedLink;
import org.librecms.contentsection.Asset; import org.librecms.contentsection.Asset;
import org.librecms.contentsection.AssetManager; import org.librecms.contentsection.AssetManager;
@ -116,6 +117,9 @@ public class RelatedInfoStep extends AbstractMvcAuthoringStep {
@Inject @Inject
private AssetTypesManager assetTypesManager; private AssetTypesManager assetTypesManager;
@Inject
private BaseUrl baseUrl;
/** /**
* Model for the details view of an {@link AttachmentList}. * Model for the details view of an {@link AttachmentList}.
*/ */
@ -143,6 +147,9 @@ public class RelatedInfoStep extends AbstractMvcAuthoringStep {
@Context @Context
private HttpServletRequest request; private HttpServletRequest request;
@Inject
private FileDetailsModel fileDetailsModel;
/** /**
* Model for the details view of an internal {@link RelatedLink}. * Model for the details view of an internal {@link RelatedLink}.
*/ */
@ -206,6 +213,11 @@ public class RelatedInfoStep extends AbstractMvcAuthoringStep {
.map(this::buildAttachmentListDto) .map(this::buildAttachmentListDto)
.collect(Collectors.toList()) .collect(Collectors.toList())
); );
relatedInfoStepModel.setFileAssetPickerBaseUrl(
baseUrl.getBaseUrl(request)
);
relatedInfoStepModel.setSectionName(getContentSection().getLabel());
} }
@GET @GET
@ -888,7 +900,7 @@ public class RelatedInfoStep extends AbstractMvcAuthoringStep {
* @return A redirect to the list of attachment lists and attachments. * @return A redirect to the list of attachment lists and attachments.
*/ */
@POST @POST
@Path("/attachmentlists/{attachmentListIdentifier}/attachments") @Path("/attachmentlists/{attachmentListIdentifier}/attachments/@create")
@Transactional(Transactional.TxType.REQUIRED) @Transactional(Transactional.TxType.REQUIRED)
public String createAttachment( public String createAttachment(
@PathParam(MvcAuthoringSteps.SECTION_IDENTIFIER_PATH_PARAM) @PathParam(MvcAuthoringSteps.SECTION_IDENTIFIER_PATH_PARAM)
@ -1387,7 +1399,8 @@ public class RelatedInfoStep extends AbstractMvcAuthoringStep {
final Optional<Bookmark> bookmarkResult; final Optional<Bookmark> bookmarkResult;
final Identifier bookmarkIdentifer = identifierParser final Identifier bookmarkIdentifer = identifierParser
.parseIdentifier(targetBookmarkIdentifier); .parseIdentifier(targetBookmarkIdentifier
);
switch (bookmarkIdentifer.getType()) { switch (bookmarkIdentifer.getType()) {
case ID: case ID:
bookmarkResult = assetRepo bookmarkResult = assetRepo

View File

@ -18,6 +18,9 @@
*/ */
package org.librecms.ui.contentsections.documents.relatedinfo; package org.librecms.ui.contentsections.documents.relatedinfo;
import org.librecms.assets.FileAsset;
import org.librecms.contentsection.AttachmentList;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@ -35,6 +38,10 @@ public class RelatedInfoStepModel {
private List<AttachmentListDto> attachmentsLists; private List<AttachmentListDto> attachmentsLists;
private String fileAssetPickerBaseUrl;
private String sectionName;
/** /**
* Gets the {@link AttachmentList}s of the current content item and converts * Gets the {@link AttachmentList}s of the current content item and converts
* them to {@link AttachmentListDto}s to make data about the lists available * them to {@link AttachmentListDto}s to make data about the lists available
@ -46,10 +53,38 @@ public class RelatedInfoStepModel {
return Collections.unmodifiableList(attachmentsLists); return Collections.unmodifiableList(attachmentsLists);
} }
public List<AttachmentListDto> getAttachmentsLists() {
return attachmentsLists;
}
public void setAttachmentsLists(List<AttachmentListDto> attachmentsLists) {
this.attachmentsLists = attachmentsLists;
}
protected void setAttachmentLists( protected void setAttachmentLists(
final List<AttachmentListDto> attachmentLists final List<AttachmentListDto> attachmentLists
) { ) {
this.attachmentsLists = new ArrayList<>(attachmentLists); this.attachmentsLists = new ArrayList<>(attachmentLists);
} }
public String getFileAssetType() {
return FileAsset.class.getName();
}
public String getFileAssetPickerBaseUrl() {
return fileAssetPickerBaseUrl;
}
public void setFileAssetPickerBaseUrl(final String fileAssetPickerBaseUrl) {
this.fileAssetPickerBaseUrl = fileAssetPickerBaseUrl;
}
public String getSectionName() {
return sectionName;
}
public void setSectionName(final String sectionName) {
this.sectionName = sectionName;
}
} }

View File

@ -1,6 +1,7 @@
<!DOCTYPE html [<!ENTITY times '&#215;'>]> <!DOCTYPE html [<!ENTITY times '&#215;'>]>
<html xmlns="http://www.w3.org/1999/xhtml" <html xmlns="http://www.w3.org/1999/xhtml"
xmlns:bootstrap="http://xmlns.jcp.org/jsf/composite/components/bootstrap" xmlns:bootstrap="http://xmlns.jcp.org/jsf/composite/components/bootstrap"
xmlns:librecms="http://xmlns.jcp.org/jsf/composite/components/librecms"
xmlns:c="http://xmlns.jcp.org/jsp/jstl/core" xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"> xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<ui:composition template="/WEB-INF/views/org/librecms/ui/contentsection/documents/authoringstep.xhtml"> <ui:composition template="/WEB-INF/views/org/librecms/ui/contentsection/documents/authoringstep.xhtml">
@ -420,18 +421,31 @@
<bootstrap:svgIcon icon="pen" /> <bootstrap:svgIcon icon="pen" />
<span class="sr-only">#{CmsDefaultStepsMessageBundle['relatedinfo.attachmentlists.edit.button']}"</span> <span class="sr-only">#{CmsDefaultStepsMessageBundle['relatedinfo.attachmentlists.edit.button']}"</span>
</a> </a>
<button class="btn btn-primary" <librecms:assetPickerButton
assetPickerId="attach-file-picker"
buttonIcon="file-earmark-plus"
buttonText="#{CmsDefaultStepsMessageBundle['relatedinfo.attachmentlists.attachment.add.label']}"
/>
<librecms:assetPicker
actionUrl="#{mvc.basePath}/#{ContentSectionModel.sectionName}/documents/#{CmsSelectedDocumentModel.itemPath}/@relatedinfo/attachmentlists/#{list.name}/attachments/@create"
assetType="#{CmsRelatedInfoStep.fileAssetType}"
assetPickerId="attach-file-picker"
baseUrl="#{CmsRelatedInfoStep.fileAssetPickerBaseUrl}"
contentSection="#{CmsRelatedInfoStep.sectionName}"
formParamName="assetUuid"
/>
<!-- <button class="btn btn-primary"
data-target="#attachmentlist-#{list.name}-add-attachment-dialog" data-target="#attachmentlist-#{list.name}-add-attachment-dialog"
data-toggle="modal" data-toggle="modal"
type="button"> type="button">
<bootstrap:svgIcon icon="file-earmark-plus" /> <bootstrap:svgIcon icon="file-earmark-plus" />
<span class="sr-only">#{CmsDefaultStepsMessageBundle['relatedinfo.attachmentlists.attachment.add.label']}</span> <span class="sr-only">#{CmsDefaultStepsMessageBundle['relatedinfo.attachmentlists.attachment.add.label']}</span>
</button> </button>-->
<a class="btn btn-primary" <a class="btn btn-primary"
href="#{mvc.basePath}/#{ContentSectionModel.sectionName}/documents/#{CmsSelectedDocumentModel.itemPath}/@relatedinfo/attachmentlists/#{list.name}/links/@create" href="#{mvc.basePath}/#{ContentSectionModel.sectionName}/documents/#{CmsSelectedDocumentModel.itemPath}/@relatedinfo/attachmentlists/#{list.name}/links/@create"
type="button"> type="button">
<bootstrap:svgIcon icon="bookmark-plus" /> <bootstrap:svgIcon icon="bookmark-plus" />
<span>#{CmsDefaultStepsMessageBundle['relatedinfo.attachmentlists.link.add.label']}</span> <span class="sr-only">#{CmsDefaultStepsMessageBundle['relatedinfo.attachmentlists.link.add.label']}</span>
</a> </a>
<button class="btn btn-danger" <button class="btn btn-danger"
type="button"> type="button">