update: เพิ่มเจ้าของผลงานในค้นหาขั้นสูง

This commit is contained in:
puri-ph4tt 2024-01-11 09:59:25 +07:00
parent 65aa1a6d15
commit 0c35ab48ad
3 changed files with 25 additions and 15 deletions

View file

@ -3,14 +3,8 @@ import { storeToRefs } from 'pinia'
import { useSearchDataStore } from '@/stores/searched-data' import { useSearchDataStore } from '@/stores/searched-data'
const { isAdvSearchCall, advSearchDataRow, advSearchDataField } = const { isAdvSearchCall, advSearchDataRow, advSearchDataField, optionsField } =
storeToRefs(useSearchDataStore()) storeToRefs(useSearchDataStore())
const optionsField = [
{ label: 'ชื่อเรื่อง (title)', value: 'title' },
{ label: 'คำสำคัญ (keyword)', value: 'keyword' },
{ label: 'หมวดหมู่ (category)', value: 'category' },
{ label: 'เนื้อหาในไฟล์ (content)', value: 'attachment.content' },
]
const optionsOp = [ const optionsOp = [
{ label: 'และ', value: 'AND' }, { label: 'และ', value: 'AND' },
{ label: 'หรือ', value: 'OR' }, { label: 'หรือ', value: 'OR' },

View file

@ -22,16 +22,10 @@ const {
isAdvSearchCall, isAdvSearchCall,
searchData, searchData,
advSearchDataField, advSearchDataField,
optionsField,
advSearchDataRow, advSearchDataRow,
} = storeToRefs(useSearchDataStore()) } = storeToRefs(useSearchDataStore())
const { getFoundFile } = useSearchDataStore() const { getFoundFile } = useSearchDataStore()
const optionsField = [
{ label: 'ชื่อเรื่อง (title)', value: 'title' },
{ label: 'คำสำคัญ (keyword)', value: 'keyword' },
{ label: 'หมวดหมู่ (category)', value: 'category' },
{ label: 'เนื้อหาในไฟล์ (content)', value: 'attachment.content' },
{ label: 'เจ้าของผลงาน (author)', value: 'author' },
]
const submitSearchData = ref<{ const submitSearchData = ref<{
AND: { AND: {
field: string field: string
@ -56,7 +50,7 @@ async function submitSearch() {
if (searchData.value.value.trim() !== '') { if (searchData.value.value.trim() !== '') {
submitSearchData.value = { AND: [], OR: [] } submitSearchData.value = { AND: [], OR: [] }
if (props.mode === 'admin') { if (props.mode === 'admin') {
optionsField.forEach((option) => { optionsField.value.forEach((option) => {
submitSearchData.value.OR.push({ submitSearchData.value.OR.push({
field: option.value, field: option.value,
value: searchData.value.value, value: searchData.value.value,
@ -117,6 +111,20 @@ async function submitSearch() {
(d: { field: string; value: string; op: string; exact: boolean }) => { (d: { field: string; value: string; op: string; exact: boolean }) => {
if (d.field && d.value.trim() !== '') { if (d.field && d.value.trim() !== '') {
const op = d.op === 'AND' ? 'AND' : 'OR' const op = d.op === 'AND' ? 'AND' : 'OR'
if (d.field == 'title') {
submitSearchData.value[op].push({
field: 'metadata.subject',
value: d.value,
exact: d.exact,
})
}
if (d.field == 'author') {
submitSearchData.value[op].push({
field: 'metadata.author',
value: d.value,
exact: d.exact,
})
}
submitSearchData.value[op].push({ submitSearchData.value[op].push({
field: d.field, field: d.field,
value: d.value, value: d.value,

View file

@ -36,6 +36,13 @@ export const useSearchDataStore = defineStore('searched', () => {
exact: false, exact: false,
}, },
]) ])
const optionsField = ref([
{ label: 'ชื่อเรื่อง (title)', value: 'title' },
{ label: 'คำสำคัญ (keyword)', value: 'keyword' },
{ label: 'หมวดหมู่ (category)', value: 'category' },
{ label: 'เนื้อหาในไฟล์ (content)', value: 'attachment.content' },
{ label: 'เจ้าของผลงาน (author)', value: 'author' },
])
const advSearchDataField = ref<AdvancedSearchFields>({ const advSearchDataField = ref<AdvancedSearchFields>({
keyword: [], keyword: [],
description: '', description: '',
@ -52,6 +59,7 @@ export const useSearchDataStore = defineStore('searched', () => {
isAdvSearchCall, isAdvSearchCall,
searchData, searchData,
advSearchDataRow, advSearchDataRow,
optionsField,
advSearchDataField, advSearchDataField,
getFoundFile, getFoundFile,
} }