Skip to content

Commit

Permalink
Message: Allow to search - refs BT#21705
Browse files Browse the repository at this point in the history
  • Loading branch information
AngelFQC committed Jun 11, 2024
1 parent 1025d1d commit 2cf10c5
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 8 deletions.
8 changes: 8 additions & 0 deletions assets/css/scss/_messages.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
&__actions {
@apply flex gap-2 justify-end items-center flex-wrap mb-4;
}

&__searcher-container {
@apply flex justify-end;

.p-inputgroup {
@apply md:w-1/3;
}
}
}

.message-show {
Expand Down
63 changes: 55 additions & 8 deletions assets/vue/views/message/MessageList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,26 @@
@page="onPage($event)"
@sort="sortingChanged($event)"
>
<template #header>
<form
class="message-list__searcher-container"
@submit.prevent="onSearch"
>
<InputGroup>
<InputText
v-model="searchText"
:placeholder="t('Search')"
type="text"
/>
<BaseButton
icon="search"
type="primary"
is-submit
/>
</InputGroup>
</form>
</template>

<Column selection-mode="multiple" />
<Column :header="showingInbox ? t('From') : t('To')">
<template #body="slotProps">
Expand Down Expand Up @@ -198,6 +218,8 @@ import { useNotification } from "../../composables/notification"
import { useMessageRelUserStore } from "../../store/messageRelUserStore"
import { useSecurityStore } from "../../store/securityStore"
import SectionHeader from "../../components/layout/SectionHeader.vue"
import InputGroup from "primevue/inputgroup"
import InputText from "primevue/inputtext"
const route = useRoute()
const router = useRouter()
Expand Down Expand Up @@ -285,6 +307,9 @@ const totalItems = computed(() => store.getters["message/getTotalItems"])
const title = ref(null)
const selectedTag = ref(null)
const searchText = ref("")
const selectedItems = ref([])
const rowClass = (data) => {
Expand All @@ -305,6 +330,22 @@ function loadMessages(reset = true) {
dtMessages.value.resetPage()
}
fetchPayload.msgType = MESSAGE_TYPE_INBOX
if (selectedTag.value) {
fetchPayload["receivers.tags.tag"] = selectedTag.value.tag
}
if (showingInbox.value) {
fetchPayload["receivers.receiver"] = securityStore.user["@id"]
} else {
fetchPayload.sender = securityStore.user["@id"]
}
if (searchText.value) {
fetchPayload.search = searchText.value
}
store.dispatch("message/fetchAll", fetchPayload)
}
Expand All @@ -313,10 +354,9 @@ const showingInbox = ref(false)
function showInbox() {
showingInbox.value = true
title.value = t("Inbox")
selectedTag.value = null
fetchPayload = {
msgType: MESSAGE_TYPE_INBOX,
"receivers.receiver": securityStore.user["@id"],
"order[sendDate]": "desc",
itemsPerPage: initialRowsPerPage,
page: 1,
Expand All @@ -328,11 +368,9 @@ function showInbox() {
function showInboxByTag(tag) {
showingInbox.value = true
title.value = tag.tag
selectedTag.value = tag
fetchPayload = {
msgType: MESSAGE_TYPE_INBOX,
"receivers.receiver": securityStore.user["@id"],
"receivers.tags.tag": tag.tag,
"order[sendDate]": "desc",
itemsPerPage: initialRowsPerPage,
page: 1,
Expand All @@ -344,10 +382,9 @@ function showInboxByTag(tag) {
function showUnread() {
showingInbox.value = true
title.value = t("Unread")
selectedTag.value = null
fetchPayload = {
msgType: MESSAGE_TYPE_INBOX,
"receivers.receiver": securityStore.user["@id"],
"order[sendDate]": "desc",
"receivers.read": false,
itemsPerPage: initialRowsPerPage,
Expand All @@ -360,9 +397,9 @@ function showUnread() {
function showSent() {
showingInbox.value = false
title.value = t("Sent")
selectedTag.value = null
fetchPayload = {
msgType: MESSAGE_TYPE_INBOX,
sender: securityStore.user["@id"],
"order[sendDate]": "desc",
itemsPerPage: initialRowsPerPage,
Expand Down Expand Up @@ -454,4 +491,14 @@ function showDlgConfirmDeleteMultiple() {
onMounted(() => {
showInbox()
})
function onSearch() {
fetchPayload = {
"order[sendDate]": "desc",
itemsPerPage: initialRowsPerPage,
page: 1,
}
loadMessages()
}
</script>
2 changes: 2 additions & 0 deletions src/CoreBundle/Entity/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Put;
use Chamilo\CoreBundle\Filter\SearchOr;
use Chamilo\CoreBundle\Repository\MessageRepository;
use Chamilo\CoreBundle\State\MessageByGroupStateProvider;
use Chamilo\CoreBundle\State\MessageProcessor;
Expand Down Expand Up @@ -76,6 +77,7 @@
BooleanFilter::class,
properties: ['receivers.read']
)]
#[ApiFilter(SearchOr::class, properties: ['title', 'content'])]
class Message
{
public const MESSAGE_TYPE_INBOX = 1;
Expand Down

0 comments on commit 2cf10c5

Please sign in to comment.