Skip to content

Commit db74c79

Browse files
javier-godoypaodb
authored andcommitted
feat: initial implementation
1 parent f582e91 commit db74c79

File tree

19 files changed

+767
-194
lines changed

19 files changed

+767
-194
lines changed

README.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
[![Published on Vaadin Directory](https://img.shields.io/badge/Vaadin%20Directory-published-00b4f0.svg)](https://vaadin.com/directory/component/template-addon)
2-
[![Stars on vaadin.com/directory](https://img.shields.io/vaadin-directory/star/template-addon.svg)](https://vaadin.com/directory/component/template-addon)
3-
[![Build Status](https://jenkins.flowingcode.com/job/template-addon/badge/icon)](https://jenkins.flowingcode.com/job/template-addon)
4-
[![Maven Central](https://img.shields.io/maven-central/v/com.flowingcode.vaadin.addons/template-addon)](https://mvnrepository.com/artifact/com.flowingcode.vaadin.addons/template-addon)
5-
[![Javadoc](https://img.shields.io/badge/javadoc-00b4f0)](https://javadoc.flowingcode.com/artifact/com.flowingcode.vaadin.addons/template-addon)
1+
[![Published on Vaadin Directory](https://img.shields.io/badge/Vaadin%20Directory-published-00b4f0.svg)](https://vaadin.com/directory/component/upload-helper-add-on)
2+
[![Stars on vaadin.com/directory](https://img.shields.io/vaadin-directory/star/upload-helper-addon.svg)](https://vaadin.com/directory/component/upload-helper-add-on)
3+
[![Build Status](https://jenkins.flowingcode.com/job/upload-helper-addon/badge/icon)](https://jenkins.flowingcode.com/job/upload-helper-addon)
4+
[![Maven Central](https://img.shields.io/maven-central/v/com.flowingcode.vaadin.addons/upload-helper-addon)](https://mvnrepository.com/artifact/com.flowingcode.vaadin.addons/upload-helper-addon)
5+
[![Javadoc](https://img.shields.io/badge/javadoc-00b4f0)](https://javadoc.flowingcode.com/artifact/com.flowingcode.vaadin.addons/upload-helper-addon)
66

7-
# Template Add-on
7+
# Upload helper Add-on
88

9-
This is a template project for building new Vaadin 24 add-ons
9+
Flow API for `vaadin-upload-file`
1010

1111
## Features
1212

13-
* List the features of your add-on in here
13+
* Provide an API for manipulating the [vaadin-upload-file](https://cdn.vaadin.com/vaadin-web-components/24.5.0/#/elements/vaadin-upload-file) element.
1414

1515
## Online demo
1616

17-
[Online demo here](http://addonsv24.flowingcode.com/template)
17+
[Online demo here](http://addonsv24.flowingcode.com/upload-helper)
1818

1919
## Download release
2020

21-
[Available in Vaadin Directory](https://vaadin.com/directory/component/template-addon)
21+
[Available in Vaadin Directory](https://vaadin.com/directory/component/upload-helper-add-on)
2222

2323
### Maven install
2424

@@ -27,7 +27,7 @@ Add the following dependencies in your pom.xml file:
2727
```xml
2828
<dependency>
2929
<groupId>com.flowingcode.vaadin.addons</groupId>
30-
<artifactId>template-addon</artifactId>
30+
<artifactId>upload-helper-addon</artifactId>
3131
<version>X.Y.Z</version>
3232
</dependency>
3333
```
@@ -44,7 +44,7 @@ To see the demo, navigate to http://localhost:8080/
4444

4545
## Release notes
4646

47-
See [here](https://github.com/FlowingCode/TemplateAddon/releases)
47+
See [here](https://github.com/FlowingCode/UploadHelper/releases)
4848

4949
## Issue tracking
5050

@@ -69,7 +69,7 @@ Then, follow these steps for creating a contribution:
6969

7070
This add-on is distributed under Apache License 2.0. For license terms, see LICENSE.txt.
7171

72-
TEMPLATE_ADDON is written by Flowing Code S.A.
72+
Upload Helper Add-On is written by Flowing Code S.A.
7373

7474
# Developer Guide
7575

pom.xml

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
<modelVersion>4.0.0</modelVersion>
66

77
<groupId>com.flowingcode.vaadin.addons</groupId>
8-
<artifactId>template-addon</artifactId>
8+
<artifactId>upload-helper-addon</artifactId>
99
<version>1.0.0-SNAPSHOT</version>
10-
<name>Template Add-on</name>
11-
<description>Template Add-on for Vaadin Flow</description>
10+
<name>Upload Helper Add-on</name>
11+
<description>Upload Helper Add-on for Vaadin Flow</description>
1212
<url>https://www.flowingcode.com/en/open-source/</url>
1313

1414
<properties>
15-
<vaadin.version>24.4.6</vaadin.version>
15+
<vaadin.version>24.5.0</vaadin.version>
1616
<selenium.version>4.10.0</selenium.version>
1717
<maven.compiler.source>17</maven.compiler.source>
1818
<maven.compiler.target>17</maven.compiler.target>
@@ -29,7 +29,7 @@
2929
<url>https://www.flowingcode.com</url>
3030
</organization>
3131

32-
<inceptionYear>2024</inceptionYear>
32+
<inceptionYear>2022</inceptionYear>
3333
<licenses>
3434
<license>
3535
<name>Apache 2</name>
@@ -39,9 +39,9 @@
3939
</licenses>
4040

4141
<scm>
42-
<url>https://github.com/FlowingCode/AddonStarter24</url>
43-
<connection>scm:git:git://github.com/FlowingCode/AddonStarter24.git</connection>
44-
<developerConnection>scm:git:ssh://git@github.com:/FlowingCode/AddonStarter24.git</developerConnection>
42+
<url>https://github.com/FlowingCode/UploadHelper</url>
43+
<connection>scm:git:git://github.com/FlowingCode/UploadHelper.git</connection>
44+
<developerConnection>scm:git:ssh://git@github.com:/FlowingCode/UploadHelper.git</developerConnection>
4545
<tag>master</tag>
4646
</scm>
4747

@@ -122,6 +122,17 @@
122122
<artifactId>vaadin-core</artifactId>
123123
<optional>true</optional>
124124
</dependency>
125+
<dependency>
126+
<groupId>org.projectlombok</groupId>
127+
<artifactId>lombok</artifactId>
128+
<version>1.18.34</version>
129+
<scope>provided</scope>
130+
</dependency>
131+
<dependency>
132+
<groupId>com.flowingcode.vaadin.test</groupId>
133+
<artifactId>testbench-rpc</artifactId>
134+
<version>1.3.0</version>
135+
</dependency>
125136
<dependency>
126137
<groupId>com.flowingcode.vaadin.addons.demo</groupId>
127138
<artifactId>commons-demo</artifactId>
@@ -313,9 +324,9 @@
313324
<configuration>
314325
<quiet>true</quiet>
315326
<doclint>none</doclint>
316-
<failOnWarnings>true</failOnWarnings>
327+
<failOnWarnings>true</failOnWarnings>
317328
<links>
318-
<link>https://javadoc.io/doc/com.vaadin/vaadin-platform-javadoc/${vaadin.version}</link>
329+
<link>https://javadoc.io/doc/com.vaadin/vaadin-platform-javadoc/${vaadin.version}</link>
319330
</links>
320331
</configuration>
321332
</plugin>
@@ -496,6 +507,7 @@
496507
<exclude>**/it/*</exclude>
497508
<exclude>**/DemoView.class</exclude>
498509
<exclude>**/DemoLayout.class</exclude>
510+
<exclude>**/AppShellConfiguratorImpl.class</exclude>
499511
</excludes>
500512
</configuration>
501513
</execution>
Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
/*-
2+
* #%L
3+
* Upload Helper Add-on
4+
* %%
5+
* Copyright (C) 2022 - 2024 Flowing Code
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.uploadhelper;
21+
22+
import com.vaadin.flow.component.upload.FinishedEvent;
23+
import com.vaadin.flow.component.upload.Upload;
24+
import elemental.json.Json;
25+
import elemental.json.JsonObject;
26+
import java.io.Serializable;
27+
import lombok.AccessLevel;
28+
import lombok.Getter;
29+
30+
/** Represents a file in the file list of an {@link Upload} component. */
31+
@SuppressWarnings("serial")
32+
public final class FileInfo implements Serializable {
33+
34+
private final String name;
35+
36+
@Getter(AccessLevel.PACKAGE)
37+
private Upload upload;
38+
39+
private Boolean complete;
40+
private Boolean indeterminate;
41+
private String errorMessage;
42+
private Integer progress;
43+
private String status;
44+
45+
/**
46+
* Constructs a {@code FileInfo} object with the specified upload and file name.
47+
*
48+
* @param upload the {@code Upload} instance representing the file upload source
49+
* @param name the name of the file being uploaded
50+
*/
51+
public FileInfo(Upload upload, String name) {
52+
this.upload = upload;
53+
this.name = name;
54+
}
55+
56+
/**
57+
* Constructs a {@code FileInfo} object from the specified finished upload event.
58+
*
59+
* @param ev the {@code FinishedEvent} representing the succeeded or failed event
60+
*/
61+
public FileInfo(FinishedEvent ev) {
62+
upload = ev.getSource();
63+
name = ev.getFileName();
64+
}
65+
66+
/** Updates this file in the upload component. */
67+
public void update() {
68+
update(false);
69+
}
70+
71+
/** Adds a new file to the upload component. */
72+
public void create() {
73+
update(true);
74+
}
75+
76+
private void update(boolean createIfNotExists) {
77+
upload.getElement().executeJs(
78+
"""
79+
var d = this;
80+
var i = d.files.findIndex(f=>f.name==$0.name);
81+
if (i<0) {
82+
if ($1) d.files = [... d.files, $0]; else return;
83+
} else {
84+
if (d.files.some((e,j)=>e.name==$0.name && j>i)) d.files=d.files.filter((e,j)=>e.name!=$0.name || j<=i);
85+
d.files[i] = Object.assign(d.files[i], $0);
86+
}
87+
d.files = Array.from(d.files);
88+
""",
89+
toJson(), createIfNotExists);
90+
}
91+
92+
private JsonObject toJson() {
93+
JsonObject json = Json.createObject();
94+
json.put("name", name);
95+
if (complete != null) {
96+
json.put("complete", complete);
97+
}
98+
if (indeterminate != null) {
99+
json.put("indeterminate", indeterminate);
100+
}
101+
if (errorMessage != null) {
102+
json.put("error", errorMessage);
103+
}
104+
if (progress != null) {
105+
json.put("progress", progress);
106+
}
107+
if (status != null) {
108+
json.put("status", status);
109+
}
110+
return json;
111+
}
112+
113+
/**
114+
* True if uploading is completed, false otherwise.
115+
*
116+
* @return This instance for method chaining
117+
*/
118+
public FileInfo complete(Boolean complete) {
119+
this.complete = complete;
120+
return this;
121+
}
122+
123+
/**
124+
* Configure the upload in complete state (i.e. uploading is completed)
125+
*
126+
* @return This instance for method chaining
127+
*/
128+
public FileInfo complete() {
129+
complete = true;
130+
return this;
131+
}
132+
133+
/**
134+
* Configure the upload in indeterminate state (i.e. the remaining time is unknown)
135+
*
136+
* @return This instance for method chaining
137+
*/
138+
public FileInfo indeterminate() {
139+
return indeterminate(true);
140+
}
141+
142+
/**
143+
* True if the remaining time is unknown, false otherwise.
144+
*
145+
* @return This instance for method chaining
146+
*/
147+
public FileInfo indeterminate(Boolean indeterminate) {
148+
this.indeterminate = indeterminate;
149+
return this;
150+
}
151+
152+
/**
153+
* Error message returned by the server, if any.
154+
*
155+
* @return This instance for method chaining
156+
*/
157+
public FileInfo errorMessage(String errorMessage) {
158+
this.errorMessage = errorMessage;
159+
return this;
160+
}
161+
162+
/**
163+
* Number representing the uploading progress.
164+
*
165+
* @return This instance for method chaining
166+
*/
167+
public FileInfo progress(Integer progress) {
168+
this.progress = progress;
169+
return this;
170+
}
171+
172+
/**
173+
* Uploading status message.
174+
*
175+
* @return This instance for method chaining
176+
*/
177+
public FileInfo status(String status) {
178+
this.status = status;
179+
return this;
180+
}
181+
182+
/** Returns the name of the uploaded file. */
183+
public String getName() {
184+
return name;
185+
}
186+
187+
/** Returns {@code true} if uploading is completed, false otherwise. */
188+
public Boolean getComplete() {
189+
return complete;
190+
}
191+
192+
/** Returns {@code true} if the remaining progress is unknown, false otherwise. */
193+
public Boolean getIndeterminate() {
194+
return indeterminate;
195+
}
196+
197+
/** Returns the error message returned by the server. */
198+
public String getErrorMessage() {
199+
return errorMessage;
200+
}
201+
202+
/** Returns a number between 0 and 100, representing the uploading progress. */
203+
public Integer getProgress() {
204+
return progress;
205+
}
206+
207+
/** Returns the uploading status. */
208+
public String getStatus() {
209+
return status;
210+
}
211+
212+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,20 @@
1+
###
2+
# #%L
3+
# Upload Helper Add-on
4+
# %%
5+
# Copyright (C) 2022 - 2024 Flowing Code
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+
###
120
vaadin.allowed-packages=com.flowingcode

0 commit comments

Comments
 (0)