summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJessica <jessica@Absolventas-MacBook-Pro.local>2018-08-20 18:21:38 +0200
committerJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2018-08-28 15:50:42 +0200
commitbac467b3f6f564b9f0056c88a2b8e2ab87a54f2e (patch)
tree5c83f5c9ba6d90b576efb2a1ecc069d3df38b16d /src
parentcad9ce3b813e83e0b4175997829e10704bc9141b (diff)
added id to sharees and used this to look for existing shares, however there is still some error in the code that does not effectively implement the filter function. Added debounce package and function.
Diffstat (limited to 'src')
-rw-r--r--src/components/Settings/SettingsAddressbookShare.vue40
-rw-r--r--src/components/Settings/SettingsAddressbookShare.vue.orig173
-rw-r--r--src/store/addressbooks.js18
-rw-r--r--src/store/addressbooks.js.orig264
4 files changed, 462 insertions, 33 deletions
diff --git a/src/components/Settings/SettingsAddressbookShare.vue b/src/components/Settings/SettingsAddressbookShare.vue
index 81087f54..c48ad657 100644
--- a/src/components/Settings/SettingsAddressbookShare.vue
+++ b/src/components/Settings/SettingsAddressbookShare.vue
@@ -21,7 +21,7 @@
-->
<template>
- <div class="addressbook__shares">
+ <div class="addressbook-shares">
<multiselect
id="users-groups-search"
:options="usersOrGroups"
@@ -58,12 +58,7 @@
import clickOutside from 'vue-click-outside'
import api from '../../services/api'
import Multiselect from 'vue-multiselect'
-import addressbookSharee from './SettingsAddressbookSharee'
-
-import clickOutside from 'vue-click-outside'
-
-import api from '../../services/api'
-
+import addressBookSharee from './SettingsAddressbookSharee'
export default {
name: 'SettingsShareAddressbook',
components: {
@@ -102,12 +97,9 @@ export default {
*
* @param {Object} chosenUserOrGroup
*/
- shareAddressbook(chosenUserOrGroup) {
+ shareAddressbook({ sharee, id, group }) {
let addressbook = this.addressbook
- let sharee = chosenUserOrGroup.match
- let group = chosenUserOrGroup.matchgroup
- this.$store.dispatch('shareAddressbook', { addressbook, sharee, group })
-
+ this.$store.dispatch('shareAddressbook', { addressbook, sharee, id, group })
},
/**
@@ -122,22 +114,18 @@ export default {
return
}
let regex = new RegExp(query, 'i')
- let existingSharees = []
- for (let j = 0; j < this.addressbook.shares.length; j++) {
- existingSharees.push(this.addressbook.shares[j].displayname + this.addressbook.shares[j].group)
- }
+ let existingSharees = this.addressbook.shares.map(share => share.id + share.group)
+ matches.filter(share => existingSharees.indexOf(share.id + group) === -1)
for (let i = 0; i < matches.length; i++) {
- if (existingSharees.indexOf(matches[i] + group) !== -1) {
- continue
- }
- let matchResult = matches[i].split(regex)
+ let matchResult = matches[i].displayname.split(regex)
let newMatch = {
- match: matches[i],
+ sharee: matches[i].displayname,
+ id: matches[i].id,
matchstart: matchResult[0],
- matchpattern: matches[i].match(regex)[0],
+ matchpattern: matches[i].displayname.match(regex)[0],
matchend: matchResult[1],
matchtag: group ? '(group)' : '(user)',
- matchgroup: group
+ group: group
}
this.usersOrGroups.push(newMatch)
}
@@ -153,10 +141,10 @@ export default {
this.usersOrGroups = []
if (query.length > 0) {
api.all([
- api.get(OC.linkToOCS('cloud', 2) + 'users?search=' + query),
- api.get(OC.linkToOCS('cloud', 2) + 'groups?search=' + query)
+ api.get(OC.linkToOCS('cloud', 2) + 'users/details?search=' + query),
+ api.get(OC.linkToOCS('cloud', 2) + 'groups/details?search=' + query)
]).then(response => {
- let matchingUsers = response[0].data.ocs.data.users
+ let matchingUsers = Object.values(response[0].data.ocs.data.users)
let matchingGroups = response[1].data.ocs.data.groups
try {
this.formatMatchResults(matchingUsers, query, false)
diff --git a/src/components/Settings/SettingsAddressbookShare.vue.orig b/src/components/Settings/SettingsAddressbookShare.vue.orig
new file mode 100644
index 00000000..1fea4a72
--- /dev/null
+++ b/src/components/Settings/SettingsAddressbookShare.vue.orig
@@ -0,0 +1,173 @@
+<!--
+ - @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"
+ :options="usersOrGroups"
+ :searchable="true"
+ :loading="isLoading"
+ :internal-search="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"
+ @input="shareAddressbook">
+ <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">
+ <div class="option__desc">
+ <span>{{ props.option.matchstart }}</span><span class="shareematch--bold">{{ props.option.matchpattern }}</span><span>{{ props.option.matchend }} {{ props.option.matchtag }}</span>
+ </div>
+ </template>
+ <span slot="noResult">{{ noResult }} </span>
+ </multiselect>
+ <!-- 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.displayname + sharee.group" :sharee="sharee" />
+ </ul>
+ </div>
+</template>
+
+<script>
+import clickOutside from 'vue-click-outside'
+import api from '../../services/api'
+import Multiselect from 'vue-multiselect'
+<<<<<<< HEAD
+import addressbookSharee from './SettingsAddressbookSharee'
+
+import clickOutside from 'vue-click-outside'
+
+import api from '../../services/api'
+
+=======
+import addressBookSharee from './SettingsAddressbookSharee'
+>>>>>>> added id to sharees and used this to look for existing shares, however there is still some error in the code that does not effectively implement the filter function. Added debounce package and function.
+export default {
+ name: 'SettingsShareAddressbook',
+ components: {
+ clickOutside,
+ Multiselect,
+ addressBookSharee
+ },
+ directives: {
+ clickOutside
+ },
+ props: {
+ addressbook: {
+ type: Object,
+ default() {
+ return {}
+ }
+ }
+ },
+ data() {
+ return {
+ isLoading: false,
+ usersOrGroups: []
+ }
+ },
+ computed: {
+ placeholder() {
+ return t('contacts', 'Share with users or groups')
+ },
+ noResult() {
+ return t('contacts', 'Oops! No elements found. Consider changing the search query.')
+ }
+ },
+ methods: {
+ /**
+ * Share addressbook
+ *
+ * @param {Object} chosenUserOrGroup
+ */
+ shareAddressbook({ sharee, id, group }) {
+ let addressbook = this.addressbook
+ this.$store.dispatch('shareAddressbook', { addressbook, sharee, id, group })
+ },
+ /**
+ * Format responses from axios.all and add them to the option array
+ *
+ * @param {Array} matches Array of matches returned from the axios request
+ * @param {String} query
+ * @param {Boolean} group
+ */
+ formatMatchResults(matches, query, group) {
+ if (matches.length < 1) {
+ return
+ }
+ let regex = new RegExp(query, 'i')
+ let existingSharees = this.addressbook.shares.map(share => share.id + share.group)
+ matches.filter(share => existingSharees.indexOf(share.id + group) === -1)
+ for (let i = 0; i < matches.length; i++) {
+ let matchResult = matches[i].displayname.split(regex)
+ let newMatch = {
+ sharee: matches[i].displayname,
+ id: matches[i].id,
+ matchstart: matchResult[0],
+ matchpattern: matches[i].displayname.match(regex)[0],
+ matchend: matchResult[1],
+ matchtag: group ? '(group)' : '(user)',
+ group: group
+ }
+ this.usersOrGroups.push(newMatch)
+ }
+ },
+ /**
+ * Use Axios api call to find matches to the query from the existing Users & Groups
+ *
+ * @param {String} query
+ */
+ asyncFind(query) {
+ this.isLoading = true
+ this.usersOrGroups = []
+ if (query.length > 0) {
+ api.all([
+ api.get(OC.linkToOCS('cloud', 2) + 'users/details?search=' + query),
+ api.get(OC.linkToOCS('cloud', 2) + 'groups/details?search=' + query)
+ ]).then(response => {
+ let matchingUsers = Object.values(response[0].data.ocs.data.users)
+ let matchingGroups = response[1].data.ocs.data.groups
+ try {
+ this.formatMatchResults(matchingUsers, query, false)
+ } catch (error) {
+ console.debug(error)
+ }
+ try {
+ this.formatMatchResults(matchingGroups, query, true)
+ } catch (error) {
+ console.debug(error)
+ }
+ }).then(() => {
+ this.isLoading = false
+ })
+ }
+ }
+ }
+}
+</script>
diff --git a/src/store/addressbooks.js b/src/store/addressbooks.js
index 1753f579..171dfc34 100644
--- a/src/store/addressbooks.js
+++ b/src/store/addressbooks.js
@@ -105,14 +105,17 @@ const mutations = {
* @param {Object} data
* @param {Object} data.addressbook the addressbook
* @param {String} data.sharee the sharee
+ * @param {Boolean} data.id id
* @param {Boolean} data.group group
*/
- shareAddressbook(state, { addressbook, sharee, group }) {
+ shareAddressbook(state, { addressbook, sharee, id, group }) {
addressbook = state.addressbooks.find(search => search.id === addressbook.id)
- let newSharee = {}
- newSharee.displayname = sharee
- newSharee.writeable = false
- newSharee.group = group
+ let newSharee = {
+ displayname: sharee,
+ id: id,
+ writeable: false,
+ group: group
+ }
addressbook.shares.push(newSharee)
},
@@ -231,11 +234,12 @@ const actions = {
* @param {Object} context Current context
* @param {Object} data.addressbook the addressbook
* @param {String} data.sharee the sharee
+ * @param {Boolean} data.id id
* @param {Boolean} data.group group
*/
- shareAddressbook(context, { addressbook, sharee, group }) {
+ shareAddressbook(context, { addressbook, sharee, id, group }) {
// Share addressbook with entered group or user
- context.commit('shareAddressbook', { addressbook, sharee, group })
+ context.commit('shareAddressbook', { addressbook, sharee, id, group })
},
/**
diff --git a/src/store/addressbooks.js.orig b/src/store/addressbooks.js.orig
new file mode 100644
index 00000000..9e8670dc
--- /dev/null
+++ b/src/store/addressbooks.js.orig
@@ -0,0 +1,264 @@
+/**
+ * @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
+ * @param {String} data.sharee the sharee
+ * @param {Boolean} data.id id
+ * @param {Boolean} data.group group
+ */
+ shareAddressbook(state, { addressbook, sharee, id, group }) {
+ addressbook = state.addressbooks.find(search => search.id === addressbook.id)
+ let newSharee = {
+ displayname: sharee,
+ id: id,
+ writeable: false,
+ group: group
+ }
+ addressbook.shares.push(newSharee)
+ },
+
+ /**
+ * Remove Sharee from addressbook shares list
+ *
+ * @param {Object} state
+ * @param {Object} sharee the sharee
+ */
+ 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} 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
+ }
+ ]
+ // 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)
+ })
+ 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} data.addressbook the addressbook
+ * @param {String} data.sharee the sharee
+ * @param {Boolean} data.id id
+ * @param {Boolean} data.group group
+ */
+ shareAddressbook(context, { addressbook, sharee, id, group }) {
+ // Share addressbook with entered group or user
+<<<<<<< HEAD
+ context.commit('shareAddressbook', { addressbook, sharee, group })
+ },
+
+ /**
+ * 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, id, group })
+>>>>>>> added id to sharees and used this to look for existing shares, however there is still some error in the code that does not effectively implement the filter function. Added debounce package and function.
+ }
+}
+
+export default { state, mutations, getters, actions }