Skip to content

Commit 0f31c71

Browse files
committed
feat/qg-273: реализован возврат на исходную страницу со страницы формы записи журнала
1 parent 56bc2d3 commit 0f31c71

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

app/src/main/kotlin/pro/qyoga/app/therapist/clients/journal/edit_entry/create/CreateJournalEntryPageController.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package pro.qyoga.app.therapist.clients.journal.edit_entry.create
22

33
import org.springframework.data.repository.findByIdOrNull
4+
import org.springframework.http.ResponseEntity
45
import org.springframework.security.core.annotation.AuthenticationPrincipal
56
import org.springframework.stereotype.Controller
67
import org.springframework.web.bind.annotation.GetMapping
@@ -9,7 +10,6 @@ import org.springframework.web.bind.annotation.PathVariable
910
import org.springframework.web.bind.annotation.PostMapping
1011
import org.springframework.web.servlet.ModelAndView
1112
import pro.azhidkov.platform.kotlin.isFailureOf
12-
import pro.azhidkov.platform.spring.http.hxRedirect
1313
import pro.qyoga.app.platform.notFound
1414
import pro.qyoga.app.therapist.clients.ClientPageModel
1515
import pro.qyoga.app.therapist.clients.ClientPageTab
@@ -68,7 +68,10 @@ class CreateJournalEntryPageController(
6868

6969
return when {
7070
result.isSuccess ->
71-
hxRedirect("/therapist/clients/$clientId/journal", "HX-Trigger" to "formSaved")
71+
ResponseEntity
72+
.ok()
73+
.header("HX-Trigger", "formSaved")
74+
.build<Unit>()
7275

7376
result.isFailureOf<DuplicatedDate>() -> {
7477
val ex = result.exceptionOrNull() as DuplicatedDate

app/src/main/resources/templates/therapist/clients/client-add_journal_entry-fragment.html

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@
6969
return serverState != null && serverState[key] !== form[key];
7070
}
7171

72+
function closeForm() {
73+
resetLocalState();
74+
window.location.href = document.referrer;
75+
}
76+
7277
window.addEventListener("htmx:afterSettle", () => {
7378
document.querySelectorAll(".form-control").forEach(it => {
7479
it.setAttribute("x-model", "form." + it.name);
@@ -78,7 +83,7 @@
7883

7984
document.body.addEventListener('formSaved', function () {
8085
console.debug('Form saved successfully, resetting local storage');
81-
resetLocalState();
86+
closeForm();
8287
});
8388

8489
</script>
@@ -136,26 +141,25 @@
136141
<div class="form-text">Начните вводить название для поиска</div>
137142
</div>
138143
</div>
139-
<div class="mb-3 col">
144+
<div class="mb-3 col">
140145

141-
<div class="form-floating">
146+
<div class="form-floating">
142147
<textarea class="form-control full-height"
143148
id="text-input" name="journalEntryText" required rows="12"
144149
th:text="${entry?.journalEntryText ?: ''}"
145150
placeholder=""
146151
></textarea>
147-
<label class="form-label" for="text-input">Запись <span class="text-danger">*</span></label>
148-
</div>
152+
<label class="form-label" for="text-input">Запись <span class="text-danger">*</span></label>
153+
</div>
149154
</div>
150155

151156
<div class="row g-2 justify-content-end">
152157
<div class="col-6 col-sm-auto text-center">
153-
<a @click="resetLocalState()"
158+
<button @click="closeForm()"
154159
class="btn btn-outline-danger"
155-
style="min-width: 110px;"
156-
th:href="@{/therapist/clients/{id}/journal(id=${client.id})}">
160+
style="min-width: 110px;">
157161
Отмена
158-
</a>
162+
</button>
159163
</div>
160164
<div class="col-6 col-sm-auto text-center">
161165
<button

app/src/test/kotlin/pro/qyoga/tests/clients/api/TherapistClientJournalApi.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ class TherapistClientJournalApi(override val authCookie: Cookie) : AuthorizedApi
9292
fun createJournalEntry(clientId: UUID, journalEntry: EditJournalEntryRq) {
9393
postNewJournalEntry(journalEntry, clientId) Then {
9494
statusCode(HttpStatus.OK.value())
95-
header("Hx-Redirect", Matchers.matchesRegex(".*" + JournalPageController.JOURNAL_PAGE_PATH.pathToRegex()))
9695
}
9796
}
9897

0 commit comments

Comments
 (0)