2019-01-14 17:23:13 +00:00
|
|
|
import fileTypeService from '../services/file_type/file_type.service.js'
|
|
|
|
|
|
|
|
const mediaViewer = {
|
|
|
|
state: {
|
|
|
|
media: [],
|
|
|
|
currentIndex: 0,
|
|
|
|
activated: false
|
|
|
|
},
|
|
|
|
mutations: {
|
|
|
|
setMedia (state, media) {
|
|
|
|
state.media = media
|
|
|
|
},
|
|
|
|
setCurrent (state, index) {
|
|
|
|
state.activated = true
|
|
|
|
state.currentIndex = index
|
|
|
|
},
|
|
|
|
close (state) {
|
|
|
|
state.activated = false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
actions: {
|
|
|
|
setMedia ({ commit }, attachments) {
|
|
|
|
const media = attachments.filter(attachment => {
|
|
|
|
const type = fileTypeService.fileType(attachment.mimetype)
|
2020-06-29 11:48:22 +00:00
|
|
|
return type === 'image' || type === 'video' || type === 'audio'
|
2019-01-14 17:23:13 +00:00
|
|
|
})
|
|
|
|
commit('setMedia', media)
|
|
|
|
},
|
|
|
|
setCurrent ({ commit, state }, current) {
|
|
|
|
const index = state.media.indexOf(current)
|
|
|
|
commit('setCurrent', index || 0)
|
|
|
|
},
|
|
|
|
closeMediaViewer ({ commit }) {
|
|
|
|
commit('close')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default mediaViewer
|