Channel list

This commit is contained in:
KennyTV 2020-08-07 13:33:45 +02:00
parent 83b6ec1f27
commit 9fc8dcaa88
No known key found for this signature in database
GPG Key ID: 6BE3B555EBC5982B
3 changed files with 138 additions and 118 deletions

View File

@ -1,36 +1,61 @@
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.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.servlet.ModelAndView;
@Controller
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")
@GetMapping("/{author}/{slug}/channels")
public Object showList(@PathVariable Object author, @PathVariable Object slug) {
return null; // TODO implement showList request controller
public ModelAndView showList(@PathVariable String author, @PathVariable String slug) {
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")
@PostMapping("/{author}/{slug}/channels")
public Object create(@PathVariable Object author, @PathVariable Object slug) {
return null; // TODO implement create request controller
public ModelAndView create(@PathVariable String author, @PathVariable String slug) {
// TODO implement create request controller
return new ModelAndView("redirect:" + routeHelper.getRouteUrl("channels.showList", author, slug));
}
@Secured("ROLE_USER")
@PostMapping("/{author}/{slug}/channels/{channel}")
public Object save(@PathVariable Object author, @PathVariable Object slug, @PathVariable Object channel) {
return null; // TODO implement save request controller
public ModelAndView save(@PathVariable String author, @PathVariable String slug, @PathVariable String channel) {
// TODO implement save request controller
return new ModelAndView("redirect:" + routeHelper.getRouteUrl("channels.showList", author, slug));
}
@Secured("ROLE_USER")
@PostMapping("/{author}/{slug}/channels/{channel}/delete")
public Object delete(@PathVariable Object author, @PathVariable Object slug, @PathVariable Object channel) {
return null; // TODO implement delete request controller
public ModelAndView delete(@PathVariable String author, @PathVariable String slug, @PathVariable String channel) {
// TODO implement delete request controller
return new ModelAndView("redirect:" + routeHelper.getRouteUrl("channels.showList", author, slug));
}
}

View File

@ -342,7 +342,6 @@ public class ProjectsController extends HangarController {
ModelAndView mv = new ModelAndView("projects/admin/notes");
ProjectData projectData = projectService.getProjectData(author, slug);
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")));
return fillModel(mv);
}

View File

@ -5,134 +5,130 @@
<#import "*/utils/form.ftlh" as form>
<#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>
<script type="text/javascript" src="<@hangar.url "javascripts/channelManage.js" />"></script>
<script @CSPNonce.attr>
PROJECT_OWNER = '${p.project.ownerName}';
PROJECT_SLUG = '${p.project.slug}';
$(function() {
initChannelManager(
"#channel-new", "", "${config.defaultChannelColor.hex}", "New channel",
"${routes.getRouteUrl("channels.create", p.project.ownerName, p.project.slug)}",
"post", "Create channel", false
);
});
<script <#--@CSPNonce.attr-->>
PROJECT_OWNER = '${p.project.ownerName}';
PROJECT_SLUG = '${p.project.slug}';
$(function () {
initChannelManager(
<#-- todo config entry -->
"#channel-new", "", "${config.defaultChannelColor.hex}", "New channel",
"${routes.getRouteUrl("channels.create", p.project.ownerName, p.project.slug)}",
"post", "Create channel", false
);
});
</script>
</#assign>
<#assign message><@spring.messageArgs code="channel.list.title" args=[p.project.ownerName, p.project.slug] /></#assign>
<@base.base title=message additionalScripts=scriptsVar>
<div class="row">
<div class="col-md-6 col-md-offset-3">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><@spring.message "channel.list.title" /></h3>
</div>
<div class="panel-body">
<p class="minor create-blurb">
<@spring.message "channel.list.description" />
</p>
<div class="col-md-6 col-md-offset-3">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><@spring.message "channel.list.title" /></h3>
</div>
<div class="panel-body">
<p class="minor create-blurb">
<@spring.message "channel.list.description" />
</p>
<table class="table no-border centered">
<tbody>
@channels.map { case (channel, versions) =>
<tr>
<td>
<div class="channel" 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>
<#if channels.size gt 1>
<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}">
<table class="table no-border centered">
<tbody>
<#list channels as channel>
<tr>
<td>
<div class="channel"
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>
<#if channels?size gt 1>
<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">
<@csrf.formField />
</@form.form>
</#if>
Delete
</div>
</td>
<@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>
<script @CSPNonce.attr>
$(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"
Delete
</div>
</td>
</#if>
<script <#--@CSPNonce.attr-->>
$(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)}",
"post", "Save changes", ${channel.isNonReviewed}
);
});
</script>
</tr>
}
</tbody>
</table>
<a href="${routes.getRouteUrl("versions.showList", p.project.ownerName, p.project.slug)}"
class="pull-left btn btn-default">
<i class="fas fa-arrow-left"></i>
</a>
<a href="#" id="channel-new" class="pull-right btn btn-primary"
<#if channels.size gte config.ore.projects.maxChannels>
disabled data-toggle="tooltip" data-placement="left"
title="<@spring.message "channel.edit.maxReached" />"
<#else>
data-toggle="modal" data-target="#channel-settings"
</#if>
>
<i class="fas fa-plus"></i>
</a>
<@modalManage.modalManage />
</div>
"post", "Save changes", ${channel.isNonReviewed?string('true', 'false')}
);
});
</script>
</tr>
</#list>
</tbody>
</table>
<a href="${routes.getRouteUrl("versions.showList", p.project.ownerName, p.project.slug)}"
class="pull-left btn btn-default">
<i class="fas fa-arrow-left"></i>
</a>
<a href="#" id="channel-new" class="pull-right btn btn-primary"
<#if channels?size gte config.projects.maxChannels>
disabled data-toggle="tooltip" data-placement="left"
title="<@spring.message "channel.edit.maxReached" />"
<#else>
data-toggle="modal" data-target="#channel-settings"
</#if>
>
<i class="fas fa-plus"></i>
</a>
<@modalManage.modalManage />
</div>
</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">&times;</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 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">&times;</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>
</@base.base>