Search in sources :

Example 1 with MusicFolderSettingsCommand

use of org.libresonic.player.command.MusicFolderSettingsCommand in project libresonic by Libresonic.

the class MusicFolderSettingsController method formBackingObject.

@ModelAttribute
protected void formBackingObject(@RequestParam(value = "scanNow", required = false) String scanNow, @RequestParam(value = "expunge", required = false) String expunge, Model model) throws Exception {
    MusicFolderSettingsCommand command = new MusicFolderSettingsCommand();
    if (scanNow != null) {
        settingsService.clearMusicFolderCache();
        mediaScannerService.scanLibrary();
    }
    if (expunge != null) {
        expunge();
    }
    command.setInterval(String.valueOf(settingsService.getIndexCreationInterval()));
    command.setHour(String.valueOf(settingsService.getIndexCreationHour()));
    command.setFastCache(settingsService.isFastCacheEnabled());
    command.setOrganizeByFolderStructure(settingsService.isOrganizeByFolderStructure());
    command.setScanning(mediaScannerService.isScanning());
    command.setMusicFolders(wrap(settingsService.getAllMusicFolders(true, true)));
    command.setNewMusicFolder(new MusicFolderSettingsCommand.MusicFolderInfo());
    model.addAttribute("command", command);
}
Also used : MusicFolderSettingsCommand(org.libresonic.player.command.MusicFolderSettingsCommand) ModelAttribute(org.springframework.web.bind.annotation.ModelAttribute)

Example 2 with MusicFolderSettingsCommand

use of org.libresonic.player.command.MusicFolderSettingsCommand in project libresonic by Libresonic.

the class MusicFolderSettingsController method onSubmit.

@RequestMapping(method = RequestMethod.POST)
protected String onSubmit(@ModelAttribute("command") MusicFolderSettingsCommand command, RedirectAttributes redirectAttributes) throws Exception {
    for (MusicFolderSettingsCommand.MusicFolderInfo musicFolderInfo : command.getMusicFolders()) {
        if (musicFolderInfo.isDelete()) {
            settingsService.deleteMusicFolder(musicFolderInfo.getId());
        } else {
            MusicFolder musicFolder = musicFolderInfo.toMusicFolder();
            if (musicFolder != null) {
                settingsService.updateMusicFolder(musicFolder);
            }
        }
    }
    MusicFolder newMusicFolder = command.getNewMusicFolder().toMusicFolder();
    if (newMusicFolder != null) {
        settingsService.createMusicFolder(newMusicFolder);
    }
    settingsService.setIndexCreationInterval(Integer.parseInt(command.getInterval()));
    settingsService.setIndexCreationHour(Integer.parseInt(command.getHour()));
    settingsService.setFastCacheEnabled(command.isFastCache());
    settingsService.setOrganizeByFolderStructure(command.isOrganizeByFolderStructure());
    settingsService.save();
    redirectAttributes.addFlashAttribute("settings_toast", true);
    redirectAttributes.addFlashAttribute("settings_reload", true);
    mediaScannerService.schedule();
    return "redirect:musicFolderSettings.view";
}
Also used : MusicFolderSettingsCommand(org.libresonic.player.command.MusicFolderSettingsCommand) MusicFolder(org.libresonic.player.domain.MusicFolder) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

MusicFolderSettingsCommand (org.libresonic.player.command.MusicFolderSettingsCommand)2 MusicFolder (org.libresonic.player.domain.MusicFolder)1 ModelAttribute (org.springframework.web.bind.annotation.ModelAttribute)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1