Add artist management to track.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 30 Jul 2012 13:58:27 +0000 (15:58 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 30 Jul 2012 13:58:27 +0000 (15:58 +0200)
src/main/java/net/pterodactylus/demoscenemusic/page/admin/EditTrackPage.java
src/main/resources/templates/admin.edit-track

index c8a9be2..05bf3d0 100644 (file)
 package net.pterodactylus.demoscenemusic.page.admin;
 
 import java.util.Collection;
+import java.util.List;
 
 import net.pterodactylus.demoscenemusic.core.Core;
+import net.pterodactylus.demoscenemusic.data.Artist;
 import net.pterodactylus.demoscenemusic.data.Party;
 import net.pterodactylus.demoscenemusic.data.Track;
 import net.pterodactylus.demoscenemusic.page.ServletRequest;
@@ -72,10 +74,14 @@ public class EditTrackPage extends AdminBasePage {
                        templateContext.set("track", track);
                        if (request.getMethod() == Method.POST) {
 
+                               String partyId = request.getServletRequest().getParameter("party");
+                               Party party = getCore().getDataManager().getPartyById(partyId);
+
+                               String artistId = request.getServletRequest().getParameter("artist");
+                               Artist artist = getCore().getDataManager().getArtistById(artistId);
+
                                /* check if a party should be removed. */
                                if ("true".equals(request.getServletRequest().getParameter("delete-party"))) {
-                                       String partyId = request.getServletRequest().getParameter("party");
-                                       Party party = getCore().getDataManager().getPartyById(partyId);
                                        Collection<Party> parties = track.getParties();
                                        parties.remove(party);
                                        track.setParties(parties);
@@ -83,13 +89,43 @@ public class EditTrackPage extends AdminBasePage {
 
                                /* check if a party should be added. */
                                if ("true".equals(request.getServletRequest().getParameter("add-party"))) {
-                                       String partyId = request.getServletRequest().getParameter("party");
-                                       Party party = getCore().getDataManager().getPartyById(partyId);
                                        Collection<Party> parties = track.getParties();
                                        parties.add(party);
                                        track.setParties(parties);
                                }
 
+                               if ("true".equals(request.getServletRequest().getParameter("delete-artist"))) {
+                                       List<Artist> artists = track.getArtists();
+                                       artists.remove(artist);
+                                       track.setArtists(artists);
+                               }
+
+                               if ("true".equals(request.getServletRequest().getParameter("move-up"))) {
+                                       List<Artist> artists = track.getArtists();
+                                       int index = artists.indexOf(artist);
+                                       if (index > 0) {
+                                               artists.remove(artist);
+                                               artists.add(index - 1, artist);
+                                       }
+                                       track.setArtists(artists);
+                               }
+
+                               if ("true".equals(request.getServletRequest().getParameter("move-down"))) {
+                                       List<Artist> artists = track.getArtists();
+                                       int index = artists.indexOf(artist);
+                                       if (index < (artists.size() - 1)) {
+                                               artists.remove(artist);
+                                               artists.add(index + 1, artist);
+                                       }
+                                       track.setArtists(artists);
+                               }
+
+                               if ("true".equals(request.getServletRequest().getParameter("add-artist"))) {
+                                       List<Artist> artists = track.getArtists();
+                                       artists.add(artist);
+                                       track.setArtists(artists);
+                               }
+
                                String name = request.getServletRequest().getParameter("name");
                                if ((name != null) && (name.trim().length() > 0)) {
                                        track.setName(name);
index cc535b9..bfc3355 100644 (file)
 
 </form>
 
+<h2>Artists</h2>
+
+<%foreach track.artists artist>
+
+       <div>Artist: <a href="admin.edit-artist?id=<%artist.id|html>"><%artist.name|html></a></div>
+
+       <form action="admin.edit-track" method="post" accept-charset="utf-8">
+               <input type="hidden" name="id" value="<%track.id|html>"/>
+               <input type="hidden" name="artist" value="<%artist.id|html>"/>
+               <button type="submit" name="delete-artist" value="true">Delete Artist</button>
+               <%notfirst><button type="submit" name="move-up" value="true">Artist &uarr;</button><%/notfirst>
+               <%notlast><button type="submit" name="move-down" value="true">Artist &darr;</button><%/notlast>
+       </form>
+
+<%/foreach>
+
+<h3>Add New Artist</h3>
+
+<form action="admin.edit-track" method="post" accept-charset="utf-8">
+
+       <input type="hidden" name="id" value="<%track.id|html>"/>
+
+       <div>
+               Add Artist:
+               <select name="artist">
+                       <%foreach dataManager.allArtists artist|sort>
+                               <option value="<%artist.id|html>"><%artist.name|html></option>
+                       <%/foreach>
+               </select>
+       </div>
+
+       <button type="submit" name="add-artist" value="true">Add Artist</button>
+
+</form>
+
 <h2>Parties</h2>
 
 <%foreach track.parties party>