Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,3 +21,6 @@
/frontend/generated
/frontend/index.html
/.claude/settings.local.json
/src/main/bundles
/src/main/frontend/generated
/src/main/frontend/index.html
68 changes: 61 additions & 7 deletions pom.xml
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.flowingcode.vaadin.addons</groupId>
<artifactId>orgchart-addon</artifactId>
<version>5.3.2-SNAPSHOT</version>
<version>5.4.0-SNAPSHOT</version>
<name>OrgChart Add-on</name>

<properties>
Expand DownExpand Up@@ -167,11 +167,6 @@
<artifactId>font-awesome</artifactId>
<version>4.7.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.13.4.2</version>
</dependency>
<dependency>
<groupId>com.flowingcode.vaadin.addons.demo</groupId>
Expand DownExpand Up@@ -585,6 +580,65 @@
</dependency>
</dependencies>
</profile>


<profile>
<id>dance</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>3.3.2</version>
<configuration>
<filesets>
<fileset>
<directory>${project.basedir}</directory>
<includes>
<include>package.json</include>
<include>package-lock.json</include>
<include>tsconfig.json</include>
<include>tsconfig.json.*</include>
<include>types.d.ts</include>
<include>types.d.ts.*</include>
<include>vite.config.ts</include>
<include>vite.generated.ts</include>
<include>webpack.config.js</include>
<include>webpack.generated.js</include>
</includes>
</fileset>
<fileset>
<directory>${project.basedir}/frontend</directory>
<includes>
<include>index.html</include>
</includes>
</fileset>
<fileset>
<directory>${project.basedir}/frontend/generated</directory>
</fileset>
Comment thread
coderabbitai[bot] marked this conversation as resolved.
<fileset>
<directory>${project.basedir}/src/main/frontend</directory>
<includes>
<include>index.html</include>
</includes>
</fileset>
<fileset>
<directory>${project.basedir}/src/main/frontend/generated</directory>
</fileset>
<fileset>
<directory>${project.basedir}/node_modules</directory>
</fileset>
<fileset>
<directory>${project.basedir}/src/main/bundles</directory>
</fileset>
<fileset>
<directory>${project.basedir}/src/main/dev-bundle</directory>
</fileset>
</filesets>
</configuration>
</plugin>
</plugins>
</build>
</profile>

</profiles>
</project>
37 changes: 22 additions & 15 deletions src/main/java/com/flowingcode/vaadin/addons/orgchart/OrgChart.java
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,15 +20,14 @@
package com.flowingcode.vaadin.addons.orgchart;


