v1.5-alpha.1

This commit is contained in:
carodej
2020-05-15 17:31:25 +02:00
parent cfecf542ca
commit 41656235fc
97 changed files with 4108 additions and 2118 deletions
+11 -16
View File
@@ -3,6 +3,8 @@ const defaultState = {
FilePreviewType: localStorage.getItem('preview_type') || 'list',
appSize: undefined,
config: undefined,
authorized: undefined,
homeDirectory: undefined,
}
const actions = {
changePreviewType: ({commit, dispatch, state, getters}) => {
@@ -14,18 +16,6 @@ const actions = {
// Change preview
commit('CHANGE_PREVIEW', previewType)
if (getters.currentFolder.location === 'trash-root') {
dispatch('getTrash')
} else {
if ( getters.currentFolder.location === 'public' ) {
dispatch('browseShared', [getters.currentFolder, false, true])
} else {
dispatch('getFolder', [getters.currentFolder, false, true])
}
}
},
fileInfoToggle: (context, visibility = undefined) => {
if (!visibility) {
@@ -40,6 +30,11 @@ const actions = {
},
}
const mutations = {
INIT(state, data) {
state.config = data.config
state.authorized = data.authCookie
state.homeDirectory = data.rootDirectory
},
FILE_INFO_TOGGLE(state, isVisible) {
state.fileInfoPanelVisible = isVisible
@@ -48,13 +43,12 @@ const mutations = {
SET_APP_WIDTH(state, scale) {
state.appSize = scale
},
SET_AUTHORIZED(state, data) {
state.authorized = data
},
CHANGE_PREVIEW(state, type) {
state.FilePreviewType = type
},
SET_CONFIG(state, config) {
state.config = config
},
}
const getters = {
fileInfoVisible: state => state.fileInfoPanelVisible,
@@ -62,6 +56,7 @@ const getters = {
appSize: state => state.appSize,
api: state => state.config.api,
config: state => state.config,
homeDirectory: state => state.homeDirectory,
}
export default {
+99 -129
View File
@@ -1,16 +1,13 @@
import axios from 'axios'
import {events} from '@/bus'
import router from '@/router'
import {includes} from 'lodash'
import i18n from '@/i18n/index'
const defaultState = {
uploadingFilesCount: undefined,
fileInfoDetail: undefined,
currentFolder: undefined,
homeDirectory: undefined,
uploadingFileProgress: 0,
filesViewWidth: undefined,
navigation: undefined,
isSearching: false,
browseHistory: [],
@@ -19,56 +16,45 @@ const defaultState = {
}
const actions = {
getFolder: (context, [folder, back = false, init = false]) => {
events.$emit('show:content')
getFolder: ({commit, getters}, [payload]) => {
commit('LOADING_STATE', {loading: true, data: []})
// Go to files view
if (!includes(['Files', 'SharedPage'], router.currentRoute.name)) {
router.push({name: 'Files'})
}
context.commit('LOADING_STATE', true)
context.commit('FLUSH_DATA')
if (payload.init)
commit('FLUSH_FOLDER_HISTORY')
// Clear search
if (context.state.isSearching) {
context.commit('CHANGE_SEARCHING_STATE', false)
if (getters.isSearching) {
commit('CHANGE_SEARCHING_STATE', false)
events.$emit('clear-query')
}
// Create current folder for history
let currentFolder = {
name: folder.name,
unique_id: folder.unique_id,
location: folder.deleted_at || folder.location === 'trash' ? 'trash' : 'base'
}
// Set folder location
payload.folder.location = payload.folder.deleted_at || payload.folder.location === 'trash' ? 'trash' : 'base'
let url = currentFolder.location === 'trash'
? '/folders/' + currentFolder.unique_id + '?trash=true'
: '/folders/' + currentFolder.unique_id
if (! payload.back)
commit('STORE_PREVIOUS_FOLDER', getters.currentFolder)
let url = payload.folder.location === 'trash'
? '/folders/' + payload.folder.unique_id + '?trash=true'
: '/folders/' + payload.folder.unique_id
axios
.get(context.getters.api + url)
.get(getters.api + url)
.then(response => {
context.commit('LOADING_STATE', false)
context.commit('GET_DATA', response.data)
context.commit('STORE_CURRENT_FOLDER', currentFolder)
commit('LOADING_STATE', {loading: false, data: response.data})
commit('STORE_CURRENT_FOLDER', payload.folder)
if (payload.back)
commit('REMOVE_BROWSER_HISTORY')
events.$emit('scrollTop')
if (back) {
context.commit('REMOVE_BROWSER_HISTORY')
} else {
if (!init) context.commit('ADD_BROWSER_HISTORY', currentFolder)
}
})
.catch(error => {
// Redirect if unauthenticated
if ([401, 403].includes(error.response.status)) {
context.commit('SET_AUTHORIZED', false)
commit('SET_AUTHORIZED', false)
router.push({name: 'SignIn'})
} else {
@@ -81,83 +67,89 @@ const actions = {
}
})
},
getShared: (context, back = false) => {
events.$emit('show:content')
getLatest: ({commit, getters}) => {
commit('LOADING_STATE', {loading: true, data: []})
// Go to files view
if (router.currentRoute.name !== 'Files') {
router.push({name: 'Files'})
}
if (!back) context.commit('FLUSH_BROWSER_HISTORY')
context.commit('FLUSH_DATA')
context.commit('LOADING_STATE', true)
// Create shared object for history
let trash = {
name: 'Shared',
commit('STORE_PREVIOUS_FOLDER', getters.currentFolder)
commit('STORE_CURRENT_FOLDER', {
name: 'Latest',
unique_id: undefined,
location: 'shared',
}
location: 'latest',
})
axios
.get(context.getters.api + '/shared-all')
.get(getters.api + '/latest')
.then(response => {
context.commit('GET_DATA', response.data)
context.commit('LOADING_STATE', false)
context.commit('STORE_CURRENT_FOLDER', trash)
context.commit('ADD_BROWSER_HISTORY', trash)
commit('LOADING_STATE', {loading: false, data: response.data})
events.$emit('scrollTop')
})
.catch(() => isSomethingWrong())
},
getShared: ({commit, getters}) => {
commit('LOADING_STATE', {loading: true, data: []})
commit('FLUSH_FOLDER_HISTORY')
let currentFolder = {
name: 'Shared',
location: 'shared',
unique_id: undefined,
}
commit('STORE_CURRENT_FOLDER', currentFolder)
axios
.get(getters.api + '/shared-all')
.then(response => {
commit('LOADING_STATE', {loading: false, data: response.data})
commit('STORE_PREVIOUS_FOLDER', currentFolder)
events.$emit('scrollTop')
})
.catch(() => {
// Show error message
events.$emit('alert:open', {
title: i18n.t('popup_error.title'),
message: i18n.t('popup_error.message'),
})
})
.catch(() => isSomethingWrong())
},
getTrash: (context, back = false) => {
events.$emit('show:content')
getParticipantUploads: ({commit, getters}) => {
commit('LOADING_STATE', {loading: true, data: []})
// Go to files view
if (router.currentRoute.name !== 'Files') {
router.push({name: 'Files'})
}
commit('STORE_PREVIOUS_FOLDER', getters.currentFolder)
commit('STORE_CURRENT_FOLDER', {
name: 'Participant Uploads',
unique_id: undefined,
location: 'participant_uploads',
})
if (!back) context.commit('FLUSH_BROWSER_HISTORY')
context.commit('FLUSH_DATA')
context.commit('LOADING_STATE', true)
axios
.get(getters.api + '/participant-uploads')
.then(response => {
commit('LOADING_STATE', {loading: false, data: response.data})
events.$emit('scrollTop')
})
.catch(() => isSomethingWrong())
},
getTrash: ({commit, getters}) => {
commit('LOADING_STATE', {loading: true, data: []})
commit('FLUSH_FOLDER_HISTORY')
// Create trash object for history
let trash = {
name: 'Trash',
unique_id: undefined,
location: 'trash-root',
}
commit('STORE_CURRENT_FOLDER', trash)
axios
.get(context.getters.api + '/trash')
.get(getters.api + '/trash')
.then(response => {
context.commit('GET_DATA', response.data)
context.commit('LOADING_STATE', false)
context.commit('STORE_CURRENT_FOLDER', trash)
context.commit('ADD_BROWSER_HISTORY', trash)
commit('LOADING_STATE', {loading: false, data: response.data})
commit('STORE_PREVIOUS_FOLDER', trash)
events.$emit('scrollTop')
})
.catch(() => {
// Show error message
events.$emit('alert:open', {
title: i18n.t('popup_error.title'),
message: i18n.t('popup_error.message'),
})
})
.catch(() => isSomethingWrong())
},
getSearchResult: ({commit, getters}, query) => {
commit('FLUSH_DATA')
commit('LOADING_STATE', true)
commit('LOADING_STATE', {loading: true, data: []})
commit('CHANGE_SEARCHING_STATE', true)
// Get route
@@ -175,30 +167,17 @@ const actions = {
params: {query: query}
})
.then(response => {
commit('LOADING_STATE', false)
commit('GET_DATA', response.data)
})
.catch(() => {
// Show error message
events.$emit('alert:open', {
title: i18n.t('popup_error.title'),
message: i18n.t('popup_error.message'),
})
commit('LOADING_STATE', {loading: false, data: response.data})
})
.catch(() => isSomethingWrong())
},
getFileDetail: (context, file) => {
getFileDetail: ({commit, getters}, file) => {
axios
.get(context.getters.api + '/file-detail/' + file.unique_id)
.get(getters.api + '/file-detail/' + file.unique_id)
.then(response => {
context.commit('LOAD_FILEINFO_DETAIL', response.data)
})
.catch(() => {
// Show error message
events.$emit('alert:open', {
title: i18n.t('popup_error.title'),
message: i18n.t('popup_error.message'),
})
commit('LOAD_FILEINFO_DETAIL', response.data)
})
.catch(() => isSomethingWrong())
},
getFolderTree: ({commit, getters}) => {
@@ -224,11 +203,7 @@ const actions = {
.catch((error) => {
reject(error)
// Show error message
events.$emit('alert:open', {
title: i18n.t('popup_error.title'),
message: i18n.t('popup_error.message'),
})
isSomethingWrong()
})
})
},
@@ -238,13 +213,11 @@ const mutations = {
UPDATE_FOLDER_TREE(state, tree) {
state.navigation = tree
},
LOADING_STATE(state, val) {
state.isLoading = val
LOADING_STATE(state, payload) {
state.data = payload.data
state.isLoading = payload.loading
},
SET_START_DIRECTORY(state, directory) {
state.homeDirectory = directory
},
FLUSH_BROWSER_HISTORY(state) {
FLUSH_FOLDER_HISTORY(state) {
state.browseHistory = []
},
FLUSH_SHARED(state, unique_id) {
@@ -252,7 +225,7 @@ const mutations = {
if (item.unique_id == unique_id) item.shared = undefined
})
},
ADD_BROWSER_HISTORY(state, folder) {
STORE_PREVIOUS_FOLDER(state, folder) {
state.browseHistory.push(folder)
},
REMOVE_BROWSER_HISTORY(state) {
@@ -295,12 +268,6 @@ const mutations = {
if (item.unique_id == data.item_id) item.shared = data
})
},
FLUSH_DATA(state) {
state.data = []
},
GET_DATA(state, loaded_data) {
state.data = loaded_data
},
ADD_NEW_FOLDER(state, folder) {
state.data.unshift(folder)
},
@@ -318,17 +285,12 @@ const mutations = {
STORE_CURRENT_FOLDER(state, folder) {
state.currentFolder = folder
},
SET_FILES_VIEW_SIZE(state, type) {
state.filesViewWidth = type
},
}
const getters = {
uploadingFileProgress: state => state.uploadingFileProgress,
uploadingFilesCount: state => state.uploadingFilesCount,
fileInfoDetail: state => state.fileInfoDetail,
filesViewWidth: state => state.filesViewWidth,
homeDirectory: state => state.homeDirectory,
currentFolder: state => state.currentFolder,
browseHistory: state => state.browseHistory,
isSearching: state => state.isSearching,
@@ -337,6 +299,14 @@ const getters = {
data: state => state.data,
}
// Show error message
function isSomethingWrong() {
events.$emit('alert:open', {
title: i18n.t('popup_error.title'),
message: i18n.t('popup_error.message'),
})
}
export default {
state: defaultState,
getters,
+31 -12
View File
@@ -1,10 +1,11 @@
import i18n from '@/i18n/index'
import router from '@/router'
import {events} from '@/bus'
import {last} from 'lodash'
import axios from 'axios'
const actions = {
moveItem: ({commit, getters}, [item_from, to_item]) => {
moveItem: ({commit, getters, dispatch}, [item_from, to_item]) => {
// Get route
let route = getters.sharedDetail && ! getters.sharedDetail.protected
@@ -19,10 +20,14 @@ const actions = {
.then(() => {
commit('REMOVE_ITEM', item_from.unique_id)
commit('INCREASE_FOLDER_ITEM', to_item.unique_id)
if (item_from.type === 'folder' && getters.currentFolder.location !== 'public')
dispatch('getAppData')
})
.catch(() => isSomethingWrong())
},
createFolder: ({commit, getters}, folderName) => {
createFolder: ({commit, getters, dispatch}, folderName) => {
// Get route
let route = getters.sharedDetail && ! getters.sharedDetail.protected
@@ -36,10 +41,14 @@ const actions = {
})
.then(response => {
commit('ADD_NEW_FOLDER', response.data)
if ( getters.currentFolder.location !== 'public' ) {
dispatch('getAppData')
}
})
.catch(() => isSomethingWrong())
},
renameItem: ({commit, getters}, data) => {
renameItem: ({commit, getters, dispatch}, data) => {
// Updated name in favourites panel
if (getters.permission === 'master' && data.type === 'folder')
@@ -57,6 +66,9 @@ const actions = {
})
.then(response => {
commit('CHANGE_ITEM_NAME', response.data)
if (data.type === 'folder' && getters.currentFolder.location !== 'public')
dispatch('getAppData')
})
.catch(() => isSomethingWrong())
},
@@ -87,9 +99,6 @@ const actions = {
commit('UPLOADING_FILE_PROGRESS', 0)
if (getters.permission === 'master')
commit('UPDATE_RECENT_UPLOAD', response.data)
resolve(response)
})
.catch(error => {
@@ -121,7 +130,7 @@ const actions = {
})
.catch(() => isSomethingWrong())
},
deleteItem: ({commit, getters}, data) => {
deleteItem: ({commit, getters, dispatch}, data) => {
// Remove file
commit('REMOVE_ITEM', data.unique_id)
@@ -131,8 +140,6 @@ const actions = {
if (data.type === 'folder')
commit('REMOVE_ITEM_FROM_FAVOURITES', data)
else
commit('REMOVE_ITEM_FROM_RECENT_UPLOAD', data.unique_id)
}
// Remove file preview
@@ -150,18 +157,30 @@ const actions = {
force_delete: data.deleted_at ? true : false
}
})
.then(() => {
// If is folder, update app data
if (data.type === 'folder' && data.unique_id === getters.currentFolder.unique_id) {
if ( getters.currentFolder.location === 'public' ) {
dispatch('browseShared', [{folder: last(getters.browseHistory), back: true, init: false}])
} else {
dispatch('getFolder', [{folder: last(getters.browseHistory), back: true, init: false}])
dispatch('getAppData')
}
}
})
.catch(() => isSomethingWrong())
},
emptyTrash: ({commit, getters}) => {
// Clear file browser
commit('FLUSH_DATA')
commit('LOADING_STATE', true)
commit('LOADING_STATE', {loading: true, data: []})
axios
.delete(getters.api + '/empty-trash')
.then(() => {
commit('LOADING_STATE', false)
commit('LOADING_STATE', {loading: false, data: []})
events.$emit('scrollTop')
// Remove file preview
+14 -21
View File
@@ -20,9 +20,11 @@ const defaultState = {
sharedFile: undefined,
}
const actions = {
browseShared: ({commit, state, getters}, [folder, back = false, init = false]) => {
commit('LOADING_STATE', true)
commit('FLUSH_DATA')
browseShared: ({commit, getters}, [payload]) => {
commit('LOADING_STATE', {loading: true, data: []})
if (payload.init)
commit('FLUSH_FOLDER_HISTORY')
// Clear search
if (getters.isSearching) {
@@ -30,35 +32,26 @@ const actions = {
events.$emit('clear-query')
}
// Create current folder for history
let currentFolder = {
name: folder.name,
unique_id: folder.unique_id,
location: 'public'
}
if (! payload.back)
commit('STORE_PREVIOUS_FOLDER', getters.currentFolder)
payload.folder.location = 'public'
let route = getters.sharedDetail.protected
? '/api/folders/' + currentFolder.unique_id + '/private'
: '/api/folders/' + currentFolder.unique_id + '/public/' + router.currentRoute.params.token +'/'
? '/api/folders/' + payload.folder.unique_id + '/private'
: '/api/folders/' + payload.folder.unique_id + '/public/' + router.currentRoute.params.token +'/'
return new Promise((resolve, reject) => {
axios
.get(route)
.then(response => {
commit('LOADING_STATE', false)
commit('GET_DATA', response.data)
commit('STORE_CURRENT_FOLDER', currentFolder)
commit('LOADING_STATE', {loading: false, data: response.data})
commit('STORE_CURRENT_FOLDER', payload.folder)
events.$emit('scrollTop')
if (back) {
if (payload.back)
commit('REMOVE_BROWSER_HISTORY')
} else {
if (!init)
commit('ADD_BROWSER_HISTORY', currentFolder)
}
resolve(response)
})
.catch((error) => {
-7
View File
@@ -80,9 +80,6 @@ const mutations = {
SET_PERMISSION(state, role) {
state.permission = role
},
SET_AUTHORIZED(state, data) {
state.authorized = data
},
DESTROY_DATA(state) {
state.authorized = false
state.app = undefined
@@ -101,16 +98,12 @@ const mutations = {
state.app.user.avatar = avatar
},
UPDATE_RECENT_UPLOAD(state, file) {
// Remove last file from altest uploads
if (state.app.latest_uploads.length === 7) state.app.latest_uploads.pop()
// Add new file to latest uploads
state.app.latest_uploads.unshift(file)
},
REMOVE_ITEM_FROM_RECENT_UPLOAD(state, unique_id) {
state.app.latest_uploads = state.app.latest_uploads.filter(file => file.unique_id !== unique_id)
},
REMOVE_ITEM_FROM_FAVOURITES(state, item) {
state.app.favourites = state.app.favourites.filter(folder => folder.unique_id !== item.unique_id)
},