Skip to content

Commit

Permalink
#494: Fix duplicate parent CET group fields.
Browse files Browse the repository at this point in the history
  • Loading branch information
mtnhan committed Nov 30, 2022
1 parent f68afc6 commit 191d51c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -411,44 +411,25 @@ public void addParentCFTs(CustomEntityTemplate parentCET) {
final String cetCode = CustomFieldTemplate.retrieveCetCode(field.getEntityClazz());
field.setPrimitiveType(customEntityTemplateService.getPrimitiveType(cetCode));
}

//Cannot edit parent CFTs
field.setDisplayOnly(true);
}

GroupedCustomField groupedCFTAndActions = new GroupedCustomField(fields.values(), "Parent", true);
GroupedCustomField groupedCFTAndActions = new GroupedCustomField(fields.values(), "ParentCET", false);

// Append actions into the hierarchy of tabs and fieldgroups
Map<String, EntityCustomAction> customActions = entityActionScriptService.findByAppliesTo(parentCetPrefix);
groupedCFTAndActions.append(customActions.values());

// Create tabs
for (GroupedCustomField level1 : groupedCFTAndActions.getChildren()) {
SortedTreeNode level1Node = new SortedTreeNode(level1.getType(), level1.getData(), groupedFields, level1.getType() == GroupedCustomFieldTreeItemType.tab);
SortedTreeNode level1Node = new SortedTreeNode(level1.getType(), level1.getData(), groupedFields, level1.getType() == GroupedCustomFieldTreeItemType.tab, true);

// Create fields of field groups
for (GroupedCustomField level2 : level1.getChildren()) {
SortedTreeNode level2Node = new SortedTreeNode(level2.getType(), level2.getData(), level1Node, level2.getType() == GroupedCustomFieldTreeItemType.fieldGroup);
SortedTreeNode level2Node = new SortedTreeNode(level2.getType(), level2.getData(), level1Node, level2.getType() == GroupedCustomFieldTreeItemType.fieldGroup, true);

// Create fields
for (GroupedCustomField level3 : level2.getChildren()) {
new SortedTreeNode(level3.getType(), level3.getData(), level2Node, null);
}
}
}

if (cachedTreeNodes != null && !cachedTreeNodes.isEmpty()) {
for (TreeNode tabNode : cachedTreeNodes) {// tab
TreeNode existedTab = getChildNodeByValue(groupedFields, tabNode.getData().toString());
if (existedTab == null) {// check tab
existedTab = new SortedTreeNode(GroupedCustomFieldTreeItemType.tab, tabNode.getData(), groupedFields, true);

}
for (TreeNode fieldGroupNode : tabNode.getChildren()) {// field groups of tab
TreeNode existedFieldGroup = getChildNodeByValue(existedTab, fieldGroupNode.getData().toString());
if (existedFieldGroup == null) {
existedFieldGroup = new SortedTreeNode(GroupedCustomFieldTreeItemType.fieldGroup, fieldGroupNode.getData(), existedTab, null);
}
new SortedTreeNode(level3.getType(), level3.getData(), level2Node, null, true);
}
}
}
Expand Down Expand Up @@ -504,6 +485,8 @@ public TreeNode getFields() {
}
}

this.addParentCFTs(entityTemplate.getSuperTemplate());

if (cachedTreeNodes != null && !cachedTreeNodes.isEmpty()) {
for (TreeNode tabNode : cachedTreeNodes) {// tab
TreeNode existedTab = getChildNodeByValue(groupedFields, tabNode.getData().toString());
Expand All @@ -520,8 +503,6 @@ public TreeNode getFields() {
}
}

this.addParentCFTs(entityTemplate.getSuperTemplate());

return groupedFields;
}

