From: David ‘Bombe’ Roden Date: Tue, 31 Jul 2012 05:09:04 +0000 (+0200) Subject: Add functions to manage groups of an artist. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=9d70913276805a0d7e0508a2aac9f2684d4d0d69;p=demoscenemusic.git Add functions to manage groups of an artist. --- diff --git a/src/main/java/net/pterodactylus/demoscenemusic/page/admin/EditArtistPage.java b/src/main/java/net/pterodactylus/demoscenemusic/page/admin/EditArtistPage.java index 8c141fa..e737e60 100644 --- a/src/main/java/net/pterodactylus/demoscenemusic/page/admin/EditArtistPage.java +++ b/src/main/java/net/pterodactylus/demoscenemusic/page/admin/EditArtistPage.java @@ -17,8 +17,11 @@ package net.pterodactylus.demoscenemusic.page.admin; +import java.util.Collection; + import net.pterodactylus.demoscenemusic.core.Core; import net.pterodactylus.demoscenemusic.data.Artist; +import net.pterodactylus.demoscenemusic.data.Group; import net.pterodactylus.demoscenemusic.page.ServletRequest; import net.pterodactylus.util.database.DatabaseException; import net.pterodactylus.util.template.Template; @@ -59,19 +62,37 @@ public class EditArtistPage extends AdminBasePage { protected void processTemplate(TemplateContext templateContext, ServletRequest request) throws RedirectException { super.processTemplate(templateContext, request); String id = request.getServletRequest().getParameter("id"); - /* TODO - check for null. */ - Artist artist; try { - artist = getCore().getDataManager().getArtistById(id); + Artist artist = getCore().getDataManager().getArtistById(id); /* TODO - check for null. */ templateContext.set("artist", artist); if (request.getMethod() == Method.POST) { String name = request.getServletRequest().getParameter("name"); - artist.setName(name); + if ((name != null) && (name.trim().length() > 0)) { + artist.setName(name); + } /* process property changes. */ processProperties(request, artist); + /* check for new group. */ + if ("true".equals(request.getServletRequest().getParameter("add-group"))) { + String groupId = request.getServletRequest().getParameter("group"); + Group group = getCore().getDataManager().getGroupById(groupId); + Collection groups = artist.getGroups(); + groups.add(group); + artist.setGroups(groups); + } + + /* check for deleted groups. */ + if ("true".equals(request.getServletRequest().getParameter("delete-group"))) { + String groupId = request.getServletRequest().getParameter("group"); + Group group = getCore().getDataManager().getGroupById(groupId); + Collection groups = artist.getGroups(); + groups.remove(group); + artist.setGroups(groups); + } + getCore().getDataManager().saveArtist(artist); throw new RedirectException("admin.edit-artist?id=" + artist.getId()); } diff --git a/src/main/resources/templates/admin.edit-artist b/src/main/resources/templates/admin.edit-artist index c63d238..77d2d35 100644 --- a/src/main/resources/templates/admin.edit-artist +++ b/src/main/resources/templates/admin.edit-artist @@ -26,6 +26,44 @@ +

Groups

+ +<%foreach artist.groups group> + +
+ + + + +
+ <%group.name|html> edit +
+ + +
+ +<%foreachelse> +

This artists does not belong to any groups.

+<%/foreach> + +

Add a Group

+ +
+ + + +
+ Add Group: + +
+ + +
+

Tracks

<%foreach artist.tracks track>