12 Commits

Author SHA1 Message Date
c484d86c59 Merge branch 'n-kawahito' of https://gitea.it-college.co.jp/2026_09_5H_Spring_KIZAKI/Monegement into k-oshita 2026-09-29 15:19:14 +09:00
78d3042299 [EDIT]マージ跡を消しました 2026-09-29 15:13:56 +09:00
ead133ba65 Merge branch 's-choi' of https://gitea.it-college.co.jp/2026_09_5H_Spring_KIZAKI/Monegement into n-kawahito
# Conflicts:
#	src/main/resources/templates/select_course.html
2026-09-29 15:13:04 +09:00
00c3041d95 [FIX]収支の選択に合わせてカテゴリが出るようにしました。 2026-09-29 15:11:35 +09:00
s-choi
65b4a9e54a [EDIT] コース削除機能を追加しました。 2026-09-29 15:09:08 +09:00
s-choi
515c789399 [EDIT] コースの情報を配分入力画面でも渡されるようにしました。 2026-09-29 15:08:49 +09:00
s-choi
7299ee0d06 [EDIT] 余計な機能を削除しました。 2026-09-29 15:08:16 +09:00
s-choi
fa0bfa7c90 [FIX] 配分まで入力してもらったあと、保存されるように修正しました。コース削除機能を追加しました。 2026-09-29 15:07:58 +09:00
s-choi
a911eaabc5 [EDIT] courseIdによる削除クエリを追加しました。 2026-09-29 15:07:10 +09:00
d27d8afbb3 Merge branch 'k-kobayashi' of https://gitea.it-college.co.jp/2026_09_5H_Spring_KIZAKI/Monegement into n-kawahito 2026-09-29 14:48:01 +09:00
kkazuya
d291306599 [FIX] 取引更新画面のカテゴリ表示不備を修正しました。 2026-09-29 14:47:37 +09:00
s-choi
52cf2b0a84 Merge branch 'k-kobayashi' of https://gitea.it-college.co.jp/2026_09_5H_Spring_KIZAKI/Monegement into s-choi 2026-09-29 12:53:49 +09:00
12 changed files with 378 additions and 156 deletions

View File

@@ -8,6 +8,4 @@ public interface AllocationService {
public List<AllocationModel> findAll(); public List<AllocationModel> findAll();
public List<AllocationModel> save(List<AllocationModel> allocationModelList);
} }

View File

@@ -3,6 +3,7 @@ package com.example.demo.app.domain.service;
import java.util.List; import java.util.List;
import com.example.demo.app.domain.model.CourseModel; import com.example.demo.app.domain.model.CourseModel;
import com.example.demo.app.presentation.form.AllocationFormList;
public interface CourseService { public interface CourseService {
@@ -12,12 +13,14 @@ public interface CourseService {
public Long findByName(String courName); public Long findByName(String courName);
public CourseModel save(CourseModel courseModel, Long userId); public CourseModel save(CourseModel courseModel, Long userId, AllocationFormList allocationFormList);
public List<CourseModel> findAllByUserId(Long userId); public List<CourseModel> findAllByUserId(Long userId);
public List<CourseModel> findAllByNull(); public List<CourseModel> findAllByNull();
public String deleteCourse(Long courseId, Long userId);
} }

View File

@@ -1,6 +1,5 @@
package com.example.demo.app.domain.service.impl; package com.example.demo.app.domain.service.impl;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@@ -26,26 +25,5 @@ public class AllocationServiceImpl implements AllocationService {
return AllocationEntity.createAllocationModelList(allocationRepository.findAll()); return AllocationEntity.createAllocationModelList(allocationRepository.findAll());
} }
public List<AllocationModel> save(List<AllocationModel> allocationModelList) {
List<AllocationEntity> allocationEntityList = new ArrayList<>();
allocationModelList.forEach(allocationModel -> {
allocationEntityList.add(
AllocationModel.convertTo(
categoryRepository.findById(allocationModel.getCategoryId()).get(),
courseRepository.findById(allocationModel.getCourseId()).get(),
allocationModel.getAllocationRatio()));
});
List<AllocationModel> result = new ArrayList<>();
for (AllocationEntity allocationEntity : allocationEntityList) {
result.add(AllocationModel.convertFrom(allocationRepository.save(allocationEntity)));
}
return result;
}
} }

