mirror of
https://github.com/HangarMC/Hangar.git
synced 2025-03-07 15:31:00 +08:00
Channel list
This commit is contained in:
parent
83b6ec1f27
commit
9fc8dcaa88
@ -1,36 +1,61 @@
|
|||||||
package me.minidigger.hangar.controller;
|
package me.minidigger.hangar.controller;
|
||||||
|
|
||||||
|
import me.minidigger.hangar.model.viewhelpers.ProjectData;
|
||||||
|
import me.minidigger.hangar.service.project.ChannelService;
|
||||||
|
import me.minidigger.hangar.service.project.ProjectService;
|
||||||
|
import me.minidigger.hangar.util.RouteHelper;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.security.access.annotation.Secured;
|
import org.springframework.security.access.annotation.Secured;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.servlet.ModelAndView;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
public class ChannelsController extends HangarController {
|
public class ChannelsController extends HangarController {
|
||||||
|
|
||||||
|
private final ProjectService projectService;
|
||||||
|
private final ChannelService channelService;
|
||||||
|
private final RouteHelper routeHelper;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public ChannelsController(ProjectService projectService, ChannelService channelService, RouteHelper routeHelper) {
|
||||||
|
this.projectService = projectService;
|
||||||
|
this.channelService = channelService;
|
||||||
|
this.routeHelper = routeHelper;
|
||||||
|
}
|
||||||
|
|
||||||
@Secured("ROLE_USER")
|
@Secured("ROLE_USER")
|
||||||
@GetMapping("/{author}/{slug}/channels")
|
@GetMapping("/{author}/{slug}/channels")
|
||||||
public Object showList(@PathVariable Object author, @PathVariable Object slug) {
|
public ModelAndView showList(@PathVariable String author, @PathVariable String slug) {
|
||||||
return null; // TODO implement showList request controller
|
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());
|
||||||
|
return fillModel(mv);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Secured("ROLE_USER")
|
@Secured("ROLE_USER")
|
||||||
@PostMapping("/{author}/{slug}/channels")
|
@PostMapping("/{author}/{slug}/channels")
|
||||||
public Object create(@PathVariable Object author, @PathVariable Object slug) {
|
public ModelAndView create(@PathVariable String author, @PathVariable String slug) {
|
||||||
return null; // TODO implement create request controller
|
// TODO implement create request controller
|
||||||
|
return new ModelAndView("redirect:" + routeHelper.getRouteUrl("channels.showList", author, slug));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Secured("ROLE_USER")
|
@Secured("ROLE_USER")
|
||||||
@PostMapping("/{author}/{slug}/channels/{channel}")
|
@PostMapping("/{author}/{slug}/channels/{channel}")
|
||||||
public Object save(@PathVariable Object author, @PathVariable Object slug, @PathVariable Object channel) {
|
public ModelAndView save(@PathVariable String author, @PathVariable String slug, @PathVariable String channel) {
|
||||||
return null; // TODO implement save request controller
|
// TODO implement save request controller
|
||||||
|
return new ModelAndView("redirect:" + routeHelper.getRouteUrl("channels.showList", author, slug));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Secured("ROLE_USER")
|
@Secured("ROLE_USER")
|
||||||
@PostMapping("/{author}/{slug}/channels/{channel}/delete")
|
@PostMapping("/{author}/{slug}/channels/{channel}/delete")
|
||||||
public Object delete(@PathVariable Object author, @PathVariable Object slug, @PathVariable Object channel) {
|
public ModelAndView delete(@PathVariable String author, @PathVariable String slug, @PathVariable String channel) {
|
||||||
return null; // TODO implement delete request controller
|
// TODO implement delete request controller
|
||||||
|
return new ModelAndView("redirect:" + routeHelper.getRouteUrl("channels.showList", author, slug));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -342,7 +342,6 @@ public class ProjectsController extends HangarController {
|
|||||||
ModelAndView mv = new ModelAndView("projects/admin/notes");
|
ModelAndView mv = new ModelAndView("projects/admin/notes");
|
||||||
ProjectData projectData = projectService.getProjectData(author, slug);
|
ProjectData projectData = projectService.getProjectData(author, slug);
|
||||||
mv.addObject("project", projectData.getProject());
|
mv.addObject("project", projectData.getProject());
|
||||||
//TODO get real notes
|
|
||||||
mv.addObject("notes", List.of(new Note().message("## 10/10\n* has everything\n* but also nothing").user("kneny")));
|
mv.addObject("notes", List.of(new Note().message("## 10/10\n* has everything\n* but also nothing").user("kneny")));
|
||||||
return fillModel(mv);
|
return fillModel(mv);
|
||||||
}
|
}
|
||||||
|
@ -5,134 +5,130 @@
|
|||||||
<#import "*/utils/form.ftlh" as form>
|
<#import "*/utils/form.ftlh" as form>
|
||||||
<#import "*/utils/csrf.ftlh" as csrf>
|
<#import "*/utils/csrf.ftlh" as csrf>
|
||||||
|
|
||||||
@import controllers.sugar.Requests.OreRequest
|
|
||||||
@import models.viewhelper.ProjectData
|
|
||||||
@import ore.OreConfig
|
|
||||||
@import ore.db.Model
|
|
||||||
@import ore.models.project.Channel
|
|
||||||
@import views.html.helper.{CSPNonce, CSRF, form}
|
|
||||||
@(p: ProjectData, channels: Seq[(Model[Channel], Int)])(implicit messages: Messages, flash: Flash, request: OreRequest[_], config: OreConfig, assetsFinder: AssetsFinder)
|
|
||||||
|
|
||||||
<#assign scriptsVar>
|
<#assign scriptsVar>
|
||||||
<script type="text/javascript" src="<@hangar.url "javascripts/channelManage.js" />"></script>
|
<script type="text/javascript" src="<@hangar.url "javascripts/channelManage.js" />"></script>
|
||||||
<script @CSPNonce.attr>
|
<script <#--@CSPNonce.attr-->>
|
||||||
PROJECT_OWNER = '${p.project.ownerName}';
|
PROJECT_OWNER = '${p.project.ownerName}';
|
||||||
PROJECT_SLUG = '${p.project.slug}';
|
PROJECT_SLUG = '${p.project.slug}';
|
||||||
$(function() {
|
$(function () {
|
||||||
initChannelManager(
|
initChannelManager(
|
||||||
"#channel-new", "", "${config.defaultChannelColor.hex}", "New channel",
|
<#-- todo config entry -->
|
||||||
"${routes.getRouteUrl("channels.create", p.project.ownerName, p.project.slug)}",
|
"#channel-new", "", "${config.defaultChannelColor.hex}", "New channel",
|
||||||
"post", "Create channel", false
|
"${routes.getRouteUrl("channels.create", p.project.ownerName, p.project.slug)}",
|
||||||
);
|
"post", "Create channel", false
|
||||||
});
|
);
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
</#assign>
|
</#assign>
|
||||||
|
|
||||||
<#assign message><@spring.messageArgs code="channel.list.title" args=[p.project.ownerName, p.project.slug] /></#assign>
|
<#assign message><@spring.messageArgs code="channel.list.title" args=[p.project.ownerName, p.project.slug] /></#assign>
|
||||||
<@base.base title=message additionalScripts=scriptsVar>
|
<@base.base title=message additionalScripts=scriptsVar>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-6 col-md-offset-3">
|
<div class="col-md-6 col-md-offset-3">
|
||||||
<div class="panel panel-default">
|
<div class="panel panel-default">
|
||||||
<div class="panel-heading">
|
<div class="panel-heading">
|
||||||
<h3 class="panel-title"><@spring.message "channel.list.title" /></h3>
|
<h3 class="panel-title"><@spring.message "channel.list.title" /></h3>
|
||||||
</div>
|
</div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
<p class="minor create-blurb">
|
<p class="minor create-blurb">
|
||||||
<@spring.message "channel.list.description" />
|
<@spring.message "channel.list.description" />
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<table class="table no-border centered">
|
<table class="table no-border centered">
|
||||||
<tbody>
|
<tbody>
|
||||||
@channels.map { case (channel, versions) =>
|
<#list channels as channel>
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<div class="channel" style="background-color: ${channel.color.hex}">${channel.name}</div>
|
<div class="channel"
|
||||||
</td>
|
style="background-color: ${channel.color.hex}">${channel.name}</div>
|
||||||
<td>
|
</td>
|
||||||
<div class="btn btn-sm yellow" data-toggle="modal" data-target="#channel-settings" id="channel-edit-${channel.id}">Edit</div>
|
<td>
|
||||||
</td>
|
<div class="btn btn-sm yellow" data-toggle="modal" data-target="#channel-settings"
|
||||||
<#if channels.size gt 1>
|
id="channel-edit-${channel.id}">Edit
|
||||||
<td>
|
</div>
|
||||||
<div class="btn btn-sm yellow"
|
</td>
|
||||||
<#if versions gt 0>
|
<#if channels?size gt 1>
|
||||||
id="channel-delete-${channel.id}" data-toggle="modal"
|
<td>
|
||||||
data-target="#modal-delete">
|
<div class="btn btn-sm yellow"
|
||||||
<#else>
|
<#if versions gt 0>
|
||||||
id="channel-delete-${channel.id}" data-channel-delete="safe-delete"
|
id="channel-delete-${channel.id}" data-toggle="modal"
|
||||||
data-channel-id="${channel.id}">
|
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)
|
<@form.form method="POST" action=routes.getRouteUrl("channels.delete", p.project.ownerName, p.project.slug, channel.name)
|
||||||
id="form-delete-${channel.id}"
|
id="form-delete-${channel.id}"
|
||||||
class="form-channel-delete">
|
class="form-channel-delete">
|
||||||
<@csrf.formField />
|
<@csrf.formField />
|
||||||
</@form.form>
|
</@form.form>
|
||||||
</#if>
|
|
||||||
Delete
|
|
||||||
</div>
|
|
||||||
</td>
|
|
||||||
</#if>
|
</#if>
|
||||||
<script @CSPNonce.attr>
|
Delete
|
||||||
$(function() {
|
</div>
|
||||||
initChannelDelete('#channel-delete-${channel.id}', '${channel.name}', ${versions});
|
</td>
|
||||||
initChannelManager(
|
</#if>
|
||||||
"#channel-edit-${channel.id}", "${channel.name}", "${channel.color.hex}",
|
<script <#--@CSPNonce.attr-->>
|
||||||
"Edit channel", "${routes.getRouteUrl("channels.save"
|
$(function () {
|
||||||
|
initChannelDelete('#channel-delete-${channel.id}', '${channel.name}', ${versions});
|
||||||
|
initChannelManager(
|
||||||
|
"#channel-edit-${channel.id}", "${channel.name}", "${channel.color.hex}",
|
||||||
|
"Edit channel", "${routes.getRouteUrl("channels.save"
|
||||||
p.project.ownerName, p.project.slug, channel.name)}",
|
p.project.ownerName, p.project.slug, channel.name)}",
|
||||||
"post", "Save changes", ${channel.isNonReviewed}
|
"post", "Save changes", ${channel.isNonReviewed?string('true', 'false')}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
</tr>
|
</tr>
|
||||||
}
|
</#list>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<a href="${routes.getRouteUrl("versions.showList", p.project.ownerName, p.project.slug)}"
|
<a href="${routes.getRouteUrl("versions.showList", p.project.ownerName, p.project.slug)}"
|
||||||
class="pull-left btn btn-default">
|
class="pull-left btn btn-default">
|
||||||
<i class="fas fa-arrow-left"></i>
|
<i class="fas fa-arrow-left"></i>
|
||||||
</a>
|
</a>
|
||||||
<a href="#" id="channel-new" class="pull-right btn btn-primary"
|
<a href="#" id="channel-new" class="pull-right btn btn-primary"
|
||||||
<#if channels.size gte config.ore.projects.maxChannels>
|
<#if channels?size gte config.projects.maxChannels>
|
||||||
disabled data-toggle="tooltip" data-placement="left"
|
disabled data-toggle="tooltip" data-placement="left"
|
||||||
title="<@spring.message "channel.edit.maxReached" />"
|
title="<@spring.message "channel.edit.maxReached" />"
|
||||||
<#else>
|
<#else>
|
||||||
data-toggle="modal" data-target="#channel-settings"
|
data-toggle="modal" data-target="#channel-settings"
|
||||||
</#if>
|
</#if>
|
||||||
>
|
>
|
||||||
<i class="fas fa-plus"></i>
|
<i class="fas fa-plus"></i>
|
||||||
</a>
|
</a>
|
||||||
<@modalManage.modalManage />
|
<@modalManage.modalManage />
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="modal fade" id="modal-delete" tabindex="-1" role="dialog" aria-labelledby="label-delete">
|
<div class="modal fade" id="modal-delete" tabindex="-1" role="dialog" aria-labelledby="label-delete">
|
||||||
<div class="modal-dialog" role="document">
|
<div class="modal-dialog" role="document">
|
||||||
<div class="modal-content">
|
<div class="modal-content">
|
||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
<button type="button" class="close" data-dismiss="modal" aria-label="<@spring.message "general.close" />">
|
<button type="button" class="close" data-dismiss="modal"
|
||||||
<span aria-hidden="true">×</span>
|
aria-label="<@spring.message "general.close" />">
|
||||||
</button>
|
<span aria-hidden="true">×</span>
|
||||||
<h4 class="modal-title" id="label-delete"><@spring.message "channel.delete" /></h4>
|
</button>
|
||||||
</div>
|
<h4 class="modal-title" id="label-delete"><@spring.message "channel.delete" /></h4>
|
||||||
<div class="modal-body">
|
</div>
|
||||||
<p><@spring.message "channel.delete.info" /></p>
|
<div class="modal-body">
|
||||||
<p class="minor">
|
<p><@spring.message "channel.delete.info" /></p>
|
||||||
<strong class="version-count"></strong> <i><@spring.message "channel.delete.info.versions" /></i>
|
<p class="minor">
|
||||||
</p>
|
<strong class="version-count"></strong> <i><@spring.message "channel.delete.info.versions" /></i>
|
||||||
</div>
|
</p>
|
||||||
<div class="modal-footer">
|
</div>
|
||||||
<button type="button" class="btn btn-default" data-dismiss="modal">
|
<div class="modal-footer">
|
||||||
<@spring.message "general.cancel" />
|
<button type="button" class="btn btn-default" data-dismiss="modal">
|
||||||
</button>
|
<@spring.message "general.cancel" />
|
||||||
<form method="post" action="#" class="form-channel-delete">
|
</button>
|
||||||
@CSRF.formField
|
<form method="post" action="#" class="form-channel-delete">
|
||||||
<button type="submit" class="btn btn-danger"><@spring.message "channel.delete" /></button>
|
<@csrf.formField />
|
||||||
</form>
|
<button type="submit" class="btn btn-danger"><@spring.message "channel.delete" /></button>
|
||||||
</div>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
</@base.base>
|
</@base.base>
|
Loading…
Reference in New Issue
Block a user