Skip to content

Commit

Permalink
- Added showDetailsPaginator to attribute model
Browse files Browse the repository at this point in the history
- Added formMode to model action
  • Loading branch information
Bas Rutten committed Oct 18, 2024
1 parent cbfc75f commit 391abc2
Show file tree
Hide file tree
Showing 17 changed files with 83 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down Expand Up @@ -43,10 +43,6 @@ public interface DefaultProperties {

String getTrueRepresentation();

GroupTogetherMode getGroupTogetherMode();

Integer getGroupTogetherWidth();

java.util.Locale getLocale();

Integer getNestingDepth();
Expand All @@ -63,6 +59,8 @@ public interface DefaultProperties {

boolean isTrimSpaces();

boolean isShowDetailsPaginator();

String getAiService();

EndpointProperties getEndpoints();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* #%L
* Dynamo Framework
* %%
* Copyright (C) 2014 - 2024 Open Circle Solutions
* Copyright (C) 2014 - 2024 Open Circle Solutions BV
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,7 +20,9 @@
* #L%
*/

public enum GroupTogetherMode {

PERCENTAGE, PIXEL
/**
* Used to indicate whether a model action is visible in view mode, edit mode, or both
*/
public enum ActionFormMode {
VIEW, EDIT, BOTH;
}
Original file line number Diff line number Diff line change
Expand Up @@ -549,4 +549,10 @@ public interface AttributeModel extends Comparable<AttributeModel> {
*/
QueryType getLookupQueryType();

/**
*
* @return whether to show paginator for details table
*/
boolean isShowDetailsPaginator();

}
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,11 @@ public interface EntityModel<T> {
*/
String SEARCH_ALLOWED = "searchAllowed";

/**
* Whether to display details paginator
*/
String SHOW_DETAILS_PAGINATOR = "showDetailsPaginator";

/**
* Indicates that quick add functionality is enabled
*/
Expand Down Expand Up @@ -482,6 +487,8 @@ public interface EntityModel<T> {

String ICON = "icon";

String FORM_MODE = "formMode";

/**
* Adds an attribute group
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,10 @@ public interface EntityModelAction {
* @return the roles that are allowed to carry out the action
*/
List<String> getRoles();

/**
* @return the action form mode (specifies whether action will
* appear in view mode, edit mode, or both)
*/
ActionFormMode getFormMode();
}
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,12 @@
*/
boolean sortable() default true;

/**
*
* @return whether to show the paginator component in a details table
*/
VisibilityType showDetailsPaginator() default VisibilityType.INHERIT;

/**
* @return whether to display a text attribute as a text field or a text area
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* #L%
*/

import org.dynamoframework.domain.model.ActionFormMode;
import org.dynamoframework.domain.model.EntityModelActionType;

import java.lang.annotation.ElementType;
Expand All @@ -44,4 +45,6 @@
String icon() default "pi-pencil";

String[] roles() default {};

ActionFormMode formMode() default ActionFormMode.VIEW;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down Expand Up @@ -111,16 +111,6 @@ public static class DefaultConfigurationProperties implements Serializable, Defa
*/
private String trueRepresentation = "true";

/**
* The default group together mode
*/
private GroupTogetherMode groupTogetherMode;

/**
* The column width from grouping together
*/
private Integer groupTogetherWidth = 300;

/**
* The default locale
*/
Expand Down Expand Up @@ -166,6 +156,11 @@ public static class DefaultConfigurationProperties implements Serializable, Defa
*/
private String aiService;

/**
* Whether to show a details table paginator
*/
private boolean showDetailsPaginator = true;

/**
* The configuration of the Dynamo endpoints
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ public class AttributeModelImpl implements AttributeModel {

private AttributeSelectMode selectMode;

private boolean showDetailsPaginator;

private boolean showPassword;

private boolean sortable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.dynamoframework.domain.model.AttributeModel;
import org.dynamoframework.domain.model.EntityModel;
import org.dynamoframework.domain.model.EntityModelAction;
import org.dynamoframework.domain.model.EntityModelActionType;
import org.dynamoframework.domain.model.*;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
Expand Down Expand Up @@ -58,6 +55,8 @@ public class EntityModelActionImpl implements EntityModelAction {

private Map<String, Optional<String>> displayNames = new ConcurrentHashMap<>();

private ActionFormMode formMode= ActionFormMode.VIEW;

@Override
public String getDisplayName(Locale locale) {
return lookup(displayNames, locale, EntityModel.DISPLAY_NAME, defaultDisplayName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ protected <T> List<AttributeModel> constructAttributeModel(PropertyDescriptor de
model.setBooleanFieldMode(dynamoProperties.getDefaults().getBooleanFieldMode());
model.setElementCollectionMode(dynamoProperties.getDefaults().getElementCollectionMode());
model.setEnumFieldMode(dynamoProperties.getDefaults().getEnumFieldMode());
model.setShowDetailsPaginator(dynamoProperties.getDefaults().isShowDetailsPaginator());

Email email = ClassUtils.getAnnotation(entityModel.getEntityClass(), fieldName,
Email.class);
Expand Down Expand Up @@ -599,6 +600,7 @@ private void addEntityModelAction(Method method, List<EntityModelAction> modelAc
actionImpl.setType(action.type());
actionImpl.setIcon(action.icon());
actionImpl.setRoles(Arrays.asList(action.roles()));
actionImpl.setFormMode(action.formMode());

EntityModel<?> actionModel = constructModel(action.id(), actionClass);
actionImpl.setEntityModel(actionModel);
Expand All @@ -614,6 +616,8 @@ private void processEntityModelActionMessageBundleOverrides(EntityModelActionImp
action::setRoles);
setStringSetting(getEntityMessage(action.getReference(), EntityModel.ICON),
action::setIcon);
setEnumSetting(getEntityMessage(action.getReference(), EntityModel.FORM_MODE),
ActionFormMode.class, action::setFormMode);
}

/**
Expand Down Expand Up @@ -1113,6 +1117,11 @@ private void setAnnotationVisibilityOverrides(Attribute attribute, AttributeMode
if (attribute.visibleInGrid() != null && !VisibilityType.INHERIT.equals(attribute.visibleInGrid()) && !nested) {
model.setVisibleInGrid(VisibilityType.SHOW.equals(attribute.visibleInGrid()));
}

// set paginator visibility
if (attribute.showDetailsPaginator() != null && !VisibilityType.INHERIT.equals(attribute.showDetailsPaginator())) {
model.setShowDetailsPaginator(VisibilityType.SHOW.equals(attribute.showDetailsPaginator()));
}
}

/**
Expand Down Expand Up @@ -1387,6 +1396,10 @@ private <T> void setAttributeModelMessageBundleOverrides(EntityModel<T> entityMo
if (!StringUtils.isEmpty(msg)) {
attributeModel.setVisibleInGrid(isVisible(msg));
}
msg = getAttributeMessage(entityModel, attributeModel, EntityModel.SHOW_DETAILS_PAGINATOR);
if (!StringUtils.isEmpty(msg)) {
attributeModel.setShowDetailsPaginator(isVisible(msg));
}

// "searchable" also supports true/false for legacy reasons
msg = getAttributeMessage(entityModel, attributeModel, EntityModel.SEARCHABLE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
public class EntityModelFactoryImplTest extends BaseMockitoTest {

@Autowired
private EntityModelFactoryImpl factory;// = new EntityModelFactoryImpl();
private EntityModelFactoryImpl factory;

private final ResourceBundleMessageSource source = new ResourceBundleMessageSource();

Expand Down Expand Up @@ -186,6 +186,8 @@ public void testDefaults() {
assertTrue(model.getWriteRoles().contains("role2"));
assertEquals(1, model.getDeleteRoles().size());
assertTrue(model.getDeleteRoles().contains("role3"));


}

@Test
Expand Down Expand Up @@ -339,6 +341,7 @@ public void testEntityModelActions() {
assertEquals("ChangedName", partialAction.getEntityModel()
.getAttributeModel("name").getDisplayName(locale));
assertTrue(partialAction.getRoles().contains("role12"));
assertEquals(partialAction.getFormMode(), ActionFormMode.BOTH);

// icon overridden in message bundle
assertEquals("iconOverride", partialAction.getIcon());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.dynamoframework.dao.BaseDao;
import org.dynamoframework.dao.impl.TestEntityDao;
import org.dynamoframework.domain.TestEntity;
import org.dynamoframework.domain.model.ActionFormMode;
import org.dynamoframework.domain.model.annotation.ModelAction;
import org.dynamoframework.service.TestEntityDTO;
import org.dynamoframework.service.TestEntityService;
Expand All @@ -45,7 +46,8 @@ protected BaseDao<Integer, TestEntity> getDao() {
}

@Override
@ModelAction(displayName = "Partial Action", id = "PartialAction", roles = {"role12"})
@ModelAction(displayName = "Partial Action", id = "PartialAction", roles = {"role12"},
formMode = ActionFormMode.BOTH)
public TestEntity partialAction(TestEntityDTO dto) {
// do nothing
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,4 +366,9 @@ public class AttributeModelResponse {
*/
private QueryTypeExternal lookupQueryType;

/**
* Whether to display a paginator in details mode
*/
private boolean showDetailsPaginator;

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import lombok.Getter;
import lombok.Setter;
import lombok.extern.jackson.Jacksonized;
import org.dynamoframework.domain.model.ActionFormMode;
import org.dynamoframework.domain.model.EntityModelActionType;

import java.util.List;
Expand All @@ -51,4 +52,7 @@ public class EntityModelActionResponse {
private String icon;

private List<String> roles;

@NotNull
private ActionFormMode formMode;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down Expand Up @@ -70,6 +70,7 @@ public AttributeModelResponse mapAttributeModel(AttributeModel model, Set<Locale
builder.cascades(mapCascades(model));
builder.ignoreInSearchFilter(model.isIgnoreInSearchFilter());
builder.groupTogetherWith(model.getGroupTogetherWith());
builder.showDetailsPaginator(model.isShowDetailsPaginator());

if (type == AttributeModelType.STRING) {
builder.email(model.isEmail());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ private EntityModelActionResponse mapAction(EntityModelAction action, Set<Locale
.type(action.getType())
.icon(action.getIcon())
.roles(new ArrayList<>(action.getRoles()))
.formMode(action.getFormMode())
.build();
}
}

0 comments on commit 391abc2

Please sign in to comment.