View File

@@ -7,14 +7,19 @@ import jakarta.transaction.Transactional;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.example.demo.app.domain.model.AllocationModel;
import com.example.demo.app.domain.model.CourseModel; import com.example.demo.app.domain.model.CourseModel;
import com.example.demo.app.domain.service.CourseService; import com.example.demo.app.domain.service.CourseService;
import com.example.demo.app.infra.entity.AllocationEntity;
import com.example.demo.app.infra.entity.CourseEntity; import com.example.demo.app.infra.entity.CourseEntity;
import com.example.demo.app.infra.entity.CourseOwnerEntity; import com.example.demo.app.infra.entity.CourseOwnerEntity;
import com.example.demo.app.infra.entity.UserEntity; import com.example.demo.app.infra.entity.UserEntity;
import com.example.demo.app.infra.repository.AllocationRepository;
import com.example.demo.app.infra.repository.CategoryRepository;
import com.example.demo.app.infra.repository.CourseOwnerRepository; import com.example.demo.app.infra.repository.CourseOwnerRepository;
import com.example.demo.app.infra.repository.CourseRepository; import com.example.demo.app.infra.repository.CourseRepository;
import com.example.demo.app.infra.repository.UserRepository; import com.example.demo.app.infra.repository.UserRepository;
import com.example.demo.app.presentation.form.AllocationFormList;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
@@ -22,9 +27,12 @@ import lombok.RequiredArgsConstructor;
@RequiredArgsConstructor @RequiredArgsConstructor
public class CourseServiceImpl implements CourseService { public class CourseServiceImpl implements CourseService {
private final AllocationRepository allocationRepository;
private final CourseRepository courseRepository; private final CourseRepository courseRepository;
private final UserRepository userRepository; private final UserRepository userRepository;
private final CourseOwnerRepository courseOwnerRepository; private final CourseOwnerRepository courseOwnerRepository;
private final CategoryRepository categoryRepository;
public List<CourseModel> findAll() { public List<CourseModel> findAll() {
@@ -49,12 +57,43 @@ public class CourseServiceImpl implements CourseService {
} }
@Transactional @Transactional
public CourseModel save(CourseModel courseModel, Long userId) { public CourseModel save(CourseModel courseModel, Long userId, AllocationFormList allocationFormList) {
List<UserEntity> userEntityList = new ArrayList<>(); List<UserEntity> userEntityList = new ArrayList<>();
userEntityList.add(userRepository.findById(userId).get()); userEntityList.add(userRepository.findById(userId).get());
CourseEntity result = courseRepository.save(CourseModel.convertTo(courseModel)); CourseEntity result = courseRepository.save(CourseModel.convertTo(courseModel));
List<AllocationModel> allocationModelList = new ArrayList<>();
allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId4(),
result.getCourseId(),
allocationFormList.getAllocationRatio4()));
allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId5(),
result.getCourseId(),
allocationFormList.getAllocationRatio5()));
allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId6(),
result.getCourseId(),
allocationFormList.getAllocationRatio6()));
allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId7(),
result.getCourseId(),
allocationFormList.getAllocationRatio7()));
allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId8(),
result.getCourseId(),
allocationFormList.getAllocationRatio8()));
allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId9(),
result.getCourseId(),
allocationFormList.getAllocationRatio9()));
allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId10(),
result.getCourseId(),
allocationFormList.getAllocationRatio10()));
allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId11(),
result.getCourseId(),
allocationFormList.getAllocationRatio11()));
allocationModelList.stream().forEach(allocation -> {
System.out.println(allocation.getCourseId());
});
UserEntity user = userRepository.findById(userId).orElse(null); UserEntity user = userRepository.findById(userId).orElse(null);
user.setCourseEntity(result); user.setCourseEntity(result);
@@ -67,8 +106,42 @@ public class CourseServiceImpl implements CourseService {
courseOwnerRepository.save(courseOwnerEntity); courseOwnerRepository.save(courseOwnerEntity);
List<AllocationEntity> allocationEntityList = new ArrayList<>();
allocationModelList.forEach(allocationModel -> {
allocationEntityList.add(
AllocationModel.convertTo(
categoryRepository.findById(allocationModel.getCategoryId()).get(),
courseRepository.findById(allocationModel.getCourseId()).get(),
allocationModel.getAllocationRatio()));
});
List<AllocationModel> resultList = new ArrayList<>();
for (AllocationEntity allocationEntity : allocationEntityList) {
resultList.add(AllocationModel.convertFrom(allocationRepository.save(allocationEntity)));
}
return CourseModel.convertFrom(result); return CourseModel.convertFrom(result);
}
@Transactional
public String deleteCourse(Long courseId, Long userId) {
UserEntity userEntity = userRepository.findById(userId).orElse(null);
System.out.println("***********************ここでエラー1");
if (userEntity.getCourseEntity().getCourseId() == courseId) {
return "selected";
}
System.out.println("***********************ここでエラー2");
allocationRepository.deleteByCourseId(courseId);
System.out.println("***********************ここでエラー3");
courseOwnerRepository.deleteByCourseId(courseId);
System.out.println("***********************ここでエラー4");
courseRepository.deleteById(courseId);
System.out.println("***********************ここでエラー5");
return "ok";
} }
} }

