Skip to content

Commit

Permalink
Add REV on update
Browse files Browse the repository at this point in the history
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
  • Loading branch information
skjnldsv committed Mar 4, 2019
1 parent bdd9383 commit df81372
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 3 deletions.
10 changes: 10 additions & 0 deletions css/ContactDetails.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
5 changes: 5 additions & 0 deletions src/components/ContactDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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 })
Expand All @@ -140,6 +144,7 @@ export default {
ContactProperty,
PropertySelect,
PropertyGroups,
PropertyRev,
AddNewProp,
ContactAvatar
},
Expand Down
49 changes: 49 additions & 0 deletions src/components/Properties/PropertyRev.vue
Original file line number Diff line number Diff line change
@@ -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: 'PropertyTitle',

props: {
value: {
type: VCardTime,
required: true,
default: null
}
},

computed: {
relativeDate() {
return OC.Util.relativeModifiedDate(this.value.toUnixTime() * 1000)
}
}
}
</script>
8 changes: 7 additions & 1 deletion src/mixins/PropertyMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*
*/
import debounce from 'debounce'
import Contact from 'Models/contact'

export default {
props: {
Expand Down Expand Up @@ -66,6 +67,10 @@ export default {
options: {
type: Array,
default: () => []
},
contact: {
type: Contact,
default: null
}
},

Expand Down Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions src/models/contact.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

/**
Expand Down Expand Up @@ -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
*
Expand Down
5 changes: 5 additions & 0 deletions src/store/contacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 14 additions & 2 deletions src/views/Contacts.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit df81372

Please sign in to comment.