Skip to content

Vue share addressbook - #595

Merged
sleepypioneer merged 21 commits into
vuefrom
vue-share-addressbook
Aug 28, 2018
Merged

sleepypioneer merged 21 commits into
vuefrom
vue-share-addressbook

Conversation

@sleepypioneer

Copy link
Copy Markdown
Member

Hi @suntala and @skjnldsv on this branch I have the changes we did in the meeting for the SCSS files. I also have been working on the share-addressbook. This is almost finished bar one styling fix, so I thought it may be worth a PR, thoughts??

@sleepypioneer sleepypioneer added the 3. to review Waiting for reviews label Aug 15, 2018
@sleepypioneer sleepypioneer self-assigned this Aug 15, 2018

@skjnldsv skjnldsv left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hum wait, a few more changes! :p

  • The bold is not working anymore in the autocompletion
    capture d ecran_2018-08-16_11-19-18
  • You still need a debounce to ensure the processed request is always the last one the user did. :)
  • see comments ;)

Comment thread css/settings-section.scss Outdated
*/


@import 'settings/settings-addressbook';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would prefer all imports on the same file :)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

copy also to the copyright header I will do this when in today as the first thing I do. Sorry forgot about the debouncer I need to think how I transfer these comments to a todo for myself, I loose them on github. I will work through the other points also. The only one is addnewaddressbook that is not my work and I think @suntala has probably updated this on her branch.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Arf, then forget about the new addressbook :) 🎉
Sorry 🙈

@@ -0,0 +1,46 @@
.addressbook__sharee {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

copyright header

@@ -0,0 +1,56 @@
.addressbook-shares {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

copyright header

Comment thread css/settings/settings-addressbook.scss Outdated
@@ -0,0 +1,31 @@
// BLOCK

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

copyright header

Comment thread css/settings/settings-addressbook.scss Outdated
}
}

// MODIFIER No newline at end of file

@skjnldsv skjnldsv Aug 16, 2018 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not necessary I guess? :)

return t('contacts', 'Share with users or groups')
},
noResult() {
return t('contacts', 'Oops! No elements found. Consider changing the search query.')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe too long?
I would go for something simpler I think.

*
* @param {Object} chosenUserOrGroup
*/
shareAddressbook(chosenUserOrGroup) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

you can also replace chosenUserOrGroup by { sharee, group }
Easier to understand and you don't need the let xxx =

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I am not sure how this should work, the chosenUserOrGroup is an object that is the return from the custom options, it looks like this:

let newMatch = {
match: matches[i],
matchstart: matchResult[0],
matchpattern: matches[i].match(regex)[0],
matchend: matchResult[1],
matchtag: group ? '(group)' : '(user)',
matchgroup: group
}

How do I tell the multiselect to only pass on the match and matchgroup as suggested?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You can still pass the full object and destructure the only desired props :)

({ match, matchgroup } = {
    match: 0,
    matchstart: 1,
    matchpattern: 2,
    matchend: 3,
    matchtag: '(user)',
    matchgroup: 4
})

match
> 0
matchgroup
> 4

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

💯

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++) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There is a cleaner way to do that.
You can map the existing shares into an array of displaynames
let existingSharees = this.addressbook.shares.map(share => share.displayname)
Then you can filter out the shares
matches.filter(share => existingSharees.indexOf(share) === -1)
And then you can use map to create your newMatch object :)

Though this raises a few questions:

  1. the group/user request returns displayNames, but we can have same displayName into a same instance
  2. we should probably retrieve both data from the ocs api. and use ids and displayNames alongside

The api doc is not updated yet, but we can use /users/details and /groups/details to get the full data of a user.
https://github.com/nextcloud/server/blob/master/apps/provisioning_api/appinfo/routes.php#L37
Though we should then probably limit the number of results: https://github.com/nextcloud/server/blob/master/apps/provisioning_api/lib/Controller/UsersController.php#L156

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think we are approaching this a little different. I receive a array of names from both the ocs.data.users and ocs.data.groups and pass them to my formating function with a boolean to say if this was from a group or not (ie a user) Then I cross check this against my existing sharees using displayName + group as a primary key.