View File

@@ -3,6 +3,7 @@ package com.example.demo.app.infra.repository;
import java.util.List; import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository; 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.jpa.repository.Query;
import com.example.demo.app.domain.model.CourseInfoModel; import com.example.demo.app.domain.model.CourseInfoModel;
@@ -29,4 +30,8 @@ public interface AllocationRepository extends JpaRepository<AllocationEntity, Al
+ " a.categoryEntity.categoryId ASC ") + " a.categoryEntity.categoryId ASC ")
List<CourseInfoModel> findAllJoinedAllocation(); List<CourseInfoModel> findAllJoinedAllocation();
@Modifying
@Query("delete from AllocationEntity a where a.courseEntity.courseId = :courseId")
void deleteByCourseId(Long courseId);
} }

View File

@@ -1,9 +1,15 @@
package com.example.demo.app.infra.repository; package com.example.demo.app.infra.repository;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import com.example.demo.app.infra.entity.CourseOwnerEntity; import com.example.demo.app.infra.entity.CourseOwnerEntity;
public interface CourseOwnerRepository extends JpaRepository<CourseOwnerEntity, Long>{ public interface CourseOwnerRepository extends JpaRepository<CourseOwnerEntity, Long>{
@Modifying
@Query("delete from CourseOwnerEntity c where c.courseEntity.courseId = :courseId")
public void deleteByCourseId(Long courseId);
} }

View File

