From a207d5e2be8091ca9c93b450fdaa07c6ad5a78eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6=20=28skjnldsv=29?= Date: Mon, 4 Mar 2019 09:55:40 +0100 Subject: [PATCH] Add REV on update MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- css/ContactDetails.scss | 10 +++++ src/components/ContactDetails.vue | 5 +++ src/components/Properties/PropertyRev.vue | 49 +++++++++++++++++++++++ src/mixins/PropertyMixin.js | 8 +++- src/models/contact.js | 28 +++++++++++++ src/store/contacts.js | 5 +++ src/views/Contacts.vue | 16 +++++++- 7 files changed, 118 insertions(+), 3 deletions(-) create mode 100644 src/components/Properties/PropertyRev.vue diff --git a/css/ContactDetails.scss b/css/ContactDetails.scss index 47464166b..e4b8c8bcf 100644 --- a/css/ContactDetails.scss +++ b/css/ContactDetails.scss @@ -115,4 +115,14 @@ padding: 0 10px; } } +} + +.property--rev { + position: absolute; + right: 22px; + bottom: 0; + height: 44px; + line-height: 44px; + color: var(--color-text-lighter); + opacity: .5; } \ No newline at end of file diff --git a/src/components/ContactDetails.vue b/src/components/ContactDetails.vue index 4e1fdddd6..13d4ee3ae 100644 --- a/src/components/ContactDetails.vue +++ b/src/components/ContactDetails.vue @@ -112,6 +112,9 @@ + + + @@ -129,6 +132,7 @@ import ContactProperty from './ContactDetails/ContactDetailsProperty' import AddNewProp from './ContactDetails/ContactDetailsAddNewProp' import PropertySelect from './Properties/PropertySelect' import PropertyGroups from './Properties/PropertyGroups' +import PropertyRev from './Properties/PropertyRev' import ContactAvatar from './ContactDetails/ContactDetailsAvatar' const updateQueue = new PQueue({ concurrency: 1 }) @@ -140,6 +144,7 @@ export default { ContactProperty, PropertySelect, PropertyGroups, + PropertyRev, AddNewProp, ContactAvatar }, diff --git a/src/components/Properties/PropertyRev.vue b/src/components/Properties/PropertyRev.vue new file mode 100644 index 000000000..03bbff8bc --- /dev/null +++ b/src/components/Properties/PropertyRev.vue @@ -0,0 +1,49 @@ + + + + + diff --git a/src/mixins/PropertyMixin.js b/src/mixins/PropertyMixin.js index 53e7735b2..5092420e6 100644 --- a/src/mixins/PropertyMixin.js +++ b/src/mixins/PropertyMixin.js @@ -20,6 +20,7 @@ * */ import debounce from 'debounce' +import Contact from 'Models/contact' export default { props: { @@ -66,6 +67,10 @@ export default { options: { type: Array, default: () => [] + }, + contact: { + type: Contact, + default: null } }, @@ -94,7 +99,8 @@ export default { watch: { /** * Since we're updating a local data based on the value prop, - * we need to make sure to update the local data on pop change + * we need to make sure to update the local data on contact change + * in case the v-Node is reused. */ value: function() { this.localValue = this.value diff --git a/src/models/contact.js b/src/models/contact.js index d284e7fce..82b418e5d 100644 --- a/src/models/contact.js +++ b/src/models/contact.js @@ -67,6 +67,13 @@ export default class Contact { console.info('This contact did not have a proper uid. Setting a new one for ', this) this.vCard.addPropertyWithValue('uid', uuid()) } + + // if no rev set, init one + if (!this.vCard.hasProperty('rev')) { + const rev = new ICAL.VCardTime() + rev.fromUnixTime(Date.now() / 1000) + this.rev = rev + } } /** @@ -137,6 +144,27 @@ export default class Contact { return true } + /** + * Return the rev + * + * @readonly + * @memberof Contact + */ + get rev() { + return this.vCard.getFirstPropertyValue('rev') + } + + /** + * Set the rev + * + * @param {string} rev the rev to set + * @memberof Contact + */ + set rev(rev) { + this.vCard.updatePropertyWithValue('rev', rev) + return true + } + /** * Return the key * diff --git a/src/store/contacts.js b/src/store/contacts.js index 09b7adefa..1a1c6d153 100644 --- a/src/store/contacts.js +++ b/src/store/contacts.js @@ -289,6 +289,11 @@ const actions = { // Checking contact validity 🙈 validate(contact) + // Update REV + const rev = new ICAL.VCardTime() + rev.fromUnixTime(Date.now() / 1000) + contact.rev = rev + let vData = ICAL.stringify(contact.vCard.jCal) // if no dav key, contact does not exists on server diff --git a/src/views/Contacts.vue b/src/views/Contacts.vue index 19663370d..c908dae3c 100644 --- a/src/views/Contacts.vue +++ b/src/views/Contacts.vue @@ -70,6 +70,7 @@ import { } from 'nextcloud-vue' import moment from 'moment' import download from 'downloadjs' +import { VCardTime } from 'ical.js' import SettingsSection from 'Components/SettingsSection' import ContactsList from 'Components/ContactsList' @@ -265,10 +266,21 @@ export default { methods: { async newContact() { - let contact = new Contact(`BEGIN:VCARD\nVERSION:4.0\nPRODID:-//Nextcloud Contacts v${oca_contacts.versionstring}\nEND:VCARD`, this.defaultAddressbook) - const properties = rfcProps.properties(this) + const rev = new VCardTime() + const contact = new Contact(` + BEGIN:VCARD + VERSION:4.0 + PRODID:-//Nextcloud Contacts v${oca_contacts.versionstring} + END:VCARD + `.trim().replace(/\t/gm, ''), + this.defaultAddressbook) + contact.fullName = t('contacts', 'New contact') + rev.fromUnixTime(Date.now() / 1000) + contact.rev = rev + // itterate over all properties (filter is not usable on objects and we need the key of the property) + const properties = rfcProps.properties(this) for (let name in properties) { if (properties[name].default) { let defaultData = properties[name].defaultValue