versionsLog, fix activity view

This commit is contained in:
KennyTV 2020-08-21 11:55:47 +02:00
parent 869b324cbe
commit 58e25b900b
No known key found for this signature in database
GPG Key ID: 6BE3B555EBC5982B
7 changed files with 80 additions and 76 deletions

View File

@ -90,8 +90,14 @@ public class VersionsController extends HangarController {
}
@RequestMapping("/{author}/{slug}/versionLog")
public Object showLog(@PathVariable Object author, @PathVariable Object slug, @RequestParam Object versionString) {
return null; // TODO implement showLog request controller
public ModelAndView showLog(@PathVariable String author, @PathVariable String slug, @RequestParam String versionString) {
ModelAndView mv = new ModelAndView("projects/versions/log");
ProjectData projectData = projectService.getProjectData(author, slug);
ProjectVersionsTable version = versionService.getVersion(projectData.getProject().getId(), versionString);
mv.addObject("project", projectData);
mv.addObject("version", version);
mv.addObject("visibilityChanges", versionService.getVersionVisibilityChanges(version.getId()));
return fillModel(mv);
}
@GetMapping("/{author}/{slug}/versions")

View File

@ -2,9 +2,9 @@ package me.minidigger.hangar.db.dao;
import me.minidigger.hangar.db.model.ProjectVersionVisibilityChangesTable;
import me.minidigger.hangar.db.model.ProjectVisibilityChangesTable;
import org.checkerframework.checker.units.qual.Time;
import org.jdbi.v3.sqlobject.config.KeyColumn;
import org.jdbi.v3.sqlobject.config.RegisterBeanMapper;
import org.jdbi.v3.sqlobject.config.ValueColumn;
import org.jdbi.v3.sqlobject.customizer.BindBean;
import org.jdbi.v3.sqlobject.customizer.Timestamped;
import org.jdbi.v3.sqlobject.statement.GetGeneratedKeys;
@ -28,16 +28,21 @@ public interface VisibilityDao {
@Timestamped
@GetGeneratedKeys
@SqlUpdate("INSERT INTO project_version_visibility_changes (created_at, created_by, version_id, comment, resolved_at, resolved_by, visibility) " +
"VALUES (:now, :createdBy, :versionId, :comment, :resolvedAt, :resolvedBy, :visibility)")
"VALUES (:now, :createdBy, :versionId, :comment, :resolvedAt, :resolvedBy, :visibility)")
ProjectVersionVisibilityChangesTable insert(@BindBean ProjectVersionVisibilityChangesTable projectVersionVisibilityChangesTable);
@SqlUpdate("UPDATE project_visibility_changes SET resolved_at = :resolvedAt, resolved_by = :resolvedBy") // I think these are the only two things that change after the fact
@SqlUpdate("UPDATE project_visibility_changes SET resolved_at = :resolvedAt, resolved_by = :resolvedBy")
// I think these are the only two things that change after the fact
void update(@BindBean ProjectVisibilityChangesTable projectVisibilityChangesTable);
@KeyColumn("user_name")
@SqlQuery("SELECT pvc.*, u.name user_name FROM project_visibility_changes pvc LEFT OUTER JOIN users u ON pvc.created_by = u.id WHERE project_id = :projectId ORDER BY created_at DESC LIMIT 1")
Map.Entry<String, ProjectVisibilityChangesTable> getLatestProjectVisibilityChange(long projectId);
@ValueColumn("user_name")
@SqlQuery("SELECT pvc.*, u.name user_name FROM project_version_visibility_changes pvc RIGHT OUTER JOIN users u ON pvc.created_by = u.id WHERE version_id = :versionId ORDER BY created_at")
Map<ProjectVersionVisibilityChangesTable, String> getProjectVersionVisibilityChanges(long versionId);
@Timestamped
@SqlUpdate("UPDATE project_visibility_changes " +
"SET resolved_at = :now, resolved_by = :userId " +
@ -48,10 +53,10 @@ public interface VisibilityDao {
@Timestamped
@SqlUpdate("UPDATE project_version_visibility_changes " +
"SET resolved_at = :now, resolved_by = :userId " +
"FROM" +
" (SELECT version_id FROM project_version_visibility_changes WHERE version_id = :versionId AND resolved_at IS NULL AND resolved_by IS NULL ORDER BY created_at LIMIT 1) as subquery " +
"WHERE project_version_visibility_changes.version_id = subquery.version_id")
"SET resolved_at = :now, resolved_by = :userId " +
"FROM" +
" (SELECT version_id FROM project_version_visibility_changes WHERE version_id = :versionId AND resolved_at IS NULL AND resolved_by IS NULL ORDER BY created_at LIMIT 1) as subquery " +
"WHERE project_version_visibility_changes.version_id = subquery.version_id")
void updateLatestVersionChange(long userId, long versionId);
}

View File

@ -45,13 +45,13 @@ public enum Visibility {
@Override
@JsonValue
public String toString() {
return String.valueOf(name);
return name;
}
@JsonCreator
public static Visibility fromValue(String text) {
for (Visibility b : Visibility.values()) {
if (String.valueOf(b.name).equals(text)) {
if (b.name.equals(text)) {
return b;
}
}

View File

@ -1,10 +1,13 @@
package me.minidigger.hangar.service;
import me.minidigger.hangar.db.dao.HangarDao;
import me.minidigger.hangar.db.dao.ProjectDao;
import me.minidigger.hangar.db.dao.ProjectVersionDao;
import me.minidigger.hangar.db.dao.VisibilityDao;
import me.minidigger.hangar.db.model.ProjectChannelsTable;
import me.minidigger.hangar.db.model.ProjectVersionTagsTable;
import me.minidigger.hangar.db.model.ProjectVersionVisibilityChangesTable;
import me.minidigger.hangar.db.model.ProjectVersionsTable;
import me.minidigger.hangar.db.model.ProjectsTable;
import me.minidigger.hangar.model.TagColor;
import me.minidigger.hangar.model.Visibility;
@ -21,10 +24,6 @@ import me.minidigger.hangar.util.HangarException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import me.minidigger.hangar.db.dao.HangarDao;
import me.minidigger.hangar.db.dao.ProjectVersionDao;
import me.minidigger.hangar.db.model.ProjectVersionsTable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -50,7 +49,7 @@ public class VersionService {
}
public ProjectVersionsTable getVersion(long projectId, String versionString) {
return versionDao.get().getProjectVersion(projectId,"", versionString);
return versionDao.get().getProjectVersion(projectId, "", versionString);
}
public ProjectVersionsTable getVersion(String author, String slug, String versionString) {
@ -112,8 +111,7 @@ public class VersionService {
UserData approveUser = userService.getUserData(projectVersion.getReviewerId());
if (approveUser == null) {
approvedBy = "Unknown";
}
else {
} else {
approvedBy = approveUser.getUser().getName();
}
}
@ -130,4 +128,8 @@ public class VersionService {
dependencies
);
}
public Map<ProjectVersionVisibilityChangesTable, String> getVersionVisibilityChanges(long versionId) {
return visibilityDao.get().getProjectVersionVisibilityChanges(versionId);
}
}

View File

@ -7,7 +7,7 @@
<tbody>
<tr>
<td style="padding: 3px;">
<i class="fas fa-circle channel-id" style="color: ${Color.getById(0).getHex()}="></i>
<i class="fas fa-circle channel-id" style="color: ${Color.getById(0).getHex()}"></i>
</td>
<td style="padding: 3px;">
<i class="fas fa-circle channel-id" style="color: ${Color.getById(1).getHex()}"></i>
@ -49,5 +49,4 @@
</tr>
</tbody>
</table>
</#macro>
</#macro>

View File

@ -2,60 +2,52 @@
<#import "*/utils/hangar.ftlh" as hangar />
<#import "*/layout/base.ftlh" as base />
@import controllers.sugar.Requests.OreRequest
@import ore.OreConfig
@import ore.db.Model
@import ore.markdown.MarkdownRenderer
@import ore.models.admin.VersionVisibilityChange
@import ore.models.project.{Project, Version}
@import ore.models.user.User
@import util.StringFormatterUtils._
@import util.syntax._
@(project: Project, version: Version, visibilityChanges: Seq[(Model[VersionVisibilityChange], Option[User])])(implicit messages: Messages, request: OreRequest[_], config: OreConfig, flash: Flash, renderer: MarkdownRenderer, assetsFinder: AssetsFinder)
<#assign message><@spring.messageArgs "version.log.logger.title" project.namespace /></#assign>
<@base.base title=message>
<div class="row">
<div class="col-md-12">
<h1><@spring.message "version.log.visibility.title" /> <a href="${routes.getRouteUrl("versions.show", project.ownerName, project.slug, version.versionString)}">${project.ownerName}/${project.slug}/versions/${version.versionString}</a></h1>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title pull-left"><@spring.message "version.log.visibility.title" /></h4>
<div class="clearfix"></div>
</div>
<table class="table table-condensed setting-no-border table-review-log">
<thead>
<tr>
<th>State</th>
<th>Time</th>
<th>Comment</th>
<th>Set by</th>
</tr>
</thead>
<tbody>
<#if visibilityChanges.isEmpty>
<tr><td>No entries founds</td></tr>
</#if>
@visibilityChanges.reverse.map { case (entry, createdBy) =>
<tr>
<td>${entry.visibility}</td>
<td>${entry.createdAt?string.long}</td>
<td>${entry.obj.render}</td>
<#if createdBy??>
<td>${createdBy.name}</td>
<#else>
<td>Unknown</td>
<div class="row">
<div class="col-md-12">
<h1><@spring.message "version.log.visibility.title" /> <a
href="${routes.getRouteUrl("versions.show", project.project.name, project.project.slug, version.versionString)}">${project.project.name}
/${project.project.slug}/versions/${version.versionString}</a></h1>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title pull-left"><@spring.message "version.log.visibility.title" /></h4>
<div class="clearfix"></div>
</div>
<table class="table table-condensed setting-no-border table-review-log">
<thead>
<tr>
<th>State</th>
<th>Time</th>
<th>Comment</th>
<th>Set by</th>
</tr>
</thead>
<tbody>
<#if !visibilityChanges?has_content>
<tr>
<td>No entries founds</td>
</tr>
</#if>
<#list visibilityChanges as entry, createdBy>
<tr>
<td>${entry.visibility}</td>
<td>${utils.prettifyDateTime(entry.createdAt)}</td>
<td>${markdownService.render(entry.comment)}</td>
<#if createdBy??>
<td>${createdBy}</td>
<#else>
<td>Unknown</td>
</#if>
</tr>
}
</tbody>
</table>
</div>
</div>
</div>
</tr>
</#list>
</tbody>
</table>
</div>
</div>
</div>
</@base.base>

View File

@ -29,7 +29,7 @@
<#if activity.class.simpleName == "ReviewActivity">
<tr>
<td>Review approved</td>
<td>${utils.prettifyDateTime(activity.endedAt!OffsetDateTime.MIN))}</td>
<td>${utils.prettifyDateTime(activity.endedAt!OffsetDateTime.MIN)}</td>
<td>for:
<a href="${routes.getRouteUrl("reviews.showReviews", activity.getProject().getOwner(), activity.getProject().getSlug(), activity.id)}">
${activity.getProject().getOwner()} / ${activity.getProject().getSlug()}
@ -39,7 +39,7 @@
<#elseif activity.class.simpleName = "FlagActivity">
<tr>
<td>Flag resolved</td>
<td>${utils.prettifyDateTime(activity.resolvedAt!OffsetDateTime.MIN))}</td> <#--TODO: activity end datetime needs to be moved to abstract Activity-->
<td>${utils.prettifyDateTime(activity.resolvedAt!OffsetDateTime.MIN)}</td> <#--TODO: activity end datetime needs to be moved to abstract Activity-->
<td>for:
<a href="${routes.getRouteUrl("projects.show", activity.getProject().getSlug(), activity.getProject().getSlug())}">
${activity.getProject().getOwner()} / ${activity.getProject().getSlug()}