diff --git a/webapp/src/views/schedule/index.vue b/webapp/src/views/schedule/index.vue index b0cca37f..be0a1e04 100644 --- a/webapp/src/views/schedule/index.vue +++ b/webapp/src/views/schedule/index.vue @@ -154,9 +154,26 @@ export default { 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) || [] } 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 @@ export default { }, 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 @@ export default { }, 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] } }) } } } diff --git a/webapp/src/views/schedule/sessions/index.vue b/webapp/src/views/schedule/sessions/index.vue index f82b86c5..95f6203e 100644 --- a/webapp/src/views/schedule/sessions/index.vue +++ b/webapp/src/views/schedule/sessions/index.vue @@ -142,9 +142,26 @@ export default { 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) || [] } 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 } @@ -192,9 +209,45 @@ export default { }, 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 } }, @@ -284,6 +337,49 @@ export default { }, 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] } }) } } }