Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/conflict #981

Merged
merged 2 commits into from
Mar 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions css/ContactDetails.scss
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@
position: relative;
height: 44px;
width: 44px;
// ! override default server class
> .icon-more-white {
// using #fffffe to trick the accessibility dark theme icon invert
@include icon-color('more', 'actions', '#fffffe', 1, true);
}
}
.header-icon {
height: 44px;
Expand Down
18 changes: 14 additions & 4 deletions css/icons.scss
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,27 @@
@include icon-color('up', 'contacts', $color-black, 1);
}

.icon-up-force-white {
// using #fffffe to trick the accessibility dark theme icon invert
@include icon-color('up', 'contacts', '#fffffe', 1);
}

.icon-history-force-white {
// using #fffffe to trick the accessibility dark theme icon invert
@include icon-color('history', 'actions', '#fffffe', 1, true);
}

.icon-delete-force-white {
// using #fffffe to trick the accessibility dark theme icon invert
@include icon-color('delete', 'contacts', '#fffffe', 1);
@include icon-color('delete', 'actions', '#fffffe', 1, true);
}

.icon-download-force-white {
// using #fffffe to trick the accessibility dark theme icon invert
@include icon-color('download', 'contacts', '#fffffe', 1);
@include icon-color('download', 'actions', '#fffffe', 1, true);
}

.icon-upload-force-white {
// using #fffffe to trick the accessibility dark theme icon invert
@include icon-color('upload', 'contacts', '#fffffe', 1);
}
@include icon-color('upload', 'actions', '#fffffe', 1, true);
}
1 change: 0 additions & 1 deletion img/delete.svg

This file was deleted.

1 change: 0 additions & 1 deletion img/download.svg

This file was deleted.

1 change: 0 additions & 1 deletion img/upload.svg

This file was deleted.

15 changes: 13 additions & 2 deletions src/components/ContactDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
content: conflict,
show: true,
trigger: 'manual',
}" class="header-icon header-icon--pulse icon-history-white"
}" class="header-icon header-icon--pulse icon-history-force-white"
@click="refreshContact" />
<div class="menu-icon">
<div v-click-outside="closeMenu" class="header-icon icon-more-white" @click="toggleMenu" />
Expand Down Expand Up @@ -127,6 +127,7 @@ import debounce from 'debounce'
import PQueue from 'p-queue'

import rfcProps from 'Models/rfcProps'
import validate from 'Services/validate'

