+ add upload date to file selection
+ select latest file if no selection is provided #SPM-28: add work 1h 20m development
This commit is contained in:
parent
e67c305322
commit
6f5eb4b24f
|
@ -2,4 +2,5 @@
|
||||||
.idea
|
.idea
|
||||||
.project
|
.project
|
||||||
target
|
target
|
||||||
.vscode
|
.vscode
|
||||||
|
*.csv
|
|
@ -9,6 +9,7 @@ import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
|
|
||||||
|
@ -36,7 +37,7 @@ public class Data {
|
||||||
//cleanup old files
|
//cleanup old files
|
||||||
if (files.isEmpty()) {
|
if (files.isEmpty()) {
|
||||||
try {
|
try {
|
||||||
Files.list(Paths.get("target/")).forEach(path -> {
|
Files.list(Paths.get("")).forEach(path -> {
|
||||||
if (path.toFile().getName().endsWith(".csv")) {
|
if (path.toFile().getName().endsWith(".csv")) {
|
||||||
try {
|
try {
|
||||||
Files.delete(path);
|
Files.delete(path);
|
||||||
|
@ -60,11 +61,11 @@ public class Data {
|
||||||
System.out.println("failed to delete file...");
|
System.out.println("failed to delete file...");
|
||||||
}
|
}
|
||||||
path = Paths.get(getFileName(uuid));
|
path = Paths.get(getFileName(uuid));
|
||||||
files.offer(new SavedFile(uuid, name));
|
files.offer(new SavedFile(uuid, name, LocalDateTime.now()));
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
files.add(new SavedFile(uuid, name));
|
files.add(new SavedFile(uuid, name, LocalDateTime.now()));
|
||||||
path = Paths.get(getFileName(uuid));
|
path = Paths.get(getFileName(uuid));
|
||||||
}
|
}
|
||||||
return path;
|
return path;
|
||||||
|
@ -91,6 +92,6 @@ public class Data {
|
||||||
@Contract(pure = true)
|
@Contract(pure = true)
|
||||||
@NotNull
|
@NotNull
|
||||||
private static String getFileName(@NotNull UUID uuid) {
|
private static String getFileName(@NotNull UUID uuid) {
|
||||||
return "target/" + uuid + ".csv";
|
return uuid + ".csv";
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -4,6 +4,7 @@ import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -20,4 +21,5 @@ class SavedFile {
|
||||||
|
|
||||||
private UUID uuid;
|
private UUID uuid;
|
||||||
private String name;
|
private String name;
|
||||||
|
private LocalDateTime date;
|
||||||
}
|
}
|
|
@ -13,7 +13,16 @@ import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.TreeSet;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* changes data from shopping times diagram into a readable format for chart.js
|
* changes data from shopping times diagram into a readable format for chart.js
|
||||||
|
|
|
@ -12,7 +12,13 @@ import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* changes data from week overview into readable format for chart.js
|
* changes data from week overview into readable format for chart.js
|
||||||
|
|
|
@ -5,22 +5,33 @@ $(document).ready(function () {
|
||||||
for (const result of results) {
|
for (const result of results) {
|
||||||
dataset.append($("<option></option>")
|
dataset.append($("<option></option>")
|
||||||
.attr("value", result.uuid)
|
.attr("value", result.uuid)
|
||||||
.text(result.name));
|
.text(result.name + " (" + result.date.date.day + "." + result.date.date.month + " "
|
||||||
|
+ result.date.time.hour + ":" + result.date.time.minute + ")"));
|
||||||
}
|
}
|
||||||
dataset.formSelect();
|
dataset.formSelect();
|
||||||
});
|
});
|
||||||
updateWeekOverviewChart();
|
updateCache();
|
||||||
updateShoppingTimesChart();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* update all charts with correct values for dataset
|
* update all charts with correct values for dataset
|
||||||
*/
|
*/
|
||||||
function updateCache() {
|
function updateCache() {
|
||||||
|
let dataset = $('#dataset');
|
||||||
let selected = $('#dataset :selected');
|
let selected = $('#dataset :selected');
|
||||||
if (selected.index() !== -1) {
|
if (typeof selected !== 'undefined' && selected.index() !== -1) {
|
||||||
updateWeekOverviewChart(selected.val());
|
updateWeekOverviewChart(selected.val());
|
||||||
updateShoppingTimesChart(selected.val());
|
updateShoppingTimesChart(selected.val());
|
||||||
|
} else {
|
||||||
|
//requesting files, getting values from html does not work...
|
||||||
|
//if no selection is provided, select newest file
|
||||||
|
request('files').then(results => {
|
||||||
|
let uuid = results[results.length - 1].uuid;
|
||||||
|
dataset.val(uuid);
|
||||||
|
updateWeekOverviewChart(uuid);
|
||||||
|
updateShoppingTimesChart(uuid);
|
||||||
|
dataset.formSelect();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -32,7 +43,7 @@ function updateCache() {
|
||||||
* @returns {Promise<result>}
|
* @returns {Promise<result>}
|
||||||
*/
|
*/
|
||||||
function request(url, id) {
|
function request(url, id) {
|
||||||
return new Promise(((resolve, reject) => {
|
return new Promise(((resolve) => {
|
||||||
if (typeof id !== 'undefined') {
|
if (typeof id !== 'undefined') {
|
||||||
requestInternal(url + '?id=' + id).then(function (data) {
|
requestInternal(url + '?id=' + id).then(function (data) {
|
||||||
resolve(data);
|
resolve(data);
|
||||||
|
@ -51,7 +62,7 @@ function request(url, id) {
|
||||||
* @returns {Promise<result>}
|
* @returns {Promise<result>}
|
||||||
*/
|
*/
|
||||||
function requestInternal(url) {
|
function requestInternal(url) {
|
||||||
return new Promise(((resolve, reject) => {
|
return new Promise(((resolve) => {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: url,
|
url: url,
|
||||||
dataType: 'json'
|
dataType: 'json'
|
||||||
|
|
Loading…
Reference in New Issue