import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.flowingcode.vaadin.addons.orgchart.client.OrgChartState;
import com.flowingcode.vaadin.addons.orgchart.event.ChildrenAddedEvent;
import com.flowingcode.vaadin.addons.orgchart.event.NodeUpdatedEvent;
import com.flowingcode.vaadin.addons.orgchart.event.NodesRemovedEvent;
import com.flowingcode.vaadin.addons.orgchart.event.ParentAddedEvent;
import com.flowingcode.vaadin.addons.orgchart.event.SiblingsAddedEvent;
import com.flowingcode.vaadin.jsonmigration.JsonMigration;
import com.flowingcode.vaadin.jsonmigration.JsonSerializer;
import com.vaadin.flow.component.AttachEvent;
import com.vaadin.flow.component.ClientCallable;
import com.vaadin.flow.component.ComponentEvent;
Expand All@@ -39,7 +38,9 @@
import com.vaadin.flow.component.dependency.NpmPackage;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.shared.Registration;
import elemental.json.Json;
import elemental.json.JsonArray;
import elemental.json.JsonValue;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand DownExpand Up@@ -97,23 +98,28 @@ protected void onAttach(AttachEvent attachEvent) {
public void initializeChart() {}

public void setValue(OrgChartItem orgChartItem) {
String value = convertToJsonObj(orgChartItem);
String value = convertToJsonObj(orgChartItem).toJson();
getState().value = value;
}

protected OrgChartState getState() {
return this.state;
}

private String convertToJsonObj(Object orgChartItem) {
String result = null;
ObjectMapper mapper = new ObjectMapper();
try {
result = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(orgChartItem);
} catch (JsonProcessingException e) {
e.printStackTrace();
private JsonValue convertToJsonObj(OrgChartState state) {
return JsonSerializer.toJson(state);
}

private JsonValue convertToJsonObj(OrgChartItem orgChartItem) {
return orgChartItem.toJson();
}

private JsonValue convertToJsonObj(List<OrgChartItem> items) {
JsonArray array = Json.createArray();
for (OrgChartItem item : items) {
array.set(array.length(), convertToJsonObj(item));
}
return result;
return array;
}

public void setChartNodeTitle(String chartNodeTitle) {
Expand DownExpand Up@@ -425,10 +431,11 @@ public void addSiblings(Integer nodeId, List<OrgChartItem> siblings) {
}

// Update the visual representation by calling the client-side method addSiblings
String siblingsJson = convertToJsonObj(siblings);
JsonValue siblingsJson = convertToJsonObj(siblings);
this.getElement().executeJs("this.addSiblings($0, $1)", nodeId, siblingsJson);
}


/**
* Handles sibling addition events from the client side. Converts the received JsonArray of
* sibling IDs to a List and fires a {@link SiblingsAddedEvent}.
Expand DownExpand Up@@ -502,7 +509,7 @@ public void addChildren(Integer nodeId, List<OrgChartItem> children) {
appendItemsToParent(targetNode, children);

// Update the visual representation
String itemsJson = convertToJsonObj(children);
JsonValue itemsJson = convertToJsonObj(children);
if (currentChildrenEmpty) {
this.getElement().executeJs("this.addChildren($0, $1)", nodeId, itemsJson);
} else {
Expand DownExpand Up@@ -636,7 +643,7 @@ public void addParent(OrgChartItem newParentItem) {
this.orgChartItem = newParentItem;

// Update the visual representation by calling the client-side method addParent
String parentJson = convertToJsonObj(newParentItem);
JsonValue parentJson = convertToJsonObj(newParentItem);
this.getElement().executeJs("this.addParent($0)", parentJson);
}

Expand DownExpand Up@@ -708,7 +715,7 @@ public void updateNode(Integer nodeId, OrgChartItem newDataItem) {
}

// Call the client-side JS function to update the visual representation
String newDataJson = convertToJsonObj(newDataItem);
JsonValue newDataJson = convertToJsonObj(newDataItem);
this.getElement().executeJs("this.updateNode($0, $1)", nodeId, newDataJson);
} else {
throw new IllegalArgumentException("Node not found: " + nodeId);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,6 +20,10 @@
package com.flowingcode.vaadin.addons.orgchart;


import elemental.json.Json;
import elemental.json.JsonArray;
import elemental.json.JsonObject;
import elemental.json.JsonValue;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
Expand All@@ -28,8 +32,6 @@
import java.util.Map;
import java.util.Optional;

import com.fasterxml.jackson.annotation.JsonProperty;

/** @author pbartolo */
@SuppressWarnings("serial")
public class OrgChartItem implements Serializable {
Expand DownExpand Up@@ -152,7 +154,6 @@ public boolean isHybrid() {
* @param hybrid {@code true} to mark this node as hybrid; {@code false}
* otherwise
*/
@JsonProperty("isHybrid")
public void setHybrid(boolean hybrid) {
this.hybrid = hybrid;
}
Expand DownExpand Up@@ -192,4 +193,36 @@ private void printChildren(OrgChartItem item, StringBuilder sb, int count) {
printChildren(item.getChildren().get(i), sb, count);
}
}

JsonValue toJson() {
JsonObject json = Json.createObject();
json.put("name", toJson(name));
json.put("title", toJson(title));
json.put("className", toJson(className));
json.put("id", id != null ? Json.create(id) : Json.createNull());
json.put("isHybrid", Json.create(hybrid));

JsonObject dataJson = Json.createObject();
if (data != null) {
for (Map.Entry<String, String> entry : data.entrySet()) {
dataJson.put(entry.getKey(), toJson(entry.getValue()));
}
}
json.put("data", dataJson);

JsonArray childrenJson = Json.createArray();
if (children != null) {
for (OrgChartItem child : children) {
childrenJson.set(childrenJson.length(), child.toJson());
}
}
json.put("children", childrenJson);

return json;
}

private static JsonValue toJson(String value) {
return value != null ? Json.create(value) : Json.createNull();
}

}
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,9 +23,11 @@
import com.flowingcode.vaadin.addons.orgchart.client.constants.ChartConstants;
import com.flowingcode.vaadin.addons.orgchart.client.enums.ChartDirectionEnum;
import java.io.Serializable;
import lombok.Getter;

/** @author pbartolo */
@SuppressWarnings("serial")
@Getter
public class OrgChartState implements Serializable {

public String value;
Expand Down
3 changes: 1 addition & 2 deletions src/main/resources/META-INF/frontend/fc-orgchart.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -33,9 +33,8 @@ import JSONDigger from "./json-digger.js";
*/
class FCOrgChart extends PolymerElement {

initializeOrgChart(statestring,data,identifier) {
initializeOrgChart(state,data,identifier) {
var $ = window.jQuery || jQuery;
var state = $.parseJSON(statestring);

let exportChart = state.chartExportButton;
let exportExt = state.chartExportFileExtension;
Expand Down
Loading