Browse Source

working on time list

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
feature/brute_force_protection
Stephan Richter 3 months ago
parent
commit
7ab844bcff
  1. 2
      core/src/main/java/de/srsoftware/umbrella/core/api/TaskService.java
  2. 16
      frontend/src/routes/time/Index.svelte
  3. 2
      task/src/main/java/de/srsoftware/umbrella/task/TaskModule.java
  4. 21
      time/src/main/java/de/srsoftware/umbrella/time/SqliteDb.java
  5. 4
      time/src/main/java/de/srsoftware/umbrella/time/TimeDb.java
  6. 65
      time/src/main/java/de/srsoftware/umbrella/time/TimeModule.java

2
core/src/main/java/de/srsoftware/umbrella/core/api/TaskService.java

@ -10,7 +10,7 @@ import java.util.List; @@ -10,7 +10,7 @@ import java.util.List;
public interface TaskService {
HashMap<Long, Task> listCompanyTasks(long companyId) throws UmbrellaException;
HashMap<Long, Task> listProjectTasks(long projectId) throws UmbrellaException;
HashMap<Long, Task> load(List<Long> taskIds);
HashMap<Long, Task> load(Collection<Long> taskIds);
Collection<Task> loadMembers(Collection<Task> tasks);
default Task loadMembers(Task task){

16
frontend/src/routes/time/Index.svelte

@ -1,9 +1,11 @@ @@ -1,9 +1,11 @@
<script>
import { onMount } from 'svelte';
import { useTinyRouter } from 'svelte-tiny-router';
import { api } from '../../urls.svelte.js';
import { t } from '../../translations.svelte.js';
let error = $state(null);
let router = useTinyRouter();
let times = $state(null);
async function loadTimes(){
@ -16,6 +18,10 @@ @@ -16,6 +18,10 @@
}
}
function openTask(tid){
router.navigate(`task/${tid}/view`);
}
onMount(loadTimes);
</script>
@ -34,14 +40,20 @@ @@ -34,14 +40,20 @@
<td>
{time.start_time}{time.end_time}
</td>
<td>
{time.duration}&nbsp;h
</td>
<td>
{time.subject}
</td>
<td>
{#each time.task_ids as tid}
{tid}&nbsp;
{#each Object.entries(time.tasks) as [tid,task]}
<a href="#" onclick={e => openTask(tid)}>{task}</a>
{/each}
</td>
<td>
{t("state_"+time.state.name.toLowerCase())}
</td>
</tr>
{/each}
</tbody>

2
task/src/main/java/de/srsoftware/umbrella/task/TaskModule.java

@ -216,7 +216,7 @@ public class TaskModule extends BaseHandler implements TaskService { @@ -216,7 +216,7 @@ public class TaskModule extends BaseHandler implements TaskService {
}
@Override
public HashMap<Long, Task> load(List<Long> taskIds) {
public HashMap<Long, Task> load(Collection<Long> taskIds) {
try {
var map = taskIds.stream().map(taskDb::load).collect(Collectors.toMap(Task::id, t -> t));
return new HashMap<>(map);

21
time/src/main/java/de/srsoftware/umbrella/time/SqliteDb.java

@ -1,12 +1,11 @@ @@ -1,12 +1,11 @@
/* © SRSoftware 2025 */
package de.srsoftware.umbrella.time;
import static de.srsoftware.tools.jdbc.Condition.equal;
import static de.srsoftware.tools.jdbc.Condition.in;
import static de.srsoftware.tools.jdbc.Condition.*;
import static de.srsoftware.tools.jdbc.Query.SelectQuery.ALL;
import static de.srsoftware.tools.jdbc.Query.select;
import static de.srsoftware.umbrella.core.Constants.ID;
import static de.srsoftware.umbrella.core.Constants.USER_ID;
import static de.srsoftware.umbrella.core.Constants.*;
import static de.srsoftware.umbrella.core.model.Time.State.Complete;
import static de.srsoftware.umbrella.time.Constants.*;
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
@ -26,7 +25,7 @@ public class SqliteDb implements TimeDb { @@ -26,7 +25,7 @@ public class SqliteDb implements TimeDb {
}
@Override
public HashMap<Long,Time> listTimes(Collection<Long> taskIds) throws UmbrellaException {
public HashMap<Long,Time> listTimes(Collection<Long> taskIds, boolean showClosed) throws UmbrellaException {
try {
var rs = select(ALL).from(TABLE_TASK_TIMES).where(TASK_ID,in(taskIds.toArray())).exec(db);
var mapFromTimesToTasks = new HashMap<Long,HashSet<Long>>();
@ -36,7 +35,9 @@ public class SqliteDb implements TimeDb { @@ -36,7 +35,9 @@ public class SqliteDb implements TimeDb {
mapFromTimesToTasks.computeIfAbsent(timeId, k -> new HashSet<>()).add(taskId);
}
rs.close();
rs = select(ALL).from(TABLE_TIMES).where(ID,in(mapFromTimesToTasks.keySet().toArray())).exec(db);
var query = select(ALL).from(TABLE_TIMES).where(ID,in(mapFromTimesToTasks.keySet().toArray()));
if (!showClosed) query.where(STATE,lessThan(Complete.code()));
rs = query.exec(db);
var times = new HashMap<Long,Time>();
while (rs.next()) {
var time = Time.of(rs);
@ -45,15 +46,17 @@ public class SqliteDb implements TimeDb { @@ -45,15 +46,17 @@ public class SqliteDb implements TimeDb {
}
rs.close();
return times;
} catch (SQLException e) {
} catch (Exception e) {
throw new UmbrellaException("Failed to load times for task list");
}
}
@Override
public HashMap<Long, Time> listUserTimes(long userId) {
public HashMap<Long, Time> listUserTimes(long userId, boolean showClosed) {
try {
var rs = select(ALL).from(TABLE_TIMES).where(USER_ID,equal(userId)).exec(db);
var query = select(ALL).from(TABLE_TIMES).where(USER_ID,equal(userId));
if (!showClosed) query.where(STATE,lessThan(Complete.code()));
var rs = query.exec(db);
var times = new HashMap<Long,Time>();
while (rs.next()) {
var time = Time.of(rs);

4
time/src/main/java/de/srsoftware/umbrella/time/TimeDb.java

@ -7,7 +7,7 @@ import java.util.Collection; @@ -7,7 +7,7 @@ import java.util.Collection;
import java.util.HashMap;
public interface TimeDb {
HashMap<Long,Time> listTimes(Collection<Long> taskIds) throws UmbrellaException;
HashMap<Long,Time> listTimes(Collection<Long> taskIds, boolean showClosed) throws UmbrellaException;
HashMap<Long,Time> listUserTimes(long userId);
HashMap<Long,Time> listUserTimes(long userId, boolean showClosed);
}

65
time/src/main/java/de/srsoftware/umbrella/time/TimeModule.java

@ -4,12 +4,10 @@ package de.srsoftware.umbrella.time; @@ -4,12 +4,10 @@ package de.srsoftware.umbrella.time;
import static de.srsoftware.umbrella.core.ConnectionProvider.connect;
import static de.srsoftware.umbrella.core.Constants.*;
import static de.srsoftware.umbrella.core.Paths.LIST;
import static de.srsoftware.umbrella.core.ResponseCode.HTTP_NOT_IMPLEMENTED;
import static de.srsoftware.umbrella.core.Util.mapValues;
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.forbidden;
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.missingFieldException;
import static de.srsoftware.umbrella.time.Constants.*;
import static java.util.function.Predicate.not;
import static java.util.stream.Collectors.toSet;
import com.sun.net.httpserver.HttpExchange;
import de.srsoftware.configuration.Configuration;
@ -23,6 +21,7 @@ import de.srsoftware.umbrella.core.model.*; @@ -23,6 +21,7 @@ import de.srsoftware.umbrella.core.model.*;
import java.io.IOException;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
public class TimeModule extends BaseHandler implements TimeService {
@ -82,54 +81,24 @@ public class TimeModule extends BaseHandler implements TimeService { @@ -82,54 +81,24 @@ public class TimeModule extends BaseHandler implements TimeService {
}
private boolean getUserTimes(UmbrellaUser user, HttpExchange ex) throws IOException {
// TODO
var taskIds = new HashSet<Long>();
Set<Long> taskIds = new HashSet<>();
Map<Long, Project> projects = projectService().listUserProjects(user.id(), true);
for (var pid : projects.keySet()) taskIds.addAll(taskService().listProjectTasks(pid).keySet());
var times = timeDb.listTimes(taskIds);
times.putAll(timeDb.listUserTimes(user.id()));
return sendContent(ex,mapValues(times));
}
/*
{
1 : {
name: Projekt 1
id: 1
times: {
3:{
name: time 3
start: 123456
end: 78901
},
4:{
name: time 4
start: 234567
end: 890123
tasks:{
5:{
name: task5
},
6:{
name: task6
}
}
}
}
},
2: {
name: Projekt 2
id: 2
times: {
7:{
name: time 7
start: 456789
end: 012345
}
}
boolean showClosed = false;
var times = timeDb.listTimes(taskIds, showClosed);
times.putAll(timeDb.listUserTimes(user.id(), showClosed));
taskIds = times.values().stream().map(Time::taskIds).flatMap(Collection::stream).collect(toSet());
var tasks = taskService().load(taskIds);
var result = new HashMap<Long,Map<String,Object>>();
for (var entry : times.entrySet()) {
var time = entry.getValue();
var map = time.toMap();
map.remove(TASK_IDS);
map.put(TASKS,time.taskIds().stream().collect(Collectors.toMap(tid -> tid, tid -> tasks.get(tid).name())));
result.put(entry.getKey(),map);
}
return sendContent(ex,result);
}
*/
private boolean listTimes(HttpExchange ex, UmbrellaUser user) throws IOException, UmbrellaException {
var json = json(ex);
@ -141,7 +110,7 @@ public class TimeModule extends BaseHandler implements TimeService { @@ -141,7 +110,7 @@ public class TimeModule extends BaseHandler implements TimeService {
long projectId = pid.longValue();
Map<Long,Task> tasksOfProject = taskService().listProjectTasks(projectId);
List<Map<String, Object>> times = timeDb.listTimes(tasksOfProject.keySet())
List<Map<String, Object>> times = timeDb.listTimes(tasksOfProject.keySet(), true)
.entrySet().stream()
.filter(entry -> !entry.getValue().isClosed())
.sorted(Comparator.comparing(entry ->entry.getValue().start()))

Loading…
Cancel
Save