Skip to content

Commit 8b34cc9

Browse files
paodbjavier-godoy
authored andcommitted
feat(demo): add new demo using node template and image in title
1 parent a8f9ee6 commit 8b34cc9

File tree

5 files changed

+111
-0
lines changed

5 files changed

+111
-0
lines changed
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*-
2+
* #%L
3+
* OrgChart Add-on
4+
* %%
5+
* Copyright (C) 2017 - 2020 Flowing Code S.A.
6+
* %%
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* #L%
19+
*/
20+
package com.flowingcode.vaadin.addons.orgchart;
21+
22+
import java.util.Arrays;
23+
24+
import com.flowingcode.vaadin.addons.orgchart.extra.TemplateLiteralRewriter;
25+
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
26+
27+
@SuppressWarnings("serial")
28+
public class ImageInTitleDemo extends VerticalLayout {
29+
30+
public ImageInTitleDemo() {
31+
OrgChart component = getOrgChartData();
32+
String nodeTemplate =
33+
"<div class='title'>"
34+
+ "${item.data.imageUrl?`<img src=${item.data.imageUrl}></img>`:''}"
35+
+ "${item.title}</div>"
36+
+ "<div class='middle content'>${item.name}</div>"
37+
+ "${item.data.mail?`<div class='custom content'>${item.data.mail}</div>`:''}";
38+
component.setNodeTemplate("item", TemplateLiteralRewriter.rewriteFunction(nodeTemplate));
39+
component.addClassNames("chart-container", "image-title-demo");
40+
41+
component.setChartTitle(
42+
"My Organization Chart Demo - Example 3 - CUSTOM TEMPLATE WITH IMAGE IN TITLE");
43+
component.setChartNodeContent("title");
44+
component.setChartExportButton(true);
45+
component.setChartExpandCollapse(true);
46+
47+
setSizeFull();
48+
add(component);
49+
}
50+
51+
private OrgChart getOrgChartData() {
52+
OrgChartItem item1 = new OrgChartItem(1, "John Williams", "Director");
53+
item1.setData("mail", "[email protected]");
54+
item1.setData("imageUrl", "images/users.png");
55+
56+
OrgChartItem item2 = new OrgChartItem(2, "Anna Thompson", "Administration");
57+
item2.setData("mail", "[email protected]");
58+
item2.setData("imageUrl", "images/users.png");
59+
60+
OrgChartItem item3 =
61+
new OrgChartItem(
62+
3, "Timothy Albert Henry Jones ", "Sub-Director of Administration Department");
63+
item3.setData("mail", "[email protected]");
64+
item3.setData("imageUrl", "images/user.png");
65+
66+
item1.setChildren(Arrays.asList(item2, item3));
67+
68+
OrgChartItem item4 = new OrgChartItem(4, "Louise Night", "Department 1");
69+
item4.setData("mail", "[email protected]");
70+
item4.setData("imageUrl", "images/user.png");
71+
72+
OrgChartItem item5 = new OrgChartItem(5, "John Porter", "Department 2");
73+
item5.setData("mail", "[email protected]");
74+
item5.setData("imageUrl", "images/user.png");
75+
76+
OrgChartItem item6 = new OrgChartItem(6, "Charles Thomas", "Department 3");
77+
item6.setData("mail", "[email protected]");
78+
item6.setData("imageUrl", "images/users.png");
79+
80+
item2.setChildren(Arrays.asList(item4, item5, item6));
81+
82+
OrgChartItem item7 = new OrgChartItem(7, "Michael Wood", "Section 3.1");
83+
item7.setData("imageUrl", "images/user.png");
84+
85+
OrgChartItem item8 = new OrgChartItem(8, "Martha Brown", "Section 3.2");
86+
item8.setData("imageUrl", "images/user.png");
87+
88+
OrgChartItem item9 = new OrgChartItem(9, "Mary Parker", "Section 3.3");
89+
item9.setData("imageUrl", "images/user.png");
90+
OrgChartItem item10 = new OrgChartItem(10, "Mary Williamson", "Section 3.4");
91+
item10.setData("imageUrl", "images/user.png");
92+
93+
item6.setChildren(Arrays.asList(item7, item8, item9, item10));
94+
95+
return new OrgChart(item1);
96+
}
97+
}

src/test/java/com/flowingcode/vaadin/addons/orgchart/OrgchartDemoView.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,13 @@ public class OrgchartDemoView extends TabbedDemo {
3838
"https://github.com/FlowingCode/OrgChartAddon/blob/master/src/test/java/com/flowingcode/vaadin/addons/orgchart/DragAndDropExportDemo.java";
3939
private static final String BOTTOMTOP_SOURCE =
4040
"https://github.com/FlowingCode/OrgChartAddon/blob/master/src/test/java/com/flowingcode/vaadin/addons/orgchart/BottomTopDemo.java";
41+
private static final String IMAGETITILE_DEMO = "Image in Title";
42+
private static final String IMAGETITILE_SOURCE =
43+
"https://github.com/FlowingCode/OrgChartAddon/blob/master/src/test/java/com/flowingcode/vaadin/addons/orgchart/ImageInTitleDemo.java";
4144

4245
public OrgchartDemoView() {
4346
addDemo(new DragAndDropExportDemo(), DRAGNDROP_DEMO, DRAGNDROP_SOURCE);
4447
addDemo(new BottomTopDemo(), BOTTOMTOP_DEMO, BOTTOMTOP_SOURCE);
48+
addDemo(new ImageInTitleDemo(), IMAGETITILE_DEMO, IMAGETITILE_SOURCE);
4549
}
4650
}

src/test/resources/META-INF/resources/frontend/styles/orgchart/demo-styles.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,13 @@ vaadin-checkbox.smallcheckbox {
5858
fc-orgchart p {
5959
max-width:70%;
6060
}
61+
62+
.image-title-demo .orgchart .title .symbol {
63+
display:none
64+
}
65+
66+
.image-title-demo img {
67+
float: left;
68+
margin-top: 4px;
69+
margin-left: 2px;
70+
}
496 Bytes
Loading
534 Bytes
Loading

0 commit comments

Comments
 (0)