Theme edit_entry functionality x2

This commit is contained in:
Michael Wain 2024-11-27 22:30:04 +03:00
parent be0c978ee7
commit 6199c3acc6
20 changed files with 191 additions and 3 deletions

View File

@ -43,6 +43,16 @@ public class DatabaseController {
bioService.saveBio(new Bio(ismale, isfemale, canDie, t.getId(), themeId));
}
private void editGender(Long id, Map<String, String> params) {
Boolean canDie = Boolean.parseBoolean(params.get("canDie"));
Boolean ismale = Boolean.parseBoolean(params.get("ismale"));
Boolean isfemale = Boolean.parseBoolean(params.get("isfemale"));
String gender_text = new String(HashUtils.decodeHexString(params.get("gender_text")));
TextDataVal t = textDataValService.save(new TextDataVal(gender_text));
Long themeId = Long.parseLong(params.get("object_selected_theme"));
bioService.updateBio(id, ismale, isfemale, canDie, t.getId(), themeId);
}
private void saveHobby(Map<String, String> params) {
Float powerRange = Float.parseFloat(params.get("powerRange"));
Float violenceRange = Float.parseFloat(params.get("violenceRange"));
@ -56,6 +66,19 @@ public class DatabaseController {
hobbyService.saveHobby(new Hobby(foodRange, powerRange, violenceRange, healRange, t.getId(), themeId));
}
private void editHobby(Long id, Map<String, String> params) {
Float powerRange = Float.parseFloat(params.get("powerRange"));
Float violenceRange = Float.parseFloat(params.get("violenceRange"));
Float healRange = Float.parseFloat(params.get("healRange"));
Float foodRange = Float.parseFloat(params.get("foodRange"));
String hobby_text = new String(HashUtils.decodeHexString(params.get("hobby_text")));
TextDataVal t = textDataValService.save(new TextDataVal(hobby_text));
Long themeId = Long.parseLong(params.get("object_selected_theme"));
hobbyService.updateHobby(id, foodRange, powerRange, violenceRange, healRange, t.getId(), themeId);
}
private void saveLuggage(Map<String, String> params) {
Float powerRange = Float.parseFloat(params.get("powerRange"));
Float violenceRange = Float.parseFloat(params.get("violenceRange"));
@ -74,6 +97,24 @@ public class DatabaseController {
luggageService.saveLuggage(new Luggage(violenceRange, powerRange, healRange, foodRange, isGarbage, t1.getId(), t2.getId(), themeId));
}
private void editLuggage(Long id, Map<String, String> params) {
Float powerRange = Float.parseFloat(params.get("powerRange"));
Float violenceRange = Float.parseFloat(params.get("violenceRange"));
Float healRange = Float.parseFloat(params.get("healRange"));
Float foodRange = Float.parseFloat(params.get("foodRange"));
Boolean isGarbage = Boolean.parseBoolean(params.get("isgarbage"));
String name_text = new String(HashUtils.decodeHexString(params.get("luggage_name_text")));
TextDataVal t1 = textDataValService.save(new TextDataVal(name_text));
String desc_text = new String(HashUtils.decodeHexString(params.get("luggage_desc_text")));
TextDataVal t2 = textDataValService.save(new TextDataVal(desc_text));
Long themeId = Long.parseLong(params.get("object_selected_theme"));
luggageService.updateLuggage(id, violenceRange, powerRange, healRange, foodRange, isGarbage, t1.getId(), t2.getId(), themeId);
}
private void saveHealth(Map<String, String> params) {
Float health_index = Float.parseFloat(params.get("health_index"));
Boolean childFree = Boolean.parseBoolean(params.get("childFree"));
@ -88,6 +129,20 @@ public class DatabaseController {
healthService.saveHealth(new Health(health_index, t1.getId(), t2.getId(), childFree, themeId));
}
private void editHealth(Long id, Map<String, String> params) {
Float health_index = Float.parseFloat(params.get("health_index"));
Boolean childFree = Boolean.parseBoolean(params.get("childFree"));
String name_text = new String(HashUtils.decodeHexString(params.get("heal_name_text")));
TextDataVal t1 = textDataValService.save(new TextDataVal(name_text));
String desc_text = new String(HashUtils.decodeHexString(params.get("heal_desc_text")));
TextDataVal t2 = textDataValService.save(new TextDataVal(desc_text));
Long themeId = Long.parseLong(params.get("object_selected_theme"));
healthService.updateHealth(id, health_index, t1.getId(), t2.getId(), childFree, themeId);
}
private void saveTheme(Map<String, String> params) {
String name_text = new String(HashUtils.decodeHexString(params.get("theme_name_text")));
TextDataVal t1 = textDataValService.save(new TextDataVal(name_text));
@ -111,6 +166,23 @@ public class DatabaseController {
workService.saveWork(new Work(healRange, powerRange, violenceRange, foodRange, t1.getId(), t2.getId(), themeId));
}
private void editWork(Long id, Map<String, String> params) {
Float powerRange = Float.parseFloat(params.get("powerRange"));
Float violenceRange = Float.parseFloat(params.get("violenceRange"));
Float healRange = Float.parseFloat(params.get("healRange"));
Float foodRange = Float.parseFloat(params.get("foodRange"));
String name_text = new String(HashUtils.decodeHexString(params.get("work_name_text")));
TextDataVal t1 = textDataValService.save(new TextDataVal(name_text));
String desc_text = new String(HashUtils.decodeHexString(params.get("work_desc_text")));
TextDataVal t2 = textDataValService.save(new TextDataVal(desc_text));
Long themeId = Long.parseLong(params.get("object_selected_theme"));
workService.updateWork(id, healRange, powerRange, violenceRange, foodRange, t1.getId(), t2.getId(), themeId);
}
private void saveDiss(Map<String, String> params) {
String name_text = new String(HashUtils.decodeHexString(params.get("diss_name_text")));
TextDataVal t1 = textDataValService.save(new TextDataVal(name_text));
@ -123,6 +195,18 @@ public class DatabaseController {
disasterService.saveDisaster(new Disaster(t1.getId(), t2.getId(), themeId));
}
private void editDiss(Long id, Map<String, String> params) {
String name_text = new String(HashUtils.decodeHexString(params.get("diss_name_text")));
TextDataVal t1 = textDataValService.save(new TextDataVal(name_text));
String desc_text = new String(HashUtils.decodeHexString(params.get("diss_desc_text")));
TextDataVal t2 = textDataValService.save(new TextDataVal(desc_text));
Long themeId = Long.parseLong(params.get("object_selected_theme"));
disasterService.updateDisaster(id, t1.getId(), t2.getId(), themeId);
}
private void saveAction(Map<String, String> params) {
String scriptBody = params.get("action_body_text");
String name_text = new String(HashUtils.decodeHexString(params.get("action_name_text")));
@ -280,8 +364,8 @@ public class DatabaseController {
return "error";
}
@PostMapping("/api/edit_entry")
public String edit_entry(@RequestParam Map<String, String> params) {
@PostMapping("/api/get_entry")
public String get_entry(@RequestParam Map<String, String> params) {
ObjectMapper mapper = new ObjectMapper();
long l = Long.parseLong(params.get("entry_id"));
try {
@ -301,6 +385,22 @@ public class DatabaseController {
return "error";
}
@PostMapping("/api/edit_entry")
public String edit_entry(@RequestParam Map<String, String> params) {
long l = Long.parseLong(params.get("entry_id"));
String section = params.get("section");
switch (section) {
case "agge" -> editGender(l, params);
case "lugg" -> editLuggage(l, params);
case "prof" -> editWork(l, params);
case "heal" -> editHealth(l, params);
case "hobb" -> editHobby(l, params);
case "diss" -> editDiss(l, params);
default -> log.error("Unknown section");
}
return "ok";
}
@PostMapping("/api/set_theme")
public String set_theme(@RequestParam Map<String, String> params) {
long theme_id = Long.parseLong(params.get("theme_id"));

View File

@ -4,8 +4,10 @@ import com.alterdekim.javabot.entities.Bio;
import com.alterdekim.javabot.entities.Disaster;
import com.alterdekim.javabot.entities.Synergy;
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;
@ -20,4 +22,9 @@ public interface BioRepository extends JpaRepository<Bio, Long> {
@Query("SELECT b FROM Bio b WHERE b.theme = :th")
List<Bio> findByTheme(@Param(value = "th") Long theme);
@Modifying
@Transactional
@Query("UPDATE Bio b SET b.isMale = :isMale, b.isFemale = :isFemale, b.canDie = :canDie, b.genderTextId = :nameId, b.theme = :themeId WHERE b.id = :uuid")
void updateBio(@Param("uuid") Long id, @Param("isMale") Boolean isMale, @Param("isFemale") Boolean isFemale, @Param("canDie") Boolean canDie, @Param("nameId") Long nameId, @Param("themeId") Long themeId);
}

View File

@ -2,8 +2,10 @@ package com.alterdekim.javabot.repository;
import com.alterdekim.javabot.entities.Disaster;
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;
@ -15,4 +17,9 @@ public interface DisasterRepository extends JpaRepository<Disaster, Long> {
@Query("SELECT d FROM Disaster d WHERE d.theme = :th")
List<Disaster> findByTheme(@Param(value = "th") Long theme);
@Transactional
@Modifying
@Query("UPDATE Disaster d SET d.nameTextId = :nameTextId, d.descTextId = :descTextId, d.theme = :theme WHERE d.id = :uuid")
void updateDisaster(@Param("uuid") Long id, Long nameTextId, Long descTextId, Long theme);
}

View File

@ -4,8 +4,10 @@ import com.alterdekim.javabot.entities.Health;
import com.alterdekim.javabot.entities.Synergy;
import com.alterdekim.javabot.entities.Work;
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;
@ -20,4 +22,10 @@ public interface HealthRepository extends JpaRepository<Health, Long> {
@Query("SELECT h FROM Health h WHERE h.theme = :th")
List<Health> findByTheme(@Param(value = "th") Long theme);
@Modifying
@Transactional
@Query("UPDATE Health h SET h.health_index = :health_index, h.textNameId = :textNameId, h.textDescId = :textDescId, h.isChildfree = :isChildfree, h.theme = :theme WHERE h.id = :uuid")
void updateHealth(@Param("uuid") Long id, @Param("health_index") Float health_index, @Param("textNameId") Long textNameId, @Param("textDescId") Long textDescId, @Param("isChildfree") Boolean isChildfree, @Param("theme") Long theme);
}

View File

@ -4,8 +4,10 @@ import com.alterdekim.javabot.entities.Health;
import com.alterdekim.javabot.entities.Hobby;
import com.alterdekim.javabot.entities.Synergy;
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;
@ -20,4 +22,9 @@ public interface HobbyRepository extends JpaRepository<Hobby, Long> {
@Query("SELECT h FROM Hobby h WHERE h.theme = :th")
List<Hobby> findByTheme(@Param(value = "th") Long theme);
@Modifying
@Transactional
@Query("UPDATE Hobby h SET h.foodstuffs = :foodstuffs, h.power = :power, h.violence = :violence, h.asocial = :asocial, h.textDescId = :nameId, h.theme = :themeId WHERE h.id = :uuid")
void updateHobby(@Param("uuid") Long id, @Param("foodstuffs") Float foodstuffs, @Param("power") Float power, @Param("violence") Float violence, @Param("asocial") Float asocial, Long nameId, Long themeId);
}

View File

@ -4,8 +4,10 @@ import com.alterdekim.javabot.entities.Hobby;
import com.alterdekim.javabot.entities.Luggage;
import com.alterdekim.javabot.entities.Synergy;
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;
@ -20,4 +22,9 @@ public interface LuggageRepository extends JpaRepository<Luggage, Long> {
@Query("SELECT l FROM Luggage l WHERE l.theme = :th")
List<Luggage> findByTheme(@Param(value = "th") Long theme);
@Modifying
@Transactional
@Query("UPDATE Luggage l SET l.violence = :violence, l.power = :power, l.asocial = :asocial, l.foodstuffs = :foodstuffs, l.garbage = :garbage, l.textNameId = :textNameId, l.textDescId = :textDescId, l.theme = :theme WHERE l.id = :uuid")
void updateLuggage(@Param("uuid") Long id, @Param("violence") Float violence, @Param("power") Float power, @Param("asocial") Float asocial, @Param("foodstuffs") Float foodstuffs, @Param("garbage") Boolean garbage, @Param("textNameId") Long textNameId, @Param("textDescId") Long textDescId, @Param("theme") Long theme);
}

View File

@ -4,8 +4,10 @@ import com.alterdekim.javabot.entities.Disaster;
import com.alterdekim.javabot.entities.Synergy;
import com.alterdekim.javabot.entities.Work;
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;
@ -20,4 +22,9 @@ public interface WorkRepository extends JpaRepository<Work, Long> {
@Query("SELECT w FROM Work w WHERE w.theme = :th")
List<Work> findByTheme(@Param(value = "th") Long theme);
@Modifying
@Transactional
@Query("UPDATE Work w SET w.asocial = :asocial, w.power = :power, w.violence = :violence, w.foodstuffs = :foodstuffs, w.textNameId = :textNameId, w.textDescId = :textDescId, w.theme = :theme WHERE w.id = :uuid")
void updateWork(@Param("uuid") Long id, @Param("asocial") Float asocial, @Param("power") Float power, @Param("violence") Float violence, @Param("foodstuffs") Float foodstuffs, @Param("textNameId") Long textNameId, @Param("textDescId") Long textDescId, @Param("theme") Long theme);
}

View File

@ -14,4 +14,6 @@ public interface BioService {
void removeById(Long id);
List<Synergy> getSynergies(Long id);
void updateBio(Long id, Boolean isMale, Boolean isFemale, Boolean canDie, Long nameId, Long themeId);
}

View File

@ -51,4 +51,9 @@ public class BioServiceImpl implements BioService {
public List<Synergy> getSynergies(Long id) {
return repository.getSynergies(id);
}
@Override
public void updateBio(Long id, Boolean isMale, Boolean isFemale, Boolean canDie, Long nameId, Long themeId) {
repository.updateBio(id, isMale, isFemale, canDie, nameId, themeId);
}
}

View File

@ -11,4 +11,6 @@ public interface DisasterService {
void removeById(long dId);
void saveDisaster(Disaster disaster);
void updateDisaster(Long id, Long nameTextId, Long descTextId, Long theme);
}

View File

@ -44,4 +44,9 @@ public class DisasterServiceImpl implements DisasterService {
public void saveDisaster(Disaster disaster) {
repository.save(disaster);
}
@Override
public void updateDisaster(Long id, Long nameTextId, Long descTextId, Long theme) {
repository.updateDisaster(id, nameTextId, descTextId, theme);
}
}

View File

@ -14,4 +14,6 @@ public interface HealthService {
void saveHealth(Health health);
List<Synergy> getSynergies(Long id);
void updateHealth(Long id, Float health_index, Long textNameId, Long textDescId, Boolean isChildfree, Long theme);
}

View File

@ -51,4 +51,9 @@ public class HealthServiceImpl implements HealthService {
public List<Synergy> getSynergies(Long id) {
return repository.getSynergies(id);
}
@Override
public void updateHealth(Long id, Float health_index, Long textNameId, Long textDescId, Boolean isChildfree, Long theme) {
repository.updateHealth(id, health_index, textNameId, textDescId, isChildfree, theme);
}
}

View File

@ -14,4 +14,6 @@ public interface HobbyService {
void removeById(Long id);
List<Synergy> getSynergies(Long id);
void updateHobby(Long id, Float foodRange, Float powerRange, Float violenceRange, Float healRange, Long nameId, Long themeId);
}

View File

@ -51,4 +51,9 @@ public class HobbyServiceImpl implements HobbyService {
public List<Synergy> getSynergies(Long id) {
return repository.getSynergies(id);
}
@Override
public void updateHobby(Long id, Float foodRange, Float powerRange, Float violenceRange, Float healRange, Long nameId, Long themeId) {
repository.updateHobby(id, foodRange, powerRange, violenceRange, healRange, nameId, themeId);
}
}

View File

@ -14,4 +14,6 @@ public interface LuggageService {
void saveLuggage(Luggage luggage);
List<Synergy> getSynergies(Long id);
void updateLuggage(Long id, Float violence, Float power, Float asocial, Float foodstuffs, Boolean garbage, Long textNameId, Long textDescId, Long theme);
}

View File

@ -49,4 +49,9 @@ public class LuggageServiceImpl implements LuggageService {
public List<Synergy> getSynergies(Long id) {
return repository.getSynergies(id);
}
@Override
public void updateLuggage(Long id, Float violence, Float power, Float asocial, Float foodstuffs, Boolean garbage, Long textNameId, Long textDescId, Long theme) {
repository.updateLuggage(id, violence, power, asocial, foodstuffs, garbage, textNameId, textDescId, theme);
}
}

View File

@ -14,4 +14,6 @@ public interface WorkService {
void saveWork(Work work);
List<Synergy> getSynergies(Long id);
void updateWork(Long id, Float asocial, Float power, Float violence, Float foodstuffs, Long textNameId, Long textDescId, Long theme);
}

View File

@ -51,4 +51,11 @@ public class WorkServiceImpl implements WorkService {
public List<Synergy> getSynergies(Long id) {
return repository.getSynergies(id);
}
@Override
public void updateWork(Long id, Float asocial, Float power, Float violence, Float foodstuffs, Long textNameId, Long textDescId, Long theme) {
repository.updateWork(id, asocial, power, violence, foodstuffs, textNameId, textDescId, theme);
}
}

View File

@ -147,6 +147,7 @@ function show_modal_edit(jobj, oid) {
}
function edit_submit_entry(obj) {
// TODO: change this
$.post("/api/remove_entry", "section="+new URL(window.location.href).searchParams.get("section")+"&entry_id="+($(obj).attr("data-entry-id")), function(data, status) {
add_entry();
});
@ -157,7 +158,7 @@ function edit_entry(obj) {
if( __ss == "actions" ) {
window.location.href = "/script-editor?script_id=" + ($(obj).attr("data-id"));
} else {
$.post("/api/edit_entry", "section="+__ss+"&entry_id="+($(obj).attr("data-id")), function(data, status) {
$.post("/api/get_entry", "section="+__ss+"&entry_id="+($(obj).attr("data-id")), function(data, status) {
var jobj = JSON.parse(data);
show_modal_edit(jobj, $(obj).attr("data-id"));
});