summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorsuntala <suntala@hotmail.com>2018-08-29 14:53:00 +0200
committersuntala <suntala@hotmail.com>2018-08-29 14:53:00 +0200
commitec51d04dc19dc9d63d08c5b3a1368c4f53bf2efa (patch)
tree14547dd48d1243a8d4d83a1bfd75a6baf5ee3470 /src
parent47d39897ba78b4550bcff4c16b15ccbcfe017aa0 (diff)
Import store into parseVcf.
Diffstat (limited to 'src')
-rw-r--r--src/components/ImportScreen.vue2
-rw-r--r--src/components/Settings/SettingsImportContacts.vue5
-rw-r--r--src/services/parseVcf.js9
-rw-r--r--src/store/addressbooks.js18
-rw-r--r--src/store/groups.js1
-rw-r--r--src/store/importState.js6
6 files changed, 30 insertions, 11 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..23a4990c 100644
--- a/src/components/Settings/SettingsImportContacts.vue
+++ b/src/components/Settings/SettingsImportContacts.vue
@@ -88,11 +88,12 @@ export default {
let file = event.target.files[0]
let reader = new FileReader()
let selectedAddressbook = this.selectedAddressbook
- this.$emit('clicked', { importing: true })
+ // 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.$emit('fileLoaded', false)
+ // self.$store.dispatch('changeStage', 'default')
}
reader.readAsText(file)
}
diff --git a/src/services/parseVcf.js b/src/services/parseVcf.js
index 86c02981..e74b083f 100644
--- a/src/services/parseVcf.js
+++ b/src/services/parseVcf.js
@@ -21,17 +21,20 @@
*/
import Contact from '../models/contact'
+import Store from '../store/index'
-export default function parseVcf(data = '', addressbook, importState) {
+export default function parseVcf(data = '', addressbook) {
let regexp = /BEGIN:VCARD[\s\S]*?END:VCARD/mgi
let vCards = data.match(regexp)
-
- importState.total = vCards.length
+ let importState = Store.getters.getImportState
if (!vCards) {
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 de2cb427..1dad9c28 100644
--- a/src/store/addressbooks.js
+++ b/src/store/addressbooks.js
@@ -192,8 +192,8 @@ const actions = {
* @param {Object} context
* @param {Object} importDetails = { vcf, addressbook }
*/
- getContactsFromAddressBook(context, { vcf, addressbook, importState }) {
- let contacts = parseVcf(vcf, addressbook, importState)
+ getContactsFromAddressBook(context, { vcf, addressbook }) {
+ let contacts = parseVcf(vcf, addressbook)
context.commit('appendContactsToAddressbook', { addressbook, contacts })
context.commit('appendContacts', contacts)
context.commit('sortContacts')
@@ -201,6 +201,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 e22af9af..4e387ab6 100644
--- a/src/store/importState.js
+++ b/src/store/importState.js
@@ -25,7 +25,7 @@ const state = {
total: 0,
accepted: 0,
denied: 0,
- stage: 'Default',
+ stage: 'default',
addressbook: ''
}
}
@@ -73,7 +73,7 @@ const mutations = {
* Change stage to the indicated one
*
* @param {Object} state
- * @param {String} stage the name of the stage ('Default', 'Importing', 'Parsing')
+ * @param {String} stage the name of the stage ('default', 'importing', 'parsing')
*/
changeStage(state, stage) {
state.importState.stage = stage
@@ -127,7 +127,7 @@ const actions = {
* Change stage to the indicated one
*
* @param {Object} context
- * @param {String} stage the name of the stage ('Default', 'Importing', 'Parsing')
+ * @param {String} stage the name of the stage ('default', 'importing', 'parsing')
*/
changeStage(context, stage) {
context.commit('changeStage', stage)