mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-05-30 15:44:41 +00:00
toggle favourites refactor
This commit is contained in:
@@ -1,12 +1,11 @@
|
|||||||
<template>
|
<template>
|
||||||
<div
|
<div
|
||||||
:class="{
|
:class="{
|
||||||
'pointer-events-none opacity-50': (disabledById && disabledById.data.id === nodes.id) || !disableId,
|
'pointer-events-none opacity-50': (disabledById && disabledById.data.id === nodes.id) || !disableId || (isRootDepth && !nodes.folders.length),
|
||||||
'mb-2.5': isRootDepth,
|
'mb-2.5': isRootDepth,
|
||||||
}"
|
}"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
:class="{ 'is-disabled-item': false }"
|
|
||||||
:style="indent"
|
:style="indent"
|
||||||
class="relative relative flex cursor-pointer select-none items-center whitespace-nowrap py-2 px-1.5 transition-all duration-150"
|
class="relative relative flex cursor-pointer select-none items-center whitespace-nowrap py-2 px-1.5 transition-all duration-150"
|
||||||
>
|
>
|
||||||
@@ -53,7 +52,7 @@
|
|||||||
<b
|
<b
|
||||||
@click="getFolder"
|
@click="getFolder"
|
||||||
class="ml-3 inline-block overflow-x-hidden text-ellipsis whitespace-nowrap text-xs font-bold transition-all duration-150"
|
class="ml-3 inline-block overflow-x-hidden text-ellipsis whitespace-nowrap text-xs font-bold transition-all duration-150"
|
||||||
:class="{ 'text-theme': isSelectedItem }"
|
:class="{'text-theme': isSelectedItem }"
|
||||||
>
|
>
|
||||||
{{ nodes.name }}
|
{{ nodes.name }}
|
||||||
</b>
|
</b>
|
||||||
|
|||||||
Vendored
+30
@@ -15,6 +15,25 @@ const itemHelpers = {
|
|||||||
store.dispatch('shareCancel')
|
store.dispatch('shareCancel')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Vue.prototype.$toggleFavourites = function (entry) {
|
||||||
|
let favourites = store.getters.user.data.relationships.favourites.data
|
||||||
|
|
||||||
|
// Check if folder is in favourites and then add/remove from favourites
|
||||||
|
if (favourites && !favourites.find((el) => el.data.id === entry.data.id)) {
|
||||||
|
// Add to favourite folder that is not selected
|
||||||
|
if (!store.getters.clipboard.includes(entry)) {
|
||||||
|
this.$store.dispatch('addToFavourites', entry)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add to favourites all selected folders
|
||||||
|
if (store.getters.clipboard.includes(entry)) {
|
||||||
|
this.$store.dispatch('addToFavourites', null)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.$store.dispatch('removeFromFavourites', entry)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Vue.prototype.$renameFileOrFolder = function (entry) {
|
Vue.prototype.$renameFileOrFolder = function (entry) {
|
||||||
events.$emit('popup:open', { name: 'rename-item', item: entry })
|
events.$emit('popup:open', { name: 'rename-item', item: entry })
|
||||||
}
|
}
|
||||||
@@ -23,6 +42,17 @@ const itemHelpers = {
|
|||||||
events.$emit('popup:open', { name: 'move', item: [entry] })
|
events.$emit('popup:open', { name: 'move', item: [entry] })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Vue.prototype.$createFolderByPopup = function () {
|
||||||
|
// Show alert message when create folder is disabled
|
||||||
|
if (store.getters.user && !store.getters.user.data.meta.restrictions.canCreateFolder) {
|
||||||
|
Vue.prototype.$temporarilyDisabledFolderCreate()
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
events.$emit('popup:open', { name: 'create-folder' })
|
||||||
|
}
|
||||||
|
|
||||||
Vue.prototype.$createFolder = function () {
|
Vue.prototype.$createFolder = function () {
|
||||||
// Show alert message when create folder is disabled
|
// Show alert message when create folder is disabled
|
||||||
if (store.getters.user && !store.getters.user.data.meta.restrictions.canCreateFolder) {
|
if (store.getters.user && !store.getters.user.data.meta.restrictions.canCreateFolder) {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<MobileContextMenu>
|
<MobileContextMenu>
|
||||||
<OptionGroup v-if="item && isFolder">
|
<OptionGroup v-if="item && isFolder">
|
||||||
<Option
|
<Option
|
||||||
@click.native="addToFavourites"
|
@click.native="$toggleFavourites(item)"
|
||||||
:title="
|
:title="
|
||||||
isInFavourites
|
isInFavourites
|
||||||
? $t('context_menu.remove_from_favourites')
|
? $t('context_menu.remove_from_favourites')
|
||||||
@@ -39,7 +39,6 @@
|
|||||||
<MobileCreateMenu>
|
<MobileCreateMenu>
|
||||||
<OptionGroup :title="$t('Upload')">
|
<OptionGroup :title="$t('Upload')">
|
||||||
<OptionUpload
|
<OptionUpload
|
||||||
:class="{ 'is-inactive': !hasCapacity }"
|
|
||||||
:title="$t('actions.upload')"
|
:title="$t('actions.upload')"
|
||||||
type="file"
|
type="file"
|
||||||
:is-hover-disabled="true"
|
:is-hover-disabled="true"
|
||||||
@@ -54,7 +53,7 @@
|
|||||||
:is-hover-disabled="true"
|
:is-hover-disabled="true"
|
||||||
/>
|
/>
|
||||||
<Option
|
<Option
|
||||||
@click.stop.native="createFolder"
|
@click.stop.native="$createFolderByPopup"
|
||||||
:title="$t('actions.create_folder')"
|
:title="$t('actions.create_folder')"
|
||||||
icon="folder-plus"
|
icon="folder-plus"
|
||||||
:is-hover-disabled="true"
|
:is-hover-disabled="true"
|
||||||
@@ -103,7 +102,7 @@
|
|||||||
<template v-slot:single-select v-if="item">
|
<template v-slot:single-select v-if="item">
|
||||||
<OptionGroup v-if="isFolder">
|
<OptionGroup v-if="isFolder">
|
||||||
<Option
|
<Option
|
||||||
@click.native="addToFavourites"
|
@click.native="$toggleFavourites(item)"
|
||||||
:title="
|
:title="
|
||||||
isInFavourites
|
isInFavourites
|
||||||
? $t('context_menu.remove_from_favourites')
|
? $t('context_menu.remove_from_favourites')
|
||||||
@@ -155,7 +154,7 @@
|
|||||||
<template v-slot:multiple-select v-if="item">
|
<template v-slot:multiple-select v-if="item">
|
||||||
<OptionGroup v-if="!hasFile">
|
<OptionGroup v-if="!hasFile">
|
||||||
<Option
|
<Option
|
||||||
@click.native="addToFavourites"
|
@click.native="$toggleFavourites(item)"
|
||||||
:title="
|
:title="
|
||||||
isInFavourites
|
isInFavourites
|
||||||
? $t('context_menu.remove_from_favourites')
|
? $t('context_menu.remove_from_favourites')
|
||||||
@@ -250,52 +249,21 @@ export default {
|
|||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
...mapGetters(['fastPreview', 'clipboard', 'config', 'user']),
|
...mapGetters(['fastPreview', 'clipboard', 'config', 'user']),
|
||||||
hasCapacity() {
|
|
||||||
// Check if storage limitation is set
|
|
||||||
if (!this.config.storageLimit) return true
|
|
||||||
|
|
||||||
// Check if user has storage
|
|
||||||
return this.user && this.user.data.attributes.storage.used <= 100
|
|
||||||
},
|
|
||||||
isFolder() {
|
isFolder() {
|
||||||
return this.item && this.item.data.type === 'folder'
|
return this.item && this.item.data.type === 'folder'
|
||||||
},
|
},
|
||||||
isInFavourites() {
|
isInFavourites() {
|
||||||
return this.favourites.find((el) => el.id === this.item.data.id)
|
return this.user.data.relationships.favourites.data.find((el) => el.data.id === this.item.data.id)
|
||||||
},
|
},
|
||||||
hasFile() {
|
hasFile() {
|
||||||
return this.clipboard.find((item) => item.data.type !== 'folder')
|
return this.clipboard.find((item) => item.data.type !== 'folder')
|
||||||
},
|
},
|
||||||
favourites() {
|
|
||||||
return this.user.data.relationships.favourites.data
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
item: undefined,
|
item: undefined,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
|
||||||
addToFavourites() {
|
|
||||||
// Check if folder is in favourites and then add/remove from favourites
|
|
||||||
if (this.favourites && !this.favourites.find((el) => el.id === this.item.data.id)) {
|
|
||||||
// Add to favourite folder that is not selected
|
|
||||||
if (!this.clipboard.includes(this.item)) {
|
|
||||||
this.$store.dispatch('addToFavourites', this.item)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add to favourites all selected folders
|
|
||||||
if (this.clipboard.includes(this.item)) {
|
|
||||||
this.$store.dispatch('addToFavourites', null)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this.$store.dispatch('removeFromFavourites', this.item)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
createFolder() {
|
|
||||||
events.$emit('popup:open', { name: 'create-folder' })
|
|
||||||
},
|
|
||||||
},
|
|
||||||
created() {
|
created() {
|
||||||
this.$store.dispatch('getFolder', this.$route.params.id)
|
this.$store.dispatch('getFolder', this.$route.params.id)
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
<template v-slot:single-select v-if="item">
|
<template v-slot:single-select v-if="item">
|
||||||
<OptionGroup v-if="isFolder">
|
<OptionGroup v-if="isFolder">
|
||||||
<Option
|
<Option
|
||||||
@click.native="addToFavourites"
|
@click.native="$toggleFavourites(item)"
|
||||||
:title="
|
:title="
|
||||||
isInFavourites
|
isInFavourites
|
||||||
? $t('context_menu.remove_from_favourites')
|
? $t('context_menu.remove_from_favourites')
|
||||||
@@ -43,7 +43,7 @@
|
|||||||
<template v-slot:multiple-select v-if="item">
|
<template v-slot:multiple-select v-if="item">
|
||||||
<OptionGroup v-if="!hasFile">
|
<OptionGroup v-if="!hasFile">
|
||||||
<Option
|
<Option
|
||||||
@click.native="addToFavourites"
|
@click.native="$toggleFavourites(item)"
|
||||||
:title="
|
:title="
|
||||||
isInFavourites
|
isInFavourites
|
||||||
? $t('context_menu.remove_from_favourites')
|
? $t('context_menu.remove_from_favourites')
|
||||||
@@ -65,7 +65,7 @@
|
|||||||
<MobileContextMenu>
|
<MobileContextMenu>
|
||||||
<OptionGroup v-if="isFolder">
|
<OptionGroup v-if="isFolder">
|
||||||
<Option
|
<Option
|
||||||
@click.native="addToFavourites"
|
@click.native="$toggleFavourites(item)"
|
||||||
:title="
|
:title="
|
||||||
isInFavourites
|
isInFavourites
|
||||||
? $t('context_menu.remove_from_favourites')
|
? $t('context_menu.remove_from_favourites')
|
||||||
@@ -163,38 +163,17 @@ export default {
|
|||||||
return this.item && this.item.type === 'folder'
|
return this.item && this.item.type === 'folder'
|
||||||
},
|
},
|
||||||
isInFavourites() {
|
isInFavourites() {
|
||||||
return this.favourites.find((el) => el.id === this.item.id)
|
return this.user.data.relationships.favourites.data.find((el) => el.id === this.item.id)
|
||||||
},
|
},
|
||||||
hasFile() {
|
hasFile() {
|
||||||
return this.clipboard.find((item) => item.type !== 'folder')
|
return this.clipboard.find((item) => item.type !== 'folder')
|
||||||
},
|
},
|
||||||
favourites() {
|
|
||||||
return this.user.data.relationships.favourites.data.attributes.folders
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
item: undefined,
|
item: undefined,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
|
||||||
addToFavourites() {
|
|
||||||
// Check if folder is in favourites and then add/remove from favourites
|
|
||||||
if (this.favourites && !this.favourites.find((el) => el.id === this.item.data.id)) {
|
|
||||||
// Add to favourite folder that is not selected
|
|
||||||
if (!this.clipboard.includes(this.item)) {
|
|
||||||
this.$store.dispatch('addToFavourites', this.item)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add to favourites all selected folders
|
|
||||||
if (this.clipboard.includes(this.item)) {
|
|
||||||
this.$store.dispatch('addToFavourites', null)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this.$store.dispatch('removeFromFavourites', this.item)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
created() {
|
created() {
|
||||||
this.$store.dispatch('getMySharedItems')
|
this.$store.dispatch('getMySharedItems')
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<MobileContextMenu>
|
<MobileContextMenu>
|
||||||
<OptionGroup v-if="item && isFolder">
|
<OptionGroup v-if="item && isFolder">
|
||||||
<Option
|
<Option
|
||||||
@click.native="addToFavourites"
|
@click.native="$toggleFavourites(item)"
|
||||||
:title="
|
:title="
|
||||||
isInFavourites
|
isInFavourites
|
||||||
? $t('context_menu.remove_from_favourites')
|
? $t('context_menu.remove_from_favourites')
|
||||||
@@ -50,7 +50,7 @@
|
|||||||
:is-hover-disabled="true"
|
:is-hover-disabled="true"
|
||||||
/>
|
/>
|
||||||
<Option
|
<Option
|
||||||
@click.stop.native="createFolder"
|
@click.stop.native="$createFolderByPopup"
|
||||||
:title="$t('actions.create_folder')"
|
:title="$t('actions.create_folder')"
|
||||||
icon="folder-plus"
|
icon="folder-plus"
|
||||||
:is-hover-disabled="true"
|
:is-hover-disabled="true"
|
||||||
@@ -107,7 +107,7 @@
|
|||||||
<template v-slot:single-select v-if="item">
|
<template v-slot:single-select v-if="item">
|
||||||
<OptionGroup v-if="isFolder">
|
<OptionGroup v-if="isFolder">
|
||||||
<Option
|
<Option
|
||||||
@click.native="addToFavourites"
|
@click.native="$toggleFavourites(item)"
|
||||||
:title="
|
:title="
|
||||||
isInFavourites
|
isInFavourites
|
||||||
? $t('context_menu.remove_from_favourites')
|
? $t('context_menu.remove_from_favourites')
|
||||||
@@ -153,7 +153,7 @@
|
|||||||
<template v-slot:multiple-select v-if="item">
|
<template v-slot:multiple-select v-if="item">
|
||||||
<OptionGroup v-if="!hasFile">
|
<OptionGroup v-if="!hasFile">
|
||||||
<Option
|
<Option
|
||||||
@click.native="addToFavourites"
|
@click.native="$toggleFavourites(item)"
|
||||||
:title="
|
:title="
|
||||||
isInFavourites
|
isInFavourites
|
||||||
? $t('context_menu.remove_from_favourites')
|
? $t('context_menu.remove_from_favourites')
|
||||||
@@ -276,41 +276,17 @@ export default {
|
|||||||
return this.item && this.item.data.type === 'folder'
|
return this.item && this.item.data.type === 'folder'
|
||||||
},
|
},
|
||||||
isInFavourites() {
|
isInFavourites() {
|
||||||
return this.favourites.find((el) => el.id === this.item.id)
|
return this.user.data.relationships.favourites.data.find((el) => el.id === this.item.id)
|
||||||
},
|
},
|
||||||
hasFile() {
|
hasFile() {
|
||||||
return this.clipboard.find((item) => item.type !== 'folder')
|
return this.clipboard.find((item) => item.type !== 'folder')
|
||||||
},
|
},
|
||||||
favourites() {
|
|
||||||
return this.user.data.relationships.favourites.data
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
item: undefined,
|
item: undefined,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
|
||||||
addToFavourites() {
|
|
||||||
// Check if folder is in favourites and then add/remove from favourites
|
|
||||||
if (this.favourites && !this.favourites.find((el) => el.id === this.item.data.id)) {
|
|
||||||
// Add to favourite folder that is not selected
|
|
||||||
if (!this.clipboard.includes(this.item)) {
|
|
||||||
this.$store.dispatch('addToFavourites', this.item)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add to favourites all selected folders
|
|
||||||
if (this.clipboard.includes(this.item)) {
|
|
||||||
this.$store.dispatch('addToFavourites', null)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this.$store.dispatch('removeFromFavourites', this.item)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
createFolder() {
|
|
||||||
events.$emit('popup:open', { name: 'create-folder' })
|
|
||||||
},
|
|
||||||
},
|
|
||||||
mounted() {
|
mounted() {
|
||||||
this.$store.dispatch('getTeamFolder', this.$route.params.id)
|
this.$store.dispatch('getTeamFolder', this.$route.params.id)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user