mirror of
https://github.com/HangarMC/Hangar.git
synced 2025-03-31 16:00:39 +08:00
fixed channel list view
This commit is contained in:
parent
29d495d17d
commit
1a3af79777
@ -1,8 +1,8 @@
|
||||
package io.papermc.hangar.controller;
|
||||
|
||||
import io.papermc.hangar.model.Color;
|
||||
import io.papermc.hangar.service.project.ChannelService;
|
||||
import io.papermc.hangar.model.viewhelpers.ProjectData;
|
||||
import io.papermc.hangar.service.project.ChannelService;
|
||||
import io.papermc.hangar.service.project.ProjectService;
|
||||
import io.papermc.hangar.util.RouteHelper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -34,8 +34,7 @@ public class ChannelsController extends HangarController {
|
||||
ModelAndView mv = new ModelAndView("projects/channels/list");
|
||||
ProjectData projectData = projectService.getProjectData(author, slug);
|
||||
mv.addObject("p", projectData);
|
||||
mv.addObject("channels", channelService.getProjectChannels(projectData.getProject().getId()));
|
||||
mv.addObject("versions", projectData.getPublicVersions());
|
||||
mv.addObject("channels", channelService.getChannelsWithVersionCount(projectData.getProject().getId()));
|
||||
return fillModel(mv);
|
||||
}
|
||||
|
||||
|
@ -1,11 +1,11 @@
|
||||
package io.papermc.hangar.db.dao;
|
||||
|
||||
import io.papermc.hangar.db.model.ProjectChannelsTable;
|
||||
import io.papermc.hangar.service.project.ChannelService;
|
||||
import io.papermc.hangar.model.Color;
|
||||
|
||||
import io.papermc.hangar.service.project.ChannelService;
|
||||
import org.jdbi.v3.core.enums.EnumByOrdinal;
|
||||
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.Define;
|
||||
import org.jdbi.v3.sqlobject.customizer.Timestamped;
|
||||
@ -16,6 +16,7 @@ import org.jdbi.v3.stringtemplate4.UseStringTemplateEngine;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Repository
|
||||
@RegisterBeanMapper(ProjectChannelsTable.class)
|
||||
@ -53,4 +54,11 @@ public interface ProjectChannelDao {
|
||||
|
||||
@SqlQuery("SELECT * FROM project_channels WHERE project_id = :projectId AND (name = :channelName OR id = :channelId)")
|
||||
ProjectChannelsTable getProjectChannel(long projectId, String channelName, Long channelId);
|
||||
|
||||
@ValueColumn("version_count")
|
||||
@SqlQuery("SELECT pc.*, COUNT(pv.id) as version_count FROM project_channels pc" +
|
||||
" LEFT JOIN project_versions pv ON pc.id = pv.channel_id" +
|
||||
" WHERE pc.project_id = :projectId" +
|
||||
" GROUP BY pc.id")
|
||||
Map<ProjectChannelsTable, Integer> getChannelsWithVersionCount(long projectId);
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class ChannelService {
|
||||
@ -43,6 +44,10 @@ public class ChannelService {
|
||||
return channelDao.get().getProjectChannels(projectId);
|
||||
}
|
||||
|
||||
public Map<ProjectChannelsTable, Integer> getChannelsWithVersionCount(long projectId) {
|
||||
return channelDao.get().getChannelsWithVersionCount(projectId);
|
||||
}
|
||||
|
||||
public ProjectChannelsTable addProjectChannel(long projectId, String channelName, Color color) {
|
||||
InvalidChannelCreationReason reason = channelDao.get().validateChannelCreation(projectId, channelName, color.getValue(), hangarConfig.projects.getMaxChannels());
|
||||
checkInvalidChannelCreationReason(reason);
|
||||
|
@ -35,7 +35,7 @@
|
||||
|
||||
<table class="table no-border centered">
|
||||
<tbody>
|
||||
<#list channels as channel>
|
||||
<#list channels as channel, versions>
|
||||
<tr>
|
||||
<td>
|
||||
<div class="channel"
|
||||
@ -50,15 +50,15 @@
|
||||
<td>
|
||||
<div class="btn btn-sm yellow"
|
||||
<#if versions gt 0>
|
||||
id="channel-delete-${channel.id}" data-toggle="modal"
|
||||
data-target="#modal-delete">
|
||||
<#else>
|
||||
id="channel-delete-${channel.id}" data-channel-delete="safe-delete"
|
||||
data-channel-id="${channel.id}">
|
||||
|
||||
<@form.form method="POST" action=routes.getRouteUrl("channels.delete", p.project.ownerName, p.project.slug, channel.name)
|
||||
id="form-delete-${channel.id}"
|
||||
class="form-channel-delete">
|
||||
id="channel-delete-${channel.id}" data-toggle="modal"
|
||||
data-target="#modal-delete">
|
||||
<#else>
|
||||
id="channel-delete-${channel.id}" data-channel-delete="safe-delete"
|
||||
data-channel-id="${channel.id}"
|
||||
>
|
||||
<@form.form method="POST" action=routes.getRouteUrl("channels.delete", p.project.ownerName, p.project.slug, channel.name)
|
||||
id="form-delete-${channel.id}"
|
||||
class="form-channel-delete">
|
||||
<@csrf.formField />
|
||||
</@form.form>
|
||||
</#if>
|
||||
@ -100,32 +100,32 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="modal fade" id="modal-delete" tabindex="-1" role="dialog" aria-labelledby="label-delete">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal"
|
||||
aria-label="<@spring.message "general.close" />">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
<h4 class="modal-title" id="label-delete"><@spring.message "channel.delete" /></h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p><@spring.message "channel.delete.info" /></p>
|
||||
<p class="minor">
|
||||
<strong class="version-count"></strong> <i><@spring.message "channel.delete.info.versions" /></i>
|
||||
</p>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal">
|
||||
<@spring.message "general.cancel" />
|
||||
</button>
|
||||
<form method="post" action="#" class="form-channel-delete">
|
||||
<@csrf.formField />
|
||||
<button type="submit" class="btn btn-danger"><@spring.message "channel.delete" /></button>
|
||||
</form>
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal"
|
||||
aria-label="<@spring.message "general.close" />">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
<h4 class="modal-title" id="label-delete"><@spring.message "channel.delete" /></h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p><@spring.message "channel.delete.info" /></p>
|
||||
<p class="minor">
|
||||
<strong class="version-count"></strong> <i><@spring.message "channel.delete.info.versions" /></i>
|
||||
</p>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal">
|
||||
<@spring.message "general.cancel" />
|
||||
</button>
|
||||
<form method="post" action="#" class="form-channel-delete">
|
||||
<@csrf.formField />
|
||||
<button type="submit" class="btn btn-danger"><@spring.message "channel.delete" /></button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user