summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJessica <jessica@Absolventas-MacBook-Pro.local>2018-08-13 18:08:27 +0200
committerJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2018-08-28 15:20:58 +0200
commitff5b6384b6cd8a25d304da30dbccc1da8f550ba0 (patch)
treefff8f79ce9cb37deb19f4b9e537bf34aa9634b3d /src
parent354569c484ad211b672e811bd53742ccd148ed6a (diff)
working version of shareAdressbook, adds sharees to addressbook object
Diffstat (limited to 'src')
-rw-r--r--src/components/Settings/SettingsAddressbookShare.vue51
-rw-r--r--src/components/Settings/SettingsAddressbookShare.vue.orig197
-rw-r--r--src/components/Settings/SettingsAddressbookSharee.vue1
-rw-r--r--src/components/Settings/SettingsSortContacts.vue4
-rw-r--r--src/store/addressbooks.js22
-rw-r--r--src/store/addressbooks.js.orig248
6 files changed, 485 insertions, 38 deletions
diff --git a/src/components/Settings/SettingsAddressbookShare.vue b/src/components/Settings/SettingsAddressbookShare.vue
index 88667bf5..3e924789 100644
--- a/src/components/Settings/SettingsAddressbookShare.vue
+++ b/src/components/Settings/SettingsAddressbookShare.vue
@@ -24,33 +24,32 @@
<div class="addressbook__shares">
<multiselect
id="users-groups-search"
- v-model="selectedUserOrGroup"
:options="usersOrGroups"
:searchable="true"
:loading="isLoading"
:internal-search="false"
- :clear-on-select="false"
- :close-on-select="false"
:options-limit="250"
:limit="3"
:max-height="600"
:show-no-results="false"
:placeholder="placeholder"
+ track-by="match"
+ label="match"
open-direction="bottom"
class="multiselect-vue"
- @search-change="asyncFind">
+ @search-change="asyncFind"
+ @input="addSharee">
+ <template slot="singleLabel" slot-scope="props"><span class="option__desc"><span class="option__title">{{ props.option.matchpattern }}</span></span></template>
<template slot="option" slot-scope="props">
- <span class="">{{ props.option.matchstart }}</span><span class="" style="font-weight: bold;">{{ props.option.matchpattern }}</span><span class="">{{ props.option.matchend }}{{ props.option.matchtag }}</span>
- </template>
- <template slot="clear" slot-scope="props">
- <div v-if="selectedUserOrGroup.length" class="multiselect__clear" @mousedown.prevent.stop="clearAll(props.search)" />
+ <div class="option__desc">
+ <span class="">{{ props.option.matchstart }}</span><span class="" style="font-weight: bold;">{{ props.option.matchpattern }}</span><span class="">{{ props.option.matchend }} {{ props.option.matchtag }}</span>
+ </div>
</template>
<span slot="noResult">{{ noResult }} </span>
</multiselect>
- <!-- <pre class="language-json"><code>{{ selectedUserOrGroup }}</code></pre> -->
<!-- list of user or groups addressbook is shared with -->
<ul v-if="addressbook.shares.length > 0" class="addressbook__shares__list">
- <address-book-sharee v-for="sharee in addressbook.shares" :key="sharee.name" :sharee="sharee" />
+ <address-book-sharee v-for="sharee in addressbook.shares" :key="sharee.displayname" :sharee="sharee" />
</ul>
</div>
</template>
@@ -84,9 +83,7 @@ export default {
data() {
return {
isLoading: false,
- usersOrGroups: [],
- selectedUserOrGroup: [],
- templateSharee: { displayname: '', writeable: false }
+ usersOrGroups: []
}
},
computed: {
@@ -98,25 +95,25 @@ export default {
}
},
methods: {
- addSharee(sharee) {
- let newSharee = {}
- Object.assign({}, this.templateSharee, newSharee)
- // not working yet need to work on!
- this.$store.dispatch('shareAddressbook', newSharee)
+ addSharee(chosenUserOrGroup) {
+ let payload = []
+ payload.push(this.addressbook)
+ payload.push(chosenUserOrGroup.match)
+ this.$store.dispatch('shareAddressbook', payload)
},
formatMatchResults(matches, query, matchTag) {
// format response from axios.all and add them to the option array
- /*
- * Case issue for query, matchpattern should reflect case in match not the query
- */
-
+ if (matches.length < 1) {
+ return
+ }
for (let i = 0; i < matches.length; i++) {
let regex = new RegExp(query, 'i')
let matchResult = matches[i].split(regex)
let newMatch = {
+ match: matches[i] + ' ' + matchTag,
matchstart: matchResult[0],
- matchpattern: query,
+ matchpattern: matches[i].match(regex)[0],
matchend: matchResult[1],
matchtag: matchTag
}
@@ -135,12 +132,12 @@ export default {
let matchingUsers = response[0].data.ocs.data.users
let matchingGroups = response[1].data.ocs.data.groups
try {
- this.formatMatchResults(matchingUsers, query, ' (user)')
+ this.formatMatchResults(matchingUsers, query, '(user)')
} catch (error) {
console.debug(error)
}
try {
- this.formatMatchResults(matchingGroups, query, ' (group)')
+ this.formatMatchResults(matchingGroups, query, '(group)')
} catch (error) {
console.debug(error)
}
@@ -149,10 +146,6 @@ export default {
this.isLoading = false
})
}
- },
-
- clearAll() {
- this.selectedUserOrGroup = []
}
}
}
diff --git a/src/components/Settings/SettingsAddressbookShare.vue.orig b/src/components/Settings/SettingsAddressbookShare.vue.orig
new file mode 100644
index 00000000..b9d1937a
--- /dev/null
+++ b/src/components/Settings/SettingsAddressbookShare.vue.orig
@@ -0,0 +1,197 @@
+<!--
+ - @copyright Copyright (c) 2018 Team Popcorn <teampopcornberlin@gmail.com>
+ -
+ - @author Team Popcorn <teampopcornberlin@gmail.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="addressbook__shares">
+ <multiselect
+ id="users-groups-search"
+ v-model="selectedUserOrGroup"
+ :options="usersOrGroups"
+<<<<<<< HEAD
+=======
+ :multiple="true"
+>>>>>>> refractored api call in share addressbook to use axios all
+ :searchable="true"
+ :loading="isLoading"
+ :internal-search="false"
+ :clear-on-select="false"
+ :close-on-select="false"
+ :options-limit="250"
+ :limit="3"
+ :max-height="600"
+ :show-no-results="false"
+<<<<<<< HEAD
+ :placeholder="placeholder"
+ open-direction="bottom"
+ class="multiselect-vue"
+ @search-change="asyncFind">
+ <template slot="option" slot-scope="props">
+ <span class="">{{ props.option.matchstart }}</span><span class="" style="font-weight: bold;">{{ props.option.matchpattern }}</span><span class="">{{ props.option.matchend }}{{ props.option.matchtag }}</span>
+=======
+ :hide-selected="true"
+ :placeholder="placeholder"
+ open-direction="bottom"
+ @search-change="asyncFind">
+ <template slot="option" slot-scope="props">
+ <span class="">{{ props.option.matchstart }}</span><span class="" style="font-weight: bold;">{{ props.option.matchpattern }}</span><span class="">{{ props.option.matchend }} {{ props.option.matchtag }}</span>
+>>>>>>> refractored api call in share addressbook to use axios all
+ </template>
+ <template slot="clear" slot-scope="props">
+ <div v-if="selectedUserOrGroup.length" class="multiselect__clear" @mousedown.prevent.stop="clearAll(props.search)" />
+ </template>
+ <span slot="noResult">{{ noResult }} </span>
+ </multiselect>
+ <!-- <pre class="language-json"><code>{{ selectedUserOrGroup }}</code></pre> -->
+ <!-- list of user or groups addressbook is shared with -->
+ <ul v-if="addressbook.shares.length > 0" class="addressbook__shares__list">
+ <address-book-sharee v-for="sharee in addressbook.shares" :key="sharee.name" :sharee="sharee" />
+ </ul>
+ </div>
+</template>
+
+<script>
+import Multiselect from 'vue-multiselect'
+import addressBookSharee from './SettingsAddressbookSharee'
+
+import clickOutside from 'vue-click-outside'
+import api from '../../services/api'
+
+import clickOutside from 'vue-click-outside'
+import api from '../../services/api'
+
+export default {
+ name: 'SettingsShareAddressBook',
+ components: {
+ clickOutside,
+ Multiselect,
+ addressBookSharee
+ },
+ directives: {
+ clickOutside
+ },
+ props: {
+ addressbook: {
+ type: Object,
+ default() {
+ return {}
+ }
+ }
+ },
+ data() {
+ return {
+ isLoading: false,
+ usersOrGroups: [],
+ selectedUserOrGroup: [],
+ templateSharee: { displayname: '', writeable: false }
+ }
+ },
+ computed: {
+ placeholder() {
+ return t('contacts', 'Share with users or groups')
+ },
+ noResult() {
+ return t('contacts', 'Oops! No elements found. Consider changing the search query.')
+ }
+ },
+ methods: {
+ addSharee(sharee) {
+ let newSharee = {}
+ Object.assign({}, this.templateSharee, newSharee)
+ // not working yet need to work on!
+ this.$store.dispatch('shareAddressbook', newSharee)
+ },
+
+<<<<<<< HEAD
+ formatMatchResults(matches, query, matchTag) {
+ // format response from axios.all and add them to the option array
+ /*
+ * Case issue for query, matchpattern should reflect case in match not the query
+ */
+
+=======
+ processMatchResults(matches, query, matchTag) {
+>>>>>>> refractored api call in share addressbook to use axios all
+ for (let i = 0; i < matches.length; i++) {
+ let regex = new RegExp(query, 'i')
+ let matchResult = matches[i].split(regex)
+ let newMatch = {
+ matchstart: matchResult[0],
+ matchpattern: query,
+ matchend: matchResult[1],
+ matchtag: matchTag
+ }
+ this.usersOrGroups.push(newMatch)
+ }
+ },
+
+ asyncFind(query) {
+ this.isLoading = true
+ this.usersOrGroups = []
+ if (query.length > 0) {
+<<<<<<< HEAD
+ api.all([
+ api.get(OC.linkToOCS('cloud', 2) + 'users?search=' + query),
+ api.get(OC.linkToOCS('cloud', 2) + 'groups?search=' + query)
+ ]).then(response => {
+ let matchingUsers = response[0].data.ocs.data.users
+ let matchingGroups = response[1].data.ocs.data.groups
+ try {
+ this.formatMatchResults(matchingUsers, query, ' (user)')
+=======
+ /*
+ * Case issue for query, matchpattern should reflect case in match not the query
+ */
+
+ api.all([api.get(OC.linkToOCS('cloud', 2) + 'users?search=' + query), api.get(OC.linkToOCS('cloud', 2) + 'groups?search=' + query)]).then(response => {
+ let matchingUsers = response[0].data.ocs.data.users
+ let matchingGroups = response[1].data.ocs.data.groups
+ try {
+ this.processMatchResults(matchingUsers, query, '(user)')
+>>>>>>> refractored api call in share addressbook to use axios all
+ } catch (error) {
+ console.debug(error)
+ }
+ try {
+<<<<<<< HEAD
+ this.formatMatchResults(matchingGroups, query, ' (group)')
+=======
+ this.processMatchResults(matchingGroups, query, '(group)')
+>>>>>>> refractored api call in share addressbook to use axios all
+ } catch (error) {
+ console.debug(error)
+ }
+ }).then(() => {
+<<<<<<< HEAD
+
+=======
+>>>>>>> refractored api call in share addressbook to use axios all
+ this.isLoading = false
+ })
+ }
+ },
+
+ clearAll() {
+ this.selectedUserOrGroup = []
+ }
+ }
+}
+</script>
diff --git a/src/components/Settings/SettingsAddressbookSharee.vue b/src/components/Settings/SettingsAddressbookSharee.vue
index f28b35ed..0cccb8b2 100644
--- a/src/components/Settings/SettingsAddressbookSharee.vue
+++ b/src/components/Settings/SettingsAddressbookSharee.vue
@@ -66,7 +66,6 @@ export default {
setTimeout(() => { this.$store.dispatch('removeSharee', this.sharee) }, 500)
},
editSharee() {
- // not working yet need to work on!
this.$store.dispatch('toggleShareeWritable', this.sharee)
}
}
diff --git a/src/components/Settings/SettingsSortContacts.vue b/src/components/Settings/SettingsSortContacts.vue
index 440e7d00..72e2b6c7 100644
--- a/src/components/Settings/SettingsSortContacts.vue
+++ b/src/components/Settings/SettingsSortContacts.vue
@@ -66,11 +66,11 @@ export default {
key: 'firstName'
},
{
- label: t('contacts', 'Lastname'),
+ label: t('contacts', 'Last name'),
key: 'lastName'
},
{
- label: t('contacts', 'Display-name'),
+ label: t('contacts', 'Display name'),
key: 'displayName'
}
]
diff --git a/src/store/addressbooks.js b/src/store/addressbooks.js
index 775c4bf9..0acc946f 100644
--- a/src/store/addressbooks.js
+++ b/src/store/addressbooks.js
@@ -105,12 +105,12 @@ const mutations = {
* @param {Object} data
* @param {Object} data.addressbook the addressbook
*/
- shareAddressbook(state, addressbook, sharee) {
+ shareAddressbook(state, [ addressbook, sharee ]) {
addressbook = state.addressbooks.find(search => search === addressbook)
let newSharee = {}
- sharee.displayname = sharee
- sharee.writable = false
- addressbook.shares.append(newSharee)
+ newSharee.displayname = sharee
+ newSharee.writeable = false
+ addressbook.shares.push(newSharee)
},
/**
@@ -128,7 +128,7 @@ const mutations = {
}
}
})
- addressbook.shares.splice(sharee, 1)
+ addressbook.shares.splice(addressbook.shares.indexOf(sharee), 1)
},
/**
@@ -174,6 +174,16 @@ const actions = {
owner: 'admin',
dav: addressbook
}
+ ]
+ // fake request
+ return new Promise((resolve, reject) => {
+ return setTimeout(() => {
+ addressbooks.forEach(addressbook => {
+ context.commit('addAddressbooks', addressbook)
+ })
+ resolve()
+ return addressbooks
+ }, 1000)
})
addressbooks.forEach(addressbook => {
context.commit('addAddressbooks', addressbook)
@@ -222,7 +232,7 @@ const actions = {
* @param {Object} addressbook Addressbook selected
* @param {Object} sharee Addressbook sharee object
*/
- shareAddressbook(contect, addressbook, sharee) {
+ shareAddressbook(context, [ addressbook, sharee ]) {
// Share addressbook with entered group or user
},
diff --git a/src/store/addressbooks.js.orig b/src/store/addressbooks.js.orig
new file mode 100644
index 00000000..542c927c
--- /dev/null
+++ b/src/store/addressbooks.js.orig
@@ -0,0 +1,248 @@
+/**
+ * @copyright Copyright (c) 2018 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/>.
+ *
+ */
+
+/* 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'
+
+import client from '../services/cdav'
+
+const addressbookModel = {
+ id: '',
+ displayName: '',
+ enabled: true,
+ owner: '',
+ shares: [],
+ contacts: {},
+ url: ''
+}
+
+const state = {
+ addressbooks: []
+}
+
+const mutations = {
+
+ /**
+ * Add addressbook into state
+ *
+ * @param {Object} state Default state
+ * @param {Object} addressbooks Addressbook
+ */
+ addAddressbooks(state, addressbook) {
+ // extend the addressbook to the default model
+ state.addressbooks.push(Object.assign({}, addressbookModel, addressbook))
+ },
+
+ /**
+ * Append a list of contacts to an addressbook
+ * and remove duplicates
+ *
+ * @param {Object} state
+ * @param {Object} data
+ * @param {Object} data.addressbook the addressbook
+ * @param {Contact[]} data.contacts array of contacts to append
+ */
+ appendContactsToAddressbook(state, { addressbook, contacts }) {
+ addressbook = state.addressbooks.find(search => search === addressbook)
+
+ // convert list into an array and remove duplicate
+ addressbook.contacts = contacts.reduce((list, contact) => {
+ if (list[contact.uid]) {
+ console.debug('Duplicate contact overrided', list[contact.uid], contact)
+ }
+ Vue.set(list, contact.uid, contact)
+ return list
+ }, addressbook.contacts)
+ },
+
+ /**
+ * Add a contact to an addressbook and overwrite if duplicate uid
+ *
+ * @param {Object} state
+ * @param {Contact} contact
+ */
+ addContactToAddressbook(state, contact) {
+ let addressbook = state.addressbooks.find(search => search.id === contact.addressbook.id)
+ Vue.set(addressbook.contacts, contact.uid, contact)
+ },
+
+ /**
+ * Delete a contact in a specified addressbook
+ *
+ * @param {Object} state
+ * @param {Contact} contact the contact to delete
+ */
+ deleteContactFromAddressbook(state, contact) {
+ let addressbook = state.addressbooks.find(search => search.id === contact.addressbook.id)
+ Vue.delete(addressbook, contact.uid)
+ },
+
+ /**
+ * Share addressbook with a user or group
+ *
+ * @param {Object} state
+ * @param {Object} data
+ * @param {Object} data.addressbook the addressbook
+ */
+ shareAddressbook(state, [ addressbook, sharee ]) {
+ addressbook = state.addressbooks.find(search => search === addressbook)
+ let newSharee = {}
+ newSharee.displayname = sharee
+ newSharee.writeable = false
+ addressbook.shares.push(newSharee)
+ },
+
+ /**
+ * Remove Share from addressbook shares list
+ *
+ * @param {Object} state
+ * @param {Object} data
+ * @param {Object} data.addressbook the addressbook
+ */
+ removeSharee(state, sharee) {
+ let addressbook = state.addressbooks.find(search => {
+ for (let i in search.shares) {
+ if (search.shares[i] === sharee) {
+ return true
+ }
+ }
+ })
+ addressbook.shares.splice(addressbook.shares.indexOf(sharee), 1)
+ },
+
+ /**
+ * Toggle sharee's writable permission
+ *
+ * @param {Object} state
+ * @param {Object} data
+ * @param {Object} data.addressbook the addressbook
+ * @param {Object} sharee the sharee
+ */
+ updateShareeWritable(state, sharee) {
+ let addressbook = state.addressbooks.find(search => {
+ for (let i in search.shares) {
+ if (search.shares[i] === sharee) {
+ return true
+ }
+ }
+ })
+ sharee = addressbook.shares.find(search => search === sharee)
+ sharee.writeable = !sharee.writeable
+ }
+
+}
+
+const getters = {
+ getAddressbooks: state => state.addressbooks
+}
+
+const actions = {
+
+ /**
+ * Retrieve and commit addressbooks
+ *
+ * @param {Object} context
+ * @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
+ }
+ })
+ addressbooks.forEach(addressbook => {
+ context.commit('addAddressbooks', addressbook)
+ })
+ return addressbooks
+ },
+
+ /**
+ * Retrieve the contacts of the specified addressbook
+ * and commit the results
+ *
+ * @param {Object} context
+ * @param {Object} addressbook
+ */
+ async getContactsFromAddressBook(context, addressbook) {
+ let contacts = parseVcf(vcfFile, addressbook)
+ context.commit('appendContactsToAddressbook', { addressbook, contacts })
+ context.commit('appendContacts', contacts)
+ context.commit('sortContacts')
+ context.commit('appendGroupsFromContacts', contacts)
+ },
+
+ /**
+ * Remove sharee from Addressbook
+ * @param {Object} context Current context
+ * @param {Object} sharee Addressbook sharee object
+ */
+ removeSharee(context, sharee) {
+ // Remove sharee from addressbook.
+ context.commit('removeSharee', sharee)
+ },
+
+ /**
+ * Toggle permissions of Addressbook Sharees writeable rights
+ * @param {Object} context Current context
+ * @param {Object} sharee Addressbook sharee object
+ */
+ toggleShareeWritable(context, sharee) {
+ // Toggle sharee edit permissions.
+ context.commit('updateShareeWritable', sharee)
+ },
+
+ /**
+ * Share Adressbook with User or Group
+ * @param {Object} context Current context
+ * @param {Object} addressbook Addressbook selected
+ * @param {Object} sharee Addressbook sharee object
+ */
+ shareAddressbook(context, [ addressbook, sharee ]) {
+ // Share addressbook with entered group or user
+<<<<<<< HEAD
+ },
+
+ /**
+ * Move a contact to the provided addressbook
+ *
+ * @param {Object} context
+ * @param {Object} data
+ * @param {Contact} data.contact
+ * @param {Object} data.addressbook
+ */
+ moveContactToAddressbook(context, { contact, addressbook }) {
+ context.commit('deleteContactFromAddressbook', contact)
+ context.commit('updateContactAddressbook', { contact, addressbook })
+ context.commit('addContactToAddressbook', contact)
+=======
+ context.commit('shareAddressbook', [ addressbook, sharee ])
+>>>>>>> working version of shareAdressbook, adds sharees to addressbook object
+ }
+}
+
+export default { state, mutations, getters, actions }