Expand Down Expand Up @@ -1187,6 +1168,7 @@ public void setIsUpdate(Boolean isUpdate) {
public class SortedTreeNode extends DefaultTreeNode {

private static final long serialVersionUID = 3694377290046737073L;
private boolean isDisplayOnly = false;

/**
* Instantiates a new sorted tree node.
Expand All @@ -1203,11 +1185,17 @@ public SortedTreeNode() {
* @param parent the parent
* @param expanded the expanded
*/
public SortedTreeNode(GroupedCustomFieldTreeItemType type, Object data, TreeNode parent, Boolean expanded) {
public SortedTreeNode(GroupedCustomFieldTreeItemType type, Object data, TreeNode parent, Boolean expanded, boolean isDisplayOnly) {
super(type.name(), data, parent);
if (expanded != null && expanded) {
this.setExpanded(true);
}

this.isDisplayOnly = isDisplayOnly;
}

public SortedTreeNode(GroupedCustomFieldTreeItemType type, Object data, TreeNode parent, Boolean expanded) {
this(type, data, parent, expanded, false);
}

/**
Expand Down Expand Up @@ -1256,8 +1244,8 @@ public String getGuiPositionForAction() {
return null;
}

public boolean isReadonly() {
return false;
public boolean isDisplayOnly() {
return this.isDisplayOnly;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
rendered="#{(node.type == 'field' or node.type == 'action') and entity.active != null and entity.active.toString() == 'false'}" />
</p:column>
<p:column headerText="#{messages['commons.actions']}" width="12%">
<h:panelGroup rendered="#{node.type == 'tab'}">
<h:panelGroup rendered="#{node.type == 'tab' and not node.isDisplayOnly()}">
<p:tooltip for="editTabBtn" value="#{messages['commons.edit']}"
showEffect="slide" hideEffect="slide" />
<p:commandButton id="editTabBtn" icon="ui-icon-document"
Expand Down Expand Up @@ -183,7 +183,7 @@
update=":fieldsForm:fields" rendered="#{node.canMoveDown()}" />
</h:panelGroup>

<h:panelGroup rendered="#{node.type == 'fieldGroup'}">
<h:panelGroup rendered="#{node.type == 'fieldGroup' and not node.isDisplayOnly()}">
<p:tooltip for="editFieldGroupBtn"
value="#{messages['commons.edit']}" showEffect="slide"
hideEffect="slide" />
Expand Down Expand Up @@ -239,24 +239,23 @@
update=":fieldsForm:fields" rendered="#{node.canMoveDown()}" />
</h:panelGroup>

<h:panelGroup rendered="#{node.type == 'field'}">
<h:panelGroup rendered="#{node.type == 'field' and not node.isDisplayOnly()}">

<p:tooltip for="editFieldBtn" value="#{messages['commons.edit']}"
showEffect="slide" hideEffect="slide" />
<p:commandButton immediate="true" id="editFieldBtn"
icon="ui-icon-document"
oncomplete="PF('cftDialog').show(); return false;"
action="#{customFieldTemplateBean.initEntity(entity.id)}"
update=":cftDialog :cftForm"
rendered="#{not entity.isDisplayOnly()}">
update=":cftDialog :cftForm">
<f:setPropertyActionListener
target="#{customFieldTemplateBean.backViewSave}"
value="customizedEntity" />
</p:commandButton>


<p:commandButton id="enablelink" icon="ui-icon-circle-check"
rendered="#{entity.disabled and not entity.isDisplayOnly()}"
rendered="#{entity.disabled}"
actionListener="#{customEntityTemplateBean.refreshFields}"
action="#{customFieldTemplateBean.enable()}" update="@form">
<f:setPropertyActionListener
Expand All @@ -265,7 +264,7 @@
message="#{messages['commons.confirmEnable']}" />
</p:commandButton>
<p:commandButton id="disablelink" icon="ui-icon-circle-close"
rendered="#{not entity.disabled and not entity.isDisplayOnly()}"
rendered="#{not entity.disabled}"
actionListener="#{customEntityTemplateBean.refreshFields}"
action="#{customFieldTemplateBean.disable()}" update="@form">
<f:setPropertyActionListener
Expand All @@ -282,8 +281,7 @@
hideEffect="slide" />

<p:commandButton id="copylink" icon="ui-icon-copy"
update=":copyCFTForm" oncomplete="PF('copyCFTDialog').show()"
rendered="#{not entity.isDisplayOnly()}">
update=":copyCFTForm" oncomplete="PF('copyCFTDialog').show()">
<f:setPropertyActionListener
target="#{customFieldTemplateBean.entity}" value="#{entity}" />
</p:commandButton>
Expand All @@ -300,8 +298,7 @@
<p:tooltip for="deletelink" value="#{messages['commons.delete']}"
showEffect="slide" hideEffect="slide" />
<p:commandButton id="deletelink" icon="ui-icon-trash"
oncomplete="fieldsDoDelete()"
rendered="#{not entity.isDisplayOnly()}">
oncomplete="fieldsDoDelete()">
<f:setPropertyActionListener
target="#{customFieldTemplateBean.entity}" value="#{entity}" />
<p:confirm header="#{messages['commons.confirmationHeader']}"
Expand All @@ -314,19 +311,21 @@
showEffect="slide" hideEffect="slide" />
<p:commandButton id="moveUpFBtn" icon="ui-icon-arrowthick-1-n"
action="#{customEntityTemplateBean.moveUp(node)}"
update=":fieldsForm:fields" rendered="#{node.canMoveUp() and not entity.isDisplayOnly()}" />
update=":fieldsForm:fields"
rendered="#{node.canMoveUp()}" />

<p:tooltip for="moveDownFBtn"
value="#{messages['action.moveDown']}" showEffect="slide"
hideEffect="slide" />
<p:commandButton id="moveDownFBtn" icon="ui-icon-arrowthick-1-s"
action="#{customEntityTemplateBean.moveDown(node)}"
update=":fieldsForm:fields" rendered="#{node.canMoveDown() and not entity.isDisplayOnly()}" />
update=":fieldsForm:fields"
rendered="#{node.canMoveDown()}" />

</h:panelGroup>


<h:panelGroup rendered="#{node.type == 'action'}">
<h:panelGroup rendered="#{node.type == 'action' and not node.isDisplayOnly()}">

<p:tooltip for="editActionBtn" value="#{messages['commons.edit']}"
showEffect="slide" hideEffect="slide" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1849,15 +1849,4 @@ public boolean isPersisted() {
public void setPersisted(boolean persisted) {
this.persisted = persisted;
}

@Transient
private boolean isDisplayOnly;

public void setDisplayOnly(boolean isDisplayOnly) {
this.isDisplayOnly = isDisplayOnly;
}

public boolean isDisplayOnly() {
return this.isDisplayOnly;
}
}

0 comments on commit 191d51c

Please sign in to comment.