From 7570a1ad5c3902ee1c8c3e43f448334eeae5a4f3 Mon Sep 17 00:00:00 2001 From: Bastien PROMPSY Date: Tue, 24 May 2022 10:45:46 +0200 Subject: [PATCH 1/4] Allow to delete multiple contacts Add checkbox on hover and add a button to delete the selected contacts Signed-off-by: Bastien PROMPSY --- src/components/ContactsList.vue | 42 ++++++++- .../ContactsList/ContactsListItem.vue | 87 ++++++++++++++----- 2 files changed, 108 insertions(+), 21 deletions(-) diff --git a/src/components/ContactsList.vue b/src/components/ContactsList.vue index 76d31d917..b7160f8ca 100644 --- a/src/components/ContactsList.vue +++ b/src/components/ContactsList.vue @@ -26,13 +26,24 @@
+ + + + {{ t('contacts', 'Delete') }} + + + + :estimate-size="68" + :extra-props={selected} + @update-check-selected="selectionChanged" /> @@ -40,6 +51,8 @@ import AppContentList from '@nextcloud/vue/dist/Components/NcAppContentList' import ContactsListItem from './ContactsList/ContactsListItem' import VirtualList from 'vue-virtual-scroll-list' +import Actions from '@nextcloud/vue/dist/Components/Actions' +import ActionButton from '@nextcloud/vue/dist/Components/ActionButton' export default { name: 'ContactsList', @@ -47,6 +60,8 @@ export default { components: { AppContentList, VirtualList, + Actions, + ActionButton, }, props: { @@ -68,6 +83,7 @@ export default { return { ContactsListItem, query: '', + selected: [], } }, @@ -157,6 +173,27 @@ export default { } return true }, + selectionChanged(newValue) { + if (this.selected.includes(newValue)) { + this.selected.splice(this.selected.indexOf(newValue), 1) + } else { + this.selected.push(newValue) + } + }, + deleteMultipleContact() { + const temp = [] + this.selected.forEach(element => { + if (this.contacts[element]) { + // delete contact + this.$store.dispatch('deleteContact', { contact: this.contacts[element] }) + temp.push(this.selected.indexOf(element), 1) + } + }) + // delete the uid in selected of the contact deleted + temp.forEach(el => { + this.selected.splice(temp, 1) + }) + }, }, } @@ -187,4 +224,7 @@ export default { padding: 0 4px; } +.merge-button { + float: right; +} diff --git a/src/components/ContactsList/ContactsListItem.vue b/src/components/ContactsList/ContactsListItem.vue index 9252e4bc6..b4631b5a3 100644 --- a/src/components/ContactsList/ContactsListItem.vue +++ b/src/components/ContactsList/ContactsListItem.vue @@ -1,28 +1,42 @@ From 5ec4f59031d7044d2ce7e9dcb95de06fc1a347fc Mon Sep 17 00:00:00 2001 From: Bastien PROMPSY Date: Tue, 24 May 2022 10:50:57 +0200 Subject: [PATCH 2/4] Allow to merge the selected contacts Add a button to merge the selected contacts Signed-off-by: Bastien PROMPSY --- src/components/ContactsList.vue | 67 +++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/src/components/ContactsList.vue b/src/components/ContactsList.vue index b7160f8ca..7074becf2 100644 --- a/src/components/ContactsList.vue +++ b/src/components/ContactsList.vue @@ -29,6 +29,11 @@ + + + {{ t('contacts', 'Merge') }} + + {{ t('contacts', 'Delete') }} @@ -194,6 +199,68 @@ export default { this.selected.splice(temp, 1) }) }, + cleanContactValue(contact, value) { + contact.jCal[1].forEach(element => { + if (element[0] === value[0] && element[3] === '' && !Array.isArray(element[3])) { + contact.jCal[1].splice(contact.jCal[1].indexOf(element), 1) + } else if (element[0] === value[0] && Array.isArray(element[3])) { + let isempty = true + value[3].forEach(arr => { + if (arr !== '') { + isempty = false + } + }) + if (isempty === false) { + contact.jCal[1].splice(contact.jCal[1].indexOf(element), 1) + } + } + }) + }, + addValue(contact, jcalvalue) { + jcalvalue.filter(element => { + // exclude the unique field we don't want to add + return !['uid', 'version', 'fn', 'prodid', 'gender', 'rev'].includes(element[0]) + }).forEach(value => { + if (Array.isArray(value[3])) { + let isempty = true + value[3].forEach(arr => { + if (arr !== '') { + isempty = false + } + }) + if (isempty === false) { + // delete blank field of the same type and push the new field + this.cleanContactValue(contact, value) + contact.jCal[1].push(value) + } + } else if (value[3] !== '') { + let include = false + contact.jCal[1].forEach(element => { + if (element[0] === value[0] && element[3] === value[3]) { + include = true + } + }) + if (!include) { + // delete blank field of the same type and push the new field + this.cleanContactValue(contact, value) + contact.jCal[1].push(value) + } + } + }) + return contact + }, + mergeContact() { + const firstContact = this.contacts[this.selected[0]] + this.selected.slice(1).forEach((element) => { + if (this.contacts[element]) { + const contactjcal = this.contacts[element].jCal[1] + this.addValue(firstContact, contactjcal) + // delete the contact merged and the uid in the selected + this.$store.dispatch('deleteContact', { contact: this.contacts[element] }) && this.selected.splice(this.selected.indexOf(element), 1) + } + }) + this.$store.dispatch('updateContact', firstContact) + }, }, } From 9725d38f4cef4a41c01f23db70e3f8eced274a91 Mon Sep 17 00:00:00 2001 From: Bastien PROMPSY Date: Mon, 30 May 2022 15:57:36 +0200 Subject: [PATCH 3/4] Allow to add the selected contacts to a group When the button 'add to group' is clicked, a multiselect appears who allow to select the group or type it Signed-off-by: Bastien PROMPSY --- src/components/ContactsList.vue | 66 ++++++++++++++++++++++++++++----- 1 file changed, 57 insertions(+), 9 deletions(-) diff --git a/src/components/ContactsList.vue b/src/components/ContactsList.vue index 7074becf2..d7fec53a4 100644 --- a/src/components/ContactsList.vue +++ b/src/components/ContactsList.vue @@ -29,16 +29,31 @@ - - - {{ t('contacts', 'Merge') }} + + + {{ t('contacts', 'Merge') }} + + + {{ t('contacts', 'Delete') }} + group.name) + .sort((a, b) => naturalCompare(a, b, { caseInsensitive: true })) + }, selectedContact() { return this.$route.params.selectedContact }, @@ -261,6 +286,29 @@ export default { }) this.$store.dispatch('updateContact', firstContact) }, + OpenMultiselect() { + this.showAddToGroup = false + this.showSelectGroup = true + }, + closeMultiselect() { + this.showAddToGroup = true + this.showSelectGroup = false + }, + addSelectedContactsToGroup(value) { + this.selected.forEach(element => { + const selectedContact = this.contacts[element] + const data = selectedContact.groups + if (!data.includes(value)) { + this.$store.dispatch('addContactToGroup', { + contact: selectedContact, + groupName: value, + }) + data.push(value) + selectedContact.groups = data + this.$store.dispatch('updateContact', selectedContact) + } + }) + }, }, } From 15e64b571770ce06594b4648fa80095cc89099f1 Mon Sep 17 00:00:00 2001 From: szaimen Date: Mon, 17 Oct 2022 21:42:18 +0200 Subject: [PATCH 4/4] fix imports Signed-off-by: szaimen --- src/components/ContactsList.vue | 6 +++--- src/components/ContactsList/ContactsListItem.vue | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/ContactsList.vue b/src/components/ContactsList.vue index d7fec53a4..613830a16 100644 --- a/src/components/ContactsList.vue +++ b/src/components/ContactsList.vue @@ -71,10 +71,10 @@ import AppContentList from '@nextcloud/vue/dist/Components/NcAppContentList' import ContactsListItem from './ContactsList/ContactsListItem' import VirtualList from 'vue-virtual-scroll-list' -import Actions from '@nextcloud/vue/dist/Components/Actions' -import ActionButton from '@nextcloud/vue/dist/Components/ActionButton' +import Actions from '@nextcloud/vue/dist/Components/NcActions' +import ActionButton from '@nextcloud/vue/dist/Components/NcActionButton' import naturalCompare from 'string-natural-compare' -import Multiselect from '@nextcloud/vue/dist/Components/Multiselect' +import Multiselect from '@nextcloud/vue/dist/Components/NcMultiselect' export default { name: 'ContactsList', diff --git a/src/components/ContactsList/ContactsListItem.vue b/src/components/ContactsList/ContactsListItem.vue index b4631b5a3..d220c28b5 100644 --- a/src/components/ContactsList/ContactsListItem.vue +++ b/src/components/ContactsList/ContactsListItem.vue @@ -36,7 +36,7 @@