refactoring part 1

This commit is contained in:
Peter Papp
2021-08-23 09:32:21 +02:00
parent a926545146
commit cc0436b8f3
8 changed files with 54 additions and 59 deletions
+3 -1
View File
@@ -108,7 +108,9 @@ export default {
})
},
mounted() {
this.$checkOS()
if (this.$isWIndows()) {
document.body.classList.add('windows')
}
}
}
</script>
@@ -115,9 +115,7 @@
return activeIndex
},
canShareItem() {
return this.$isThisLocation([
'base', 'latest', 'shared'
])
return this.$isThisRoute(this.$route, ['Files', 'RecentUploads', 'MySharedItems'])
},
},
methods: {
@@ -121,7 +121,7 @@ export default {
},
canEditName() {
return !this.$isMobile()
&& !this.$isThisLocation(['trash', 'trash-root'])
&& !this.$isThisRoute(this.$route, ['Trash'])
&& !this.$checkPermission('visitor')
&& !(this.sharedDetail && this.sharedDetail.type === 'file')
},
@@ -117,7 +117,7 @@ export default {
return mimetypes.includes(this.item.mimetype) && this.item.type === 'audio'
},
canEditName() {
return !this.$isMobile() && !this.$isThisLocation(['trash', 'trash-root']) && !this.$checkPermission('visitor') && !(this.sharedDetail && this.sharedDetail.type === 'file')
return !this.$isMobile() && !this.$isThisRoute(this.$route, ['Trash']) && !this.$checkPermission('visitor') && !(this.sharedDetail && this.sharedDetail.type === 'file')
},
canDrag() {
return !this.isDeleted && this.$checkPermission(['master', 'editor'])
+18 -34
View File
@@ -212,20 +212,6 @@ const FunctionHelpers = {
return locations.includes(route.name)
}
Vue.prototype.$isThisLocation = function (location) {
// Get current location
let currentLocation = store.getters.currentFolder && store.getters.currentFolder.location ? store.getters.currentFolder.location : undefined
// Check if type is object
if (typeof location === 'Object' || location instanceof Object) {
return location.includes(currentLocation)
} else {
return currentLocation === location
}
}
Vue.prototype.$checkPermission = function (type) {
let currentPermission = store.getters.permission
@@ -239,22 +225,6 @@ const FunctionHelpers = {
}
}
Vue.prototype.$isMobile = function () {
const toMatch = [
/Android/i,
/webOS/i,
/iPhone/i,
/iPad/i,
/iPod/i,
/BlackBerry/i,
/Windows Phone/i
]
return toMatch.some(toMatchItem => {
return navigator.userAgent.match(toMatchItem)
})
}
Vue.prototype.$isSomethingWrong = function () {
events.$emit('alert:open', {
title: i18n.t('popup_error.title'),
@@ -305,10 +275,8 @@ const FunctionHelpers = {
}
// Detect windows
Vue.prototype.$checkOS = function () {
if (navigator.userAgent.indexOf('Windows') != -1) {
document.body.classList.add('windows')
}
Vue.prototype.$isWIndows = function () {
return navigator.userAgent.indexOf('Windows') != -1
}
// Check if device is Apple
@@ -328,6 +296,22 @@ const FunctionHelpers = {
})
}
Vue.prototype.$isMobile = function () {
const toMatch = [
/Android/i,
/webOS/i,
/iPhone/i,
/iPad/i,
/iPod/i,
/BlackBerry/i,
/Windows Phone/i
]
return toMatch.some(toMatchItem => {
return navigator.userAgent.match(toMatchItem)
})
}
Vue.prototype.$closePopup = function () {
events.$emit('popup:close')
}
+12 -14
View File
@@ -104,11 +104,10 @@ const actions = {
events.$emit('newFolder:focus', response.data.id)
}, 10)
if (! Vue.prototype.$isThisRoute(router, ['Public']))
dispatch('getAppData')
if (Vue.prototype.$isThisRoute(router, ['Public']))
if (Vue.prototype.$isThisRoute(router.currentRoute, ['Public']))
dispatch('getFolderTree')
else
dispatch('getAppData')
})
.catch(() => Vue.prototype.$isSomethingWrong())
@@ -132,9 +131,9 @@ const actions = {
.then(response => {
commit('CHANGE_ITEM_NAME', response.data)
if (data.type === 'folder' && getters.currentFolder.location !== 'public')
if (data.type === 'folder' && ! Vue.prototype.$isThisRoute(router.currentRoute, ['Public']))
dispatch('getAppData')
if (data.type === 'folder' && getters.currentFolder.location === 'public')
if (data.type === 'folder' && Vue.prototype.$isThisRoute(router.currentRoute, ['Public']))
dispatch('getFolderTree')
})
.catch(() => Vue.prototype.$isSomethingWrong())
@@ -179,7 +178,7 @@ const actions = {
commit('SHIFT_FROM_FILE_QUEUE')
// Check if user is in uploading folder, if yes, than show new file
if (response.data.folder_id == getters.currentFolder.id) {
if (response.data.folder_id === getters.currentFolder.id) {
// Add uploaded item into view
commit('ADD_NEW_ITEMS', response.data)
@@ -283,7 +282,7 @@ const actions = {
items.forEach(data => {
itemsToDelete.push({
force_delete: data.deleted_at ? true : false,
force_delete: !!data.deleted_at,
type: data.type,
id: data.id
})
@@ -325,7 +324,7 @@ const actions = {
})
.then(() => {
itemsToDelete.forEach(data => {
/*itemsToDelete.forEach(data => {
// If is folder, update app data
if (data.type === 'folder') {
@@ -339,13 +338,12 @@ const actions = {
}
}
}
})
})*/
if (getters.currentFolder.location !== 'public')
dispatch('getAppData')
if (getters.currentFolder.location === 'public')
if (Vue.prototype.$isThisRoute(router.currentRoute, ['Public']))
dispatch('getFolderTree')
else
dispatch('getAppData')
})
.catch(() => Vue.prototype.$isSomethingWrong())
-1
View File
@@ -42,7 +42,6 @@ const actions = {
})
},
getSingleFile: ({commit}) => {
axios.get(`/api/browse/file/${router.currentRoute.params.token}`)
.then(response => {
commit('STORE_SHARED_FILE', response.data)