Skip to content

Commit

Permalink
added report ID suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
cvogt729 committed Feb 14, 2022
1 parent b6fb47d commit b61b6dc
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 9 deletions.
2 changes: 1 addition & 1 deletion root/info.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<extension version="1">
<name>ReportFTP</name>
<description>Can be configured to send scheduled reports to an FTP server.</description>
<version>0.1.0</version>
<version>0.1.1</version>
<vendor>Automatic Controls Equipment Systems, Inc.</vendor>
</extension>
9 changes: 9 additions & 0 deletions src/aces/webctrl/ftp/core/ConfigReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ public class ConfigReader {
private char[] arr;
private int i = 0;
private int len;
public ConfigReader(StringBuilder sb, char[] arr){
this.arr = arr;
len = arr.length;
skipUntil("label");
String ID = nextToken();
if (ID.length()>0){
sb.append("<option value=\"").append(Utility.escapeHTML(ID)).append("\">\n");
}
}
public ConfigReader(char[] arr){
String ID, local, remote;
this.arr = arr;
Expand Down
16 changes: 10 additions & 6 deletions src/aces/webctrl/ftp/core/Servers.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,22 @@ public class Servers {
private volatile static Path dataFile;
/** Contains a list of {@code Server} objects. */
private final static ArrayList<Server> servers = new ArrayList<Server>();
/** Controls access to report config files. */
public final static Object configReadLock = new Object();
/**
* Analyzes current scheduled reports, and sends them to the appropriate servers.
*/
public static void run(){
if (servers.size()>0 && ftp.compareAndSet(false,true)){
try{
try(
DirectoryStream<Path> stream = Files.newDirectoryStream(Initializer.configs);
){
for (Path config:stream){
if (Files.isReadable(config)){
new ConfigReader(java.nio.charset.StandardCharsets.UTF_8.decode(ByteBuffer.wrap(Files.readAllBytes(config))).array());
synchronized (configReadLock){
try(
DirectoryStream<Path> stream = Files.newDirectoryStream(Initializer.configs);
){
for (Path config:stream){
if (Files.isReadable(config)){
new ConfigReader(java.nio.charset.StandardCharsets.UTF_8.decode(ByteBuffer.wrap(Files.readAllBytes(config))).array());
}
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/aces/webctrl/ftp/web/ReportPage.html
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ <h1>Report List For __SERVER__</h1>
<th>Actions</th>
</tr>
<tr id="newRow">
<td><input id="newLabel" type="text" class="e c" oninput="resize(this)"></td>
<td><input id="newLabel" list="reportIDs" class="e c" oninput="resize(this)"></td>
<td><input id="newFolder" type="text" class="e c" oninput="resize(this)"></td>
<td><button class="e" onclick="submitNew(this)">Add New Report</button></td>
</tr>
Expand All @@ -142,6 +142,9 @@ <h3 class="e">Status: <span id="statusText" style="color:red">Idle</span></h3>
<br>
<a href="https://github.com/automatic-controls/report-ftp-addon/blob/main/README.md" target="_blank">Documentation</a>
<span id="hiddenSpan" style="min-width:14em;color:black;display:inline-block;position:absolute;left:-100000px"></span>
<datalist id="reportIDs">
<!--__REPORTS__-->
</datalist>
</div>
<script>
resize(newLabel);
Expand Down
18 changes: 17 additions & 1 deletion src/aces/webctrl/ftp/web/ReportPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.nio.*;
import java.nio.file.*;
public class ReportPage extends HttpServlet {
private volatile static String html = null;
@Override public void init() throws ServletException {
Expand Down Expand Up @@ -53,8 +55,22 @@ public boolean test(Report r){
return false;
}
});
String str = html.replace("__ID__", ID).replace("__SERVER__", s.getHost()).replace("//__INIT_SCRIPT__", sb.toString());
sb.setLength(0);
synchronized (Servers.configReadLock){
try(
DirectoryStream<Path> stream = Files.newDirectoryStream(Initializer.configs);
){
for (Path config:stream){
if (Files.isReadable(config)){
new ConfigReader(sb, java.nio.charset.StandardCharsets.UTF_8.decode(ByteBuffer.wrap(Files.readAllBytes(config))).array());
}
}
}catch(Throwable t){}
}
str = str.replace("<!--__REPORTS__-->", sb.toString());
res.setContentType("text/html");
res.getWriter().print(html.replace("__ID__", ID).replace("__SERVER__", s.getHost()).replace("//__INIT_SCRIPT__", sb.toString()));
res.getWriter().print(str);
}else{
switch (type){
case "clear":{
Expand Down

0 comments on commit b61b6dc

Please sign in to comment.