@@ -13,7 +13,6 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import com.example.demo.aop.aspect.SessionCheck; import com.example.demo.aop.aspect.SessionCheck;
import com.example.demo.app.domain.model.AllocationModel;
import com.example.demo.app.domain.model.CourseModel; import com.example.demo.app.domain.model.CourseModel;
import com.example.demo.app.domain.model.LoginModel; import com.example.demo.app.domain.model.LoginModel;
import com.example.demo.app.domain.service.AllocationService; import com.example.demo.app.domain.service.AllocationService;
@@ -111,48 +110,44 @@ public class CourseController {
LoginModel loginUser = (LoginModel) session.getAttribute(SessionKeyword.LOGIN_USER); LoginModel loginUser = (LoginModel) session.getAttribute(SessionKeyword.LOGIN_USER);
CourseForm form = CourseForm model.addAttribute("courseForm", courseForm);
.convertFrom(courseService.save(CourseForm.convertTo(courseForm), loginUser.getUserId()));
session.setAttribute(PageReturnAttributeKeyword.COURSE_ID, form.getCourseId());
return TransitionTargetPageNameKeyword.COURSE_CREATE_RATIO_HTML; return TransitionTargetPageNameKeyword.COURSE_CREATE_RATIO_HTML;
} }
@SessionCheck @SessionCheck
@PostMapping(TransitionTargetPageNameKeyword.COURSE_CREATE) @PostMapping(TransitionTargetPageNameKeyword.COURSE_CREATE)
public String createCoursePost(@ModelAttribute AllocationFormList allocationFormList, HttpSession session) { public String createCoursePost(@ModelAttribute CourseForm courseForm,
@ModelAttribute AllocationFormList allocationFormList, HttpSession session) {
LoginModel loginUser = (LoginModel) session.getAttribute(SessionKeyword.LOGIN_USER);
List<AllocationModel> allocationModelList = new ArrayList<>(); courseService.save(CourseForm.convertTo(courseForm), loginUser.getUserId(), allocationFormList);
allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId4(),
(Long) session.getAttribute(PageReturnAttributeKeyword.COURSE_ID),
allocationFormList.getAllocationRatio4()));
allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId5(),
(Long) session.getAttribute(PageReturnAttributeKeyword.COURSE_ID),
allocationFormList.getAllocationRatio5()));
allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId6(),
(Long) session.getAttribute(PageReturnAttributeKeyword.COURSE_ID),
allocationFormList.getAllocationRatio6()));
allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId7(),
(Long) session.getAttribute(PageReturnAttributeKeyword.COURSE_ID),
allocationFormList.getAllocationRatio7()));
allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId8(),
(Long) session.getAttribute(PageReturnAttributeKeyword.COURSE_ID),
allocationFormList.getAllocationRatio8()));
allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId9(),
(Long) session.getAttribute(PageReturnAttributeKeyword.COURSE_ID),
allocationFormList.getAllocationRatio9()));
allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId10(),
(Long) session.getAttribute(PageReturnAttributeKeyword.COURSE_ID),
allocationFormList.getAllocationRatio10()));
allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId11(),
(Long) session.getAttribute(PageReturnAttributeKeyword.COURSE_ID),
allocationFormList.getAllocationRatio11()));
allocationService.save(allocationModelList);
return TransitionTargetPageNameKeyword.REDIRECT + TransitionTargetPageNameKeyword.COURSE; return TransitionTargetPageNameKeyword.REDIRECT + TransitionTargetPageNameKeyword.COURSE;
} }
@SessionCheck
@PostMapping("/course/delete")
public String createCoursePost(@RequestParam Long courseId, HttpSession session, Model model) {
LoginModel loginUser = (LoginModel) session.getAttribute(SessionKeyword.LOGIN_USER);
System.out.println("**********************cousrId: " + courseId);
String condition = courseService.deleteCourse(courseId, loginUser.getUserId());
if (condition.equals("selected")) {
model.addAttribute("message", "適用中のコースは選べません");
return TransitionTargetPageNameKeyword.REDIRECT + TransitionTargetPageNameKeyword.COURSE;
} else if (condition.equals("ok")) {
return TransitionTargetPageNameKeyword.REDIRECT + TransitionTargetPageNameKeyword.COURSE;
}
model.addAttribute("message", "エラーが発生しました");
return TransitionTargetPageNameKeyword.REDIRECT + TransitionTargetPageNameKeyword.COURSE;
}
} }

View File

@@ -297,6 +297,23 @@ public class TransactionController {
transactionService.findMoneyRecord(transactionId), transactionService.findMoneyRecord(transactionId),
CategoryForm.convertFrom(categoryService.findByTransactionId(transactionId)).getTransactionType()); CategoryForm.convertFrom(categoryService.findByTransactionId(transactionId)).getTransactionType());
List<CategoryForm> expenseList = new ArrayList<CategoryForm>();
List<CategoryForm> incomeList = new ArrayList<CategoryForm>();
for (CategoryForm categoryForm : categoryFormList) {
if (categoryForm.getTransactionType() == 0) {
expenseList.add(categoryForm);
} else {
incomeList.add(categoryForm);
}
}
model.addAttribute(PageReturnAttributeKeyword.EXPENSE_LIST, expenseList);
model.addAttribute(PageReturnAttributeKeyword.INCOME_LIST, incomeList);
model.addAttribute(PageReturnAttributeKeyword.TRANSACTION_ID, transactionId); model.addAttribute(PageReturnAttributeKeyword.TRANSACTION_ID, transactionId);
model.addAttribute(PageReturnAttributeKeyword.TRANSACTION_FORM, transactionForm); model.addAttribute(PageReturnAttributeKeyword.TRANSACTION_FORM, transactionForm);
@@ -305,6 +322,8 @@ public class TransactionController {
model.addAttribute(PageReturnAttributeKeyword.TODAY, today); model.addAttribute(PageReturnAttributeKeyword.TODAY, today);
session.setAttribute(SessionKeyword.T_TYPE, transactionForm.getTransactionType());
return TransitionTargetPageNameKeyword.TRANSACTION_UPDATE_HTML; return TransitionTargetPageNameKeyword.TRANSACTION_UPDATE_HTML;
} }

