+ 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
|
||||
.project
|
||||
target
|
||||
.vscode
|
||||
.vscode
|
||||
*.csv
|
|
@ -9,6 +9,7 @@ import java.io.IOException;
|
|||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
|
||||
|
@ -36,7 +37,7 @@ public class Data {
|
|||
//cleanup old files
|
||||
if (files.isEmpty()) {
|
||||
try {
|
||||
Files.list(Paths.get("target/")).forEach(path -> {
|
||||
Files.list(Paths.get("")).forEach(path -> {
|
||||
if (path.toFile().getName().endsWith(".csv")) {
|
||||
try {
|
||||
Files.delete(path);
|
||||
|
@ -60,11 +61,11 @@ public class Data {
|
|||
System.out.println("failed to delete file...");
|
||||
}
|
||||
path = Paths.get(getFileName(uuid));
|
||||
files.offer(new SavedFile(uuid, name));
|
||||
files.offer(new SavedFile(uuid, name, LocalDateTime.now()));
|
||||
|
||||
|
||||
} else {
|
||||
files.add(new SavedFile(uuid, name));
|
||||
files.add(new SavedFile(uuid, name, LocalDateTime.now()));
|
||||
path = Paths.get(getFileName(uuid));
|
||||
}
|
||||
return path;
|
||||
|
@ -91,6 +92,6 @@ public class Data {
|
|||
@Contract(pure = true)
|
||||
@NotNull
|
||||
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.ToString;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
|
@ -20,4 +21,5 @@ class SavedFile {
|
|||
|
||||
private UUID uuid;
|
||||
private String name;
|
||||
private LocalDateTime date;
|
||||
}
|
|
@ -13,7 +13,16 @@ import java.io.File;
|
|||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
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
|
||||
|
|
|
@ -12,7 +12,13 @@ import java.io.File;
|
|||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
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
|
||||
|
|
|
@ -5,22 +5,33 @@ $(document).ready(function () {
|
|||
for (const result of results) {
|
||||
dataset.append($("<option></option>")
|
||||
.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();
|
||||
});
|
||||
updateWeekOverviewChart();
|
||||
updateShoppingTimesChart();
|
||||
updateCache();
|
||||
});
|
||||
|
||||
/**
|
||||
* update all charts with correct values for dataset
|
||||
*/
|
||||
function updateCache() {
|
||||
let dataset = $('#dataset');
|
||||
let selected = $('#dataset :selected');
|
||||
if (selected.index() !== -1) {
|
||||
if (typeof selected !== 'undefined' && selected.index() !== -1) {
|
||||
updateWeekOverviewChart(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>}
|
||||
*/
|
||||
function request(url, id) {
|
||||
return new Promise(((resolve, reject) => {
|
||||
return new Promise(((resolve) => {
|
||||
if (typeof id !== 'undefined') {
|
||||
requestInternal(url + '?id=' + id).then(function (data) {
|
||||
resolve(data);
|
||||
|
@ -51,7 +62,7 @@ function request(url, id) {
|
|||
* @returns {Promise<result>}
|
||||
*/
|
||||
function requestInternal(url) {
|
||||
return new Promise(((resolve, reject) => {
|
||||
return new Promise(((resolve) => {
|
||||
$.ajax({
|
||||
url: url,
|
||||
dataType: 'json'
|
||||
|
|
Loading…
Reference in New Issue