Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: APPS-3122 Rearrange ongoing events to be after the current events on eventSeries Listing page #96

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 56 additions & 4 deletions composables/useEventSeriesListSearchFilter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// TODO Convert this composable into TypeScript

export default function useEventSeriesListSearchFilter() {
return { pastEventSeriesQuery, currentEventSeriesQuery }
return { pastEventSeriesQuery, currentEventSeriesQueryCurrent, currentEventSeriesQueryOngoing }
}

async function pastEventSeriesQuery(
Expand Down Expand Up @@ -58,7 +58,7 @@ async function pastEventSeriesQuery(
return data
}

async function currentEventSeriesQuery(
async function currentEventSeriesQueryCurrent(
currentPage = 1,
documentsPerPage = 10,
sort,
Expand Down Expand Up @@ -97,7 +97,7 @@ async function currentEventSeriesQuery(
should: [
{
term: {
ongoing: true,
ongoing: false,
},
},
{
Expand All @@ -108,7 +108,59 @@ async function currentEventSeriesQuery(
},
},
],
minimum_should_match: 1,
minimum_should_match: 2,
}
},
...parseSort(sort, orderBy),
}),
}
)

const data = await response.json()
return data
}

async function currentEventSeriesQueryOngoing(
currentPage = 1,
documentsPerPage = 10,
sort,
orderBy,
source = ['*'],
) {
const config = useRuntimeConfig()
if (
config.public.esReadKey === '' ||
config.public.esURL === '' ||
config.public.esAlias === ''
)
return

const response = await fetch(
`${config.public.esURL}/${config.public.esAlias}/_search`,
{
headers: {
Authorization: `ApiKey ${config.public.esReadKey}`,
'Content-Type': 'application/json',
},
method: 'POST',
body: JSON.stringify({
from: (currentPage - 1) * documentsPerPage,
size: documentsPerPage,
_source: [...source],
query: {
bool: {
filter: [
{
term: {
'sectionHandle.keyword': 'ftvaEventSeries',
},
},
{
term: {
ongoing: true,
},
}
]
}
},
...parseSort(sort, orderBy),
Expand Down
33 changes: 27 additions & 6 deletions pages/series/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -137,17 +137,38 @@ async function searchES() {

isLoading.value = true
// COMPOSABLE
const { currentEventSeriesQuery, pastEventSeriesQuery } = useEventSeriesListSearchFilter()
const { currentEventSeriesQueryCurrent, currentEventSeriesQueryOngoing, pastEventSeriesQuery } = useEventSeriesListSearchFilter()

try {
let results

if (currentView.value === 'current') {
results = await currentEventSeriesQuery(currentPage.value,
documentsPerPage,
'startDate',
'asc',
['*'],)
const [currentSeriesResult, ongoingSeriesResult] = await Promise.all([
currentEventSeriesQueryCurrent(
currentPage.value,
documentsPerPage,
'startDate',
'asc',
['*']
),
currentEventSeriesQueryOngoing(
currentPage.value,
documentsPerPage,
'startDate',
'asc',
['*']
)
])

// Combine results with current series first, ongoing series last
const currentSeries = currentSeriesResult?.hits?.hits || []
const ongoingSeries = ongoingSeriesResult?.hits?.hits || []
results = {
hits: {
hits: [...currentSeries, ...ongoingSeries],
total: { value: currentSeries.length + ongoingSeries.length },
},
}
} else {
results = await pastEventSeriesQuery(currentPage.value,
documentsPerPage,
Expand Down
Loading