use of org.springframework.web.servlet.view.RedirectView in project libresonic by Libresonic.
the class GettingStartedController method gettingStarted.
@RequestMapping(method = RequestMethod.GET)
public ModelAndView gettingStarted(HttpServletRequest request) {
if (request.getParameter("hide") != null) {
settingsService.setGettingStartedEnabled(false);
settingsService.save();
return new ModelAndView(new RedirectView("home.view"));
}
Map<String, Object> map = new HashMap<>();
;
map.put("runningAsRoot", "root".equals(System.getProperty("user.name")));
return new ModelAndView("gettingStarted", "model", map);
}
use of org.springframework.web.servlet.view.RedirectView in project libresonic by Libresonic.
the class MainController method handleRequestInternal.
@RequestMapping(method = RequestMethod.GET)
protected ModelAndView handleRequestInternal(@RequestParam(name = "showAll", required = false) Boolean showAll, HttpServletRequest request, HttpServletResponse response) throws Exception {
Map<String, Object> map = new HashMap<>();
Player player = playerService.getPlayer(request, response);
List<MediaFile> mediaFiles = getMediaFiles(request);
if (mediaFiles.isEmpty()) {
return new ModelAndView(new RedirectView("notFound.view"));
}
MediaFile dir = mediaFiles.get(0);
if (dir.isFile()) {
dir = mediaFileService.getParentOf(dir);
}
// Redirect if root directory.
if (mediaFileService.isRoot(dir)) {
return new ModelAndView(new RedirectView("home.view?"));
}
String username = securityService.getCurrentUsername(request);
if (!securityService.isFolderAccessAllowed(dir, username)) {
return new ModelAndView(new RedirectView("accessDenied.view"));
}
UserSettings userSettings = settingsService.getUserSettings(username);
List<MediaFile> children = mediaFiles.size() == 1 ? mediaFileService.getChildrenOf(dir, true, true, true) : getMultiFolderChildren(mediaFiles);
List<MediaFile> files = new ArrayList<>();
List<MediaFile> subDirs = new ArrayList<>();
for (MediaFile child : children) {
if (child.isFile()) {
files.add(child);
} else {
subDirs.add(child);
}
}
int userPaginationPreference = userSettings.getPaginationSize();
if (userPaginationPreference <= 0) {
showAll = true;
}
boolean thereIsMoreSubDirs = trimToSize(showAll, subDirs, userPaginationPreference);
boolean thereIsMoreSAlbums = false;
mediaFileService.populateStarredDate(dir, username);
mediaFileService.populateStarredDate(children, username);
map.put("dir", dir);
map.put("files", files);
map.put("subDirs", subDirs);
map.put("ancestors", getAncestors(dir));
map.put("coverArtSizeMedium", CoverArtScheme.MEDIUM.getSize());
map.put("coverArtSizeLarge", CoverArtScheme.LARGE.getSize());
map.put("player", player);
map.put("user", securityService.getCurrentUser(request));
map.put("visibility", userSettings.getMainVisibility());
map.put("showAlbumYear", settingsService.isSortAlbumsByYear());
map.put("showArtistInfo", userSettings.isShowArtistInfoEnabled());
map.put("partyMode", userSettings.isPartyModeEnabled());
map.put("brand", settingsService.getBrand());
map.put("viewAsList", isViewAsList(request, userSettings));
if (dir.isAlbum()) {
List<MediaFile> sieblingAlbums = getSieblingAlbums(dir);
thereIsMoreSAlbums = trimToSize(showAll, sieblingAlbums, userPaginationPreference);
map.put("sieblingAlbums", sieblingAlbums);
map.put("artist", guessArtist(children));
map.put("album", guessAlbum(children));
}
try {
MediaFile parent = mediaFileService.getParentOf(dir);
map.put("parent", parent);
map.put("navigateUpAllowed", !mediaFileService.isRoot(parent));
} catch (SecurityException x) {
// Happens if Podcast directory is outside music folder.
}
map.put("thereIsMore", (thereIsMoreSubDirs || thereIsMoreSAlbums) && !BooleanUtils.isTrue(showAll));
Integer userRating = ratingService.getRatingForUser(username, dir);
Double averageRating = ratingService.getAverageRating(dir);
if (userRating == null) {
userRating = 0;
}
if (averageRating == null) {
averageRating = 0.0D;
}
map.put("userRating", 10 * userRating);
map.put("averageRating", Math.round(10.0D * averageRating));
map.put("starred", mediaFileService.getMediaFileStarredDate(dir.getId(), username) != null);
String view;
if (isVideoOnly(children)) {
view = "videoMain";
} else if (dir.isAlbum()) {
view = "albumMain";
} else {
view = "artistMain";
}
return new ModelAndView(view, "model", map);
}
use of org.springframework.web.servlet.view.RedirectView in project libresonic by Libresonic.
the class PlaylistController method handleRequestInternal.
@RequestMapping(method = RequestMethod.GET)
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
Map<String, Object> map = new HashMap<>();
int id = ServletRequestUtils.getRequiredIntParameter(request, "id");
User user = securityService.getCurrentUser(request);
String username = user.getUsername();
UserSettings userSettings = settingsService.getUserSettings(username);
Player player = playerService.getPlayer(request, response);
Playlist playlist = playlistService.getPlaylist(id);
if (playlist == null) {
return new ModelAndView(new RedirectView("notFound"));
}
map.put("playlist", playlist);
map.put("user", user);
map.put("player", player);
map.put("editAllowed", username.equals(playlist.getUsername()) || securityService.isAdmin(username));
map.put("partyMode", userSettings.isPartyModeEnabled());
return new ModelAndView("playlist", "model", map);
}
use of org.springframework.web.servlet.view.RedirectView in project libresonic by Libresonic.
the class SettingsController method handleRequestInternal.
@RequestMapping(method = RequestMethod.GET)
protected ModelAndView handleRequestInternal(HttpServletRequest request) throws Exception {
User user = securityService.getCurrentUser(request);
// Redirect to music folder settings if admin.
String view = user.isAdminRole() ? "musicFolderSettings" : "personalSettings";
return new ModelAndView(new RedirectView(view));
}
use of org.springframework.web.servlet.view.RedirectView in project libresonic by Libresonic.
the class SetRatingController method handleRequestInternal.
@RequestMapping(method = RequestMethod.GET)
protected ModelAndView handleRequestInternal(HttpServletRequest request) throws Exception {
int id = ServletRequestUtils.getRequiredIntParameter(request, "id");
Integer rating = ServletRequestUtils.getIntParameter(request, "rating");
if (rating == 0) {
rating = null;
}
MediaFile mediaFile = mediaFileService.getMediaFile(id);
String username = securityService.getCurrentUsername(request);
ratingService.setRatingForUser(username, mediaFile, rating);
return new ModelAndView(new RedirectView("main.view?id=" + id));
}
Aggregations