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

Support multi language filter track/session/room #237

Closed
wants to merge 14 commits into from
Closed
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
106 changes: 101 additions & 5 deletions webapp/src/views/schedule/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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

View workflow job for this annotation

GitHub Actions / build

Requires a space before '}'

Check failure on line 165 in webapp/src/views/schedule/index.vue

View workflow job for this annotation

GitHub Actions / build

Closing curly brace should be on the same line as opening curly brace or on the line after the previous block
} 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
}
Expand Down Expand Up @@ -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 => {
Copy link

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.

function filterSessionTypes(schedule, language = 'en') {
  const setSessionType = new Set()
  schedule.session_type.forEach(t => {
    if (typeof t.session_type === 'string' && t.language === language) {
      setSessionType.add(t.session_type)
    }
  })
  return setSessionType
}

const setSessionType = filterSessionTypes(this.schedule, enLanguage)

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
}

Check failure on line 238 in webapp/src/views/schedule/index.vue

View workflow job for this annotation

GitHub Actions / build

Closing curly brace does not appear on the same line as the subsequent block
else if (sessionTypeKeyArray[i] === enLanguage) {
isEnglish = true
if (i === sessionTypeKeyArray.length - 1) {
setSessionType.add(t.session_type[enLanguage])
}
}

Check failure on line 244 in webapp/src/views/schedule/index.vue

View workflow job for this annotation

GitHub Actions / build

Closing curly brace does not appear on the same line as the subsequent block
else {
if (i === sessionTypeKeyArray.length - 1) {
if (isEnglish) {
setSessionType.add(t.session_type[enLanguage])
}

Check failure on line 249 in webapp/src/views/schedule/index.vue

View workflow job for this annotation

GitHub Actions / build

Closing curly brace does not appear on the same line as the subsequent block
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
}
},
Expand Down Expand Up @@ -296,6 +349,49 @@
},
resetOnlyFavs() {
this.onlyFavs = false
},
getLanguage() {
return localStorage.getItem('userLanguage') || 'en'
},
filterLanguage(data) {
Copy link

Choose a reason for hiding this comment

The 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.

import { languageUtils } from '@/utils/languageUtils'

// ...

methods: {
  filterLanguage(data) {
    return languageUtils.filterLanguage(data, this.getLanguage())
  },

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
}

Check failure on line 372 in webapp/src/views/schedule/index.vue

View workflow job for this annotation

GitHub Actions / build

Closing curly brace does not appear on the same line as the subsequent block
else if (keyArray[i] === enLanguage) {
isEnglish = true
if (i === keyArray.length - 1) {
setMap.set(t.id, t.name[enLanguage])
}
}

Check failure on line 378 in webapp/src/views/schedule/index.vue

View workflow job for this annotation

GitHub Actions / build

Closing curly brace does not appear on the same line as the subsequent block
else {
if (i === keyArray.length - 1) {
if (isEnglish) {
setMap.set(t.id, t.name[enLanguage])
}

Check failure on line 383 in webapp/src/views/schedule/index.vue

View workflow job for this annotation

GitHub Actions / build

Closing curly brace does not appear on the same line as the subsequent block
else {
setMap.set(t.id, t.name[keyArray[i]])
}
}
}
}
}
}
)

return Array.from(setMap).map(t => { return { value: t[0], label: t[1] } })
}
}
}
Expand Down
106 changes: 101 additions & 5 deletions webapp/src/views/schedule/sessions/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,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 153 in webapp/src/views/schedule/sessions/index.vue

View workflow job for this annotation

GitHub Actions / build

Requires a space before '}'

Check failure on line 153 in webapp/src/views/schedule/sessions/index.vue

View workflow job for this annotation

GitHub Actions / build

Closing curly brace should be on the same line as opening curly brace or on the line after the previous block
} 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
}
Expand Down Expand Up @@ -192,9 +209,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.rooms.data = this.filterLanguage(this.schedule.rooms)
filter.tracks.data = this.filterLanguage(this.schedule.tracks)
return filter
}
},
Expand Down Expand Up @@ -284,6 +337,49 @@
},
resetOnlyFavs() {
this.onlyFavs = false
},
getLanguage() {
return localStorage.getItem('userLanguage') || 'en'
},
filterLanguage(data) {
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] } })
}
}
}
Expand Down
Loading