View File

@@ -24,58 +24,64 @@
<div class="mb-3"> <div class="mb-3">
<label class="form-label" for="allocationRatio4">固定費</label> <label class="form-label" for="allocationRatio4">固定費</label>
<input class="form-control" type="number" min="0" max="100" onchange="inputChange()" id="allocationRatio4" th:field="*{allocationRatio4}" required> <input class="form-control" type="number" min="0" max="100" onchange="inputChange()"
id="allocationRatio4" th:field="*{allocationRatio4}" required>
</div> </div>
<br> <br>
<div class="mb-3"> <div class="mb-3">
<label class="form-label" for="allocationRatio5">食費</label> <label class="form-label" for="allocationRatio5">食費</label>
<input class="form-control" type="number" min="0" max="100" onchange="inputChange()" id="allocationRatio5" th:field="*{allocationRatio5}" required> <input class="form-control" type="number" min="0" max="100" onchange="inputChange()"
id="allocationRatio5" th:field="*{allocationRatio5}" required>
</div> </div>
<br> <br>
<div class="mb-3"> <div class="mb-3">
<label class="form-label" for="allocationRatio6">交通費</label> <label class="form-label" for="allocationRatio6">交通費</label>
<input class="form-control" type="number" min="0" max="100" onchange="inputChange()" id="allocationRatio6" th:field="*{allocationRatio6}" required> <input class="form-control" type="number" min="0" max="100" onchange="inputChange()"
id="allocationRatio6" th:field="*{allocationRatio6}" required>
</div> </div>
<br> <br>
<div class="mb-3"> <div class="mb-3">
<label class="form-label" for="allocationRatio7">日用品費</label> <label class="form-label" for="allocationRatio7">日用品費</label>
<input class="form-control" type="number" min="0" max="100" onchange="inputChange()" id="allocationRatio7" th:field="*{allocationRatio7}" required> <input class="form-control" type="number" min="0" max="100" onchange="inputChange()"
id="allocationRatio7" th:field="*{allocationRatio7}" required>
</div> </div>
<br> <br>
<div class="mb-3"> <div class="mb-3">
<label class="form-label" for="allocationRatio8">被服/美容費</label> <label class="form-label" for="allocationRatio8">被服/美容費</label>
<input class="form-control" type="number" min="0" max="100" onchange="inputChange()" id="allocationRatio8" th:field="*{allocationRatio8}" required> <input class="form-control" type="number" min="0" max="100" onchange="inputChange()"
id="allocationRatio8" th:field="*{allocationRatio8}" required>
</div> </div>
<br> <br>
<div class="mb-3"> <div class="mb-3">
<label class="form-label" for="allocationRatio9">医療費</label> <label class="form-label" for="allocationRatio9">医療費</label>
<input class="form-control" type="number" min="0" max="100" onchange="inputChange()" id="allocationRatio9" th:field="*{allocationRatio9}" required> <input class="form-control" type="number" min="0" max="100" onchange="inputChange()"
id="allocationRatio9" th:field="*{allocationRatio9}" required>
</div> </div>
<br> <br>
<div class="mb-3"> <div class="mb-3">
<label class="form-label" for="allocationRatio10">趣味/娯楽費</label> <label class="form-label" for="allocationRatio10">趣味/娯楽費</label>
<input class="form-control" type="number" min="0" max="100" onchange="inputChange()" id="allocationRatio10" <input class="form-control" type="number" min="0" max="100" onchange="inputChange()"
th:field="*{allocationRatio10}" required> id="allocationRatio10" th:field="*{allocationRatio10}" required>
</div> </div>
<br> <br>
<div class="mb-3"> <div class="mb-3">
<label class="form-label" for="allocationRatio11">その他</label> <label class="form-label" for="allocationRatio11">その他</label>
<input class="form-control" type="number" min="0" max="100" onchange="inputChange()" id="allocationRatio11" <input class="form-control" type="number" min="0" max="100" onchange="inputChange()"
th:field="*{allocationRatio11}" required> id="allocationRatio11" th:field="*{allocationRatio11}" required>
</div> </div>
<div class="mb-3"> <div class="mb-3">
@@ -88,7 +94,15 @@
<button type="submit" class="btn btn-primary" id="submit" disabled="true">登録</button> <button type="submit" class="btn btn-primary" id="submit" disabled="true">登録</button>
</div> </div>
</form>
<span th:object="${courseForm}">
<input type="hidden" id="courseName" th:field="*{courseName}" required>
<br>
<input type="hidden" id="description" th:field="*{description}">
</span>
</div>
</div> </div>
</div> </div>
</div> </div>

