Added link in Action logs table

This commit is contained in:
Francesco 2023-09-30 14:52:14 +02:00
parent cb7e18a920
commit fd2728083b
3 changed files with 30 additions and 7 deletions

View File

@ -280,7 +280,7 @@ public class DefaultDbAdminController {
attr.addFlashAttribute("error", e.getMessage());
}
saveAction(new UserAction(schema.getTableName(), id, "DELETE"));
saveAction(new UserAction(schema.getTableName(), id, "DELETE", schema.getClassName()));
return "redirect:/" + properties.getBaseUrl() + "/model/" + className;
}
@ -310,7 +310,7 @@ public class DefaultDbAdminController {
attr.addFlashAttribute("message", "Deleted " + countDeleted + " of " + ids.length + " items");
for (String id : ids) {
saveAction(new UserAction(schema.getTableName(), id, "DELETE"));
saveAction(new UserAction(schema.getTableName(), id, "DELETE", schema.getClassName()));
}
return "redirect:/" + properties.getBaseUrl() + "/model/" + className;
@ -375,7 +375,7 @@ public class DefaultDbAdminController {
repository.attachManyToMany(schema, newPrimaryKey, multiValuedParams);
pkValue = newPrimaryKey.toString();
attr.addFlashAttribute("message", "Item created successfully.");
saveAction(new UserAction(schema.getTableName(), pkValue, "CREATE"));
saveAction(new UserAction(schema.getTableName(), pkValue, "CREATE", schema.getClassName()));
} catch (DataIntegrityViolationException e) {
attr.addFlashAttribute("errorTitle", "Unable to INSERT row");
attr.addFlashAttribute("error", e.getMessage());
@ -399,7 +399,7 @@ public class DefaultDbAdminController {
repository.update(schema, params, files);
repository.attachManyToMany(schema, pkValue, multiValuedParams);
attr.addFlashAttribute("message", "Item saved successfully.");
saveAction(new UserAction(schema.getTableName(), pkValue, "EDIT"));
saveAction(new UserAction(schema.getTableName(), pkValue, "EDIT", schema.getClassName()));
} catch (DataIntegrityViolationException e) {
attr.addFlashAttribute("errorTitle", "Unable to UPDATE row (no changes applied)");
attr.addFlashAttribute("error", e.getMessage());
@ -415,7 +415,7 @@ public class DefaultDbAdminController {
Object newPrimaryKey = repository.create(schema, params, files, pkValue);
repository.attachManyToMany(schema, newPrimaryKey, multiValuedParams);
attr.addFlashAttribute("message", "Item created successfully");
saveAction(new UserAction(schema.getTableName(), pkValue, "CREATE"));
saveAction(new UserAction(schema.getTableName(), pkValue, "CREATE", schema.getClassName()));
} catch (DataIntegrityViolationException e) {
attr.addFlashAttribute("errorTitle", "Unable to INSERT row (no changes applied)");
attr.addFlashAttribute("error", e.getMessage());

View File

@ -2,6 +2,7 @@ package tech.ailef.dbadmin.internal.model;
import java.time.LocalDateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.datetime.standard.DateTimeFormatterFactory;
import jakarta.persistence.Column;
@ -10,6 +11,9 @@ import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Lob;
import jakarta.persistence.Transient;
import tech.ailef.dbadmin.external.DbAdmin;
import tech.ailef.dbadmin.external.dbmapping.DbObjectSchema;
/**
* An action executed by any user from the web UI.
@ -28,6 +32,9 @@ public class UserAction {
@Column(nullable = false)
private String sql;
@Column(nullable = false)
private String javaClass;
@Column(nullable = false)
private String onTable;
@ -40,9 +47,10 @@ public class UserAction {
public UserAction() {
}
public UserAction(String onTable, String primaryKey, String actionType) {
public UserAction(String onTable, String primaryKey, String actionType, String javaClass) {
this.createdAt = LocalDateTime.now();
this.sql = "SQL TODO";
this.javaClass = javaClass;
this.onTable = onTable;
this.actionType = actionType;
this.primaryKey = primaryKey;
@ -99,4 +107,12 @@ public class UserAction {
public String getFormattedDate() {
return new DateTimeFormatterFactory("YYYY-MM-dd HH:mm:ss").createDateTimeFormatter().format(createdAt);
}
public String getJavaClass() {
return javaClass;
}
public void setJavaClass(String javaClass) {
this.javaClass = javaClass;
}
}

View File

@ -109,7 +109,14 @@
</td>
<td th:text="${entry.getOnTable()}">
</td>
<td th:text="${entry.getPrimaryKey()}">
<td>
<th:block th:if="${entry.getActionType() != 'DELETE'}">
<a th:href="|/${baseUrl}/model/${entry.getJavaClass()}/show/${entry.getPrimaryKey()}|"
th:text="${entry.getPrimaryKey()}"></a>
</th:block>
<th:block th:if="${entry.getActionType() == 'DELETE'}">
<span th:text="${entry.getPrimaryKey()}"></span>
</th:block>
</td>
<td th:text="${entry.getFormattedDate()}">
</td>