import ContactProperty from './ContactDetails/ContactDetailsProperty'
import AddNewProp from './ContactDetails/ContactDetailsAddNewProp'
Expand Down Expand Up @@ -162,6 +163,8 @@ export default {

data() {
return {
// if true, the local contact have been fixed and requires a push
fixed: false,
/**
* Local off-store clone of the selected contact for edition
* because we can't edit contacts data outside the store.
Expand Down Expand Up @@ -368,6 +371,7 @@ export default {
* Send the local clone of contact to the store
*/
async updateContact() {
this.fixed = false
this.loadingUpdate = true
await this.$store.dispatch('updateContact', this.localContact)
this.loadingUpdate = false
Expand Down Expand Up @@ -421,6 +425,9 @@ export default {
Object.create(Object.getPrototypeOf(contact)),
contact
)

this.fixed = validate(localContact)

this.localContact = localContact
this.loadingData = false
} catch (error) {
Expand All @@ -438,10 +445,14 @@ export default {
} else {
// create empty contact and copy inner data
// wait for an update to really push the contact on the server!
this.localContact = Object.assign(
let localContact = Object.assign(
Object.create(Object.getPrototypeOf(contact)),
contact
)

this.fixed = validate(localContact)

this.localContact = localContact
this.loadingData = false
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/Properties/PropertyGroups.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

<script>
import debounce from 'debounce'
import Contact from '../../models/contact'
import Contact from 'Models/contact'

export default {
name: 'PropertyGroups',
Expand Down
4 changes: 2 additions & 2 deletions src/services/parseVcf.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
*
*/

import Contact from '../models/contact'
import Store from '../store/index'
import Contact from 'Models/contact'
import Store from 'Store/index'

export default function parseVcf(data = '', addressbook) {
let regexp = /BEGIN:VCARD[\s\S]*?END:VCARD/mgi
Expand Down
6 changes: 4 additions & 2 deletions src/services/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@
*
*/

import Contact from '../models/contact'
import Contact from 'Models/contact'
import checks from './checks/'

export default function(contact) {
let result = false
if (contact instanceof Contact) {

// Going through every checks
Expand All @@ -37,14 +38,15 @@ export default function(contact) {
console.warn('The following contact needed a correction that failed:', check.name, contact)
} else {
// SUCCESS 💪
result = true
console.info('The following contact has been repaired:', check.name, contact)
}
}
} catch (error) {
console.error('Error during the check:', check.name, contact, error)
}
})

return result
} else {
throw new Error('Invalid contact provided')
}
Expand Down
26 changes: 22 additions & 4 deletions src/store/contacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

import Vue from 'vue'
import ICAL from 'ical.js'
import Contact from '../models/contact'
import validate from '../services/validate'
import Contact from 'Models/contact'
import validate from 'Services/validate'

const state = {
// Using objects for performance
Expand Down Expand Up @@ -232,6 +232,22 @@ const mutations = {
*/
setOrder(state, orderKey = 'displayName') {
state.orderKey = orderKey
},

/**
* Set a contact as `in conflict` with the server data
*
* @param {Object} state the store data
* @param {Object} data destructuring object
* @param {Contact} data.contact the contact to update
* @param {String} data.etag the etag to set
*/
setContactAsConflict(state, { contact, etag }) {
if (state.contacts[contact.key] && contact instanceof Contact) {
state.contacts[contact.key].conflict = etag
} else {
console.error('Error while handling the following contact', contact)
}
}
}

Expand Down Expand Up @@ -314,12 +330,14 @@ const actions = {
// all clear, let's update the store
context.commit('updateContact', contact)
})
.catch((error) => {
.catch(error => {
console.info(error)
// wrong etag, we most likely have a conflict
if (error && error.status === 412) {
// saving the new etag so that the user can manually
// trigger a fetchCompleteData without any further errors
contact.conflict = error.xhr.getResponseHeader('etag')
context.commit('setContactAsConflict', { contact, etag: error.xhr.getResponseHeader('etag') })
console.error('This contact is outdated, the server refused it', contact)
}
})
} else {
Expand Down
6 changes: 4 additions & 2 deletions src/views/Contacts.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<template>
<app-content app-name="contacts" :class="{'icon-loading': loading}">
<!-- new-contact-button + navigation + settings -->
<template slot="navigation">
<app-navigation slot="navigation">
<!-- new-contact-button -->
<app-navigation-new v-if="!loading" button-id="new-contact-button" :text="t('contacts','New contact')"
button-class="icon-add" :disabled="!defaultAddressbook" @click="newContact" />
Expand All @@ -38,7 +38,7 @@
<app-navigation-settings v-if="!loading">
<settings-section />
</app-navigation-settings>
</template>
</app-navigation>

<template slot="content">
<!-- go back to list when in details mode -->
Expand All @@ -64,6 +64,7 @@
<script>
import {
AppContent,
AppNavigation,
AppNavigationItem,
AppNavigationNew,
AppNavigationSettings
Expand All @@ -87,6 +88,7 @@ export default {

components: {
AppContent,
AppNavigation,
AppNavigationItem,
AppNavigationNew,
AppNavigationSettings,
Expand Down
1 change: 1 addition & 0 deletions webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ module.exports = {
Mixins: path.resolve(__dirname, 'src/mixins/'),
Models: path.resolve(__dirname, 'src/models/'),
Services: path.resolve(__dirname, 'src/services/'),
Store: path.resolve(__dirname, 'src/store/'),
Views: path.resolve(__dirname, 'src/views/')
},
extensions: ['*', '.js', '.vue', '.json']
Expand Down