diff options
author | Jessica <jessica@Absolventas-MacBook-Pro.local> | 2018-08-14 16:32:12 +0200 |
---|---|---|
committer | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2018-08-28 15:39:17 +0200 |
commit | 9569af1cad121bfcee756939f1ca33c4c8157108 (patch) | |
tree | ac9a7bbcf8f5fdbfeb23657048ee3fc99b9ae016 /src | |
parent | 8505db5262f11033534ad8e7c4feecf5fe36271d (diff) |
refractored and changed comments, fixed bug with search for sharees function
Diffstat (limited to 'src')
-rw-r--r-- | src/components/Settings/SettingsAddressbook.vue | 4 | ||||
-rw-r--r-- | src/components/Settings/SettingsAddressbookShare.vue | 50 | ||||
-rw-r--r-- | src/components/SettingsSection.vue | 8 | ||||
-rw-r--r-- | src/store/addressbooks.js | 23 | ||||
-rw-r--r-- | src/store/addressbooks.js.orig | 285 |
5 files changed, 338 insertions, 32 deletions
diff --git a/src/components/Settings/SettingsAddressbook.vue b/src/components/Settings/SettingsAddressbook.vue index 8544794b..cdceca25 100644 --- a/src/components/Settings/SettingsAddressbook.vue +++ b/src/components/Settings/SettingsAddressbook.vue @@ -39,7 +39,7 @@ </a> </li> <!-- sharing input --> - <share-addressbook v-if="shareOpen" :addressbook="addressbook" /> + <share-address-book v-if="shareOpen" :addressbook="addressbook" /> </div> </template> @@ -53,7 +53,7 @@ export default { name: 'SettingsAddressbook', components: { popoverMenu, - shareAddressbook, + shareAddressBook, clickOutside }, directives: { diff --git a/src/components/Settings/SettingsAddressbookShare.vue b/src/components/Settings/SettingsAddressbookShare.vue index f1ebb54e..81087f54 100644 --- a/src/components/Settings/SettingsAddressbookShare.vue +++ b/src/components/Settings/SettingsAddressbookShare.vue @@ -38,23 +38,25 @@ open-direction="bottom" class="multiselect-vue" @search-change="asyncFind" - @input="addSharee"> + @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 class="">{{ props.option.matchstart }}</span><span class="" style="font-weight: bold;">{{ props.option.matchpattern }}</span><span class="">{{ props.option.matchend }} {{ props.option.matchtag }}</span> + <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"> - <addressbook-sharee v-for="sharee in addressbook.shares" :key="sharee.displayname + sharee.group" :sharee="sharee" /> + <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' import addressbookSharee from './SettingsAddressbookSharee' @@ -67,7 +69,7 @@ export default { components: { clickOutside, Multiselect, - addressbookSharee + addressBookSharee }, directives: { clickOutside @@ -95,25 +97,38 @@ export default { } }, methods: { - addSharee(chosenUserOrGroup) { - let payload = [] - payload.push(this.addressbook) - payload.push(chosenUserOrGroup.match) - payload.push(chosenUserOrGroup.matchgroup) - this.$store.dispatch('shareAddressbook', payload) + /** + * Share addressbook + * + * @param {Object} chosenUserOrGroup + */ + shareAddressbook(chosenUserOrGroup) { + let addressbook = this.addressbook + let sharee = chosenUserOrGroup.match + let group = chosenUserOrGroup.matchgroup + this.$store.dispatch('shareAddressbook', { addressbook, sharee, 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) { - // format response from axios.all and add them to the option array if (matches.length < 1) { 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) + } for (let i = 0; i < matches.length; i++) { - for (let j = 0; j < this.addressbook.shares.length; j++) { - if (this.addressbook.shares[j].displayname === matches[i] && this.addressbook.shares[j].group === group) { - return - } + if (existingSharees.indexOf(matches[i] + group) !== -1) { + continue } let matchResult = matches[i].split(regex) let newMatch = { @@ -128,6 +143,11 @@ export default { } }, + /** + * 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 = [] diff --git a/src/components/SettingsSection.vue b/src/components/SettingsSection.vue index 99e2f7c9..ffd8ef63 100644 --- a/src/components/SettingsSection.vue +++ b/src/components/SettingsSection.vue @@ -23,9 +23,9 @@ <template> <div> <ul id="address-book-list"> - <addressbook v-for="addressbook in addressbooks" :key="addressbook.id" :addressbook="addressbook" /> + <address-Book v-for="addressbook in addressbooks" :key="addressbook.id" :addressbook="addressbook" /> </ul> - <add-addressbook :addressbooks="addressbooks" /> + <add-address-Book :addressbooks="addressbooks" /> <import-contacts :addressbooks="addressbooks" class="settings-section" /> <sort-contacts class="settings-section" /> @@ -41,8 +41,8 @@ import sortContacts from '../components/Settings/SettingsSortContacts' export default { name: 'SettingsSection', components: { - addressbook, - addAddressbook, + addressBook, + addAddressBook, importContacts, sortContacts }, diff --git a/src/store/addressbooks.js b/src/store/addressbooks.js index b768d72d..1753f579 100644 --- a/src/store/addressbooks.js +++ b/src/store/addressbooks.js @@ -104,21 +104,23 @@ const mutations = { * @param {Object} state * @param {Object} data * @param {Object} data.addressbook the addressbook + * @param {String} data.sharee the sharee + * @param {Boolean} data.group group */ - shareAddressbook(state, [ addressbook, sharee ]) { - addressbook = state.addressbooks.find(search => search === addressbook) + shareAddressbook(state, { addressbook, sharee, group }) { + addressbook = state.addressbooks.find(search => search.id === addressbook.id) let newSharee = {} newSharee.displayname = sharee newSharee.writeable = false + newSharee.group = group addressbook.shares.push(newSharee) }, /** - * Remove Share from addressbook shares list + * Remove Sharee from addressbook shares list * * @param {Object} state - * @param {Object} data - * @param {Object} data.addressbook the addressbook + * @param {Object} sharee the sharee */ removeSharee(state, sharee) { let addressbook = state.addressbooks.find(search => { @@ -135,8 +137,6 @@ const mutations = { * 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) { @@ -229,12 +229,13 @@ const actions = { /** * Share Adressbook with User or Group * @param {Object} context Current context - * @param {Object} addressbook Addressbook selected - * @param {Object} sharee Addressbook sharee object + * @param {Object} data.addressbook the addressbook + * @param {String} data.sharee the sharee + * @param {Boolean} data.group group */ - shareAddressbook(context, [ addressbook, sharee, group ]) { + shareAddressbook(context, { addressbook, sharee, group }) { // Share addressbook with entered group or user - context.commit('shareAddressbook', [ addressbook, sharee, group ]) + context.commit('shareAddressbook', { addressbook, sharee, group }) }, /** diff --git a/src/store/addressbooks.js.orig b/src/store/addressbooks.js.orig new file mode 100644 index 00000000..141b8b31 --- /dev/null +++ b/src/store/addressbooks.js.orig @@ -0,0 +1,285 @@ +/** + * @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.group group + */ +<<<<<<< HEAD + shareAddressbook(state, [ addressbook, sharee ]) { + addressbook = state.addressbooks.find(search => search === addressbook) +======= + shareAddressbook(state, { addressbook, sharee, group }) { + addressbook = state.addressbooks.find(search => search.id === addressbook.id) +>>>>>>> refractored and changed comments, fixed bug with search for sharees function + let newSharee = {} + newSharee.displayname = sharee + newSharee.writeable = false + 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', +<<<<<<< HEAD + dav: addressbook +======= + shares: [], + contacts: {} + }, + { + id: 'ab2', + displayName: 'Addressbook 2', + enabled: false, + owner: 'admin', + shares: [], + contacts: {} + }, + { + id: 'ab3', + displayName: 'Addressbook 3', + enabled: true, + owner: 'User1', + shares: [], + contacts: {} +>>>>>>> refractored and changed comments, fixed bug with search for sharees function + } + ] + // 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.group group + */ + shareAddressbook(context, { addressbook, sharee, 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, group }) +>>>>>>> refractored and changed comments, fixed bug with search for sharees function + } +} + +export default { state, mutations, getters, actions } |