diff options
author | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2019-03-04 09:55:40 +0100 |
---|---|---|
committer | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2019-03-04 10:53:36 +0100 |
commit | a207d5e2be8091ca9c93b450fdaa07c6ad5a78eb (patch) | |
tree | a9ee8d476dfc44fe9b86f0ee8aa124e121b22671 | |
parent | bdd93836aa0613e5f9c61f2496505e4c45f1febc (diff) |
Add REV on update
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
-rw-r--r-- | css/ContactDetails.scss | 10 | ||||
-rw-r--r-- | src/components/ContactDetails.vue | 5 | ||||
-rw-r--r-- | src/components/Properties/PropertyRev.vue | 49 | ||||
-rw-r--r-- | src/mixins/PropertyMixin.js | 8 | ||||
-rw-r--r-- | src/models/contact.js | 28 | ||||
-rw-r--r-- | src/store/contacts.js | 5 | ||||
-rw-r--r-- | src/views/Contacts.vue | 16 |
7 files changed, 118 insertions, 3 deletions
diff --git a/css/ContactDetails.scss b/css/ContactDetails.scss index 47464166..e4b8c8bc 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 4e1fdddd..13d4ee3a 100644 --- a/src/components/ContactDetails.vue +++ b/src/components/ContactDetails.vue @@ -112,6 +112,9 @@ <property-groups :prop-model="groupsModel" :value.sync="groups" :contact="contact" :is-read-only="isReadOnly" class="property--groups property--last" /> + <!-- Last modified--> + <property-rev v-if="contact.rev" :value="contact.rev" /> + <!-- new property select --> <add-new-prop v-if="!isReadOnly" :contact="contact" /> </section> @@ -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 00000000..03bbff8b --- /dev/null +++ b/src/components/Properties/PropertyRev.vue @@ -0,0 +1,49 @@ +<!-- + - @copyright Copyright (c) 2019 John Molakvoæ <skjnldsv@protonmail.com> + - + - @author John Molakvoæ <skjnldsv@protonmail.com> + - + - @license GNU AGPL version 3 or any later version + - + - This program is free software: you can redistribute it and/or modify + - it under the terms of the GNU Affero General Public License as + - published by the Free Software Foundation, either version 3 of the + - License, or (at your option) any later version. + - + - This program is distributed in the hope that it will be useful, + - but WITHOUT ANY WARRANTY; without even the implied warranty of + - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + - GNU Affero General Public License for more details. + - + - You should have received a copy of the GNU Affero General Public License + - along with this program. If not, see <http://www.gnu.org/licenses/>. + - + --> + +<template> + <div class="property--rev"> + {{ t('contacts', 'Last modified') }} {{ relativeDate }} + </div> +</template> + +<script> +import { VCardTime } from 'ical.js' + +export default { + name: 'PropertyRev', + + props: { + value: { + type: VCardTime, + required: true, + default: null + } + }, + + computed: { + relativeDate() { + return OC.Util.relativeModifiedDate(this.value.toUnixTime() * 1000) + } + } +} +</script> diff --git a/src/mixins/PropertyMixin.js b/src/mixins/PropertyMixin.js index 53e7735b..5092420e 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 d284e7fc..82b418e5 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 + } } /** @@ -138,6 +145,27 @@ export default class Contact { } /** + * 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 * * @readonly diff --git a/src/store/contacts.js b/src/store/contacts.js index 09b7adef..1a1c6d15 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 19663370..c908dae3 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 |