Skip to content

Commit

Permalink
feat: Allow to insert Navigation in a designated index by conf - MEED…
Browse files Browse the repository at this point in the history
…-7693 - Meeds-io/MIPs#165

This change will allow to insert a node navigation into a designated existing navigation. This will allow to extend an existing navigation by extension mechanism instead of redefining the whole navigation.xml file.
  • Loading branch information
boubaker committed Nov 4, 2024
1 parent d671eec commit e846bfa
Show file tree
Hide file tree
Showing 32 changed files with 1,042 additions and 727 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
import org.exoplatform.portal.mop.navigation.NodeState;
import org.exoplatform.portal.mop.page.PageKey;

import lombok.Getter;
import lombok.Setter;

/**
* @author <a href="mailto:[email protected]">Peter Palaga</a>
*
Expand Down Expand Up @@ -60,6 +63,10 @@ public class PageNode extends PageNodeContainer {
/** . */
private long updatedDate;

@Getter
@Setter
private int order = -1;

public I18NString getLabels() {
return labels;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import java.util.Map;
import java.util.Set;

import org.apache.commons.lang3.StringUtils;

import org.exoplatform.commons.utils.Safe;
import org.exoplatform.portal.mop.storage.NavigationStorage;

Expand Down Expand Up @@ -52,7 +54,22 @@ public void onCreate(NodeContext<N> target, NodeContext<N> parent, NodeContext<N
throws HierarchyException {

//
NodeData[] result = persistence.createNode(Safe.parseLong(parent.data.id), previous != null ? Safe.parseLong(previous.data.id) : null, name, target.state);
Integer index = null;
int size = parent.getSize();
if (size > 1) {
int i = 0;
while (index == null && i < size) {
if (StringUtils.equals(parent.get(i).getName(), name)) {
index = i;
}
i++;
}
}
NodeData[] result = persistence.createNode(Safe.parseLong(parent.data.id),
previous != null ? Safe.parseLong(previous.data.id) : null,
name,
target.state,
index);

//
parent.data = result[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,11 @@ void addChange(NodeChange<NodeContext<N>> change) {
} else if (change instanceof NodeChange.Created<?>) {
NodeChange.Created<NodeContext<N>> added = (NodeChange.Created<NodeContext<N>>) change;
if (added.previous != null) {
added.previous.insertAfter(added.target);
added.previous.insertAfter(added.target);
} else if (added.parent.getSize() > 0) {
added.parent.get(0).insertBefore(added.target);
} else {
added.parent.insertAt(0, added.target);
added.parent.insertFirst(added.target);
}
} else if (change instanceof NodeChange.Moved<?>) {
NodeChange.Moved<NodeContext<N>> moved = (NodeChange.Moved<NodeContext<N>>) change;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ public interface NavigationStorage {
*/
NodeData[] loadNodes(String pageRef);

NodeData[] createNode(Long parentId, Long previousId, String name, NodeState state);
default NodeData[] createNode(Long parentId, Long previousId, String name, NodeState state) {
return createNode(parentId, previousId, name, state, null);
}

NodeData destroyNode(Long targetId);

Expand All @@ -51,4 +53,6 @@ public interface NavigationStorage {

boolean destroyNavigation(SiteKey siteKey);

NodeData[] createNode(Long parentId, Long previousId, String name, NodeState state, Integer index);

}
1 change: 1 addition & 0 deletions component/api/src/main/resources/binding.xml
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@
<value name="visibility" field="visibility" usage="optional" default="DISPLAYED"/>
<value name="page-reference" field="pageReference" usage="optional"
deserializer="org.exoplatform.portal.config.serialize.JibxStringSerialize.deserializeString"/>
<value name="insertion-index" field="order" usage="optional" default="-1" />
<collection get-method="getNodes" set-method="setNodes" usage="optional"
item-type="org.exoplatform.portal.config.model.PageNode"/>
</mapping>
Expand Down
1 change: 1 addition & 0 deletions component/api/src/main/resources/gatein_objects_1_13.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
<xs:element name="end-publication-date" type="xs:string" minOccurs="0" maxOccurs="1"/>
<xs:element name="visibility" type="visibility" default="DISPLAYED" minOccurs="0" maxOccurs="1"/>
<xs:element name="page-reference" type="xs:string" minOccurs="0" maxOccurs="1"/>
<xs:element name="insertion-index" type="xs:string" minOccurs="0" maxOccurs="1"/>
<xs:element name="node" type="nodeType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
Expand Down
Loading

0 comments on commit e846bfa

Please sign in to comment.