From: David ‘Bombe’ Roden Date: Thu, 19 Apr 2012 13:04:49 +0000 (+0200) Subject: Add page to show tracks by an artist. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=c4c00ea331e495884f03b87ecede23c8f51fc735;p=demoscenemusic.git Add page to show tracks by an artist. --- diff --git a/src/main/java/net/pterodactylus/demoscenemusic/page/ArtistPage.java b/src/main/java/net/pterodactylus/demoscenemusic/page/ArtistPage.java new file mode 100644 index 0000000..e92726f --- /dev/null +++ b/src/main/java/net/pterodactylus/demoscenemusic/page/ArtistPage.java @@ -0,0 +1,69 @@ +/* + * DemosceneMusic - ArtistPage.java - Copyright © 2012 David Roden + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.pterodactylus.demoscenemusic.page; + +import java.util.Collection; + +import net.pterodactylus.demoscenemusic.core.Core; +import net.pterodactylus.demoscenemusic.data.Artist; +import net.pterodactylus.demoscenemusic.data.Track; +import net.pterodactylus.util.database.DatabaseException; +import net.pterodactylus.util.template.Template; +import net.pterodactylus.util.template.TemplateContext; +import net.pterodactylus.util.template.TemplateContextFactory; +import net.pterodactylus.util.web.RedirectException; + +/** + * TODO + * + * @author David ‘Bombe’ Roden + */ +public class ArtistPage extends BasePage { + + /** + * @param core + * @param templateContextFactory + * @param template + * @param pageName + */ + public ArtistPage(Core core, TemplateContextFactory templateContextFactory, Template template) { + super(core, templateContextFactory, template, "artist"); + } + + // + // TEMPLATEPAGE METHODS + // + + /** + * {@inheritDoc} + */ + @Override + protected void processTemplate(TemplateContext templateContext, ServletRequest request) throws RedirectException { + try { + Artist artist = getCore().getDataManager().getArtistById(request.getServletRequest().getParameter("id")); + if (artist != null) { + Collection tracks = getCore().getDataManager().getTracksByArtist(artist.id()); + templateContext.set("artist", artist); + templateContext.set("tracks", tracks); + } + } catch (DatabaseException de1) { + /* TODO */ + } + } + +} diff --git a/src/main/resources/templates/artist b/src/main/resources/templates/artist new file mode 100644 index 0000000..655c4d8 --- /dev/null +++ b/src/main/resources/templates/artist @@ -0,0 +1,21 @@ +<%ifnull artist> +<%include include/header title=="Unknown Artist"> +

Unknown artist ID.

+<%else> +<%include include/header title=artist.name> + +

<% artist.name|html>

+ +

Tracks by <% artist.name|html>

+ +<%foreach tracks track|sort> +<%first><%/last> +<%foreachelse> +

This artist does not have any tracks.

+<%/foreach> + +<%/if> + +<%include include/footer> \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/web.xml.template b/src/main/webapp/WEB-INF/web.xml.template index 090d062..5a31a7b 100644 --- a/src/main/webapp/WEB-INF/web.xml.template +++ b/src/main/webapp/WEB-INF/web.xml.template @@ -32,6 +32,10 @@ TemplateServlet net.pterodactylus.demoscenemusic.core.TemplateServlet + artist + net.pterodactylus.demoscenemusic.page.ArtistPage + + artists net.pterodactylus.demoscenemusic.page.ArtistsPage