Skip to content

Commit

Permalink
[Backport 2.23.x] GEOS-11279 allow one field multiple tabs (#7432)
Browse files Browse the repository at this point in the history
* GEOS-11279 allow one field multiple tabs

* GEOS-11279 allow one field multiple tabs (doc)

* GEOS-11279 allow one field multiple tabs (fix style)

* [GEOS-11278] metadata: only selected tab is submitted, space lenience

* [GEOS-11278] metadata: only selected tab is submitted, fix spelling errors

---------

Co-authored-by: NielsCharlier <niels@scitus.be>
  • Loading branch information
aaime and NielsCharlier authored Feb 19, 2024
1 parent 5785f5a commit 32911d2
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 8 deletions.
3 changes: 2 additions & 1 deletion doc/en/user/source/extensions/metadata/uiconfiguration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ For example:
tab
^^^
Optionally, attributes may be displayed on separate tabs. All tabs must be listed under `tabs` in the main configuration. Then this
property is used to assign each attribute to a tab, so that the custom metadata panel is divided in tabs:
property is used to assign each attribute to one or more tab (separated by comma),
so that the custom metadata panel is divided in tabs:

.. figure:: images/metadata-tabs.png

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public interface AttributeConfiguration extends Serializable {

String getLabel();

String getTab();
List<String> getTab();

void setLabel(String label);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
package org.geoserver.metadata.data.dto.impl;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import java.util.ArrayList;
import java.util.List;
import org.geoserver.metadata.data.dto.AttributeConfiguration;
Expand Down Expand Up @@ -37,7 +38,8 @@ public class AttributeConfigurationImpl implements AttributeConfiguration {

String condition;

String tab;
@JsonDeserialize(using = CommaSeparatedDeserializer.class)
List<String> tab;

public AttributeConfigurationImpl() {}

Expand Down Expand Up @@ -106,7 +108,7 @@ public String getCondition() {
}

@Override
public String getTab() {
public List<String> getTab() {
return tab;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* (c) 2023 Open Source Geospatial Foundation - all rights reserved
* This code is licensed under the GPL 2.0 license, available at the root
* application directory.
*/
package org.geoserver.metadata.data.dto.impl;

import com.fasterxml.jackson.core.JacksonException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.google.common.collect.Lists;
import java.io.IOException;
import java.util.List;

public class CommaSeparatedDeserializer extends JsonDeserializer<List<String>> {

@Override
public List<String> deserialize(JsonParser p, DeserializationContext ctxt)
throws IOException, JacksonException {
return Lists.newArrayList(p.getText().split("\\s*,\\s*"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down Expand Up @@ -93,8 +94,9 @@ private boolean shouldDisplay(AttributeConfiguration config) {
if (tab == null) {
return true;
} else {
String attConfigTab = config.getTab() == null ? "" : config.getTab();
return attConfigTab.equals(tab);
List<String> attConfigTab =
config.getTab() == null ? Collections.singletonList("") : config.getTab();
return attConfigTab.contains(tab);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void testTabs() throws IOException {
(GeoServerTablePanel<AttributeConfiguration>)
tester.getComponentFromLastRenderedPage(
"publishedinfo:tabs:panel:metadataPanel:panel:attributesPanel:attributesTablePanel");
assertEquals(4, attPanel.getDataProvider().size());
assertEquals(5, attPanel.getDataProvider().size());

logout();
}
Expand Down Expand Up @@ -108,4 +108,43 @@ public void testSave() throws IOException {
((Map<String, Object>) layer.getResource().getMetadata().get("custom"))
.get("extra-text"));
}

@Test
public void testMultiTabField() throws IOException {

login();
layer = geoServer.getCatalog().getLayerByName("mylayer");
assertNotNull(layer);
ResourceConfigurationPage page = new ResourceConfigurationPage(layer, false);
tester.startPage(page);
((TabbedPanel<?>) tester.getComponentFromLastRenderedPage("publishedinfo:tabs"))
.setSelectedTab(4);
tester.submitForm("publishedinfo");
tester.assertComponent("publishedinfo:tabs:panel:metadataPanel", TabbedPanel.class);
tester.assertComponent("publishedinfo:tabs:panel:metadataPanel:panel", MetadataPanel.class);

assertEquals(
"extra-text",
tester.getComponentFromLastRenderedPage(
"publishedinfo:tabs:panel:metadataPanel:panel:attributesPanel:attributesTablePanel:listContainer:items:7:itemProperties:0:component")
.getDefaultModelObject());

FormTester formTester = tester.newFormTester("publishedinfo");
formTester.setValue(
"tabs:panel:metadataPanel:panel:attributesPanel:attributesTablePanel:listContainer:items:7:itemProperties:1:component:textfield",
"new-value");

tester.clickLink("publishedinfo:tabs:panel:metadataPanel:tabs-container:tabs:2:link");

assertEquals(
"extra-text",
tester.getComponentFromLastRenderedPage(
"publishedinfo:tabs:panel:metadataPanel:panel:attributesPanel:attributesTablePanel:listContainer:items:5:itemProperties:0:component")
.getDefaultModelObject());
assertEquals(
"new-value",
tester.getComponentFromLastRenderedPage(
"publishedinfo:tabs:panel:metadataPanel:panel:attributesPanel:attributesTablePanel:listContainer:items:5:itemProperties:1:component:textfield")
.getDefaultModelObject());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ attributes:
tab: tab3
- key: extra-text
fieldType: TEXT
tab: tab1
tab: tab1, tab3
csvImports:
- sourcetarget.csv

Expand Down

0 comments on commit 32911d2

Please sign in to comment.