Skip to content

Commit 2cf10c5

Browse files
committed
Message: Allow to search - refs BT#21705
1 parent 1025d1d commit 2cf10c5

File tree

3 files changed

+65
-8
lines changed

3 files changed

+65
-8
lines changed

assets/css/scss/_messages.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22
&__actions {
33
@apply flex gap-2 justify-end items-center flex-wrap mb-4;
44
}
5+
6+
&__searcher-container {
7+
@apply flex justify-end;
8+
9+
.p-inputgroup {
10+
@apply md:w-1/3;
11+
}
12+
}
513
}
614

715
.message-show {

assets/vue/views/message/MessageList.vue

Lines changed: 55 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,26 @@
9393
@page="onPage($event)"
9494
@sort="sortingChanged($event)"
9595
>
96+
<template #header>
97+
<form
98+
class="message-list__searcher-container"
99+
@submit.prevent="onSearch"
100+
>
101+
<InputGroup>
102+
<InputText
103+
v-model="searchText"
104+
:placeholder="t('Search')"
105+
type="text"
106+
/>
107+
<BaseButton
108+
icon="search"
109+
type="primary"
110+
is-submit
111+
/>
112+
</InputGroup>
113+
</form>
114+
</template>
115+
96116
<Column selection-mode="multiple" />
97117
<Column :header="showingInbox ? t('From') : t('To')">
98118
<template #body="slotProps">
@@ -198,6 +218,8 @@ import { useNotification } from "../../composables/notification"
198218
import { useMessageRelUserStore } from "../../store/messageRelUserStore"
199219
import { useSecurityStore } from "../../store/securityStore"
200220
import SectionHeader from "../../components/layout/SectionHeader.vue"
221+
import InputGroup from "primevue/inputgroup"
222+
import InputText from "primevue/inputtext"
201223
202224
const route = useRoute()
203225
const router = useRouter()
@@ -285,6 +307,9 @@ const totalItems = computed(() => store.getters["message/getTotalItems"])
285307
286308
const title = ref(null)
287309
310+
const selectedTag = ref(null)
311+
const searchText = ref("")
312+
288313
const selectedItems = ref([])
289314
290315
const rowClass = (data) => {
@@ -305,6 +330,22 @@ function loadMessages(reset = true) {
305330
dtMessages.value.resetPage()
306331
}
307332
333+
fetchPayload.msgType = MESSAGE_TYPE_INBOX
334+
335+
if (selectedTag.value) {
336+
fetchPayload["receivers.tags.tag"] = selectedTag.value.tag
337+
}
338+
339+
if (showingInbox.value) {
340+
fetchPayload["receivers.receiver"] = securityStore.user["@id"]
341+
} else {
342+
fetchPayload.sender = securityStore.user["@id"]
343+
}
344+
345+
if (searchText.value) {
346+
fetchPayload.search = searchText.value
347+
}
348+
308349
store.dispatch("message/fetchAll", fetchPayload)
309350
}
310351
@@ -313,10 +354,9 @@ const showingInbox = ref(false)
313354
function showInbox() {
314355
showingInbox.value = true
315356
title.value = t("Inbox")
357+
selectedTag.value = null
316358
317359
fetchPayload = {
318-
msgType: MESSAGE_TYPE_INBOX,
319-
"receivers.receiver": securityStore.user["@id"],
320360
"order[sendDate]": "desc",
321361
itemsPerPage: initialRowsPerPage,
322362
page: 1,
@@ -328,11 +368,9 @@ function showInbox() {
328368
function showInboxByTag(tag) {
329369
showingInbox.value = true
330370
title.value = tag.tag
371+
selectedTag.value = tag
331372
332373
fetchPayload = {
333-
msgType: MESSAGE_TYPE_INBOX,
334-
"receivers.receiver": securityStore.user["@id"],
335-
"receivers.tags.tag": tag.tag,
336374
"order[sendDate]": "desc",
337375
itemsPerPage: initialRowsPerPage,
338376
page: 1,
@@ -344,10 +382,9 @@ function showInboxByTag(tag) {
344382
function showUnread() {
345383
showingInbox.value = true
346384
title.value = t("Unread")
385+
selectedTag.value = null
347386
348387
fetchPayload = {
349-
msgType: MESSAGE_TYPE_INBOX,
350-
"receivers.receiver": securityStore.user["@id"],
351388
"order[sendDate]": "desc",
352389
"receivers.read": false,
353390
itemsPerPage: initialRowsPerPage,
@@ -360,9 +397,9 @@ function showUnread() {
360397
function showSent() {
361398
showingInbox.value = false
362399
title.value = t("Sent")
400+
selectedTag.value = null
363401
364402
fetchPayload = {
365-
msgType: MESSAGE_TYPE_INBOX,
366403
sender: securityStore.user["@id"],
367404
"order[sendDate]": "desc",
368405
itemsPerPage: initialRowsPerPage,
@@ -454,4 +491,14 @@ function showDlgConfirmDeleteMultiple() {
454491
onMounted(() => {
455492
showInbox()
456493
})
494+
495+
function onSearch() {
496+
fetchPayload = {
497+
"order[sendDate]": "desc",
498+
itemsPerPage: initialRowsPerPage,
499+
page: 1,
500+
}
501+
502+
loadMessages()
503+
}
457504
</script>

src/CoreBundle/Entity/Message.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use ApiPlatform\Metadata\GetCollection;
1717
use ApiPlatform\Metadata\Post;
1818
use ApiPlatform\Metadata\Put;
19+
use Chamilo\CoreBundle\Filter\SearchOr;
1920
use Chamilo\CoreBundle\Repository\MessageRepository;
2021
use Chamilo\CoreBundle\State\MessageByGroupStateProvider;
2122
use Chamilo\CoreBundle\State\MessageProcessor;
@@ -76,6 +77,7 @@
7677
BooleanFilter::class,
7778
properties: ['receivers.read']
7879
)]
80+
#[ApiFilter(SearchOr::class, properties: ['title', 'content'])]
7981
class Message
8082
{
8183
public const MESSAGE_TYPE_INBOX = 1;

0 commit comments

Comments
 (0)