View File

@@ -23,6 +23,13 @@
</th:block> </th:block>
<form th:action="${mode == 'regist'} ? @{/user/register/return}: @{/change}" method="post"> <form th:action="${mode == 'regist'} ? @{/user/register/return}: @{/change}" method="post">
<th:block th:if="${mode == 'change'}">
<form th:action="@{/course/create}" method="get">
<button type="submit">新規登録</button>
</form>
</th:block>
<form th:action="${mode == 'regist'} ? @{/user/register/return}: @{/change}" id="totalForm" method="post">
<button type="submit" class="btn btn-primary w-100">確定</button> <button type="submit" class="btn btn-primary w-100">確定</button>
<div class="accordion" id="accordionExample"> <div class="accordion" id="accordionExample">
@@ -35,6 +42,8 @@
aria-controls="'collapse' + ${course.courseId}"> aria-controls="'collapse' + ${course.courseId}">
<span th:text="${course.courseName}"></span> <span th:text="${course.courseName}"></span>
</button> </button>
<p style="width: 120px;"><button type="button" class="btn btn-danger w-100"
th:attr="data-course-id=${course.courseId}" onclick="deleteCourse(this)">削除</button></p>
</h2> </h2>
<div th:id="'collapse' + ${course.courseId}" class="accordion-collapse collapse" <div th:id="'collapse' + ${course.courseId}" class="accordion-collapse collapse"
data-bs-parent="#accordionExample" style="padding-bottom: 120px;"> data-bs-parent="#accordionExample" style="padding-bottom: 120px;">
@@ -62,6 +71,43 @@
<div th:replace="~{footer :: footer}"></div> <div th:replace="~{footer :: footer}"></div>
</th:block> </th:block>
<script th:inline="javascript">
const message = /*[[${message}]]*/ null;
if (message != null) {
alert(message);
}
function deleteCourse(button) {
const courseId = button.dataset.courseId;
const totalForm = document.getElementById("totalForm");
const input = document.createElement("input");
const radioButtons = totalForm.querySelectorAll('input[name="courseId"]');
radioButtons.forEach(radio => {
radio.disabled = true;
});
input.type = "hidden";
input.name = "courseId";
input.value = courseId;
totalForm.appendChild(input);
totalForm.action = "/course/delete";
totalForm.method = "post";
courseId.value = courseId;
totalForm.submit();
}
</script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.7/dist/js/bootstrap.bundle.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.7/dist/js/bootstrap.bundle.min.js"></script>
</body> </body>

View File

