1
1
<template >
2
- <div class =" h3 mb-4" >{{ $t('Comments') }}</div >
3
- <CommentsFilterForm class =" mb-4" v-model =" filters" />
4
- <VTableServer :items =" comments" :itemsLength =" comments.length" :is-loading =" commentsIsLoading" >
5
- <VColumn :header =" $t('Id')" field =" id" />
6
- <VColumn :header =" $t('Name')" field =" name" />
7
- <VColumn :header =" $t('Email')" field =" email" />
8
- <VColumn :header =" $t('Post')" field =" postId" >
9
- <template #body >
10
- <button class =" btn btn-sm btn-outline-info" title =" View Related Post" >
11
- <i class =" bi-eye" />
2
+ <div class =" h3 mb-4" >{{ $t('Comments') }}</div >
3
+ <CommentsFilterForm class =" mb-4" v-model =" filters" />
4
+ <VTableServer :items =" comments" :itemsLength =" comments.length" :is-loading =" commentsIsLoading" >
5
+ <VColumn :header =" $t('Id')" field =" id" />
6
+ <VColumn :header =" $t('Name')" field =" name" />
7
+ <VColumn :header =" $t('Email')" field =" email" />
8
+ <VColumn :header =" $t('Post')" field =" postId" >
9
+ <template #body >
10
+ <button class =" btn btn-sm btn-outline-info" title =" View Related Post" >
11
+ <i class =" bi-eye" />
12
+ </button >
13
+ </template >
14
+ </VColumn >
15
+ <VColumn :header =" $t('Text')" field =" body" />
16
+ <VColumn :header =" $t('Status')" field =" id" >
17
+ <template #body =" { item } " >
18
+ <span v-if =" item.status === 'PENDING'" >
19
+ {{ $t('Pending') }}
20
+ </span >
21
+ <span v-if =" item.status === 'CONFIRMED'" >
22
+ {{ $t('Confirmed') }}
23
+ </span >
24
+ <span v-if =" item.status === 'REJECTED'" >
25
+ {{ $('Rejected') }}
26
+ </span >
27
+ </template >
28
+ </VColumn >
29
+ <VColumn :header =" $t('Actions')" field =" id" >
30
+ <template #body >
31
+ <div class =" d-flex gap-2" >
32
+ <button class =" btn btn-danger btn-sm" >
33
+ <i class =" bi-ban" />
12
34
</button >
13
- </template >
14
- </VColumn >
15
- <VColumn :header =" $t('Text')" field =" body" />
16
- <VColumn :header =" $t('Status')" field =" id" >
17
- <template #body =" { item } " >
18
- <span v-if =" item.status==='PENDING'" >
19
- {{ $t('Pending') }}
20
- </span >
21
- <span v-if =" item.status==='CONFIRMED'" >
22
- {{$t('Confirmed')}}
23
- </span >
24
- <span v-if =" item.status==='REJECTED'" >
25
- {{ $('Rejected') }}
26
- </span >
27
- </template >
28
- </VColumn >
29
- <VColumn :header =" $t('Actions')" field =" id" >
30
- <template #body >
31
- <div class =" d-flex gap-2" >
32
- <button class =" btn btn-danger btn-sm" >
33
- <i class =" bi-ban" />
34
- </button >
35
- <button class =" btn btn-success btn-sm z-3" data-bs-toggle =" tooltip" data-bs-placement =" top"
36
- data-bs-title =" Tooltip on top" >
37
- <i class =" bi-check-circle" />
38
- </button >
39
- </div >
40
- </template >
41
- </VColumn >
42
- </VTableServer >
35
+ <button class =" btn btn-success btn-sm z-3" data-bs-toggle =" tooltip" data-bs-placement =" top"
36
+ data-bs-title =" Tooltip on top" >
37
+ <i class =" bi-check-circle" />
38
+ </button >
39
+ </div >
40
+ </template >
41
+ </VColumn >
42
+ </VTableServer >
43
43
</template >
44
44
45
45
<script >
@@ -48,30 +48,38 @@ import VColumn from '@/components/data-table/VColumn.vue';
48
48
import VTableServer from ' @/components/data-table/VTableServer.vue' ;
49
49
import { useFetchComments } from ' @/composables/comments.composable' ;
50
50
import { useApplyFilters } from ' @/composables/filter.composable' ;
51
- import { watch } from ' vue' ;
51
+ import { computed } from ' vue' ;
52
52
53
53
export default {
54
54
name: ' CommentsView' ,
55
55
setup () {
56
56
const { comments , commentsIsLoading , fetchComments } = useFetchComments ()
57
57
58
- const filters = useApplyFilters ({
59
- querySearch: undefined ,
60
- status: undefined ,
61
- email: undefined
62
- });
58
+ fetchComments ({})
63
59
60
+ const filters = useApplyFilters ({
61
+ searchQuery: undefined ,
62
+ status: undefined ,
63
+ email: undefined
64
+ });
65
+
66
+ const filteredComments = computed (() => {
67
+ const enteredEmail = filters? .email && filters .email .trim ().toLowerCase ();
68
+ const query = filters? .searchQuery && isNaN (Number (filters .querySearch )) ? filters .searchQuery .trim ().toLowerCase () : undefined ;
69
+ const status = filters? .status && filters .status .trim ();
70
+
71
+ const matchesEmail = (email ) => enteredEmail && email .trim ().toLowerCase ().includes (enteredEmail)
72
+ const matchesQuery = (id ,body ,name )=> id=== Number (query) || body .trim ().toLowerCase ().includes (query) || name .trim ().toLowerCase ().includes (query)
73
+
74
+ return comments .value ? .filter (comment => {
75
+ if (! query && ! enteredEmail && ! status) return true ;
76
+ return matchesEmail (comment .email ) || matchesQuery (comment .id , comment .body , comment .name ) || status === comment .status ;
77
+ });
78
+ });
64
79
65
- function fetch () {
66
- const config = {}
67
- return fetchComments (config)
68
- }
69
- fetch ()
70
- watch ([], () => fetchComments ())
71
80
72
-
73
81
return {
74
- comments,
82
+ comments: filteredComments ,
75
83
commentsIsLoading,
76
84
filters
77
85
}
0 commit comments