implemented loading and display of journal.
Nächste Schritte: der Hinweis "you can view/edit xxx at https://…" sollte zwar in der Mail auftauchen, nicht aber im Journal – hier muss also nochmal nachgearbeitet werden Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -1,21 +1,23 @@
|
||||
/* © SRSoftware 2025 */
|
||||
package de.srsoftware.umbrella.messagebus.events;
|
||||
|
||||
import de.srsoftware.tools.Mappable;
|
||||
import de.srsoftware.umbrella.core.constants.Field;
|
||||
import de.srsoftware.umbrella.core.model.ObjectWithId;
|
||||
import static de.srsoftware.umbrella.core.Util.mapMarkdown;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.*;
|
||||
import static java.time.ZoneOffset.UTC;
|
||||
|
||||
import de.srsoftware.umbrella.core.model.ObjectWithId;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Map;
|
||||
|
||||
import static de.srsoftware.umbrella.core.constants.Field.*;
|
||||
|
||||
public class JournalEntry extends ObjectWithId {
|
||||
|
||||
long timestamp, userId, entityId;
|
||||
LocalDateTime timestamp;
|
||||
long userId, entityId;
|
||||
String action, description, module;
|
||||
|
||||
public JournalEntry(long id, long timestamp, long userId, String module, long entityId, String action, String description){
|
||||
public JournalEntry(long id, LocalDateTime timestamp, long userId, String module, long entityId, String action, String description){
|
||||
super(id);
|
||||
this.timestamp = timestamp;
|
||||
this.userId = userId;
|
||||
@@ -26,7 +28,7 @@ public class JournalEntry extends ObjectWithId {
|
||||
}
|
||||
public static JournalEntry of(ResultSet rs) throws SQLException {
|
||||
var id = rs.getLong(ID);
|
||||
var timestamp = rs.getLong(TIMESTAMP);
|
||||
var timestamp = LocalDateTime.ofEpochSecond(rs.getLong(TIMESTAMP),0, UTC);
|
||||
var userId = rs.getLong(USER_ID);
|
||||
var module = rs.getString(MODULE);
|
||||
var entityId = rs.getLong(ENTITY_ID);
|
||||
@@ -36,6 +38,10 @@ public class JournalEntry extends ObjectWithId {
|
||||
return new JournalEntry(id, timestamp, userId, module, entityId, action, description);
|
||||
}
|
||||
|
||||
public long userId(){
|
||||
return userId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> toMap() {
|
||||
return map(
|
||||
@@ -44,7 +50,7 @@ public class JournalEntry extends ObjectWithId {
|
||||
MODULE, module,
|
||||
ENTITY_ID, entityId,
|
||||
ACTION, action,
|
||||
DESCRIPTION, description
|
||||
DESCRIPTION, mapMarkdown(description)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,9 +10,6 @@ import static de.srsoftware.umbrella.messagebus.events.Event.EventType.MEMBER_AD
|
||||
|
||||
import de.srsoftware.umbrella.core.constants.Field;
|
||||
import de.srsoftware.umbrella.core.model.*;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -83,6 +83,8 @@ public class Field {
|
||||
public static final String ITEM = "item";
|
||||
public static final String ITEM_CODE = "item_code";
|
||||
|
||||
public static final String JOURNAL = "journal";
|
||||
|
||||
public static final String KEY = "key";
|
||||
|
||||
public static final String LANGUAGE = "language";
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/* © SRSoftware 2025 */
|
||||
package de.srsoftware.umbrella.core.model;
|
||||
|
||||
import de.srsoftware.tools.Mappable;
|
||||
import de.srsoftware.umbrella.core.constants.Field;
|
||||
|
||||
import java.security.InvalidParameterException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -3,7 +3,6 @@ package de.srsoftware.umbrella.core.model;
|
||||
|
||||
import static java.text.MessageFormat.format;
|
||||
|
||||
import de.srsoftware.tools.Mappable;
|
||||
import de.srsoftware.umbrella.core.constants.Field;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
@@ -4,14 +4,28 @@
|
||||
import { t } from '../../translations.svelte';
|
||||
let { module, entityId } = $props();
|
||||
|
||||
let data = $state({journal:[]});
|
||||
|
||||
async function loadJournal(){
|
||||
const url = api(`journal/${module}/${entityId}`);
|
||||
const res = await get(url);
|
||||
if (res.ok) {
|
||||
data = await res.json();
|
||||
} else error(res);
|
||||
}
|
||||
|
||||
$effect(loadJournal);
|
||||
</script>
|
||||
|
||||
...
|
||||
<ul>
|
||||
{#each data.journal as entry (entry.id)}
|
||||
<li>
|
||||
<span class="date">{entry.timestamp.replace('T',' ')}</span>
|
||||
<span class="actor">{data.user_list[entry.user_id].name}</span>:
|
||||
<span class="action">{t(entry.action)}</span>
|
||||
<div>
|
||||
{@html entry.description.rendered}
|
||||
</div>
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
|
||||
@@ -364,14 +364,15 @@
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<h3>{t('Journal')}</h3>
|
||||
<div>
|
||||
<Journal module="task" entityId={id} />
|
||||
</div>
|
||||
<h3>{t('notes')}</h3>
|
||||
<div>
|
||||
<Notes module="task" entity_id={id} />
|
||||
</div>
|
||||
<h3>{t('Journal')}</h3>
|
||||
<div>
|
||||
<Journal module="task" entityId={id} />
|
||||
</div>
|
||||
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
/* © SRSoftware 2025 */
|
||||
package de.srsoftware.umbrella.journal;
|
||||
|
||||
import de.srsoftware.umbrella.core.model.UmbrellaUser;
|
||||
import de.srsoftware.umbrella.messagebus.events.Event;
|
||||
import de.srsoftware.umbrella.messagebus.events.JournalEntry;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public interface JournalDb {
|
||||
void logEvent(Event<?> event);
|
||||
|
||||
List<JournalEntry> list(String module, long entityId, HashMap<Long, UmbrellaUser> userLoader);
|
||||
List<JournalEntry> list(String module, long entityId);
|
||||
}
|
||||
|
||||
@@ -3,8 +3,6 @@ package de.srsoftware.umbrella.journal;
|
||||
|
||||
import static de.srsoftware.umbrella.core.ConnectionProvider.connect;
|
||||
import static de.srsoftware.umbrella.core.ModuleRegistry.userService;
|
||||
import static de.srsoftware.umbrella.core.constants.Path.PARENT_CANDIDATES;
|
||||
import static de.srsoftware.umbrella.core.constants.Path.TAGGED;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.invalidField;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.missingField;
|
||||
import static de.srsoftware.umbrella.journal.Constants.CONFIG_DATABASE;
|
||||
@@ -21,12 +19,12 @@ import de.srsoftware.umbrella.core.constants.Field;
|
||||
import de.srsoftware.umbrella.core.constants.Text;
|
||||
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
|
||||
import de.srsoftware.umbrella.core.model.Token;
|
||||
import de.srsoftware.umbrella.core.model.UmbrellaUser;
|
||||
import de.srsoftware.umbrella.messagebus.EventListener;
|
||||
import de.srsoftware.umbrella.messagebus.events.Event;
|
||||
|
||||
import de.srsoftware.umbrella.messagebus.events.JournalEntry;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
|
||||
@@ -55,8 +53,14 @@ public class JournalModule extends BaseHandler implements EventListener {
|
||||
if (head == null) throw missingField(Field.ENTITY_ID);
|
||||
try {
|
||||
var entityId = Long.parseLong(head);
|
||||
var entries = journalDb.list(module, entityId, userService().loader());
|
||||
return sendContent(ex,entries); // TODO: map entries
|
||||
var entries = journalDb.list(module, entityId);
|
||||
var loader = userService().loader();
|
||||
var userMap = new HashMap<Long,Object>();
|
||||
for (var entry : entries) userMap.put(entry.userId(),loader.get(entry.userId()).toMap());
|
||||
return sendContent(ex,Map.of(
|
||||
Field.USER_LIST,userMap,
|
||||
Field.JOURNAL,entries.stream().map(JournalEntry::toMap).toList()
|
||||
));
|
||||
} catch (NumberFormatException e) {
|
||||
throw invalidField(Field.ENTITY_ID, Text.NUMBER);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
/* © SRSoftware 2025 */
|
||||
package de.srsoftware.umbrella.journal;
|
||||
|
||||
import static de.srsoftware.tools.NotImplemented.notImplemented;
|
||||
import static de.srsoftware.tools.jdbc.Condition.equal;
|
||||
import static de.srsoftware.tools.jdbc.Query.SelectQuery.ALL;
|
||||
import static de.srsoftware.tools.jdbc.Query.insertInto;
|
||||
@@ -13,20 +12,14 @@ import static de.srsoftware.umbrella.journal.Constants.TABLE_JOURNAL;
|
||||
import static java.text.MessageFormat.format;
|
||||
|
||||
import de.srsoftware.umbrella.core.BaseDb;
|
||||
import de.srsoftware.umbrella.core.constants.Field;
|
||||
import de.srsoftware.umbrella.core.constants.Module;
|
||||
import de.srsoftware.umbrella.core.constants.Text;
|
||||
import de.srsoftware.umbrella.core.model.UmbrellaUser;
|
||||
import de.srsoftware.umbrella.messagebus.events.Event;
|
||||
import de.srsoftware.umbrella.messagebus.events.JournalEntry;
|
||||
import de.srsoftware.umbrella.messagebus.events.TaskEvent;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class SqliteDb extends BaseDb implements JournalDb{
|
||||
@@ -65,7 +58,7 @@ public class SqliteDb extends BaseDb implements JournalDb{
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<JournalEntry> list(String module, long entityId, HashMap<Long, UmbrellaUser> userLoader) {
|
||||
public List<JournalEntry> list(String module, long entityId) {
|
||||
try {
|
||||
var rs = select(ALL).from(TABLE_JOURNAL).where(MODULE, equal(module)).where(ENTITY_ID,equal(entityId)).exec(db);
|
||||
var list = new ArrayList<JournalEntry>();
|
||||
|
||||
@@ -6,7 +6,6 @@ import static de.srsoftware.tools.Optionals.*;
|
||||
import static de.srsoftware.tools.Strings.uuid;
|
||||
import static de.srsoftware.umbrella.core.ConnectionProvider.connect;
|
||||
import static de.srsoftware.umbrella.core.ModuleRegistry.postBox;
|
||||
import static de.srsoftware.umbrella.core.ModuleRegistry.userService;
|
||||
import static de.srsoftware.umbrella.core.ResponseCode.*;
|
||||
import static de.srsoftware.umbrella.core.ResponseCode.HTTP_SERVER_ERROR;
|
||||
import static de.srsoftware.umbrella.core.Util.*;
|
||||
@@ -165,11 +164,15 @@ public class UserModule extends BaseHandler implements UserService {
|
||||
@Override
|
||||
public HashMap<Long, UmbrellaUser> loader() {
|
||||
return new HashMap<Long, UmbrellaUser>(){
|
||||
public UmbrellaUser get(long id) {
|
||||
@Override
|
||||
public UmbrellaUser get(Object key) {
|
||||
if (key instanceof Long id){
|
||||
var user = super.get(id);
|
||||
if (user == null) put(id, user = loadUser(id));
|
||||
return user;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user