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,21 +5,14 @@
<#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>
<script <#--@CSPNonce.attr-->>
PROJECT_OWNER = '${p.project.ownerName}';
PROJECT_SLUG = '${p.project.slug}';
$(function() {
$(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
@ -30,7 +23,6 @@
<#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">
@ -44,15 +36,18 @@
<table class="table no-border centered">
<tbody>
@channels.map { case (channel, versions) =>
<#list channels as channel>
<tr>
<td>
<div class="channel" style="background-color: ${channel.color.hex}">${channel.name}</div>
<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>
<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>
<#if channels?size gt 1>
<td>
<div class="btn btn-sm yellow"
<#if versions gt 0>
@ -72,19 +67,19 @@
</div>
</td>
</#if>
<script @CSPNonce.attr>
$(function() {
<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}
"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)}"
@ -92,7 +87,7 @@
<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>
<#if channels?size gte config.projects.maxChannels>
disabled data-toggle="tooltip" data-placement="left"
title="<@spring.message "channel.edit.maxReached" />"
<#else>
@ -112,7 +107,8 @@
<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" />">
<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>
@ -128,7 +124,7 @@
<@spring.message "general.cancel" />
</button>
<form method="post" action="#" class="form-channel-delete">
@CSRF.formField
<@csrf.formField />
<button type="submit" class="btn btn-danger"><@spring.message "channel.delete" /></button>
</form>
</div>