Browse Source

edit bug edit proj edit user beres

athrainsky 1 year ago
parent
commit
879e4077a7

File diff suppressed because it is too large
+ 0 - 581
hs_err_pid9528.log


File diff suppressed because it is too large
+ 0 - 1938
replay_pid9528.log


+ 54 - 21
src/main/kotlin/com/server/alb/controllers/BugController.kt

@@ -3,7 +3,6 @@ package com.server.alb.controllers
 import com.server.alb.models.*
 import com.server.alb.repositories.*
 import com.server.alb.services.BugService
-import com.server.alb.services.BugValidationService.Companion.isValid
 import com.server.alb.services.ProjectService
 import com.server.alb.services.UserService
 import jakarta.servlet.http.HttpServletRequest
@@ -188,7 +187,6 @@ class BugController(
             }
         }
         println(bug)
-        println(bindingResult)
         return if (bindingResult.hasErrors()) {
             model.addAttribute("user", getUser())
             model.addAttribute("platform", getPlatform())
@@ -202,15 +200,17 @@ class BugController(
         }
     }
 
-    @RequestMapping(value = ["/save"], method = [RequestMethod.POST])
+    @PostMapping(value = ["/save"])
     fun saveBug(
         @Valid @ModelAttribute("bug") bug: ListBug,
+        bindingResult: BindingResult,
         redirectAttributes: RedirectAttributes,
-        result: BindingResult,
         request: HttpServletRequest,
+        model: Model
     ): String {
         val referer: String = request.getHeader("Referer")
         val url = referer.split("=")
+        val url2 = referer.split("8080/")
         if (bug.qcId == null) {
             val myUserDetails = SecurityContextHolder.getContext().authentication.name
             val userLogin = userRepository.findByUsername(myUserDetails)
@@ -218,18 +218,32 @@ class BugController(
                 bug.qcId = userLogin.get()
             }
         }
-        val successMessage: String = if (isValid(bug)) {
-            bugService.save(bug)
-            "Success save bug"
+        return if (bindingResult.hasErrors()) {
+            println(bug)
+            model.addAttribute("listQc", getUser())
+            model.addAttribute("listPro", getUser())
+            model.addAttribute("platform", getPlatform())
+            model.addAttribute("bug", bug)
+            model.addAttribute("worList", worList)
+            model.addAttribute("wStList", wStList)
+            model.addAttribute("dStList", dStList)
+            model.addAttribute("qcResultType", qcResultType)
+            redirectAttributes.addFlashAttribute("successMessage", "invalid value")
+            "redirect:/" + url2.last()
         } else {
-            "Failed ! Please try again"
+            bugService.save(bug)
+            redirectAttributes.addFlashAttribute("successMessage", "Success save bug")
+            if (referer.endsWith("=index")) "redirect:/" + url.last() else "redirect:/" + url.last()
         }
-        redirectAttributes.addFlashAttribute("successMessage", successMessage)
-        return if (referer.endsWith("=index")) "redirect:/" + url.last() else "redirect:/" + url.last()
     }
 
-    @RequestMapping(value = ["/saveUser"], method = [RequestMethod.POST])
-    fun saveUserEdit(@Valid @ModelAttribute("userRole") userRole: UserRole): String {
+    @PostMapping(value = ["/saveUser"])
+    fun saveUserEdit(
+        @Valid @ModelAttribute("userRole") userRole: UserRole,
+        bindingResult: BindingResult,
+        redirectAttributes: RedirectAttributes,
+        model: Model
+    ): String {
         val existUser = userService[userRole.id]
         val editUser = User()
         editUser.id = userRole.id
@@ -237,19 +251,38 @@ class BugController(
         editUser.password = passwordEncoder.encode(userRole.password)
         editUser.roles = userRole.role
         editUser.isEnabled = true
-        if (userService.checkIfValidOldPassword(userRole.oldPass, existUser.password)) {
-            userService.save(editUser)
+        println(editUser)
+        model.addAttribute("role", getRole())
+        val check = userService.checkIfValidOldPassword(userRole.oldPass, existUser.password)
+        if (!check) {
+            redirectAttributes.addFlashAttribute("successMessage", "old password not match")
+            return "redirect:/userList/edit/" + editUser.id
+        } else if (bindingResult.hasErrors()) {
+            redirectAttributes.addFlashAttribute("successMessage", "invalid value")
+            return "redirect:/userList/edit/" + editUser.id
         }
+        userService.save(editUser)
         return "redirect:/userList"
     }
 
-    @RequestMapping(value = ["/saveProj"], method = [RequestMethod.POST])
-    fun saveProjEdit(@Valid @ModelAttribute("project") project: Project): String {
-        projectService.save(project)
-        return "redirect:/proj"
+    @PostMapping(value = ["/saveProj"])
+    fun saveProjEdit(
+        @Valid @ModelAttribute("project") project: Project,
+        bindingResult: BindingResult,
+        redirectAttributes: RedirectAttributes,
+        model: Model
+    ): String {
+        return if (bindingResult.hasErrors()) {
+            println(project)
+            redirectAttributes.addFlashAttribute("successMessage", "invalid value")
+            "redirect:/proj/edit/" + project.id
+        } else {
+            projectService.save(project)
+            "redirect:/proj"
+        }
     }
 
-    @RequestMapping("/edit/{id}")
+    @GetMapping("/edit/{id}")
     fun showEditBugForm(
         @PathVariable(name = "id") id: Long,
         @RequestParam page: String,
@@ -267,7 +300,7 @@ class BugController(
         return mav
     }
 
-    @RequestMapping("/userList/edit/{id}")
+    @GetMapping("/userList/edit/{id}")
     fun editUser(@PathVariable(name = "id") id: Long): ModelAndView {
         val mav = ModelAndView("edit_user")
         val user: User = userService[id]
@@ -281,7 +314,7 @@ class BugController(
         return mav
     }
 
-    @RequestMapping("/proj/edit/{id}")
+    @GetMapping("/proj/edit/{id}")
     fun editProject(@PathVariable(name = "id") id: Long): ModelAndView {
         val mav = ModelAndView("edit_proj")
         val project: Project = projectService[id]

+ 4 - 0
src/main/kotlin/com/server/alb/models/User.kt

@@ -39,4 +39,8 @@ class User() {
         }
     }
 
+    override fun toString(): String {
+        return ("User [id=$id,username=$username, password=$password, isEnabled=$isEnabled, roles=$roles]")
+    }
+
 }

+ 1 - 2
src/main/kotlin/com/server/alb/services/BugValidationService.kt

@@ -7,10 +7,9 @@ import org.springframework.stereotype.Service
 
 @Service
 class BugValidationService {
-
     companion object {
         fun isValid(bug: ListBug?): Boolean {
-            return (bug != null && StringUtils.isNotBlank(bug.description) && StringUtils.isNotBlank(bug.link))
+            return (bug != null && StringUtils.isNotEmpty(bug.description) && StringUtils.isNotBlank(bug.link))
         }
     }
 

+ 4 - 2
src/main/resources/templates/add_bug.html

@@ -22,7 +22,8 @@
                 <td><select th:field="*{platform}">
                     <option th:each="platform: ${platform}" th:value="${platform.id}" th:text="${platform.name}"/>
                 </select></td>
-                <td th:if="${#fields.hasErrors('platform')}" th:errors="*{platform}" style="color:red">Platform Error</td>
+                <td th:if="${#fields.hasErrors('platform')}" th:errors="*{platform}" style="color:red">Platform Error
+                </td>
             </tr>
             <tr>
                 <td>Link Good Day:</td>
@@ -40,7 +41,8 @@
             <tr>
                 <td>Bug:</td>
                 <td><input type="text" th:field="*{description}" class="form-control"/></td>
-                <td th:if="${#fields.hasErrors('description')}" th:errors="*{description}" style="color:red">Bug Error</td>
+                <td th:if="${#fields.hasErrors('description')}" th:errors="*{description}" style="color:red">Bug Error
+                </td>
             </tr>
             <tr>
                 <td>Link Image:</td>

+ 10 - 4
src/main/resources/templates/edit_bug.html

@@ -10,9 +10,8 @@
 <body>
 <div class="container py-5 h-100">
     <h1>Edit Bug</h1>
+    <span th:text="${successMessage}" style="color:red"></span>
     <br/>
-    <div th:each="project: ${project}">
-    </div>
     <form action="#" th:action="@{/save}" th:object="${bug}" method="post">
         <table>
             <tr>
@@ -21,8 +20,8 @@
             </tr>
             <tr>
                 <td>Tanggal QC:</td>
-                <td><input type="date" pattern="dd-MM-yyyy" th:field="*{date}" class="form-control">
-                </td>
+                <td><input type="date" pattern="dd-MM-yyyy" th:field="*{date}" class="form-control"></td>
+                <td th:if="${#fields.hasErrors('date')}" th:errors="*{date}" style="color:red">Tanggal Error</td>
             </tr>
             <tr>
                 <td>Tim QC:</td>
@@ -36,10 +35,13 @@
                     <option value="">Pilih..</option>
                     <option th:each="platform: ${platform}" th:value="${platform.id}" th:text="${platform.name}"/>
                 </select></td>
+                <td th:if="${#fields.hasErrors('platform')}" th:errors="*{platform}" style="color:red">Platform Error
+                </td>
             </tr>
             <tr>
                 <td>Link Good Day:</td>
                 <td><input type="text" th:field="*{link}" class="form-control"/></td>
+                <td th:if="${#fields.hasErrors('link')}" th:errors="*{link}" style="color:red">Link Error</td>
             </tr>
             <tr>
                 <td>Hasil QC:</td>
@@ -48,16 +50,20 @@
                     <option th:each="qcResultType: ${qcResultType}" th:value="${qcResultType}"
                             th:text="${qcResultType.display}"/>
                 </select></td>
+                <td th:if="${#fields.hasErrors('result')}" th:errors="*{result}" style="color:red">Hasil QC Error</td>
             </tr>
             <tr>
                 <td>Bug:</td>
                 <td><input type="text" th:field="*{description}" class="form-control"/></td>
+                <td th:if="${#fields.hasErrors('description')}" th:errors="*{description}" style="color:red">Bug Error
+                </td>
             </tr>
             <tr>
                 <td>Programmer:</td>
                 <td><select th:field="*{proId}">
                     <option th:each="user: ${listPro}" th:value="${user.id}" th:text="${user.username}"/>
                 </select></td>
+                <td th:if="${#fields.hasErrors('proId')}" th:errors="*{proId}" style="color:red">Programmer Error</td>
             </tr>
             <tr>
                 <td>Link Image:</td>

+ 6 - 3
src/main/resources/templates/edit_proj.html

@@ -10,6 +10,7 @@
 <body>
 <div class="container py-5 h-100">
     <h1>Edit Project</h1>
+    <span th:text="${successMessage}" style="color:red"></span>
     <br/>
     <form action="#" th:action="@{/saveProj}" th:object="${project}" method="post">
         <table>
@@ -19,12 +20,14 @@
             </tr>
             <tr>
                 <td>Project Name:</td>
-                <td><input type="text" th:field="*{name}" class="form-control">
-                </td>
+                <td><input type="text" th:field="*{name}" class="form-control"></td>
+                <td th:if="${#fields.hasErrors('name')}" th:errors="*{name}" style="color:red">name Error</td>
             </tr>
             <tr>
                 <td>Description:</td>
-                <td><input type="text" th:field="*{description}" class="form-control">
+                <td><input type="text" th:field="*{description}" class="form-control"></td>
+                <td th:if="${#fields.hasErrors('description')}" th:errors="*{description}" style="color:red">description
+                    Error
                 </td>
             </tr>
             <tr>

+ 5 - 0
src/main/resources/templates/edit_user.html

@@ -10,6 +10,7 @@
 <body>
 <div class="container py-5 h-100">
     <h1>Edit User</h1>
+    <span th:text="${successMessage}" style="color:red"></span>
     <br/>
     <form action="#" th:action="@{/saveUser}" th:object="${userRole}" method="post">
         <table>
@@ -20,22 +21,26 @@
             <tr>
                 <td>User Name:</td>
                 <td><input type="text" th:field="*{username}" class="form-control">
+                <td th:if="${#fields.hasErrors('username')}" th:errors="*{username}" style="color:red">username Error</td>
                 </td>
             </tr>
             <tr>
                 <td>Old Password:</td>
                 <td><input id="oldPass" type="password" th:field="*{oldPass}" class="form-control">
+                <td th:if="${#fields.hasErrors('oldPass')}" th:errors="*{oldPass}" style="color:red">oldPass Error</td>
                 </td>
             </tr>
             <tr>
                 <td>New Password:</td>
                 <td><input id="password" type="password" th:field="*{password}" class="form-control">
+                <td th:if="${#fields.hasErrors('password')}" th:errors="*{password}" style="color:red">password Error</td>
                 </td>
             </tr>
             <tr>
                 <td>Role:</td>
                 <td><select th:field="*{role}">
                     <option th:each="role: ${role}" th:value="${role.id}" th:text="${role.name}"></option>
+                    <td th:if="${#fields.hasErrors('role')}" th:errors="*{role}" style="color:red">role Error</td>
                 </select></td>
             </tr>
             <tr>

+ 1 - 1
src/main/resources/templates/inPro.html

@@ -78,7 +78,7 @@
             <td th:text="${bug.development}">Development</td>
             <td th:text="${bug._displayDevStat}">QC</td>
             <td sec:authorize="hasAnyAuthority('ADMIN', 'QC')">
-                <a th:href="@{'/edit/' + ${bug.id} + '?page=inPro' +${project}}">Edit</a> &nbsp;&nbsp;&nbsp;&nbsp;
+                <a th:href="@{'/edit/' + ${bug.id} + '?page=inPro/' +${project}}">Edit</a> &nbsp;&nbsp;&nbsp;&nbsp;
                 <a th:href="@{'/delete2/' + ${bug.id}}">Delete</a>
             </td>
         </tr>