@@ -113,7 +113,7 @@
<div th:replace="~{footer :: footer}"></div> <div th:replace="~{footer :: footer}"></div>
<script inline="javascript"> <script th:inline="javascript">
const transactionType = document.getElementById("transactionType"); const transactionType = document.getElementById("transactionType");
const categoryId = document.getElementById("categoryId"); const categoryId = document.getElementById("categoryId");
@@ -122,16 +122,9 @@
const tType = '[[${session.tType}]]'; const tType = '[[${session.tType}]]';
if (tType == "0") { function toggleCategory() {
transactionType.value = 0;
} else if (tType == "1") {
transactionType.value = 1;
}
if (transactionType.value === "0") {
transactionType.addEventListener("change", function () {
if (this.value === "0") {
for (let i = 0; i < expenseList.length; i++) { for (let i = 0; i < expenseList.length; i++) {
expenseList[i].style.display = ""; expenseList[i].style.display = "";
@@ -141,7 +134,7 @@
incomeList[i].style.display = "none"; incomeList[i].style.display = "none";
} }
} else if (this.value === "1") { } else if (transactionType.value === "1") {
for (let i = 0; i < expenseList.length; i++) { for (let i = 0; i < expenseList.length; i++) {
expenseList[i].style.display = "none"; expenseList[i].style.display = "none";
@@ -161,9 +154,24 @@
incomeList[i].style.display = "none"; incomeList[i].style.display = "none";
} }
} }
}
transactionType.addEventListener("change", function () {
toggleCategory();
categoryId.value = ""; categoryId.value = "";
}); });
if (tType == "0") {
transactionType.value = "0";
} else if (tType == "1") {
transactionType.value = "1";
}
toggleCategory();
</script> </script>

View File

@@ -83,18 +83,33 @@
カテゴリ カテゴリ
</label> </label>
<select id="categoryId" <!-- <select id="categoryId"-->
class="form-select" <!-- class="form-select"-->
th:field="*{categoryId}" <!-- th:field="*{categoryId}"-->
required> <!-- required>-->
<!-- <option value="">-->
<!-- 選択してください-->
<!-- </option>-->
<!-- <option th:each="category : ${categoryFormList}"-->
<!-- th:value="${category.categoryId}"-->
<!-- th:text="${category.categoryName}">-->
<!-- </option>-->
<!-- </select>-->
<select id="categoryId" class="form-select" th:field="*{categoryId}" required>
<option value=""> <option value="">
選択してください 選択してください
</option> </option>
<option th:each="category : ${categoryFormList}" <option class="expenseListClass" th:each="category : ${expenseList}"
th:value="${category.categoryId}" th:value="${category.categoryId}" th:text="${category.categoryName}">
th:text="${category.categoryName}"> </option>
<option class="incomeListClass" th:each="category : ${incomeList}"
th:value="${category.categoryId}" th:text="${category.categoryName}">
</option> </option>
</select> </select>
@@ -141,6 +156,68 @@
<div th:replace="~{footer :: footer}"> <div th:replace="~{footer :: footer}">
</div> </div>
<script th:inline="javascript">
const transactionType = document.getElementById("transactionType");
const categoryId = document.getElementById("categoryId");
const expenseList = document.getElementsByClassName("expenseListClass");
const incomeList = document.getElementsByClassName("incomeListClass");
const tType = '[[${session.tType}]]';
function toggleCategory() {
if (transactionType.value === "0") {
for (let i = 0; i < expenseList.length; i++) {
expenseList[i].style.display = "";
}
for (let i = 0; i < incomeList.length; i++) {
incomeList[i].style.display = "none";
}
} else if (transactionType.value === "1") {
for (let i = 0; i < expenseList.length; i++) {
expenseList[i].style.display = "none";
}
for (let i = 0; i < incomeList.length; i++) {
incomeList[i].style.display = "";
}
} else {
for (let i = 0; i < expenseList.length; i++) {
expenseList[i].style.display = "none";
}
for (let i = 0; i < incomeList.length; i++) {
incomeList[i].style.display = "none";
}
}
}
transactionType.addEventListener("change", function () {
toggleCategory();
categoryId.value = "";
});
if (tType == "0") {
transactionType.value = "0";
} else if (tType == "1") {
transactionType.value = "1";
}
toggleCategory();
</script>
</body> </body>
</html> </html>