Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new props #613

Merged
merged 5 commits into from
Sep 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/components/ContactDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,16 @@

<!-- properties iteration -->
<!-- using contact.key in the key and index as key to avoid conflicts between similar data and exact key -->
<contact-details-property v-for="(property, index) in sortedProperties" :key="index+contact.key" :index="index"
<contact-property v-for="(property, index) in sortedProperties" :key="index+contact.key" :index="index"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We had actually been talking about whether to use both "contact" and "details" or not when naming the component we created for the avatar management issue.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! What did you settle for? :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ContactAvatar, like you. My concern is just that we also have the list avatar to think of.

:sorted-properties="sortedProperties" :property="property" :contact="contact"
@updatedcontact="updateContact" />

<!-- addressbook change select - no last property because class is not applied here-->
<property-select :prop-model="addressbookModel" :value.sync="addressbook" :is-first-property="true"
:is-last-property="false" :options="addressbooksOptions" class="property--addressbooks" />

<!-- new property select -->
<add-new-prop :contact="contact" />
</section>
</template>
</div>
Expand All @@ -105,7 +108,8 @@ import Contact from '../models/contact'
import rfcProps from '../models/rfcProps.js'

import PopoverMenu from './core/popoverMenu'
import ContactDetailsProperty from './ContactDetails/ContactDetailsProperty'
import ContactProperty from './ContactDetails/ContactDetailsProperty'
import AddNewProp from './ContactDetails/ContactDetailsAddNewProp'
import PropertySelect from './Properties/PropertySelect'
import PropertyGroups from './Properties/PropertyGroups'

Expand All @@ -116,9 +120,10 @@ export default {

components: {
PopoverMenu,
ContactDetailsProperty,
ContactProperty,
PropertySelect,
PropertyGroups
PropertyGroups,
AddNewProp
},

directives: {
Expand Down
82 changes: 82 additions & 0 deletions src/components/ContactDetails/ContactDetailsAddNewProp.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<!--
- @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/>.
-
-->

<template>
<div class="grid-span-2 property">

<!-- title -->
<property-title :icon="'icon-add'" :readable-name="t('contacts', 'Add new property')" />

<div class="property__row">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BEM! 💥

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An issue? Or was it just a comment stating the awesomeness of bem? :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the css way of stating the awesomeness of an app maintainer :)

<div class="property__label" />

<!-- type selector -->
<multiselect :options="availableProperties" :placeholder="t('contacts', 'Choose property type')" class="multiselect-vue property__value"
track-by="id" label="name" @input="addProp" />
</div>
</div>
</template>

<script>
import rfcProps from '../../models/rfcProps.js'
import Contact from '../../models/contact'
import propertyTitle from '../Properties/PropertyTitle'

import Multiselect from 'vue-multiselect'

export default {
name: 'ContactDetailsAddNewProp',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you remove "new" from the name or find another way of shortening it? Or like above use just "contact" or "details" but not both?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like 'ContactAddNewProp' ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's what I meant.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we totally can. Can you create a pull request or an issue? :)


components: {
propertyTitle,
Multiselect
},

props: {
contact: {
type: Contact,
default: null
}
},

computed: {
availableProperties() {
return Object.keys(rfcProps.properties).map(key => {
return {
id: key,
name: rfcProps.properties[key].readableName
}
})
}
},

methods: {
addProp({ id }) {
let defaultData = rfcProps.properties[id].defaultValue
let property = this.contact.vCard.addPropertyWithValue(id, defaultData ? defaultData.value : '')
if (defaultData && defaultData.type) {
property.setParameter('type', defaultData.type)
}
}
}
}
</script>
6 changes: 3 additions & 3 deletions src/models/contact.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ export default class Contact {
* @memberof Contact
*/
get groups() {
let prop = this.vCard.getFirstProperty('categories')
if (prop) {
return this.vCard.getFirstProperty('categories').getValues()
let groupsProp = this.vCard.getFirstProperty('categories')
if (groupsProp) {
return groupsProp.getValues()
}
return []
}
Expand Down
10 changes: 6 additions & 4 deletions src/services/parseVcf.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,19 @@ export default function parseVcf(data = '', addressbook) {

importState.total = vCards.length

return vCards.map(vCard => {
// Not using map because we want to only push valid contacts
// map force to return at least undefined
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Good to know and it's nice to see a real life example of reduce being used.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😊

return vCards.reduce((contacts, vCard) => {
try {
// console.log(vCards.indexOf(vCard))
let contact = new Contact(vCard, addressbook)
importState.accepted++
return contact
contacts.push(contact)
} catch (e) {
// Parse error! Do not stop here...
importState.denied++
// eslint-disable-next-line
console.error(e)
}
})
return contacts
}, [])
}
24 changes: 23 additions & 1 deletion src/store/FakeName.vcf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ MEMBER:urn:uuid:cd314b39-b71a-41cf-b4eb-5cb61dd6fa24
REV:2017-07-27T05:56:33Z
UID:5acf667e-1cbf-48a8-87fe-546ee31a0b23
END:VCARD

BEGIN:VCARD
VERSION:2.1
FN:Jean Dupont
N:Dupont;Jean
ADR;WORK;PREF;QUOTED-PRINTABLE:;Bruxelles 1200=Belgique;6A Rue Th. Decuyper
LABEL;QUOTED-PRINTABLE;WORK;PREF:Rue Th. Decuyper 6A=Bruxelles 1200=Belgique
TEL;CELL:+1234 56789
EMAIL;INTERNET:jean.dupont@example.com
UID:dfs541fds15
END:VCARD

BEGIN:VCARD
VERSION:4.0
KIND:org
Expand All @@ -18,7 +30,7 @@ BEGIN:VCARD
VERSION:3.0
N:Cunningham;Liam;;Mr.;
FN:Liam Cunningham
NICKNAME:Begivaing81
NICKNAME;TYPE=work:Begivaing81
BDAY;VALUE=text:5/26/1981
GENDER:male
ORG:Central Hardware;
Expand All @@ -28,6 +40,16 @@ CATEGORIES:Tech,University
TEL;TYPE=VOICE,HOME;VALUE=text:06-22957835
ADR;TYPE=HOME:;;Beilen;DR;9413 BA;Netherlands
END:VCARD

BEGIN:VCARD
VERSION:4.0
FN:Simon Perreault
N:Perreault;Simon;;;ing. jr,M.Sc.
BDAY:--0203
ANNIVERSARY:20090808T1430-0500
GENDER:M
END:VCARD

BEGIN:VCARD
VERSION:3.0
N:Kamiński;Przemysł;;Mr.;
Expand Down
28 changes: 16 additions & 12 deletions src/store/groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,22 @@ const mutations = {
appendGroupsFromContacts(state, contacts) {
// init groups list
let groups = Object.values(contacts)
.map(contact => contact.groups.map(group => {
// extend group to model
return {
name: group,
contacts: []
}
})[0])
// ensure we only have one group of each
state.groups = state.groups.concat(groups)
.filter(function(group, index, self) {
return group && self.findIndex(search => search && search.name === group.name) === index
})
// iterate on every contacts
.reduce((groups, contact) => {
// transform group names into Object
contact.groups.map(groupName => {
// overriding existing groups: remove duplicates
groups[groupName] = {
name: groupName,
contacts: []
}
})
return groups
}, {})

// store in state
state.groups = Object.values(groups)

// append keys to groups
Object.values(contacts)
.forEach(contact => {
Expand Down