Bugfixes for MediaStep
parent
e3970246c3
commit
eb1f0b1cba
|
|
@ -36,6 +36,7 @@ import org.librecms.contentsection.FolderRepository;
|
||||||
import org.librecms.contentsection.FolderType;
|
import org.librecms.contentsection.FolderType;
|
||||||
|
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
@ -117,7 +118,7 @@ public class Assets {
|
||||||
public String findAssets(
|
public String findAssets(
|
||||||
@PathParam("content-section") final String section,
|
@PathParam("content-section") final String section,
|
||||||
@QueryParam("query") @DefaultValue("") final String query,
|
@QueryParam("query") @DefaultValue("") final String query,
|
||||||
@QueryParam("type") final String type) {
|
@QueryParam("type") final String typeParam) {
|
||||||
|
|
||||||
final ContentSection contentSection = sectionRepo
|
final ContentSection contentSection = sectionRepo
|
||||||
.findByLabel(section)
|
.findByLabel(section)
|
||||||
|
|
@ -126,23 +127,36 @@ public class Assets {
|
||||||
|
|
||||||
final List<Asset> assets;
|
final List<Asset> assets;
|
||||||
if ((query == null || query.trim().isEmpty())
|
if ((query == null || query.trim().isEmpty())
|
||||||
&& (type == null || type.trim().isEmpty())) {
|
&& (typeParam == null || typeParam.trim().isEmpty())) {
|
||||||
assets = assetRepo.findByContentSection(contentSection);
|
assets = assetRepo.findByContentSection(contentSection);
|
||||||
} else if ((query != null && !query.trim().isEmpty())
|
} else if ((query != null && !query.trim().isEmpty())
|
||||||
&& (type == null || type.trim().isEmpty())) {
|
&& (typeParam == null || typeParam.trim().isEmpty())) {
|
||||||
assets = assetRepo.findByTitleAndContentSection(query,
|
assets = assetRepo.findByTitleAndContentSection(query,
|
||||||
contentSection);
|
contentSection);
|
||||||
} else if ((query == null || query.trim().isEmpty())
|
} else if ((query == null || query.isBlank())
|
||||||
&& (type != null && !type.trim().isEmpty())) {
|
&& (typeParam != null && !typeParam.isBlank())) {
|
||||||
final Class<? extends Asset> assetType = toAssetTypeClass(type);
|
final String[] types = typeParam.split(",");
|
||||||
assets = assetRepo.findByTypeAndContentSection(assetType,
|
assets = new ArrayList<>();
|
||||||
contentSection);
|
for (final String type : types) {
|
||||||
|
final Class<? extends Asset> assetType = toAssetTypeClass(
|
||||||
|
type
|
||||||
|
);
|
||||||
|
final List<Asset> result = assetRepo
|
||||||
|
.findByTypeAndContentSection(assetType, contentSection);
|
||||||
|
assets.addAll(result);
|
||||||
|
}
|
||||||
|
assets.sort(
|
||||||
|
(asset1, asset2) -> asset1.getDisplayName().compareTo(
|
||||||
|
asset2.getDisplayName()
|
||||||
|
)
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
final Class<? extends Asset> assetType = toAssetTypeClass(type);
|
final Class<? extends Asset> assetType = toAssetTypeClass(typeParam);
|
||||||
assets = assetRepo.findByTitleAndTypeAndContentSection(
|
assets = assetRepo.findByTitleAndTypeAndContentSection(
|
||||||
query,
|
query,
|
||||||
assetType,
|
assetType,
|
||||||
contentSection);
|
contentSection
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
final JsonArrayBuilder arrayBuilder = Json.createArrayBuilder();
|
final JsonArrayBuilder arrayBuilder = Json.createArrayBuilder();
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,7 @@ public class MediaStep extends AbstractMvcAuthoringStep {
|
||||||
*/
|
*/
|
||||||
static final String PATH_FRAGMENT = "media";
|
static final String PATH_FRAGMENT = "media";
|
||||||
|
|
||||||
private static final String MEDIA_LIST_PREFIX = ".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 +186,7 @@ public class MediaStep extends AbstractMvcAuthoringStep {
|
||||||
getDocument()
|
getDocument()
|
||||||
.getAttachments()
|
.getAttachments()
|
||||||
.stream()
|
.stream()
|
||||||
.filter(list -> !list.getName().startsWith(MEDIA_LIST_PREFIX))
|
.filter(list -> list.getName().startsWith(MEDIA_LIST_PREFIX))
|
||||||
.map(this::buildMediaListDto)
|
.map(this::buildMediaListDto)
|
||||||
.collect(Collectors.toList())
|
.collect(Collectors.toList())
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ import org.librecms.ui.contentsections.documents.MvcAuthoringSteps;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import javax.enterprise.context.RequestScoped;
|
import javax.enterprise.context.RequestScoped;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
@ -97,7 +98,12 @@ public class MediaStepService {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
final List<AttachmentList> attachmentLists = document.getAttachments();
|
final List<AttachmentList> attachmentLists = document
|
||||||
|
.getAttachments()
|
||||||
|
.stream()
|
||||||
|
.filter(
|
||||||
|
list -> list.getName().startsWith(MediaStep.MEDIA_LIST_PREFIX))
|
||||||
|
.collect(Collectors.toList());
|
||||||
final List<String> attachmentListsOrder = order
|
final List<String> attachmentListsOrder = order
|
||||||
.getMediaListsOrder();
|
.getMediaListsOrder();
|
||||||
|
|
||||||
|
|
@ -139,6 +145,11 @@ public class MediaStepService {
|
||||||
final AttachmentList attachmentList = document
|
final AttachmentList attachmentList = document
|
||||||
.getAttachments()
|
.getAttachments()
|
||||||
.stream()
|
.stream()
|
||||||
|
.filter(
|
||||||
|
list -> list.getName().startsWith(
|
||||||
|
MediaStep.MEDIA_LIST_PREFIX
|
||||||
|
)
|
||||||
|
)
|
||||||
.filter(list -> attachmentsOrder.getKey().equals(list.getUuid()))
|
.filter(list -> attachmentsOrder.getKey().equals(list.getUuid()))
|
||||||
.findAny()
|
.findAny()
|
||||||
.orElseThrow(
|
.orElseThrow(
|
||||||
|
|
|
||||||
|
|
@ -18,34 +18,19 @@
|
||||||
*/
|
*/
|
||||||
package org.librecms.ui.contentsections.documents.relatedinfo;
|
package org.librecms.ui.contentsections.documents.relatedinfo;
|
||||||
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
import org.libreccm.l10n.GlobalizationHelper;
|
|
||||||
import org.libreccm.security.PermissionChecker;
|
|
||||||
import org.librecms.contentsection.AssetManager;
|
|
||||||
import org.librecms.contentsection.AssetRepository;
|
|
||||||
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;
|
||||||
import org.librecms.contentsection.ContentItemL10NManager;
|
|
||||||
import org.librecms.contentsection.ContentItemManager;
|
|
||||||
import org.librecms.contentsection.ContentItemRepository;
|
import org.librecms.contentsection.ContentItemRepository;
|
||||||
import org.librecms.contentsection.ContentSection;
|
import org.librecms.contentsection.ContentSection;
|
||||||
import org.librecms.contentsection.ContentTypeRepository;
|
|
||||||
import org.librecms.contentsection.FolderManager;
|
|
||||||
import org.librecms.contentsection.FolderRepository;
|
|
||||||
import org.librecms.contentsection.ItemAttachment;
|
import org.librecms.contentsection.ItemAttachment;
|
||||||
import org.librecms.contentsection.ItemAttachmentManager;
|
import org.librecms.contentsection.ItemAttachmentManager;
|
||||||
import org.librecms.ui.contentsections.AssetFolderTree;
|
|
||||||
import org.librecms.ui.contentsections.AssetPermissionsModel;
|
|
||||||
import org.librecms.ui.contentsections.AssetPermissionsModelProvider;
|
|
||||||
import org.librecms.ui.contentsections.ContentSectionsUi;
|
import org.librecms.ui.contentsections.ContentSectionsUi;
|
||||||
import org.librecms.ui.contentsections.DocumentFolderTree;
|
|
||||||
import org.librecms.ui.contentsections.DocumentPermissions;
|
|
||||||
import org.librecms.ui.contentsections.documents.MvcAuthoringSteps;
|
import org.librecms.ui.contentsections.documents.MvcAuthoringSteps;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import javax.enterprise.context.RequestScoped;
|
import javax.enterprise.context.RequestScoped;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
@ -115,7 +100,11 @@ public class RelatedInfoStepService {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
final List<AttachmentList> attachmentLists = document.getAttachments();
|
final List<AttachmentList> attachmentLists = document
|
||||||
|
.getAttachments()
|
||||||
|
.stream()
|
||||||
|
.filter(list -> !list.getName().startsWith("."))
|
||||||
|
.collect(Collectors.toList());
|
||||||
final List<String> attachmentListsOrder = order
|
final List<String> attachmentListsOrder = order
|
||||||
.getAttachmentListsOrder();
|
.getAttachmentListsOrder();
|
||||||
|
|
||||||
|
|
@ -157,6 +146,7 @@ public class RelatedInfoStepService {
|
||||||
final AttachmentList attachmentList = document
|
final AttachmentList attachmentList = document
|
||||||
.getAttachments()
|
.getAttachments()
|
||||||
.stream()
|
.stream()
|
||||||
|
.filter(list -> !list.getName().startsWith("."))
|
||||||
.filter(list -> attachmentsOrder.getKey().equals(list.getUuid()))
|
.filter(list -> attachmentsOrder.getKey().equals(list.getUuid()))
|
||||||
.findAny()
|
.findAny()
|
||||||
.orElseThrow(
|
.orElseThrow(
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ let mediaSortables: {
|
||||||
} = {};
|
} = {};
|
||||||
|
|
||||||
document.addEventListener("DOMContentLoaded", function (event) {
|
document.addEventListener("DOMContentLoaded", function (event) {
|
||||||
const mediaLists = document.querySelector(".cms.media-lists");
|
const mediaLists = document.querySelector(".cms-media-lists");
|
||||||
|
|
||||||
if (mediaLists) {
|
if (mediaLists) {
|
||||||
mediaListSortable = initMediaLists(mediaLists as HTMLElement);
|
mediaListSortable = initMediaLists(mediaLists as HTMLElement);
|
||||||
|
|
@ -71,6 +71,7 @@ function initMedias(medias: HTMLElement): Sortable {
|
||||||
}
|
}
|
||||||
|
|
||||||
function enableSaveButton(event: SortableEvent) {
|
function enableSaveButton(event: SortableEvent) {
|
||||||
|
console.log("Enabling save buttons...");
|
||||||
const saveOrderButtons = document.querySelectorAll(
|
const saveOrderButtons = document.querySelectorAll(
|
||||||
".media-save-order-button"
|
".media-save-order-button"
|
||||||
);
|
);
|
||||||
|
|
@ -120,18 +121,24 @@ function moveMedia(event: SortableEvent) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveOrder() {
|
function saveOrder() {
|
||||||
|
console.log("Creating mediaOrder object...");
|
||||||
|
console.dir(mediaListSortable);
|
||||||
|
console.dir(movedMedia);
|
||||||
|
console.dir(mediaSortables);
|
||||||
const mediaOrder: MediaStepMediaOrder = {
|
const mediaOrder: MediaStepMediaOrder = {
|
||||||
mediaListsOrder: mediaListSortable.toArray(),
|
mediaListsOrder: mediaListSortable.toArray(),
|
||||||
mediaOrder: {},
|
mediaOrder: {},
|
||||||
movedMedia
|
movedMedia
|
||||||
};
|
};
|
||||||
|
|
||||||
|
console.dir(mediaOrder.mediaOrder);
|
||||||
|
|
||||||
for (let key in mediaSortables) {
|
for (let key in mediaSortables) {
|
||||||
mediaOrder.mediaOrder[key] =
|
mediaOrder.mediaOrder[key] =
|
||||||
mediaSortables[key].toArray();
|
mediaSortables[key].toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
// console.dir(mediaOrder);
|
console.dir(mediaOrder);
|
||||||
const cmsMedia = document.querySelector(".cms-media-lists");
|
const cmsMedia = document.querySelector(".cms-media-lists");
|
||||||
if (!cmsMedia) {
|
if (!cmsMedia) {
|
||||||
showGeneralError();
|
showGeneralError();
|
||||||
|
|
@ -145,6 +152,7 @@ function saveOrder() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log("spinner on");
|
||||||
const saveOrderButtons = document.querySelectorAll(".media-save-order-button");
|
const saveOrderButtons = document.querySelectorAll(".media-save-order-button");
|
||||||
for (let i = 0; i < saveOrderButtons.length; i++) {
|
for (let i = 0; i < saveOrderButtons.length; i++) {
|
||||||
const saveOrderButton: HTMLButtonElement = saveOrderButtons[
|
const saveOrderButton: HTMLButtonElement = saveOrderButtons[
|
||||||
|
|
@ -157,6 +165,7 @@ function saveOrder() {
|
||||||
spinner?.classList.toggle("d-none");
|
spinner?.classList.toggle("d-none");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log("fetch POST");
|
||||||
const headers = new Headers();
|
const headers = new Headers();
|
||||||
headers.append("Content-Type", "application/json");
|
headers.append("Content-Type", "application/json");
|
||||||
fetch(baseUrl, {
|
fetch(baseUrl, {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue