diff --git a/src/components/ContactsList.vue b/src/components/ContactsList.vue
index 03d44efee..237d3def3 100644
--- a/src/components/ContactsList.vue
+++ b/src/components/ContactsList.vue
@@ -22,13 +22,35 @@
-
+
+ :estimate-size="68"
+ :extra-props={selected}
+ @update-check-selected="selectionChanged" />
@@ -36,6 +58,8 @@
import AppContentList from '@nextcloud/vue/dist/Components/AppContentList'
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',
@@ -43,6 +67,8 @@ export default {
components: {
AppContentList,
VirtualList,
+ Actions,
+ ActionButton,
},
props: {
@@ -63,6 +89,7 @@ export default {
data() {
return {
ContactsListItem,
+ selected: [],
}
},
@@ -148,6 +175,147 @@ 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)
+ })
+ },
+ 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
+ element[3].forEach(arr => {
+ if (arr !== '') {
+ isempty = false
+ }
+ })
+ if (isempty === true) {
+ contact.jCal[1].splice(contact.jCal[1].indexOf(element), 1)
+ }
+ }
+ })
+ },
+ addValue(firstContact, 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 (value[0] === 'categories') {
+ value.slice(3).forEach(element => {
+ const data = firstContact.groups
+ if (!firstContact.groups.includes(element)) {
+ data.push(element)
+ this.$store.dispatch('addContactToGroup', {
+ contact: firstContact,
+ groupName: element,
+ })
+ firstContact.groups = data
+ }
+ })
+ } else 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(firstContact, value)
+ firstContact.jCal[1].push(value)
+ }
+ } else if (value[3] !== '') {
+ let include = false
+ firstContact.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(firstContact, value)
+ firstContact.jCal[1].push(value)
+ }
+ }
+ })
+ return firstContact
+ },
+ 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.$store.dispatch('updateContact', firstContact)
+ this.selected = []
+ },
+ getKey(contact, index) {
+ if (!this.selected.includes(contact[index].key)) {
+ this.selected.push(contact[index].key)
+ }
+ },
+ verifyContact(contactOne, contactTwo) {
+ let isOk = false
+ contactOne.forEach(element => {
+ contactTwo.forEach(el => {
+ if (el[3] === element[3] && el[3] !== '' && element[3] !== '') {
+ isOk = true
+ }
+ })
+ })
+ return isOk
+ },
+ deleteTempContact(contact) {
+ contact.forEach(element => {
+ this.selected.forEach(el => {
+ if (element.key === el) {
+ contact.splice(contact.indexOf(element), 1)
+ }
+ })
+ })
+ return contact
+ },
+ autoMergeContact() {
+ const contact = this.list.filter(item => this.matchSearch(this.contacts[item.key]))
+ for (let i = 0; i < contact.length; i++) {
+ const val = contact.map(item => this.contacts[item.key].jCal[1].filter(el => { return !['uid', 'version', 'prodid', 'rev', 'adr'].includes(el[0]) }))
+ this.getKey(contact, i)
+ for (let n = 0; n < val.length; n++) {
+ if (n !== i) {
+ if (this.verifyContact(val[i], val[n])) {
+ this.getKey(contact, n)
+ }
+ }
+ }
+ this.deleteTempContact(contact)
+ if (this.selected.length > 1) {
+ this.mergeContact()
+ }
+ this.selected = []
+ }
+ },
},
}
@@ -163,4 +331,8 @@ export default {
.contacts-list__header {
min-height: 48px;
}
+
+.merge-button {
+ float: right;
+}
diff --git a/src/components/ContactsList/ContactsListItem.vue b/src/components/ContactsList/ContactsListItem.vue
index 0a17c83e3..20c9f5ca5 100644
--- a/src/components/ContactsList/ContactsListItem.vue
+++ b/src/components/ContactsList/ContactsListItem.vue
@@ -1,28 +1,42 @@
-
+ @mouseover="hover = true"
+ @mouseleave="hover = false">
+
+
+
+
+