Migrate random play queues to Spring 4

master
François-Xavier Thomas 8 years ago
parent 7ccc81c85f
commit 22fe408818
No known key found for this signature in database
GPG Key ID: 64337406D2DD45CE
  1. 89
      libresonic-main/src/main/java/org/libresonic/player/controller/RandomPlayQueueController.java
  2. 13
      libresonic-main/src/main/webapp/WEB-INF/jsp/more.jsp
  3. 20
      libresonic-main/src/main/webapp/WEB-INF/libresonic-servlet.xml

@ -19,39 +19,60 @@
*/
package org.libresonic.player.controller;
import java.text.NumberFormat;
import java.util.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.StringUtils;
import org.apache.taglibs.standard.lang.jstl.IntegerDivideOperator;
import org.libresonic.player.domain.*;
import org.libresonic.player.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.ServletRequestBindingException;
import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.ParameterizableViewController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
/**
* Controller for the creating a random play queue.
*
* @author Sindre Mehus
*/
public class RandomPlayQueueController extends ParameterizableViewController {
@Controller
@RequestMapping("/randomPlayQueue.view")
public class RandomPlayQueueController {
@Autowired
private PlayerService playerService;
private List<ReloadFrame> reloadFrames;
@Autowired
private MediaFileService mediaFileService;
@Autowired
private SecurityService securityService;
@Autowired
private SettingsService settingsService;
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
@RequestMapping(method = RequestMethod.POST)
protected String handleRandomPlayQueue(
ModelMap model,
HttpServletRequest request,
HttpServletResponse response,
@RequestParam(value = "size") int size,
@RequestParam(value = "genre", required = false) String genre,
@RequestParam(value = "year", required = false) String year,
@RequestParam(value = "songRating", required = false) String songRating,
@RequestParam(value = "lastPlayedValue", required = false) String lastPlayedValue,
@RequestParam(value = "lastPlayedComp", required = false) String lastPlayedComp,
@RequestParam(value = "albumRatingValue", required = false) Integer albumRatingValue,
@RequestParam(value = "albumRatingComp", required = false) String albumRatingComp,
@RequestParam(value = "playCountValue", required = false) Integer playCountValue,
@RequestParam(value = "playCountComp", required = false) String playCountComp,
@RequestParam(value = "format", required = false) String format,
@RequestParam(value = "autoRandom", required = false) String autoRandom
) throws Exception {
int size = ServletRequestUtils.getRequiredIntParameter(request, "size");
String genre;
Integer fromYear = null;
Integer toYear = null;
Integer minAlbumRating = null;
@ -64,13 +85,11 @@ public class RandomPlayQueueController extends ParameterizableViewController {
boolean doesShowUnstarredSongs = false;
// Handle the genre filter
genre = request.getParameter("genre");
if (StringUtils.equalsIgnoreCase("any", genre)) {
genre = null;
}
// Handle the release year filter
String year = request.getParameter("year");
if (!StringUtils.equalsIgnoreCase("any", year)) {
String[] tmp = StringUtils.split(year);
fromYear = Integer.parseInt(tmp[0]);
@ -78,7 +97,6 @@ public class RandomPlayQueueController extends ParameterizableViewController {
}
// Handle the song rating filter
String songRating = request.getParameter("songRating");
if (StringUtils.equalsIgnoreCase("any", songRating)) {
doesShowStarredSongs = true;
doesShowUnstarredSongs = true;
@ -91,8 +109,6 @@ public class RandomPlayQueueController extends ParameterizableViewController {
}
// Handle the last played date filter
String lastPlayedValue = request.getParameter("lastPlayedValue");
String lastPlayedComp = request.getParameter("lastPlayedComp");
Calendar lastPlayed = Calendar.getInstance();
lastPlayed.setTime(new Date());
switch (lastPlayedValue) {
@ -132,10 +148,6 @@ public class RandomPlayQueueController extends ParameterizableViewController {
}
// Handle the album rating filter
Integer albumRatingValue = null;
try { albumRatingValue = Integer.parseInt(request.getParameter("albumRatingValue")); }
catch (NumberFormatException e) { }
String albumRatingComp = request.getParameter("albumRatingComp");
if (albumRatingValue != null) {
switch (albumRatingComp) {
case "lt":
@ -162,10 +174,6 @@ public class RandomPlayQueueController extends ParameterizableViewController {
}
// Handle the play count filter
Integer playCountValue = null;
try { playCountValue = Integer.parseInt(request.getParameter("playCountValue")); }
catch (NumberFormatException e) { }
String playCountComp = request.getParameter("playCountComp");
if (playCountValue != null) {
switch (playCountComp) {
case "lt":
@ -192,7 +200,6 @@ public class RandomPlayQueueController extends ParameterizableViewController {
}
// Handle the format filter
String format = request.getParameter("format");
if (StringUtils.equalsIgnoreCase(format, "any")) format = null;
// Handle the music folder filter
@ -223,16 +230,18 @@ public class RandomPlayQueueController extends ParameterizableViewController {
PlayQueue playQueue = player.getPlayQueue();
playQueue.addFiles(shouldAddToPlayList, mediaFileService.getRandomSongs(criteria, user.getUsername()));
if (request.getParameter("autoRandom") != null) {
if (autoRandom != null) {
playQueue.setRandomSearchCriteria(criteria);
}
Map<String, Object> map = new HashMap<String, Object>();
// Render the 'reload' view to reload the play queue and the main page
List<ReloadFrame> reloadFrames = new ArrayList<>();
reloadFrames.add(new ReloadFrame("playQueue", "playQueue.view?"));
reloadFrames.add(new ReloadFrame("main", "more.view"));
Map<String, Object> map = new HashMap<>();
map.put("reloadFrames", reloadFrames);
ModelAndView result = super.handleRequestInternal(request, response);
result.addObject("model", map);
return result;
model.addAttribute("model", map);
return "reload";
}
private List<MusicFolder> getMusicFolders(HttpServletRequest request) throws ServletRequestBindingException {
@ -243,24 +252,4 @@ public class RandomPlayQueueController extends ParameterizableViewController {
}
return settingsService.getMusicFoldersForUser(username, selectedMusicFolderId);
}
public void setPlayerService(PlayerService playerService) {
this.playerService = playerService;
}
public void setReloadFrames(List<ReloadFrame> reloadFrames) {
this.reloadFrames = reloadFrames;
}
public void setSecurityService(SecurityService securityService) {
this.securityService = securityService;
}
public void setSettingsService(SettingsService settingsService) {
this.settingsService = settingsService;
}
public void setMediaFileService(MediaFileService mediaFileService) {
this.mediaFileService = mediaFileService;
}
}

@ -67,7 +67,16 @@
}
elements = form.getElementsByTagName("select");
for (var i = 0; i < elements.length; i++) {
if (data[elements[i].name]) elements[i].value = data[elements[i].name];
var element = elements[i];
var value = data[element.name];
if (value) {
for (var j = 0; j < element.options.length; j++) {
if (element.options[j].value == value) {
element.value = value;
break;
}
}
}
}
}
@ -168,7 +177,7 @@
<option value="gt">&gt;</option>
</select>
<select name="albumRatingValue">
<option value="any" selected="selected"><fmt:message key="more.random.any"/></option>
<option value="" selected="selected"><fmt:message key="more.random.any"/></option>
<option value="0">0 <fmt:message key="more.random.stars"/></option>
<option value="1">1 <fmt:message key="more.random.star"/></option>
<option value="2">2 <fmt:message key="more.random.stars"/></option>

@ -125,25 +125,6 @@
<property name="mediaFileService" ref="mediaFileService"/>
<property name="securityService" ref="securityService"/>
</bean>
<bean id="randomPlayQueueController" class="org.libresonic.player.controller.RandomPlayQueueController">
<property name="viewName" value="reload"/>
<property name="playerService" ref="playerService"/>
<property name="mediaFileService" ref="mediaFileService"/>
<property name="securityService" ref="securityService"/>
<property name="settingsService" ref="settingsService"/>
<property name="reloadFrames">
<list>
<bean class="org.libresonic.player.controller.ReloadFrame">
<property name="frame" value="playQueue"/>
<property name="view" value="playQueue.view?"/>
</bean>
<bean class="org.libresonic.player.controller.ReloadFrame">
<property name="frame" value="main"/>
<property name="view" value="more.view"/>
</bean>
</list>
</property>
</bean>
<bean id="changeCoverArtController" class="org.libresonic.player.controller.ChangeCoverArtController">
<property name="viewName" value="changeCoverArt"/>
<property name="mediaFileService" ref="mediaFileService"/>
@ -349,7 +330,6 @@
<prop key="/createShare.view">shareManagementController</prop>
<prop key="/setRating.view">setRatingController</prop>
<prop key="/top.view">topController</prop>
<prop key="/randomPlayQueue.view">randomPlayQueueController</prop>
<prop key="/changeCoverArt.view">changeCoverArtController</prop>
<!--
login.view has moved to the LoginController

Loading…
Cancel
Save