themes select/deselect ability

This commit is contained in:
Michael Wain 2024-11-27 19:53:05 +03:00
parent 965e1975c1
commit 4f592f42fe
5 changed files with 38 additions and 0 deletions

View File

@ -288,4 +288,12 @@ public class DatabaseController {
}
return "error";
}
@PostMapping("/api/set_theme")
public String set_theme(@RequestParam Map<String, String> params) {
long theme_id = Long.parseLong(params.get("theme_id"));
boolean state = Boolean.parseBoolean(params.get("selected_state"));
themeService.setThemeState(theme_id, state);
return "ok";
}
}

View File

@ -2,7 +2,10 @@ package com.alterdekim.javabot.repository;
import com.alterdekim.javabot.entities.GameTheme;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Optional;
@ -14,4 +17,9 @@ public interface GameThemeRepository extends JpaRepository<GameTheme, Long> {
@Query("SELECT t FROM GameTheme t WHERE t.isSelected = true")
List<GameTheme> findAllSelected();
@Transactional
@Modifying
@Query("UPDATE GameTheme t SET t.isSelected = :state WHERE t.id = :uuid")
void updateThemeState(@Param("uuid") Long themeId, @Param("state") Boolean themeState);
}

View File

@ -13,4 +13,6 @@ public interface GameThemeService {
void saveGameTheme(GameTheme gameTheme);
List<GameTheme> getSelectedThemes();
void setThemeState(Long themeId, Boolean themeState);
}

View File

@ -37,4 +37,9 @@ public class GameThemeServiceImpl implements GameThemeService {
public List<GameTheme> getSelectedThemes() {
return repository.findAllSelected();
}
@Override
public void setThemeState(Long themeId, Boolean themeState) {
repository.updateThemeState(themeId, themeState);
}
}

View File

@ -294,4 +294,19 @@ $(function() {
$(this).addClass("btn-secondary");
}
});
$(".is-selected-theme").click(function() {
if( $(this).attr("data-selected") == "true" ) {
$(this).attr("data-selected", "false");
$(this).removeClass("btn-success");
$(this).html($("#selected_button_texts").attr("data-notselected"));
$(this).addClass("btn-secondary");
} else {
$(this).attr("data-selected", "true");
$(this).removeClass("btn-secondary");
$(this).html($("#selected_button_texts").attr("data-selected"));
$(this).addClass("btn-success");
}
$.post("/api/set_theme", "theme_id="+($(this).attr("data-id"))+"&selected_state="+($(this).attr("data-selected")), function(data, status) {});
});
});