-
Notifications
You must be signed in to change notification settings - Fork 23
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
Support multi language filter track/session/room #237
Changes from all commits
5c63899
dea7ac3
233ff24
559f164
d0f8839
112ea46
ec412bf
cf15dfd
5c1d37f
3ca293d
498e675
5e8d586
9e48abc
ca60bd2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -154,9 +154,26 @@ | |
let founds = null | ||
if (selectedIds.length) { | ||
if (results && results.length) { | ||
founds = self.schedule.talks.filter(t => selectedIds.includes(t[refKey]) && results && results.includes(t.id))?.map(i => i.id) || [] | ||
founds = self.schedule.talks.filter(t => { | ||
if (refKey === 'session_type') { | ||
if (typeof t.session_type === 'string') { | ||
return selectedIds.includes(t.session_type) && results.includes(t.id) | ||
} else { | ||
return Object.keys(t.session_type).some(key => selectedIds.includes(t.session_type[key])) && results.includes(t.id) | ||
} | ||
} | ||
return selectedIds.includes(t[refKey]) && results && results.includes(t.id)})?.map(i => i.id) || [] | ||
Check failure on line 165 in webapp/src/views/schedule/index.vue GitHub Actions / build
|
||
} else { | ||
founds = self.schedule.talks.filter(t => { return selectedIds.includes(t[refKey]) })?.map(i => i.id) || [] | ||
founds = self.schedule.talks.filter(t => { | ||
if (refKey === 'session_type') { | ||
if (typeof t.session_type === 'string') { | ||
return selectedIds.includes(t.session_type) | ||
} else { | ||
return Object.keys(t.session_type).some(key => selectedIds.includes(t.session_type[key])) | ||
} | ||
} | ||
return selectedIds.includes(t[refKey]) | ||
})?.map(i => i.id) || [] | ||
} | ||
results = founds | ||
} | ||
|
@@ -204,9 +221,45 @@ | |
}, | ||
filter() { | ||
const filter = this.defaultFilter | ||
filter.tracks.data = this.schedule.tracks.map(t => { t.value = t.id; t.label = t.name; return t }) | ||
filter.rooms.data = this.schedule.rooms.map(t => { t.value = t.id; t.label = t.name; return t }) | ||
filter.types.data = this.schedule.session_type.map(t => { t.value = t.session_type; t.label = t.session_type; return t }) | ||
const setSessionType = new Set() | ||
const enLanguage = 'en' | ||
|
||
this.schedule.session_type.forEach(t => { | ||
if (typeof t.session_type === 'string') { | ||
setSessionType.add(t.session_type) | ||
} else { | ||
const sessionTypeKeyArray = Object.keys(t.session_type) | ||
let isEnglish = false | ||
|
||
for (let i = 0; i < sessionTypeKeyArray.length; i++) { | ||
if (sessionTypeKeyArray[i] === this.getLanguage()) { | ||
setSessionType.add(t.session_type[sessionTypeKeyArray[i]]) | ||
break | ||
} | ||
else if (sessionTypeKeyArray[i] === enLanguage) { | ||
isEnglish = true | ||
if (i === sessionTypeKeyArray.length - 1) { | ||
setSessionType.add(t.session_type[enLanguage]) | ||
} | ||
} | ||
else { | ||
if (i === sessionTypeKeyArray.length - 1) { | ||
if (isEnglish) { | ||
setSessionType.add(t.session_type[enLanguage]) | ||
} | ||
else { | ||
setSessionType.add(t.session_type[sessionTypeKeyArray[i]]) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}) | ||
|
||
filter.types.data = Array.from(setSessionType).map(t => { return { value: t, label: t } }) | ||
filter.tracks.data = this.filterLanguage(this.schedule.tracks) | ||
filter.rooms.data = this.filterLanguage(this.schedule.rooms) | ||
|
||
return filter | ||
} | ||
}, | ||
|
@@ -296,6 +349,49 @@ | |
}, | ||
resetOnlyFavs() { | ||
this.onlyFavs = false | ||
}, | ||
getLanguage() { | ||
return localStorage.getItem('userLanguage') || 'en' | ||
}, | ||
filterLanguage(data) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: Extract duplicate code into a shared module or mixin The changes in both 'index.vue' and 'sessions/index.vue' are nearly identical. Consider extracting this functionality into a shared module or mixin to improve maintainability and reduce duplication.
|
||
const setMap = new Map() | ||
const enLanguage = 'en' | ||
|
||
data.forEach( | ||
t => { | ||
if (typeof t.name === 'string') { | ||
setMap.set(t.id, t.name) | ||
} else { | ||
const keyArray = Object.keys(t.name) | ||
let isEnglish = false | ||
|
||
for (let i = 0; i < keyArray.length; i++) { | ||
if (keyArray[i] === this.getLanguage()) { | ||
setMap.set(t.id, t.name[keyArray[i]]) | ||
break | ||
} | ||
else if (keyArray[i] === enLanguage) { | ||
isEnglish = true | ||
if (i === keyArray.length - 1) { | ||
setMap.set(t.id, t.name[enLanguage]) | ||
} | ||
} | ||
else { | ||
if (i === keyArray.length - 1) { | ||
if (isEnglish) { | ||
setMap.set(t.id, t.name[enLanguage]) | ||
} | ||
else { | ||
setMap.set(t.id, t.name[keyArray[i]]) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
) | ||
|
||
return Array.from(setMap).map(t => { return { value: t[0], label: t[1] } }) | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Consider extracting common language filtering logic into a separate function
The language filtering logic is repeated in multiple places. Creating a reusable function would improve maintainability and reduce code duplication.