I love how concise the map function is, just trying to figure out how to do this here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, my example is just to cross check against existing sharees :)

// let newAddressBooksArray = addressBooks.push(addressBook)
let addressBook = this.$refs.addressBook.value
let addressBooks = this.$store.getters.getAddressbooks
let newAddressBooksArray = addressBooks.push(addressBook)

@skjnldsv skjnldsv Aug 16, 2018 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You cannot do that. You are not allowed to mutate data outside the store :)

Comment thread src/store/addressbooks.js Outdated
sharee.displayname = sharee
sharee.writable = false
addressbook.shares.append(newSharee)
newSharee.displayname = sharee

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You can do that directly in the object declaration

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

💯

@sleepypioneer

Copy link
Copy Markdown
Member Author

@skjnldsv I believe I have covered the changes requested, sorry if I have missed any but I think this is good to go.

let matchingGroups = response[1].data.ocs.data.groups
try {
this.formatMatchResults(matchingUsers, query, false)
debounce(this.formatMatchResults(matchingUsers, query, false), 250, true)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I used 500 in the details, but this is a different behavior, so 250 is also fine :)

Comment thread src/components/SettingsSection.vue Outdated
<div>
<ul id="address-book-list">
<address-book v-for="addressbook in addressbooks" :key="addressbook.id" :addressbook="addressbook" />
<address-Book v-for="addressbook in addressbooks" :key="addressbook.id" :addressbook="addressbook" />

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why the capital B ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

mistake!

Comment thread src/store/addressbooks.js Outdated
displayname: sharee,
id: id,
writeable: false,
group: group

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Quick tip, you can just put group since it will be the same as group: group.
But don't bother, it's just a quick knowledge bump ;)

<template>
<li class="addressbook__sharee">
<span class="icon icon-group" />
<span v-if="sharee.group" class="icon icon-group" />

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

you could just do <span :class="sharee.group ? 'icon-group' : 'icon-user'" />

console.debug(error)
}
try {
debounce(this.formatMatchResults(matchingGroups, query, true), 250, true)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is wrongly positioned, the debounce should be before the request, or we'll still get a big amount of requests which data won't be up to date. :)

See https://github.com/nextcloud/contacts/blob/vue/src/components/properties/PropertyMultipleText.vue#L123

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I've taken 500 for the wait, correct?

sharee: matches[i].displayname,
id: matches[i].id,
matchstart: matchResult[0],
matchpattern: matches[i].displayname.match(regex)[0],

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

match will return undefined if no match. so undefined[0] will throw an error :)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

so I have done a check that match has a length and if not just returned out of it

let regex = new RegExp(query, 'i')
let existingSharees = this.addressbook.shares.map(share => share.id + share.group)
matches = matches.filter(share => existingSharees.indexOf(share.id + group) === -1)
for (let i = 0; i < matches.length; i++) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You can also directly do that in a map :)

            this.usersOrGroups.concat(matches.map(match => {
                let matchResult = match.displayname.split(regex)
                return {
                    sharee: match.displayname,
                    id: match.id,
                    matchstart: matchResult[0],
                    matchpattern: match.displayname.match(regex)[0],
                    matchend: matchResult[1],
                    matchtag: group ? '(group)' : '(user)',
                    group
                }
            }))

@sleepypioneer

sleepypioneer commented Aug 21, 2018 •

Copy link
Copy Markdown
Member Author

Nice notes! I will get on them, thank you :)

@skjnldsv I have made those changes mentioned above. There is still this conflict with the js/contacts.js I am not sure how to handle this file it always seems to be an issue

Jessica and others added 20 commits August 28, 2018 14:54
Signed-off-by: John Molakvoæ (skjnldsv) <[email protected]>
Signed-off-by: John Molakvoæ (skjnldsv) <[email protected]>
…r there is still some error in the code that does not effectively implement the filter function. Added debounce package and function.
Signed-off-by: John Molakvoæ (skjnldsv) <[email protected]>
@skjnldsv
skjnldsv force-pushed the vue-share-addressbook branch from 1e0c066 to ea5973c Compare August 28, 2018 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. to review Waiting for reviews

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants