diff options
author | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2018-11-09 13:07:58 +0100 |
---|---|---|
committer | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2018-11-09 13:20:41 +0100 |
commit | 17e8723adc5a616c745924f8afebeb614376d737 (patch) | |
tree | c5a8fc178f6dd870748b488a7f5be10c0c0e6681 /src | |
parent | 0f72d40d46e426bbb53750ced048a0da2212a796 (diff) |
Fix tests & add MOVE
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/components/ContactDetails.vue | 72 | ||||
-rw-r--r-- | src/components/Settings/SettingsAddressbook.vue | 3 | ||||
-rw-r--r-- | src/store/addressbooks.js | 24 | ||||
-rw-r--r-- | src/store/contacts.js | 23 | ||||
-rw-r--r-- | src/views/Contacts.vue | 2 |
5 files changed, 67 insertions, 57 deletions
diff --git a/src/components/ContactDetails.vue b/src/components/ContactDetails.vue index d78bfa3c..0d50248a 100644 --- a/src/components/ContactDetails.vue +++ b/src/components/ContactDetails.vue @@ -113,7 +113,6 @@ import Vue from 'vue' import VTooltip from 'v-tooltip' import debounce from 'debounce' -import Contact from '../models/contact' import rfcProps from '../models/rfcProps.js' import ContactProperty from './ContactDetails/ContactDetailsProperty' @@ -145,7 +144,7 @@ export default { type: Boolean, default: true }, - uid: { + contactKey: { type: String, default: undefined } @@ -276,7 +275,7 @@ export default { */ addressbooksOptions() { return this.addressbooks - .filter(addressbook => addressbook.readOnly) + .filter(addressbook => !addressbook.readOnly) .map(addressbook => { return { id: addressbook.id, @@ -290,22 +289,22 @@ export default { return this.$store.getters.getAddressbooks }, contact() { - return this.$store.getters.getContact(this.uid) + return this.$store.getters.getContact(this.contactKey) } }, watch: { contact: function() { - if (this.uid) { - this.selectContact(this.uid) + if (this.contactKey) { + this.selectContact(this.contactKey) } } }, beforeMount() { // load the desired data if we already selected a contact - if (this.uid) { - this.selectContact(this.uid) + if (this.contactKey) { + this.selectContact(this.contactKey) } }, @@ -314,12 +313,10 @@ export default { * Executed on the 'updatedcontact' event * Send the local clone of contact to the store */ - updateContact() { + async updateContact() { this.loadingUpdate = true - this.$store.dispatch('updateContact', this.contact) - .then(() => { - this.loadingUpdate = false - }) + await this.$store.dispatch('updateContact', this.contact) + this.loadingUpdate = false }, /** @@ -343,12 +340,12 @@ export default { * Fetch updated data if necessary * Scroll to the selected contact if exists * - * @param {string} uid the contact uid + * @param {string} key the contact key */ - selectContact(uid) { + selectContact(key) { // local version of the contact this.loadingData = true - let contact = this.$store.getters.getContact(uid) + let contact = this.$store.getters.getContact(key) if (contact) { // if contact exists AND if exists on server @@ -356,11 +353,10 @@ export default { this.$store.dispatch('fetchFullContact', { contact }) .then(() => { // create empty contact and copy inner data - let localContact = new Contact( - 'BEGIN:VCARD\nUID:' + contact.uid + '\nEND:VCARD', - contact.addressbook + let localContact = Object.assign( + Object.create(Object.getPrototypeOf(contact)), + contact ) - localContact.updateContact(contact.jCal) this.localContact = localContact this.loadingData = false }) @@ -373,9 +369,9 @@ export default { } else { // create empty contact and copy inner data // wait for an update to really push the contact on the server! - this.localContact = new Contact( - 'BEGIN:VCARD\nUID:' + contact.uid + '\nEND:VCARD', - contact.addressbook + this.localContact = Object.assign( + Object.create(Object.getPrototypeOf(contact)), + contact ) this.loadingData = false } @@ -404,20 +400,30 @@ export default { * * @param {string} addressbookId the desired addressbook ID */ - moveContactToAddressbook(addressbookId) { + async moveContactToAddressbook(addressbookId) { let addressbook = this.addressbooks.find(search => search.id === addressbookId) this.loadingUpdate = true - // TODO Properly implement the MOVE request if (addressbook) { - this.$store.dispatch('moveContactToAddressbook', { - // we need to use the store contact, not the local contact - // using this.contact and not this.localContact - contact: this.contact, - addressbook - }).then(() => { - this.updateContact() + try { + const contact = await this.$store.dispatch('moveContactToAddressbook', { + // we need to use the store contact, not the local contact + // using this.contact and not this.localContact + contact: this.contact, + addressbook + }) + // select the contact again + this.$router.push({ + name: 'contact', + params: { + selectedGroup: this.$route.params.selectedGroup, + selectedContact: contact.key + } + }) this.loadingUpdate = false - }) + } catch (error) { + console.error(error) + this.loadingUpdate = false + } } }, diff --git a/src/components/Settings/SettingsAddressbook.vue b/src/components/Settings/SettingsAddressbook.vue index 4ec5dcdc..26931977 100644 --- a/src/components/Settings/SettingsAddressbook.vue +++ b/src/components/Settings/SettingsAddressbook.vue @@ -75,7 +75,6 @@ export default { editingName: false, copied: false, copySuccess: true, - readOnly: this.addressbook.readOnly, toggleEnabledLoading: false, deleteAddressbookLoading: false, renameLoading: false, @@ -107,7 +106,7 @@ export default { ] // check if addressbook is readonly - if (!this.readOnly) { + if (!this.addressbook.readOnly) { menu.push({ icon: this.renameLoading ? 'icon-loading-small' : 'icon-rename', // check if editing name diff --git a/src/store/addressbooks.js b/src/store/addressbooks.js index c2f73cd7..c37a106e 100644 --- a/src/store/addressbooks.js +++ b/src/store/addressbooks.js @@ -425,31 +425,21 @@ const actions = { * @param {Object} data destructuring object * @param {Contact} data.contact the contact to move * @param {Object} data.addressbook the addressbook to move the contact to + * @returns {Contact} the new contact object */ async moveContactToAddressbook(context, { contact, addressbook }) { // only local move if the contact doesn't exists on the server if (contact.dav) { - // TODO: implement proper move - // await contact.dav.move(addressbook.dav) - // .catch((error) => { - // console.error(error) - // OC.Notification.showTemporary(t('contacts', 'An error occurred')) - // }) - let vData = ICAL.stringify(contact.vCard.jCal) - let newDav - await addressbook.dav.createVCard(vData) - .then((response) => { newDav = response }) - .catch((error) => { throw error }) - await contact.dav.delete() - .catch((error) => { - console.error(error) - OC.Notification.showTemporary(t('contacts', 'An error occurred')) - }) - await Vue.set(contact, 'dav', newDav) + try { + await contact.dav.move(addressbook.dav) + } catch (error) { + throw error + } } await context.commit('deleteContactFromAddressbook', contact) await context.commit('updateContactAddressbook', { contact, addressbook }) await context.commit('addContactToAddressbook', contact) + return contact } } diff --git a/src/store/contacts.js b/src/store/contacts.js index feac4c63..0bcd8cc1 100644 --- a/src/store/contacts.js +++ b/src/store/contacts.js @@ -152,12 +152,27 @@ const mutations = { */ updateContactAddressbook(state, { contact, addressbook }) { if (state.contacts[contact.key] && contact instanceof Contact) { - // replace contact object data + // replace contact object data by creating a new contact let oldKey = contact.key - let newContact = new Contact(contact.dav.data, addressbook) - Vue.set(state.contacts, newContact.key, newContact) + + // hijack reference + var newContact = contact + + // delete old key, cut reference Vue.delete(state.contacts, oldKey) + // replace addressbook + Vue.set(newContact, 'addressbook', addressbook) + + // set new key, re-assign reference + Vue.set(state.contacts, newContact.key, newContact) + + // Update sorted contacts list, replace at exact same position + let index = state.sortedContacts.findIndex(search => search.key === oldKey) + state.sortedContacts[index] = { + key: newContact.key, + value: newContact[state.orderKey] + } } else { console.error('Error while replacing the addressbook of following contact', contact) } @@ -218,7 +233,7 @@ const mutations = { const getters = { getContacts: state => state.contacts, getSortedContacts: state => state.sortedContacts, - getContact: (state) => (uid) => state.contacts[uid], + getContact: (state) => (key) => state.contacts[key], getOrderKey: state => state.orderKey } diff --git a/src/views/Contacts.vue b/src/views/Contacts.vue index 749341a3..bcb8eff0 100644 --- a/src/views/Contacts.vue +++ b/src/views/Contacts.vue @@ -39,7 +39,7 @@ <content-list :list="contactsList" :contacts="contacts" :loading="loading" :search-query="searchQuery" /> <!-- main contacts details --> - <contact-details :loading="loading" :uid="selectedContact" /> + <contact-details :loading="loading" :contact-key="selectedContact" /> </template> </div> </div> |