summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/components/ImportScreen.vue2
-rw-r--r--src/components/Settings/SettingsImportContacts.vue9
-rw-r--r--src/services/cdav.js44
-rw-r--r--src/services/parseVcf.js5
-rw-r--r--src/store/addressbooks.js39
-rw-r--r--src/store/groups.js1
-rw-r--r--src/store/importState.js106
-rw-r--r--src/views/Contacts.vue30
8 files changed, 188 insertions, 48 deletions
diff --git a/src/components/ImportScreen.vue b/src/components/ImportScreen.vue
index e0f3f827..c55816d5 100644
--- a/src/components/ImportScreen.vue
+++ b/src/components/ImportScreen.vue
@@ -21,7 +21,7 @@
-->
<template>
- <div class="emptycontent import-screen">
+ <div v-if="importState.stage != 'default'" class="emptycontent import-screen">
<p class="icon-upload" />
<h3 class="import-screen__header">{{ t('contacts', 'Importing into') }} {{ addressbook }}</h3>
<progress :max="importState.total" :value="importState.accepted" class="import-screen__progress" />
diff --git a/src/components/Settings/SettingsImportContacts.vue b/src/components/Settings/SettingsImportContacts.vue
index 53cf2f01..80f418f7 100644
--- a/src/components/Settings/SettingsImportContacts.vue
+++ b/src/components/Settings/SettingsImportContacts.vue
@@ -88,11 +88,20 @@ export default {
let file = event.target.files[0]
let reader = new FileReader()
let selectedAddressbook = this.selectedAddressbook
+<<<<<<< HEAD
+ // this.$store.dispatch('changeStage', 'parsing')
+ let self = this
+ reader.onload = function(e) {
+ // self.$store.dispatch('changeStage', 'importing')
+ self.$store.dispatch('getContactsFromAddressBook', { vcf: reader.result, addressbook: selectedAddressbook, importState: this.importState })
+ // self.$store.dispatch('changeStage', 'default')
+=======
this.$emit('clicked', { importing: true })
let self = this
reader.onload = function(e) {
self.$store.dispatch('getContactsFromAddressBook', { vcf: reader.result, addressbook: selectedAddressbook, importState: this.importState })
self.$emit('fileLoaded', false)
+>>>>>>> 699af87659b724df00df77da2c9b66ec9013c2d6
}
reader.readAsText(file)
}
diff --git a/src/services/cdav.js b/src/services/cdav.js
index baecc096..043444fd 100644
--- a/src/services/cdav.js
+++ b/src/services/cdav.js
@@ -20,28 +20,28 @@
*
*/
-import cdav from 'cdav-library'
+// import cdav from 'cdav-library'
-function xhrProvider() {
- var headers = {
- 'X-Requested-With': 'XMLHttpRequest',
- 'requesttoken': OC.requestToken
- }
- var xhr = new XMLHttpRequest()
- var oldOpen = xhr.open
+// function xhrProvider() {
+// var headers = {
+// 'X-Requested-With': 'XMLHttpRequest',
+// 'requesttoken': OC.requestToken
+// }
+// var xhr = new XMLHttpRequest()
+// var oldOpen = xhr.open
- // override open() method to add headers
- xhr.open = function() {
- var result = oldOpen.apply(this, arguments)
- for (let name in headers) {
- xhr.setRequestHeader(name, headers[name])
- }
- return result
- }
- OC.registerXHRForErrorProcessing(xhr)
- return xhr
-}
+// // override open() method to add headers
+// xhr.open = function() {
+// var result = oldOpen.apply(this, arguments)
+// for (let name in headers) {
+// xhr.setRequestHeader(name, headers[name])
+// }
+// return result
+// }
+// OC.registerXHRForErrorProcessing(xhr)
+// return xhr
+// }
-export default new cdav.DavClient({
- rootUrl: OC.linkToRemote('dav')
-}, xhrProvider)
+// export default new cdav.DavClient({
+// rootUrl: OC.linkToRemote('dav')
+// }, xhrProvider)
diff --git a/src/services/parseVcf.js b/src/services/parseVcf.js
index 86c02981..66aca511 100644
--- a/src/services/parseVcf.js
+++ b/src/services/parseVcf.js
@@ -21,10 +21,12 @@
*/
import Contact from '../models/contact'
+import Store from '../store/index'
export default function parseVcf(data = '', addressbook, importState) {
let regexp = /BEGIN:VCARD[\s\S]*?END:VCARD/mgi
let vCards = data.match(regexp)
+ let importState = Store.getters.getImportState
importState.total = vCards.length
@@ -32,6 +34,9 @@ export default function parseVcf(data = '', addressbook, importState) {
console.debug('Error during the parsing of the following vcf file: ', data)
return []
}
+
+ importState.total = vCards.length
+
return vCards.map(vCard => {
try {
// console.log(vCards.indexOf(vCard))
diff --git a/src/store/addressbooks.js b/src/store/addressbooks.js
index f92568d8..062351c0 100644
--- a/src/store/addressbooks.js
+++ b/src/store/addressbooks.js
@@ -24,7 +24,7 @@
import parseVcf from '../services/parseVcf'
import Vue from 'vue'
-import client from '../services/cdav'
+// import client from '../services/cdav'
const addressbookModel = {
id: '',
@@ -168,15 +168,15 @@ const actions = {
* @returns {Promise} fetch and commit
*/
async getAddressbooks(context) {
- let addressbooks = client.addressbookHomes.map(addressbook => {
- return {
- id: 'ab1',
- displayName: 'Addressbook 1',
- enabled: true,
- owner: 'admin',
- dav: addressbook
- }
- })
+ // let addressbooks = client.addressbookHomes.map(addressbook => {
+ let addressbooks = [{
+ id: 'ab1',
+ displayName: 'Addressbook 1',
+ enabled: true,
+ owner: 'admin'
+ // dav: addressbook
+ }]
+ // })
addressbooks.forEach(addressbook => {
context.commit('addAddressbooks', addressbook)
@@ -192,8 +192,13 @@ const actions = {
* @param {Object} context
* @param {Object} importDetails = { vcf, addressbook }
*/
+<<<<<<< HEAD
+ getContactsFromAddressBook(context, { vcf, addressbook }) {
+ let contacts = parseVcf(vcf, addressbook)
+=======
getContactsFromAddressBook(context, { vcf, addressbook, importState }) {
let contacts = parseVcf(vcf, addressbook, importState)
+>>>>>>> 699af87659b724df00df77da2c9b66ec9013c2d6
context.commit('appendContactsToAddressbook', { addressbook, contacts })
context.commit('appendContacts', contacts)
context.commit('sortContacts')
@@ -201,6 +206,20 @@ const actions = {
},
/**
+ *
+ * @param {Object} context
+ * @param {Object} importDetails = { vcf, addressbook }
+ */
+ importContactsIntoAddressbook(context, { vcf, addressbook }) {
+ let contacts = parseVcf(vcf, addressbook)
+ contacts.forEach(contact => {
+ context.commit('addContact', contact)
+ context.commit('addContactToAddressbook', contact)
+ context.commit('appendGroupsFromContacts', [contact])
+ })
+ },
+
+ /**
* Remove sharee from Addressbook
* @param {Object} context Current context
* @param {Object} sharee Addressbook sharee object
diff --git a/src/store/groups.js b/src/store/groups.js
index ca261603..9c3061be 100644
--- a/src/store/groups.js
+++ b/src/store/groups.js
@@ -30,6 +30,7 @@ const mutations = {
*
* @param {Object} state
* @param {Contact[]} contacts
+ * TODO: create single contact mutation
*/
appendGroupsFromContacts(state, contacts) {
// init groups list
diff --git a/src/store/importState.js b/src/store/importState.js
index e0f0b52e..4b85085c 100644
--- a/src/store/importState.js
+++ b/src/store/importState.js
@@ -24,11 +24,67 @@ const state = {
importState: {
total: 0,
accepted: 0,
+<<<<<<< HEAD
+ denied: 0,
+ stage: 'default',
+ addressbook: ''
+=======
denied: 0
+>>>>>>> 699af87659b724df00df77da2c9b66ec9013c2d6
}
}
const mutations = {
+<<<<<<< HEAD
+ /**
+ * Increment the number of contacts accepted
+ *
+ * @param {Object} state
+ */
+ incrementAccepted(state) {
+ state.importState.accepted++
+ },
+
+ /**
+ * Increment the number of contacts denied
+ *
+ * @param {Object} state
+ */
+ incrementDenied(state) {
+ state.importState.denied++
+ },
+
+ /**
+ * Set the total number of contacts
+ *
+ * @param {Object} state
+ * @param {String} total the total number of contacts to import
+ */
+ setTotal(state, total) {
+ state.importState.total = total
+ },
+
+ /**
+ * Set the address book name
+ *
+ * @param {Object} state
+ * @param {String} addressbook the name of the address book to import into
+ */
+ setAddressbook(state, addressbook) {
+ state.importState.addressbook = addressbook
+ },
+
+ /**
+ * Change stage to the indicated one
+ *
+ * @param {Object} state
+ * @param {String} stage the name of the stage ('default', 'importing', 'parsing')
+ */
+ changeStage(state, stage) {
+ state.importState.stage = stage
+ }
+=======
+>>>>>>> 699af87659b724df00df77da2c9b66ec9013c2d6
}
const getters = {
@@ -36,6 +92,56 @@ const getters = {
}
const actions = {
+<<<<<<< HEAD
+ /**
+ * Increment the number of contacts accepted
+ *
+ * @param {Object} context
+ */
+ incrementAccepted(context) {
+ context.commit('incrementAccepted')
+ },
+
+ /**
+ * Increment the number of contacts denied
+ *
+ * @param {Object} context
+ */
+ incrementDenied(context) {
+ context.commit('incrementDenied')
+ },
+
+ /**
+ * Set the total number of contacts
+ *
+ * @param {Object} context
+ * @param {String} total the total number of contacts to import
+ */
+ setTotal(context, total) {
+ context.commit('setTotal', total)
+ },
+
+ /**
+ * Set the address book name
+ *
+ * @param {Object} context
+ * @param {String} addressbook the name of the address book to import into
+ */
+ setAddressbook(context, addressbook) {
+ context.commit('setAddressbook', addressbook)
+ },
+
+ /**
+ * Change stage to the indicated one
+ *
+ * @param {Object} context
+ * @param {String} stage the name of the stage ('default', 'importing', 'parsing')
+ */
+ changeStage(context, stage) {
+ context.commit('changeStage', stage)
+ }
+=======
+>>>>>>> 699af87659b724df00df77da2c9b66ec9013c2d6
}
export default { state, mutations, getters, actions }
diff --git a/src/views/Contacts.vue b/src/views/Contacts.vue
index deeafa00..57c99675 100644
--- a/src/views/Contacts.vue
+++ b/src/views/Contacts.vue
@@ -54,7 +54,7 @@ import importScreen from '../components/ImportScreen'
import Contact from '../models/contact'
import rfcProps from '../models/rfcProps.js'
-import client from '../services/cdav.js'
+// import client from '../services/cdav.js'
export default {
components: {
@@ -187,22 +187,22 @@ export default {
beforeMount() {
// get addressbooks then get contacts
- client.connect({ enableCardDAV: true }).then(() => {
- this.$store.dispatch('getAddressbooks')
- .then(() => {
- Promise.all(this.addressbooks.map(async addressbook => {
- await this.$store.dispatch('getContactsFromAddressBook', addressbook)
- })).then(() => {
- this.loading = false
- this.selectFirstContactIfNone()
- })
+ // client.connect({ enableCardDAV: true }).then(() => {
+ this.$store.dispatch('getAddressbooks')
+ .then(() => {
+ Promise.all(this.addressbooks.map(async addressbook => {
+ await this.$store.dispatch('getContactsFromAddressBook', addressbook)
+ })).then(() => {
+ this.loading = false
+ this.selectFirstContactIfNone()
})
+ })
// check local storage for orderKey
- if (localStorage.getItem('orderKey')) {
- // run setOrder mutation with local storage key
- this.$store.commit('setOrder', localStorage.getItem('orderKey'))
- }
- })
+ if (localStorage.getItem('orderKey')) {
+ // run setOrder mutation with local storage key
+ this.$store.commit('setOrder', localStorage.getItem('orderKey'))
+ }
+ // })
},
methods: {