RelatedInfo step save sort works now, cleanup

pull/10/head
Jens Pelzetter 2021-07-31 15:05:56 +02:00
parent 7eaba5ee31
commit 0b2f844e49
14 changed files with 1043 additions and 946 deletions

View File

@ -114,11 +114,11 @@ class RelatedInfoStepController {
.sorted((list1, list2) -> list1.compareTo(list2))
.collect(Collectors.toList());
toMove.setOrder(0);
toMove.setListOrder(0);
lists
.stream()
.filter(current -> !current.equals(toMove))
.forEach(current -> current.setOrder(current.getOrder() + 1));
.forEach(current -> current.setListOrder(current.getListOrder() + 1));
lists.forEach(entityManager::merge);
}
@ -207,11 +207,11 @@ class RelatedInfoStepController {
final int afterIndex = lists.indexOf(after);
for (int i = afterIndex + 1; i < lists.size(); i++) {
final AttachmentList current = lists.get(i);
current.setOrder(current.getOrder() + 1);
current.setListOrder(current.getListOrder() + 1);
entityManager.merge(current);
}
toMove.setOrder(afterIndex + 1);
toMove.setListOrder(afterIndex + 1);
entityManager.merge(toMove);
}

View File

@ -85,7 +85,7 @@ import static org.librecms.CmsConstants.DB_SCHEMA;
query = "SELECT l FROM AttachmentList l "
+ "WHERE l.name = :name "
+ "AND l.item = :item "
+ "ORDER BY l.order")
+ "ORDER BY l.listOrder")
})
public class AttachmentList implements Comparable<AttachmentList>,
Identifiable,
@ -121,11 +121,11 @@ public class AttachmentList implements Comparable<AttachmentList>,
private String name;
/**
* A order index for ordering multiple attachment lists with the same
* {@link #name}.
* A listOrder index for ordering multiple attachment lists with the same
{@link #name}.
*/
@Column(name = "LIST_ORDER")
private long order;
private long listOrder;
/**
* The localised title of the list.
@ -201,12 +201,12 @@ public class AttachmentList implements Comparable<AttachmentList>,
this.name = name;
}
public long getOrder() {
return order;
public long getListOrder() {
return listOrder;
}
public void setOrder(final long order) {
this.order = order;
public void setListOrder(final long listOrder) {
this.listOrder = listOrder;
}
public LocalizedString getTitle() {
@ -254,7 +254,7 @@ public class AttachmentList implements Comparable<AttachmentList>,
final int nameCompare = name.compareTo(other.getName());
if (nameCompare == 0) {
return Long.compare(order, other.getOrder());
return Long.compare(listOrder, other.getListOrder());
} else {
return nameCompare;
}
@ -266,7 +266,7 @@ public class AttachmentList implements Comparable<AttachmentList>,
hash = 29 * hash + (int) (listId ^ (listId >>> 32));
hash = 29 * hash + Objects.hashCode(uuid);
hash = 29 * hash + Objects.hashCode(name);
hash = 29 * hash + (int) (order ^ (order >>> 32));
hash = 29 * hash + (int) (listOrder ^ (listOrder >>> 32));
hash = 29 * hash + Objects.hashCode(title);
hash = 29 * hash + Objects.hashCode(description);
hash = 29 * hash + Objects.hashCode(attachments);
@ -299,7 +299,7 @@ public class AttachmentList implements Comparable<AttachmentList>,
System.out.println("uuid is not equal");
return false;
}
if (order != other.getOrder()) {
if (listOrder != other.getListOrder()) {
return false;
}
if (!Objects.equals(name, other.getName())) {
@ -344,7 +344,7 @@ public class AttachmentList implements Comparable<AttachmentList>,
listId,
uuid,
name,
order,
listOrder,
Objects.toString(title),
Objects.toString(description),
Objects.toString(attachments),

View File

@ -70,7 +70,7 @@ public class AttachmentListManager {
*/
private void normalizeOrder(final List<AttachmentList> lists) {
for (int i = 0; i < lists.size(); i++) {
lists.get(i).setOrder(i);
lists.get(i).setListOrder(i);
entityManager.merge(lists.get(i));
}
}
@ -201,14 +201,14 @@ public class AttachmentListManager {
if (lists.isEmpty()) {
lastOrder = 0;
} else {
lastOrder = lists.get(lists.size() - 1).getOrder();
lastOrder = lists.get(lists.size() - 1).getListOrder();
}
final AttachmentList list = new AttachmentList();
list.setItem(draft);
list.setName(name);
list.setUuid(UUID.randomUUID().toString());
list.setOrder(lastOrder + 1);
list.setListOrder(lastOrder + 1);
draft.addAttachmentList(list);
@ -270,10 +270,10 @@ public class AttachmentListManager {
list.setItem(draft);
list.setName(name);
list.setUuid(UUID.randomUUID().toString());
list.setOrder(listPos);
list.setListOrder(listPos);
for (long i = listPos; i < lists.size(); i++) {
lists.get((int) i).setOrder(i + 1);
lists.get((int) i).setListOrder(i + 1);
entityManager.merge(lists.get((int) i));
}
@ -336,21 +336,21 @@ public class AttachmentListManager {
.getAttachments();
final Optional<AttachmentList> list1 = lists.stream()
.filter(list -> list.getOrder() == attachmentList.getOrder())
.filter(list -> list.getListOrder() == attachmentList.getListOrder())
.findFirst();
final Optional<AttachmentList> list2 = lists.stream()
.filter(list -> list.getOrder() >= attachmentList.getOrder() + 1)
.filter(list -> list.getListOrder() >= attachmentList.getListOrder() + 1)
.findFirst();
if (!list2.isPresent()) {
return;
}
final long order1 = list1.get().getOrder();
final long order2 = list2.get().getOrder();
final long order1 = list1.get().getListOrder();
final long order2 = list2.get().getListOrder();
list1.get().setOrder(order2);
list2.get().setOrder(order1);
list1.get().setListOrder(order2);
list2.get().setListOrder(order1);
entityManager.merge(list1.get());
entityManager.merge(list2.get());
@ -374,10 +374,10 @@ public class AttachmentListManager {
.getAttachments();
final Optional<AttachmentList> list1 = lists.stream()
.filter(list -> list.getOrder() == attachmentList.getOrder())
.filter(list -> list.getListOrder() == attachmentList.getListOrder())
.findFirst();
final List<AttachmentList> lower = lists.stream()
.filter(list -> list.getOrder() <= attachmentList.getOrder() - 1)
.filter(list -> list.getListOrder() <= attachmentList.getListOrder() - 1)
.collect(Collectors.toList());
Collections.sort(lower);
@ -392,11 +392,11 @@ public class AttachmentListManager {
return;
}
final long order1 = list1.get().getOrder();
final long order2 = list2.get().getOrder();
final long order1 = list1.get().getListOrder();
final long order2 = list2.get().getListOrder();
list1.get().setOrder(order2);
list2.get().setOrder(order1);
list1.get().setListOrder(order2);
list2.get().setListOrder(order1);
entityManager.merge(list1.get());
entityManager.merge(list2.get());

View File

@ -65,7 +65,6 @@ import javax.persistence.OrderBy;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
/**
* Base type for all content item types. Specifies some common properties.
*
@ -94,8 +93,7 @@ import javax.xml.bind.annotation.XmlElementWrapper;
+ " )"
+ " ) "
+ " OR true = :isSystemUser OR true = :isAdmin"
+ " )")
,
+ " )"),
@NamedQuery(
name = "ContentItem.findByUuid",
query
@ -114,8 +112,7 @@ import javax.xml.bind.annotation.XmlElementWrapper;
+ " )"
+ " ) "
+ " OR true = :isSystemUser OR true = :isAdmin"
+ " )")
,
+ " )"),
@NamedQuery(
name = "ContentItem.findByType",
query
@ -134,8 +131,7 @@ import javax.xml.bind.annotation.XmlElementWrapper;
+ " )"
+ " ) "
+ " OR true = :isSystemUser OR true = :isAdmin"
+ " )")
,
+ " )"),
@NamedQuery(
name = "ContentItem.findByIdAndType",
query
@ -155,8 +151,7 @@ import javax.xml.bind.annotation.XmlElementWrapper;
+ " )"
+ " ) "
+ " OR true = :isSystemUser OR true = :isAdmin"
+ " )")
,
+ " )"),
@NamedQuery(
name = "ContentItem.findByUuidAndType",
query
@ -176,8 +171,7 @@ import javax.xml.bind.annotation.XmlElementWrapper;
+ " )"
+ " ) "
+ " OR true = :isSystemUser OR true = :isAdmin"
+ " )")
,
+ " )"),
@NamedQuery(
name = "ContentItem.findByContentSection",
query = "SELECT DISTINCT i "
@ -197,8 +191,7 @@ import javax.xml.bind.annotation.XmlElementWrapper;
+ " )"
+ " )"
+ " OR true = :isSystemUser OR true = :isAdmin"
+ ")")
,
+ ")"),
@NamedQuery(
name = "ContentItem.findByContentSectionAndVersion",
query = "SELECT DISTINCT i "
@ -219,8 +212,7 @@ import javax.xml.bind.annotation.XmlElementWrapper;
+ " )"
+ " )"
+ " OR true = :isSystemUser OR true = :isAdmin"
+ ")")
,
+ ")"),
@NamedQuery(
name = "ContentItem.findByNameAndContentSection",
query = "SELECT DISTINCT i "
@ -241,8 +233,7 @@ import javax.xml.bind.annotation.XmlElementWrapper;
+ " )"
+ " )"
+ " OR true = :isSystemUser OR true = :isAdmin"
+ ")")
,
+ ")"),
@NamedQuery(
name = "ContentItem.findByNameAndContentSectionAndVersion",
query = "SELECT DISTINCT i "
@ -264,9 +255,7 @@ import javax.xml.bind.annotation.XmlElementWrapper;
+ " )"
+ " )"
+ " OR true = :isSystemUser OR true = :isAdmin"
+ ")")
,
+ ")"),
@NamedQuery(
name = "ContentItem.findByTypeAndContentSection",
query = "SELECT DISTINCT i "
@ -287,8 +276,7 @@ import javax.xml.bind.annotation.XmlElementWrapper;
+ " )"
+ " )"
+ " OR true = :isSystemUser OR true = :isAdmin"
+ ")")
,
+ ")"),
@NamedQuery(
name = "ContentItem.findByTypeAndContentSectionAndVersion",
query = "SELECT DISTINCT i "
@ -311,9 +299,7 @@ import javax.xml.bind.annotation.XmlElementWrapper;
+ " )"
+ " OR true = :isSystemUser OR true = :isAdmin"
+ ")"
)
,
),
@NamedQuery(
name = "ContentItem.findByNameAndTypeAndContentSection",
query = "SELECT DISTINCT i "
@ -335,8 +321,7 @@ import javax.xml.bind.annotation.XmlElementWrapper;
+ " )"
+ " )"
+ " OR true = :isSystemUser OR true = :isAdmin"
+ ")")
,
+ ")"),
@NamedQuery(
name = "ContentItem.findByNameAndTypeAndContentSectionAndVersion",
query = "SELECT DISTINCT i "
@ -359,8 +344,7 @@ import javax.xml.bind.annotation.XmlElementWrapper;
+ " )"
+ " )"
+ " OR true = :isSystemUser OR true = :isAdmin"
+ ")")
,
+ ")"),
@NamedQuery(
name = "ContentItem.findByFolder",
@ -382,8 +366,7 @@ import javax.xml.bind.annotation.XmlElementWrapper;
+ " )"
+ " )"
+ " OR true = :isSystemUser OR true = :isAdmin"
+ " )")
,
+ " )"),
@NamedQuery(
name = "ContentItem.countItemsInFolder",
query
@ -404,8 +387,7 @@ import javax.xml.bind.annotation.XmlElementWrapper;
+ " )"
+ " )"
+ " OR true = :isSystemUser OR true = :isAdmin"
+ " )")
,
+ " )"),
@NamedQuery(
name = "ContentItem.findByNameInFolder",
query
@ -428,8 +410,7 @@ import javax.xml.bind.annotation.XmlElementWrapper;
+ " )"
+ " )"
+ " OR true = :isSystemUser OR true = :isAdmin"
+ " )")
,
+ " )"),
@NamedQuery(
name = "ContentItem.countByNameInFolder",
query = "SELECT COUNT(DISTINCT i)"
@ -451,8 +432,7 @@ import javax.xml.bind.annotation.XmlElementWrapper;
+ " )"
+ " )"
+ " OR true = :isSystemUser OR true = :isAdmin"
+ " )")
,
+ " )"),
@NamedQuery(
name = "ContentItem.filterByFolderAndName",
query = "SELECT DISTINCT i "
@ -474,8 +454,7 @@ import javax.xml.bind.annotation.XmlElementWrapper;
+ " )"
+ " OR true = :isSystemUser OR true = :isAdmin"
+ " ) "
+ "ORDER BY i.displayName")
,
+ "ORDER BY i.displayName"),
@NamedQuery(
name = "ContentItem.countFilterByFolderAndName",
query = "SELECT COUNT(DISTINCT i) FROM ContentItem i "
@ -496,8 +475,7 @@ import javax.xml.bind.annotation.XmlElementWrapper;
+ " )"
+ " OR true = :isSystemUser OR true = :isAdmin"
+ " )"
)
,
),
@NamedQuery(
name = "ContentItem.filterByFolderAndType",
query = "SELECT DISTINCT i "
@ -519,8 +497,7 @@ import javax.xml.bind.annotation.XmlElementWrapper;
+ " )"
+ " OR true = :isSystemUser OR true = :isAdmin"
+ " ) "
+ "ORDER BY i.displayName")
,
+ "ORDER BY i.displayName"),
@NamedQuery(
name = "ContentItem.filterByFolderAndTypeAndName",
query = "SELECT DISTINCT i "
@ -543,15 +520,13 @@ import javax.xml.bind.annotation.XmlElementWrapper;
+ " )"
+ " OR true = :isSystemUser OR true = :isAdmin"
+ " ) "
+ "ORDER BY i.displayName")
,
+ "ORDER BY i.displayName"),
@NamedQuery(
name = "ContentItem.hasLiveVersion",
query = "SELECT (CASE WHEN COUNT(i) > 0 THEN true ELSE false END) "
+ "FROM ContentItem i "
+ "WHERE i.itemUuid = :uuid "
+ "AND i.version = org.librecms.contentsection.ContentItemVersion.LIVE")
,
+ "AND i.version = org.librecms.contentsection.ContentItemVersion.LIVE"),
@NamedQuery(
name = "ContentItem.findDraftVersion",
query
@ -563,8 +538,7 @@ import javax.xml.bind.annotation.XmlElementWrapper;
+ "AND "
+ "((p.grantee IN :roles "
+ "AND p.grantedPrivilege = '" + ItemPrivileges.PREVIEW + "' "
+ ") OR true = :isSystemUser OR true = :isAdmin)")
,
+ ") OR true = :isSystemUser OR true = :isAdmin)"),
@NamedQuery(
name = "ContentItem.findLiveVersion",
query
@ -579,8 +553,7 @@ import javax.xml.bind.annotation.XmlElementWrapper;
+ "'"
+ ItemPrivileges.VIEW_PUBLISHED
+ "' "
+ ") OR true = :isSystemUser OR true = :isAdmin)")
,
+ ") OR true = :isSystemUser OR true = :isAdmin)"),
@NamedQuery(
name = "ContentItem.findItemWithWorkflow",
query = "SELECT DISTINCT i "
@ -697,7 +670,7 @@ public class ContentItem extends CcmObject implements Serializable, Exportable {
private String ancestors;
@OneToMany(mappedBy = "item", fetch = FetchType.LAZY)
@OrderBy("order ASC")
@OrderBy("list_order ASC")
@XmlElementWrapper(name = "attachments", namespace = CMS_XML_NS)
@JsonIgnore
private List<AttachmentList> attachments;
@ -850,7 +823,6 @@ public class ContentItem extends CcmObject implements Serializable, Exportable {
}
public List<AttachmentList> getAttachments() {
Collections.sort(attachments);
return Collections.unmodifiableList(attachments);
}

View File

@ -680,7 +680,7 @@ public class ContentItemManager {
.getDescription());
targetList.setItem(target);
targetList.setName(sourceList.getName());
targetList.setOrder(sourceList.getOrder());
targetList.setListOrder(sourceList.getListOrder());
copyLocalizedString(sourceList.getTitle(), targetList.getTitle());
targetList.setUuid(UUID.randomUUID().toString());
@ -1116,7 +1116,7 @@ public class ContentItemManager {
targetList.setName(sourceList.getName());
copyLocalizedString(sourceList.getTitle(),
targetList.getTitle());
targetList.setOrder(sourceList.getOrder());
targetList.setListOrder(sourceList.getListOrder());
targetList.setUuid(UUID.randomUUID().toString());
} else {
targetList = liveItem.getAttachments().get(i);

View File

@ -164,7 +164,7 @@ public abstract class AbstractContentItemRenderer implements Serializable {
* "listId": {@link AttachmentList#getListId()}
* "uuid": {@link AttachmentList#getUuid()}
* "name": {@link AttachmentList#getName()}
* "order": {@link AttachmentList#getOrder()}
* "order": {@link AttachmentList#getListOrder()}
* "title": {@link AttachmentList#getTitle()}
* "description": {@link AttachmentList#getDescription()}
* "attachments": {@link AttachmentList#getAttachments()}
@ -189,7 +189,7 @@ public abstract class AbstractContentItemRenderer implements Serializable {
result.put("listId", attachmentList.getListId());
result.put("uuid", attachmentList.getUuid());
result.put("name", attachmentList.getName());
result.put("order", attachmentList.getOrder());
result.put("order", attachmentList.getListOrder());
result.put("title", attachmentList.getTitle().getValue(language));
result.put("description",
attachmentList.getDescription().getValue(language));

View File

@ -2141,7 +2141,7 @@ public class RelatedInfoStep extends AbstractMvcAuthoringStep {
);
dto.setListId(attachmentList.getListId());
dto.setName(attachmentList.getName());
dto.setOrder(attachmentList.getOrder());
dto.setOrder(attachmentList.getListOrder());
dto.setTitle(
globalizationHelper
.getValueFromLocalizedString(

View File

@ -55,7 +55,7 @@ public class RelatedInfoStepModel {
}
public List<AttachmentListDto> getAttachmentsLists() {
return attachmentsLists;
return Collections.unmodifiableList(attachmentsLists);
}
public void setAttachmentsLists(List<AttachmentListDto> attachmentsLists) {

View File

@ -0,0 +1 @@
/home/jensp/pwi/libreccm/git/libreccm/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contentsection/assets/edit-contactable.xhtml

View File

@ -88,7 +88,15 @@
<button class="btn btn-secondary save-order-button"
disabled="disabled"
type="button">
<span class="save-icon">
<bootstrap:svgIcon icon="save" />
</span>
<span class="save-spinner d-none">
<span aria-hidden="true"
class="spinner-border spinner-border-sm"
role="status"></span>
<span class="sr-only">#{CmsDefaultStepsMessageBundle['relatedinfo.attachmentlists.order.save.inprogress']}</span>
</span>
<span>#{CmsDefaultStepsMessageBundle['relatedinfo.attachmentlists.order.save']}</span>
</button>
</div>
@ -293,7 +301,15 @@
<button class="btn btn-secondary save-order-button"
disabled="disabled"
type="button">
<span class="save-icon">
<bootstrap:svgIcon icon="save" />
</span>
<span class="save-spinner d-none">
<span aria-hidden="true"
class="spinner-border spinner-border-sm"
role="status"></span>
<span class="sr-only">#{CmsDefaultStepsMessageBundle['relatedinfo.attachmentlists.order.save.inprogress']}</span>
</span>
<span>#{CmsDefaultStepsMessageBundle['relatedinfo.attachmentlists.order.save']}</span>
</button>
</div>

View File

@ -238,3 +238,4 @@ relatedinfo.attachments.info.dialog.title=Attachment {1} of list {0}
relatedinfo.attachments.info.dialog.close=Close
relatedinfo.attachments.info.dialog.title.label=Title
relatedinfo.attachments.info.dialog.type.label=Type
relatedinfo.attachmentlists.order.save.inprogress=Saving...

View File

@ -238,3 +238,4 @@ relatedinfo.attachments.info.dialog.title=Anhang {1} der List {0}
relatedinfo.attachments.info.dialog.close=Schlie\u00dfen
relatedinfo.attachments.info.dialog.title.label=Titel
relatedinfo.attachments.info.dialog.type.label=Typ
relatedinfo.attachmentlists.order.save.inprogress=Speichere...

View File

@ -149,6 +149,17 @@ function saveOrder() {
"data-baseUrl attribute on cms-attachment-lists container is missing or empty."
);
}
const saveOrderButtons = document.querySelectorAll(".save-order-button");
for (let i = 0; i < saveOrderButtons.length; i++) {
const saveOrderButton: HTMLButtonElement = saveOrderButtons[i] as HTMLButtonElement;
saveOrderButton.disabled = true;
const saveIcon = saveOrderButton.querySelector(".save-icon");
const spinner = saveOrderButton.querySelector(".save-spinner");
saveIcon?.classList.toggle("d-none");
spinner?.classList.toggle("d-none");
}
const headers = new Headers();
headers.append("Content-Type", "application/json");
fetch(baseUrl, {
@ -159,15 +170,30 @@ function saveOrder() {
})
.then(response => {
if (response.ok) {
const saveOrderButtons =
document.querySelectorAll("save-order-button");
// const saveOrderButtons =
// document.querySelectorAll(".save-order-button");
for (let i = 0; i < saveOrderButtons.length; i++) {
const saveOrderButton: HTMLButtonElement = saveOrderButtons[
i
] as HTMLButtonElement;
saveOrderButton.disabled = true;
// saveOrderButton.disabled = true;
const saveIcon = saveOrderButton.querySelector(".save-icon");
const spinner = saveOrderButton.querySelector(".save-spinner");
saveIcon?.classList.toggle("d-none");
spinner?.classList.toggle("d-none");
}
} else {
showSaveError();
for (let i = 0; i < saveOrderButtons.length; i++) {
const saveOrderButton: HTMLButtonElement = saveOrderButtons[
i
] as HTMLButtonElement;
saveOrderButton.disabled = false;
const saveIcon = saveOrderButton.querySelector(".save-icon");
const spinner = saveOrderButton.querySelector(".save-spinner");
saveIcon?.classList.toggle("d-none");
spinner?.classList.toggle("d-none");
}
throw Error(
`Failed to save attachments order. Response status: ${response.status}, statusText: ${response.statusText}`
);
@ -175,6 +201,16 @@ function saveOrder() {
})
.catch(error => {
showSaveError();
for (let i = 0; i < saveOrderButtons.length; i++) {
const saveOrderButton: HTMLButtonElement = saveOrderButtons[
i
] as HTMLButtonElement;
saveOrderButton.disabled = false;
const saveIcon = saveOrderButton.querySelector(".save-icon");
const spinner = saveOrderButton.querySelector(".save-spinner");
saveIcon?.classList.toggle("d-none");
spinner?.classList.toggle("d-none");
}
throw new Error(`Failed to save attachments order: ${error}`);
});
}