Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drag'n'Drop support #2834

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"vue-slide-up-down": "^2.0.1",
"vue-tabs-component": "^1.5.0",
"vuex": "^3.1.3",
"vue-draggable": "^2.0.6",
"vuex-router-sync": "^5.0.0"
},
"browserslist": [
Expand Down
30 changes: 30 additions & 0 deletions src/components/NavigationAccountExpandCollapse.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
<script>
import AppNavigationItem from '@nextcloud/vue/dist/Components/AppNavigationItem'

import logger from '../logger'

export default {
name: 'NavigationAccountExpandCollapse',
components: {
Expand All @@ -45,11 +47,39 @@ export default {
return this.account.collapsed ? t('mail', 'Show all folders') : t('mail', 'Collapse folders')
},
},
data() {
return {
timeoutID: '',
key: 'collapse-' + this.account.id,
classes: ['collapse-folders'],
text: this.account.collapsed ? t('mail', 'Show all folders') : t('mail', 'Collapse folders'),
action: () => this.$store.commit('toggleAccountCollapsed', this.account.id),
}
},
methods: {
toggleCollapse() {
this.$store.commit('toggleAccountCollapsed', this.account.id)
},
},
mounted() {
this.$el.ondragenter = () => {
logger.debug('drag enter on expand-collapse component')

// this.style.background = '#F5F5F5'
clearTimeout(this.timeoutID)
this.timeoutID = setTimeout(() => {
logger.debug('expanding folder list for drag and drop')

this.$store.commit('toggleAccountCollapsed', this.account.id)
this.timeoutID = undefined
}, 800)
}
this.$el.ondragleave = () => {
logger.debug('drag leave on expand-collapse component')

clearTimeout(this.timeoutID)
}
}
}
</script>

Expand Down
72 changes: 47 additions & 25 deletions src/components/NavigationFolder.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
:icon="icon"
:title="title"
:to="to"
:menu-open.sync="menuOpen"
:open.sync="folderOpen"
@update:menuOpen="onMenuToggle"
>
<!-- actions -->
Expand Down Expand Up @@ -122,6 +124,10 @@ export default {
},
data() {
return {
timeoutID: '',
folderOpen: false,
menuOpen: false,
loadingFolderStats: true,
folderStats: undefined,
loadingMarkAsRead: false,
}
Expand Down Expand Up @@ -155,31 +161,21 @@ export default {
filter: this.filter ? this.filter : undefined,
},
}
},
subFolders() {
return this.$store.getters.getSubfolders(this.account.id, this.folder.id)
},
statsText() {
if (this.folderStats && 'total' in this.folderStats && 'unread' in this.folderStats) {
if (this.folderStats.unread === 0) {
return n('mail', '{total} message', '{total} messages', this.folderStats.total, {
total: this.folderStats.total,
})
} else {
return n(
'mail',
'{unread} unread of {total}',
'{unread} unread of {total}',
this.folderStats.unread,
{
total: this.folderStats.total,
unread: this.folderStats.unread,
}
)
}
}
return t('mail', 'Loading …')
},
}
},
mounted() {
this.$el.ondragenter = () => {
//this.style.background = '#F5F5F5'
clearTimeout(this.timeoutID)
this.timeoutID = setTimeout(() => {
this.folderOpen = !this.folderOpen
this.timeoutID = ''
}, 800)
}
this.$el.ondragleave = () => {
//this.style.background = ''
clearTimeout(this.timeoutID)
}
},
methods: {
/**
Expand Down Expand Up @@ -246,6 +242,32 @@ export default {
.catch((error) => logger.error(`could not mark folder ${this.folder.id} as read`, {error}))
.then(() => (this.loadingMarkAsRead = false))
},

subFolders() {
return this.$store.getters.getSubfolders(this.account.id, this.folder.id)
},

statsText() {
if (this.folderStats && 'total' in this.folderStats && 'unread' in this.folderStats) {
if (this.folderStats.unread === 0) {
return n('mail', '{total} message', '{total} messages', this.folderStats.total, {
total: this.folderStats.total,
})
} else {
return n(
'mail',
'{unread} unread of {total}',
'{unread} unread of {total}',
this.folderStats.unread,
{
total: this.folderStats.total,
unread: this.folderStats.unread,
}
)
}
}
return t('mail', 'Loading …')
},
},
}
</script>
10 changes: 10 additions & 0 deletions src/service/MessageService.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,13 @@ export function deleteMessage(accountId, folderId, id) {

return axios.delete(url).then((resp) => resp.data)
}

export function moveMessage(accountId, startFolderId, targetFolderId, id) {
const url = generateUrl('/apps/mail/api/accounts/{accountId}/folders/{startFolderId}/messages/{id}/move', {
accountId,
startFolderId,
id,
})

return HttpClient.post(url, {destAccountId: accountId, destFolderId: targetFolderId}).then(resp => resp.data)
}
28 changes: 28 additions & 0 deletions src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import {
fetchEnvelope,
fetchEnvelopes,
fetchMessage,
moveMessage,
setEnvelopeFlag,
syncEnvelopes,
} from '../service/MessageService'
Expand Down Expand Up @@ -534,6 +535,33 @@ export default {
newUid: uid,
})
},
moveMessage({getters, commit}, data) {
const folder = getters.getFolder(data.accountId, data.startFolderId)
commit('removeEnvelope', {
accountId: data.accountId,
folder,
id: data.msgId,
})
return moveMessage(data.accountId, data.startFolderId, data.targetFolderId, data.msgId)
.then(() => {
commit('removeMessage', {
accountId: data.accountId,
folder,
id: data.msgId,
})
console.log('message moved')
})
.catch(err => {
console.error('could not move message', err)
const env = getters.getEnvelope(data.accountId, data.startFolderId, data.msgId)
commit('addEnvelope', {
accountId: data.accountId,
folder,
env,
})
throw err
})
},
deleteMessage({getters, commit}, {accountId, folderId, id}) {
commit('removeEnvelope', {accountId, folderId, id})

Expand Down
Loading