api resource refactoring

This commit is contained in:
Peter Papp
2021-08-27 09:41:14 +02:00
parent 5c6a873b02
commit e0e060e5a1
22 changed files with 173 additions and 79 deletions
+3 -8
View File
@@ -160,13 +160,6 @@ const mutations = {
})
},
CHANGE_ITEM_NAME(state, updatedFile) {
// Rename filename in clipboard
if (state.clipboard && state.clipboard.data.id === updatedFile.data.id) {
state.clipboard = updatedFile
}
// Rename item name in data view
state.entries.find(item => {
if (item.data.id === updatedFile.data.id) {
item.data.attributes.name = updatedFile.data.attributes.name
@@ -177,7 +170,9 @@ const mutations = {
},
UPDATE_SHARED_ITEM(state, data) {
state.entries.find(item => {
if (item.data.id === data.item_id) item.shared = data
if (item.data.id === data.data.attributes.item_id) {
item.data.relationships.shared = data
}
})
},
ADD_NEW_FOLDER(state, folder) {
+7 -7
View File
@@ -60,7 +60,7 @@ const actions = {
axios
.post(route, {
to_id: to_item.data.id ? to_item.data.id : null,
to_id: to_item.id ? to_item.id : null,
items: itemsToMove
})
.then(() => {
@@ -70,7 +70,8 @@ const actions = {
if (item.type === 'folder')
dispatch('getAppData')
if (getters.currentFolder.location === 'public')
if (Vue.prototype.$isThisRoute(router.currentRoute, ['Public']))
dispatch('getFolderTree')
})
})
@@ -100,7 +101,7 @@ const actions = {
// Set focus on new folder name
setTimeout(() => {
events.$emit('newFolder:focus', response.data.id)
events.$emit('newFolder:focus', response.data.data.id)
}, 10)
if (Vue.prototype.$isThisRoute(router.currentRoute, ['Public']))
@@ -322,13 +323,12 @@ const actions = {
items: itemsToDelete
})
.then(() => {
itemsToDelete.forEach(data => {
// If is folder, update app data
if (data.data.type === 'folder') {
if (data.type === 'folder') {
if (data.data.id === getters.currentFolder.data.id) {
if (data.id === getters.currentFolder.data.id) {
if (getters.currentFolder.location === 'public') {
dispatch('browseShared')
@@ -345,7 +345,7 @@ const actions = {
dispatch('getAppData')
})
.catch(() => Vue.prototype.$isSomethingWrong())
//.catch(() => Vue.prototype.$isSomethingWrong())
},
emptyTrash: ({commit, getters}) => {
+5 -5
View File
@@ -77,8 +77,8 @@ const actions = {
items = getters.clipboard
}
items.forEach(data => {
tokens.push(data.shared.token)
items.forEach(item => {
tokens.push(item.data.relationships.shared.data.attributes.token)
})
axios
@@ -91,12 +91,12 @@ const actions = {
items.forEach(item => {
// Remove item from file browser
if ( getters.currentFolder && getters.currentFolder.location === 'shared' ) {
commit('REMOVE_ITEM', item.id)
if ( getters.currentFolder && Vue.prototype.$isThisRoute(router.currentRoute, ['MySharedItems']) ) {
commit('REMOVE_ITEM', item.data.id)
}
// Flush shared data
commit('FLUSH_SHARED', item.id)
commit('FLUSH_SHARED', item.data.id)
commit('CLIPBOARD_CLEAR')
})
resolve(true)
+7 -8
View File
@@ -56,14 +56,13 @@ const actions = {
if (!folder)
items = context.getters.clipboard
items.forEach((data) => {
if (data.type === 'folder') {
items.forEach((item) => {
if (context.getters.user.data.relationships.favourites.data.attributes.folders.find(folder => folder.id === data.id)) return
if (item.data.type === 'folder') {
addFavourites.push({
id: data.id
})
if (context.getters.user.data.relationships.favourites.data.attributes.folders.find(folder => folder.id === item.data.id)) return
addFavourites.push({id: item.data.id})
}
})
@@ -98,7 +97,7 @@ const actions = {
commit('REMOVE_ITEM_FROM_FAVOURITES', folder)
axios
.post(getters.api + '/folders/favourites/' + folder.id, {
.post(getters.api + '/folders/favourites/' + folder.data.id, {
_method: 'delete'
})
.catch(() => {
@@ -136,7 +135,7 @@ const mutations = {
state.user.data.relationships.settings.data.attributes.avatar = avatar
},
REMOVE_ITEM_FROM_FAVOURITES(state, item) {
state.user.data.relationships.favourites.data.attributes.folders = state.user.data.relationships.favourites.data.attributes.folders.filter(folder => folder.id !== item.id)
state.user.data.relationships.favourites.data.attributes.folders = state.user.data.relationships.favourites.data.attributes.folders.filter(folder => folder.id !== item.data.id)
},
UPDATE_NAME_IN_FAVOURITES(state, data) {
state.user.data.relationships.favourites.data.attributes.folders.find(folder => {