Skip to content

Commit 78a32a0

Browse files
committed
feat/qg-274: поле ввода терапевтической задачи переведено на компонент комбобокса
Помимо приведения UI/UX к актуальному гайдлайну, это решило проблему с потерей данных после поиска ТЗ
1 parent 510783e commit 78a32a0

File tree

16 files changed

+69
-42
lines changed

16 files changed

+69
-42
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class CreateJournalEntryOp(
3030
checkNotNull(client) { "Client for journal entry not found by id=$clientId" }
3131

3232
val therapeuticTask = therapeuticTasksRepo.getOrCreate(
33-
TherapeuticTask(principal.id, editJournalEntryRq.therapeuticTaskName)
33+
TherapeuticTask(principal.id, editJournalEntryRq.therapeuticTaskTitle)
3434
)
3535
val newEntry = JournalEntry(
3636
client.ref(),

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ data class CreateJournalEntryPageModel(
2121
ModelAndView(
2222
viewId(JOURNAL_ENTRY_VIEW_NAME, fragment), mapOf(
2323
"client" to client,
24+
"entry" to null,
2425
"entryDate" to entryDate,
2526
"duplicatedDate" to duplicatedDate,
2627
"formAction" to createFormAction(client.ref())

app/src/main/kotlin/pro/qyoga/app/therapist/clients/journal/edit_entry/edit/EditJournalEntryOp.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class EditJournalEntryOp(
2626
principal: QyogaUserDetails,
2727
): JournalEntry? {
2828
val therapeuticTask = therapeuticTasksRepo.getOrCreate(
29-
TherapeuticTask(principal.id, editJournalEntryRq.therapeuticTaskName)
29+
TherapeuticTask(principal.id, editJournalEntryRq.therapeuticTaskTitle)
3030
)
3131

3232
val query = query {

app/src/main/kotlin/pro/qyoga/app/therapist/therapy/therapeutic_tasks/components/SearchTherapeuticTasksController.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class SearchTherapeuticTasksController(
1919

2020
@GetMapping
2121
fun search(
22-
@RequestParam("therapeuticTaskName") searchKey: String,
22+
@RequestParam(SEARCH_KEY_PARAM_NAME) searchKey: String,
2323
@AuthenticationPrincipal therapist: QyogaUserDetails,
2424
): ModelAndView {
2525
val tasks =
@@ -35,4 +35,8 @@ class SearchTherapeuticTasksController(
3535
)
3636
}
3737

38+
companion object {
39+
const val SEARCH_KEY_PARAM_NAME = "therapeuticTaskName"
40+
}
41+
3842
}

app/src/main/kotlin/pro/qyoga/core/clients/journals/dtos/EditJournalEntryRq.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
package pro.qyoga.core.clients.journals.dtos
22

3-
import com.fasterxml.jackson.annotation.JsonFormat
4-
import org.springframework.format.annotation.DateTimeFormat
53
import pro.azhidkov.platform.spring.sdj.ergo.hydration.resolveOrThrow
64
import pro.qyoga.core.clients.journals.model.JournalEntry
7-
import pro.qyoga.l10n.RUSSIAN_DATE_FORMAT_PATTERN
5+
import pro.qyoga.core.therapy.therapeutic_tasks.model.TherapeuticTaskRef
86
import java.time.LocalDate
97

108

119
data class EditJournalEntryRq(
12-
@DateTimeFormat(pattern = RUSSIAN_DATE_FORMAT_PATTERN)
13-
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = RUSSIAN_DATE_FORMAT_PATTERN)
1410
val date: LocalDate,
15-
val therapeuticTaskName: String,
11+
val therapeuticTask: TherapeuticTaskRef?,
12+
val therapeuticTaskTitle: String,
1613
val journalEntryText: String,
1714
val version: Long
1815
) {
1916

2017
constructor(journalEntry: JournalEntry) : this(
2118
journalEntry.date,
19+
journalEntry.therapeuticTask,
2220
journalEntry.therapeuticTask.resolveOrThrow().name,
2321
journalEntry.entryText,
2422
journalEntry.version

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

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
th:fragment="journalEntryForm"
2323
th:hx-post="${formAction}"
2424
x-data="entryData()"
25-
x-init="$watch('form', (form) => saveLocalState(form))">
25+
x-init="$watch('form', (form) => saveLocalState(form), {deep: true})">
2626

2727
<script id="formDraft" th:inline="javascript">
2828
let serverState = /*[[${entry}]]*/ null;
@@ -36,7 +36,7 @@
3636

3737
let formData;
3838
if (serverState == null) {
39-
formData = localState || {version: 0, date: entryDate};
39+
formData = localState || {version: 0, date: entryDate, therapeuticTask: {id: null}};
4040
} else if (serverState.version === localState?.version) {
4141
formData = localState
4242
} else {
@@ -49,7 +49,11 @@
4949
return {
5050
form: formData,
5151
serverState: serverState,
52-
hasUnsavedChanges: hasUnsavedEdits || newCardWasntSaved
52+
hasUnsavedChanges: hasUnsavedEdits || newCardWasntSaved,
53+
therapeuticTaskSelected(event) {
54+
this.form.therapeuticTask = {id: event.detail.itemId};
55+
this.form.therapeuticTaskTitle = event.detail.itemTitle;
56+
}
5357
}
5458
}
5559

@@ -101,27 +105,34 @@
101105
min="2000-01-01"
102106
name="date"
103107
required
104-
th:classappend="${duplicatedDate} ? 'is-invalid' : ''"
108+
th:classappend="${duplicatedDate} ? 'is-invalid' : ''"
105109
th:value="${entry?.date ?: entryDate}"
106110
type="date">
107111
<label for="date">Дата <span class="text-danger">*</span></label>
108-
<div class="invalid-feedback" id="duplicatedDateMessage">
109-
Запись за эту дату уже существует
112+
<div class="invalid-feedback" id="duplicatedDateMessage">
113+
Запись за эту дату уже существует
114+
</div>
110115
</div>
111116
</div>
112-
<div class="mb-3 col">
113-
<label class="form-label" for="task-input">Терапевтическая задача</label>
114-
<input class="form-control"
115-
hx-get="/therapist/therapeutic-tasks/autocomplete-search"
116-
id="task-input" minlength="3" name="therapeuticTaskName" required
117-
hx-swap="outerHTML"
118-
hx-target="#therapeuticTasks"
119-
hx-trigger="input[inputType != 'insertReplacementText' && target.value.length > 2] delay:0.3s"
120-
list="therapeuticTasks"
121-
th:value="${entry?.therapeuticTaskName ?: ''}"
122-
type="text"
117+
118+
<div @itemSelected="therapeuticTaskSelected($event)" class="mb-3 col">
119+
<combo-box-fragment id="therapeuticTask"
120+
th:replace="~{components/combo-box.html :: comboBox(
121+
name='therapeuticTask',
122+
fetchUrl='/therapist/therapeutic-tasks/autocomplete-search-combo-box',
123+
value=${entry?.therapeuticTask?.id},
124+
valueName=${entry?.therapeuticTaskTitle},
125+
placeholderView=~{:: #therapeuticTaskPlaceholder},
126+
itemSelected='therapeuticTaskSelected($event)',
127+
minlength=2,
128+
maxlength=50,
129+
required=true,
130+
selectOnly=false)}"
123131
>
124-
<datalist id="therapeuticTasks"></datalist>
132+
<label id="therapeuticTaskPlaceholder">Терапевтическая задача <span
133+
class="text-danger">*</span></label>
134+
</combo-box-fragment>
135+
<div class="form-text">Начните вводить название для поиска</div>
125136
</div>
126137
</div>
127138
<div class="mb-3 col">

app/src/test/kotlin/pro/qyoga/tests/cases/app/therapist/clients/journal/CreateJournalEntryFragmentTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class CreateJournalEntryFragmentTest : QYogaAppIntegrationBaseTest() {
7575
// Проверка
7676
document.select("body form").single() shouldBeComponent CreateJournalEntryForm
7777
CreateJournalEntryForm.dateInput.value(document) shouldBe LocalDate.now().toString()
78-
CreateJournalEntryForm.therapeuticTaskNameInput.value(document) shouldBe createJournalEntryRequest.therapeuticTaskName
78+
CreateJournalEntryForm.therapeuticTaskComboBox.title(document) shouldBe createJournalEntryRequest.therapeuticTaskTitle
7979
CreateJournalEntryForm.entryTextInput.value(document) shouldBe createJournalEntryRequest.journalEntryText
8080
document shouldHaveElement JournalEntryForm.DUPLICATED_DATE_MESSAGE
8181
}

app/src/test/kotlin/pro/qyoga/tests/cases/app/therapist/clients/journal/EditJournalEntryPageTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class EditJournalEntryPageTest : QYogaAppIntegrationBaseTest() {
8484
// Проверка
8585
document.select("body form").single() shouldBeComponent EditJournalEntryForm
8686
EditJournalEntryForm.dateInput.value(document) shouldBe firstEntryDate.toString()
87-
EditJournalEntryForm.therapeuticTaskNameInput.value(document) shouldBe editJournalEntryRequest.therapeuticTaskName
87+
EditJournalEntryForm.therapeuticTaskComboBox.title(document) shouldBe editJournalEntryRequest.therapeuticTaskTitle
8888
EditJournalEntryForm.entryTextInput.value(document) shouldBe editJournalEntryRequest.journalEntryText
8989
document shouldHaveElement JournalEntryForm.DUPLICATED_DATE_MESSAGE
9090
}

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,12 @@ class TherapistClientJournalApi(override val authCookie: Cookie) : AuthorizedApi
116116
formParam(CreateJournalEntryForm.version.name, journalEntry.version)
117117
formParam(CreateJournalEntryForm.dateInput.name, journalEntry.date.toString())
118118
formParam(
119-
CreateJournalEntryForm.therapeuticTaskNameInput.name,
120-
journalEntry.therapeuticTaskName
119+
CreateJournalEntryForm.therapeuticTaskComboBox.name,
120+
""
121+
)
122+
formParam(
123+
CreateJournalEntryForm.therapeuticTaskComboBox.titleInputId,
124+
journalEntry.therapeuticTaskTitle
121125
)
122126
formParam(CreateJournalEntryForm.entryTextInput.name, journalEntry.journalEntryText)
123127
pathParam("clientId", clientId)
@@ -160,8 +164,12 @@ class TherapistClientJournalApi(override val authCookie: Cookie) : AuthorizedApi
160164
formParam(CreateJournalEntryForm.version.name, journalEntry.version)
161165
formParam(CreateJournalEntryForm.dateInput.name, journalEntry.date.toString())
162166
formParam(
163-
CreateJournalEntryForm.therapeuticTaskNameInput.name,
164-
journalEntry.therapeuticTaskName
167+
CreateJournalEntryForm.therapeuticTaskComboBox.name,
168+
""
169+
)
170+
formParam(
171+
CreateJournalEntryForm.therapeuticTaskComboBox.titleInputId,
172+
journalEntry.therapeuticTaskTitle
165173
)
166174
formParam(CreateJournalEntryForm.entryTextInput.name, journalEntry.journalEntryText)
167175
pathParam("clientId", clientId)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import org.jsoup.nodes.Document
1010
import org.springframework.http.HttpStatus
1111
import pro.qyoga.app.therapist.therapy.therapeutic_tasks.components.TherapeuticTasksComboBoxController
1212
import pro.qyoga.core.therapy.therapeutic_tasks.model.TherapeuticTask
13-
import pro.qyoga.tests.pages.therapist.clients.journal.entry.CreateJournalEntryForm
1413
import pro.qyoga.tests.pages.therapist.clients.journal.entry.TherapeuticTasksSearchResult
14+
import pro.qyoga.tests.pages.therapist.therapy.programs.EditProgramForm
1515
import pro.qyoga.tests.pages.therapist.therapy.therapeutic_tasks.TherapeuticTasksListPage
1616

1717
class TherapistTherapeuticTasksApi(override val authCookie: Cookie) : AuthorizedApi {
@@ -32,7 +32,7 @@ class TherapistTherapeuticTasksApi(override val authCookie: Cookie) : Authorized
3232
fun autocompleteSearch(searchKey: String): Document {
3333
return Given {
3434
authorized()
35-
queryParams(CreateJournalEntryForm.therapeuticTaskNameInput.name, searchKey)
35+
queryParams(EditProgramForm.therapeuticTaskInput.name, searchKey)
3636
} When {
3737
get(TherapeuticTasksSearchResult.PATH)
3838
} Then {

0 commit comments

Comments
 (0)