daily calendar works

This commit is contained in:
Jörg Henke
2022-07-26 17:52:07 +02:00
parent f754832ee0
commit 676fa63471
6 changed files with 68 additions and 9 deletions

View File

@ -41,6 +41,8 @@ dependencies {
implementation 'org.webjars:datatables:1.11.3' implementation 'org.webjars:datatables:1.11.3'
implementation 'org.webjars:jquery-ui:1.13.0' implementation 'org.webjars:jquery-ui:1.13.0'
implementation 'com.google.code.gson:gson:2.9.0';
implementation 'org.webjars.bowergithub.datatables:datatables:1.10.21' implementation 'org.webjars.bowergithub.datatables:datatables:1.10.21'
implementation 'org.keycloak:keycloak-spring-boot-starter:17.0.1' implementation 'org.keycloak:keycloak-spring-boot-starter:17.0.1'

View File

@ -58,6 +58,31 @@ public class DoneBean implements Serializable, Comparable<DoneBean> {
this.fkBilling = billing.getPk(); this.fkBilling = billing.getPk();
} }
private final String nullable(Object o, String format) {
if (o == null) {
return "null";
} else if (o instanceof Integer) {
return String.valueOf(o);
} else if (o instanceof LocalDateTime) {
LocalDateTime ldt = (LocalDateTime) o;
return new StringBuilder("\"").append(ldt.format(DateTimeFormatter.ofPattern(format))).append("\"").toString();
} else if (o instanceof VBillingRecord) {
VBillingRecord b = (VBillingRecord) o;
return new StringBuilder("\"").append(b.getCsskey()).append("\"").toString();
} else {
return new StringBuilder("\"").append(o).append("\"").toString();
}
}
public final String toJson() {
StringBuilder buf = new StringBuilder("{");
buf.append("\"from\": ").append(nullable(timeFrom, "HH:mm"));
buf.append(", \"until\": ").append(nullable(timeUntil, "HH:mm"));
buf.append(", \"billing\": ").append(nullable(billing, null));
buf.append("}");
return buf.toString();
}
@Override @Override
public final String toString() { public final String toString() {
StringBuilder buf = new StringBuilder("DoneBean{"); StringBuilder buf = new StringBuilder("DoneBean{");

View File

@ -45,9 +45,11 @@ public class DoneController {
Duration maxWorkTime = Duration.ofHours(8); // TODO: to the configuration file Duration maxWorkTime = Duration.ofHours(8); // TODO: to the configuration file
LocalDate day = doneModel.getDay(); LocalDate day = doneModel.getDay();
List<DoneBean> list = doneService.getList(day, username); List<DoneBean> list = doneService.getList(day, username);
SummaryBean bean = new SummaryBean(list, day, maxWorkTime);
model.addAttribute("doneList", list); model.addAttribute("doneList", list);
model.addAttribute("doneModel", doneModel); model.addAttribute("doneModel", doneModel);
model.addAttribute("sum", new SummaryBean(list, day, maxWorkTime)); model.addAttribute("sum", bean);
model.addAttribute("schedule", bean.toJson()); // TODO: add the other days of that week
model.addAttribute("projectList", doneService.getProjects(false)); model.addAttribute("projectList", doneService.getProjects(false));
model.addAttribute("moduleList", doneService.getModules(false)); model.addAttribute("moduleList", doneService.getModules(false));
model.addAttribute("jobList", doneService.getJobs(false)); model.addAttribute("jobList", doneService.getJobs(false));

View File

@ -4,6 +4,7 @@ import java.io.Serializable;
import java.time.Duration; import java.time.Duration;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List; import java.util.List;
/** /**
@ -24,6 +25,24 @@ public class SummaryBean implements Serializable {
this.maxDayWorktime = maxDayWorktime; this.maxDayWorktime = maxDayWorktime;
} }
public String toJson() {
StringBuilder buf = new StringBuilder("{");
buf.append("\"maxDayWorktime\": \"").append(String.format("%02d:%02d", maxDayWorktime.toHoursPart(), maxDayWorktime.toMinutesPart()));
buf.append("\", \"daySlot\": ").append(day == null ? "null" : day.getDayOfWeek().getValue());
buf.append(", \"schedule\": [");
boolean first = true;
for (DoneBean bean : list) {
if (!first) {
buf.append(", ");
} else {
first = false;
}
buf.append(bean.toJson());
}
buf.append("]}");
return buf.toString();
}
@Override @Override
public String toString() { public String toString() {
StringBuilder buf = new StringBuilder("{"); StringBuilder buf = new StringBuilder("{");

View File

@ -41,7 +41,6 @@ class Schedule {
var hours = parseInt(timeArray[0]); var hours = parseInt(timeArray[0]);
var minutes = parseInt(timeArray[1]); var minutes = parseInt(timeArray[1]);
var pixels = parseInt((hours + (minutes / 60)) * hourHeight); var pixels = parseInt((hours + (minutes / 60)) * hourHeight);
console.log("convert " + time + " to " + pixels);
return pixels; return pixels;
} }
@ -57,7 +56,6 @@ class Schedule {
var w = dayWidth; var w = dayWidth;
var h = parseInt(this.time2pixel(until, hourHeight) - y); var h = parseInt(this.time2pixel(until, hourHeight) - y);
ctx.beginPath(); ctx.beginPath();
console.log("draw " + x + "," + y + " -> +" + w + "," + h);
ctx.fillRect(x, y, w, h); ctx.fillRect(x, y, w, h);
ctx.strokeRect(x, y, w, h); ctx.strokeRect(x, y, w, h);
} }

View File

@ -189,12 +189,25 @@
let height = parseInt($("#schedule").css("min-height")); let height = parseInt($("#schedule").css("min-height"));
var schedule = new Schedule("#schedule", width, height); var schedule = new Schedule("#schedule", width, height);
var ctx = $("#scheduleCanvas")[0].getContext("2d"); var ctx = $("#scheduleCanvas")[0].getContext("2d");
/* TODO: replace by weekly times */ var currentDayRecords = JSON.parse('[(${schedule})]');
schedule.drawSlot(ctx, 2, "07:15", "10:30", "black", "green"); var scheduleRecords = currentDayRecords.schedule;
schedule.drawSlot(ctx, 2, "10:30", "10:45", "black", "gray"); var daySlot = currentDayRecords.daySlot;
schedule.drawSlot(ctx, 2, "10:45", "12:00", "black", "red"); for (var i = 0; i < scheduleRecords.length; i++) {
schedule.drawSlot(ctx, 2, "13:00", "17:15", "black", "blue"); var r = scheduleRecords[i];
var cssClass = r.billing;
var color = "#aaaaaa";
if (cssClass == "WP5") {
color = "#aa0000";
} else if (cssClass == "WP4") {
color = "#0000aa";
} else if (cssClass == "WP2") {
color = "#aaaa00";
} else if (cssClass == "TA3") {
color = "#00aa00";
}
/* daySlot 7 = sunday, but this should be slot 0 */
schedule.drawSlot(ctx, daySlot > 6 ? 0 : daySlot, r.from, r.until, "black", color);
}
var localeUrl = '[[@{/js/dataTables/de.json}]]'; var localeUrl = '[[@{/js/dataTables/de.json}]]';
$("#project_table").DataTable({ $("#project_table").DataTable({
"language" : { "language" : {