From 4f197293844a5569688dd8d510a1f5c23fb215e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6=20=28skjnldsv=29?= Date: Tue, 28 Aug 2018 18:27:58 +0200 Subject: Import progress work by @suntala MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- src/components/ImportScreen.vue | 42 +++++++++++++++ src/components/Settings/SettingsImportContacts.vue | 62 ++++++++++++++++++---- src/components/SettingsSection.vue | 27 +++++++++- src/services/parseVcf.js | 14 +++-- src/store/addressbooks.js | 9 ++-- src/store/contacts.js | 1 - src/store/importState.js | 41 ++++++++++++++ src/store/index.js | 4 +- src/views/Contacts.vue | 3 ++ 9 files changed, 180 insertions(+), 23 deletions(-) create mode 100644 src/components/ImportScreen.vue create mode 100644 src/store/importState.js (limited to 'src') diff --git a/src/components/ImportScreen.vue b/src/components/ImportScreen.vue new file mode 100644 index 00000000..e0f3f827 --- /dev/null +++ b/src/components/ImportScreen.vue @@ -0,0 +1,42 @@ + + + + + diff --git a/src/components/Settings/SettingsImportContacts.vue b/src/components/Settings/SettingsImportContacts.vue index c67fdb63..608f054d 100644 --- a/src/components/Settings/SettingsImportContacts.vue +++ b/src/components/Settings/SettingsImportContacts.vue @@ -19,17 +19,20 @@ - along with this program. If not, see . - --> +// ☞ 5bfb0d3f-5288-48ce-9dc1-94c2b08cf3ca @@ -47,26 +50,65 @@ export default { directives: { clickOutside }, - // props: ['addressbooks'], props: { - addressbooks: { - type: Array, - required: false, - default: undefined + importState: { + type: Object, + default: () => { + return { + total: 0, + accepted: 0, + denied: 0 + } + } } }, data() { return { - value: '' + importDestination: '' } }, computed: { + addressbooks() { + return this.$store.getters.getAddressbooks + }, options() { - return [t('contacts', 'Contacts')].concat(this.addressbooks.map(x => x.displayName)) + return this.addressbooks.map(addressbook => { + return { + id: addressbook.id, + displayName: addressbook.displayName + } + }) + }, + importState() { + return this.$store.getters.getImportState + }, + selectedAddressbook: { + get() { + if (this.importDestination) { + return this.addressbooks.find(addressbook => addressbook.id === this.importDestination.id) + } + // default is first address book of the list + return this.addressbooks[0] + }, + set(value) { + this.importDestination = value + } } }, methods: { - + processFile(event) { + let file = event.target.files[0] + let reader = new FileReader() + let selectedAddressbook = this.selectedAddressbook + 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) + } + reader.readAsText(file) + } } } +// ☞ f34b2e1a-1610-4a5f-bdbf-9a83325796fe diff --git a/src/components/SettingsSection.vue b/src/components/SettingsSection.vue index f5a8968a..14f9e150 100644 --- a/src/components/SettingsSection.vue +++ b/src/components/SettingsSection.vue @@ -26,8 +26,8 @@ - - + @@ -46,10 +46,33 @@ export default { importContacts, sortContacts }, + props: { + importState: { + type: Object, + default: () => { + return { + total: 0, + accepted: 0, + denied: 0 + } + } + } + }, computed: { // store getters addressbooks() { return this.$store.getters.getAddressbooks + }, + importState() { + return this.$store.getters.getImportState + } + }, + methods: { + onClickImport(event) { + this.$emit('clicked', event) + }, + onLoad(event) { + this.$emit('fileLoaded', false) } } } diff --git a/src/services/parseVcf.js b/src/services/parseVcf.js index 2a2039d5..86c02981 100644 --- a/src/services/parseVcf.js +++ b/src/services/parseVcf.js @@ -1,7 +1,7 @@ /** - * @copyright Copyright (c) 2018 John Molakvoæ + * @copyright Copyright (c) 2018 Team Popcorn * - * @author John Molakvoæ + * @author Team Popcorn * * @license GNU AGPL version 3 or any later version * @@ -22,19 +22,25 @@ import Contact from '../models/contact' -export default function parseVcf(data = '', addressbook) { +export default function parseVcf(data = '', addressbook, importState) { let regexp = /BEGIN:VCARD[\s\S]*?END:VCARD/mgi let vCards = data.match(regexp) + importState.total = vCards.length + if (!vCards) { console.debug('Error during the parsing of the following vcf file: ', data) return [] } return vCards.map(vCard => { try { - return new Contact(vCard, addressbook) + // console.log(vCards.indexOf(vCard)) + let contact = new Contact(vCard, addressbook) + importState.accepted++ + return contact } catch (e) { // Parse error! Do not stop here... + importState.denied++ // eslint-disable-next-line console.error(e) } diff --git a/src/store/addressbooks.js b/src/store/addressbooks.js index bb1858f2..f92568d8 100644 --- a/src/store/addressbooks.js +++ b/src/store/addressbooks.js @@ -21,7 +21,6 @@ */ /* eslint-disable-next-line import/no-webpack-loader-syntax */ -import vcfFile from '!raw-loader!./FakeName.vcf' import parseVcf from '../services/parseVcf' import Vue from 'vue' @@ -187,14 +186,14 @@ const actions = { }, /** - * Retrieve the contacts of the specified addressbook + * Retrieve the contacts for the specified address book * and commit the results * * @param {Object} context - * @param {Object} addressbook + * @param {Object} importDetails = { vcf, addressbook } */ - async getContactsFromAddressBook(context, addressbook) { - let contacts = parseVcf(vcfFile, addressbook) + getContactsFromAddressBook(context, { vcf, addressbook, importState }) { + let contacts = parseVcf(vcf, addressbook, importState) context.commit('appendContactsToAddressbook', { addressbook, contacts }) context.commit('appendContacts', contacts) context.commit('sortContacts') diff --git a/src/store/contacts.js b/src/store/contacts.js index 9554766a..1b42d049 100644 --- a/src/store/contacts.js +++ b/src/store/contacts.js @@ -178,7 +178,6 @@ const mutations = { setOrder(state, orderKey = 'displayName') { state.orderKey = orderKey } - } const getters = { diff --git a/src/store/importState.js b/src/store/importState.js new file mode 100644 index 00000000..e0f0b52e --- /dev/null +++ b/src/store/importState.js @@ -0,0 +1,41 @@ +/** + * @copyright Copyright (c) 2018 Team Popcorn + * + * @author Team Popcorn + * + * @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 . + * + */ + +const state = { + importState: { + total: 0, + accepted: 0, + denied: 0 + } +} + +const mutations = { +} + +const getters = { + getImportState: state => state.importState +} + +const actions = { +} + +export default { state, mutations, getters, actions } diff --git a/src/store/index.js b/src/store/index.js index 94ecf0f4..8bd7c2c0 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -25,6 +25,7 @@ import Vuex from 'vuex' import addressbooks from './addressbooks' import contacts from './contacts' import groups from './groups' +import importState from './importState' Vue.use(Vuex) @@ -34,7 +35,8 @@ export default new Vuex.Store({ modules: { addressbooks, contacts, - groups + groups, + importState }, mutations diff --git a/src/views/Contacts.vue b/src/views/Contacts.vue index 5eaef100..de02006b 100644 --- a/src/views/Contacts.vue +++ b/src/views/Contacts.vue @@ -32,6 +32,8 @@
+ + @@ -47,6 +49,7 @@ import appNavigation from '../components/core/appNavigation' import settingsSection from '../components/SettingsSection' import contentList from '../components/ContentList' import contactDetails from '../components/ContactDetails' +import importScreen from '../components/ImportScreen' import Contact from '../models/contact' import rfcProps from '../models/rfcProps.js' -- cgit v1.2.3 From 699af87659b724df00df77da2c9b66ec9013c2d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6=20=28skjnldsv=29?= Date: Tue, 28 Aug 2018 18:37:16 +0200 Subject: Rebase and compile fixes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- src/components/Settings/SettingsImportContacts.vue | 15 +-------------- src/components/SettingsSection.vue | 17 +---------------- src/views/Contacts.vue | 3 ++- 3 files changed, 4 insertions(+), 31 deletions(-) (limited to 'src') diff --git a/src/components/Settings/SettingsImportContacts.vue b/src/components/Settings/SettingsImportContacts.vue index 608f054d..53cf2f01 100644 --- a/src/components/Settings/SettingsImportContacts.vue +++ b/src/components/Settings/SettingsImportContacts.vue @@ -1,3 +1,4 @@ + -// ☞ 5bfb0d3f-5288-48ce-9dc1-94c2b08cf3ca