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

@ -57,6 +57,31 @@ public class DoneBean implements Serializable, Comparable<DoneBean> {
this.fkJob = activity.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
public final String toString() {

View File

@ -45,9 +45,11 @@ public class DoneController {
Duration maxWorkTime = Duration.ofHours(8); // TODO: to the configuration file
LocalDate day = doneModel.getDay();
List<DoneBean> list = doneService.getList(day, username);
SummaryBean bean = new SummaryBean(list, day, maxWorkTime);
model.addAttribute("doneList", list);
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("moduleList", doneService.getModules(false));
model.addAttribute("jobList", doneService.getJobs(false));

View File

@ -4,6 +4,7 @@ import java.io.Serializable;
import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
/**
@ -23,6 +24,24 @@ public class SummaryBean implements Serializable {
this.day = day;
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
public String toString() {

View File

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

View File

@ -189,12 +189,25 @@
let height = parseInt($("#schedule").css("min-height"));
var schedule = new Schedule("#schedule", width, height);
var ctx = $("#scheduleCanvas")[0].getContext("2d");
/* TODO: replace by weekly times */
schedule.drawSlot(ctx, 2, "07:15", "10:30", "black", "green");
schedule.drawSlot(ctx, 2, "10:30", "10:45", "black", "gray");
schedule.drawSlot(ctx, 2, "10:45", "12:00", "black", "red");
schedule.drawSlot(ctx, 2, "13:00", "17:15", "black", "blue");
var currentDayRecords = JSON.parse('[(${schedule})]');
var scheduleRecords = currentDayRecords.schedule;
var daySlot = currentDayRecords.daySlot;
for (var i = 0; i < scheduleRecords.length; i++) {
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}]]';
$("#project_table").DataTable({
"language" : {