Skip to content

Commit

Permalink
Fixed tables
Browse files Browse the repository at this point in the history
Possibility to add custom hidden fields to existing property page content
  • Loading branch information
RHarryH committed Feb 8, 2024
1 parent 7cc82db commit c11e257
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package com.avispa.ecm.model.configuration.propertypage.content;

import com.avispa.ecm.model.configuration.propertypage.content.control.Control;
import com.avispa.ecm.model.configuration.propertypage.content.control.Hidden;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;
import lombok.Setter;
Expand All @@ -37,4 +38,23 @@ public class PropertyPageContent {
private PropertyPageContext context;
private String size = "normal";
private List<Control> controls;

/**
* Adds hidden control on the root level of control hierarchy (can't be nested in lists, tables or even columns).
* It can be called only after successful mapping of property page configuration.
*
* @param property property name
* @param value value
*/
public void addHiddenControl(String property, Object value) {
if (controls == null) {
throw new IllegalStateException("Map property page configuration to this object first");
}

Hidden hidden = new Hidden();
hidden.setProperty(property);
hidden.setValue(value);

controls.add(hidden);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
public class Table extends PropertyControl {
private List<PropertyControl> controls;

private boolean fixed;
private int size;

public Table() {
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/json-schemas/control/table.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
"readonly": {
"type": "boolean"
},
"fixed": {
"type": "boolean"
},
"property": {
"type": "string",
"pattern": "^[a-zA-Z](?:[a-zA-Z\\d.]*[a-zA-Z\\d])?+$"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Avispa ECM - a small framework for implementing basic ECM solution
* Copyright (C) 2024 Rafał Hiszpański
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package com.avispa.ecm.model.configuration.propertypage.content;

import com.avispa.ecm.model.configuration.propertypage.content.control.Hidden;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertThrows;

/**
* @author Rafał Hiszpański
*/
class PropertyPageContentTest {
@Test
void givenEmptyPropertyPageContent_whenAddHidden_thenThrowException() {
var content = new PropertyPageContent();
assertThrows(IllegalStateException.class, () -> content.addHiddenControl("test", "test"));
}

@Test
void givenCorrectPropertyPageContent_whenAddHidden_thenNewControlAppears() {
var content = new PropertyPageContent();
content.setControls(new ArrayList<>());
content.addHiddenControl("test", "test");

assertFalse(content.getControls().isEmpty());
assertInstanceOf(Hidden.class, content.getControls().get(0));
}
}

0 comments on commit c11e257

Please sign in to comment.