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

Sorting contacts #21

Open
cnovel opened this issue Jul 20, 2016 · 5 comments
Open

Sorting contacts #21

cnovel opened this issue Jul 20, 2016 · 5 comments

Comments

@cnovel
Copy link

cnovel commented Jul 20, 2016

Currently when syncing with contacts, it seems the order is arbitrary. It would be great if the contacts where sorted alphabetically.

@jojorb
Copy link
Owner

jojorb commented Jul 23, 2016

yes! thank you to remind me that!
It should be an easy fix with the lib underscore-min.js already loaded.

@jojorb
Copy link
Owner

jojorb commented Nov 18, 2016

obviously the task is for me a bit more complex than i through, i may need some help from a cozy front dev

edit: see code here app.js#L716

Try to use of the lib underscore to sort contacts here :

            for (i = 0; i < res.length; i++) {
                var mAd = _.findWhere(res[i].key.datapoints, {name: 'adr'}, {type: 'main'});
                if (mAd !== undefined && mAd.value !== undefined) {
                    // mAd.value.join('\n');
                    var adrr = mAd.value.join('');
                    var mAdz = adrr.replace(/\n/g, ' ');
                    console.log('Success: Get Contacts Address');

@Zykino
Copy link

Zykino commented Nov 29, 2016

If you are using underscore's collection to manage the list of contact you can use sortBy : http://underscorejs.org/#sortBy

_.sortBy(yourContactListFiltered, 'name');

Maybe the _.find function is what you need to filter the list (didn't really understand your code and where it comes from)

@jojorb
Copy link
Owner

jojorb commented Nov 30, 2016

yeah i know, it's really not easy to read,

in fact the basic is:

cozysdk.run('Contact', 'all', {}, function (err, res)

and the template for the sidebar

		var template =
		'<tr><th data-id="' + res[i].id +
		'" class="contactmap" rowspan="4" align="top">' + altUpics +
		'</th><th align="left">' + res[i].key.fn + '</th></tr><tr>' +
		'<td class="data-add" id="updatecontact' + res[i].id + '">' +
		adrsidebar +
		'</td></tr><tr><td></td></tr><tr></tr>';

		HTML = HTML + template;

where res[i].key.fn are the name, i think it sort by id for now but not by key.fn...

@Zykino
Copy link

Zykino commented Dec 2, 2016

Just as a reminder since I don't have much time and will continue on this later`.

Breakpoints here : https://github.com/RobyRemzy/cozy-map/blob/db21da17f3683c8e046af35b8b6d4b0a79872aa3/src/app.js#L710

In console enter this

var a = _.filter(res, function (num) {return num.key.datapoints[2] && num.key.datapoints[2].name == 'adr';})

Need to check all the values in the datapoints tab instead of just "2" but it's returning me a contact, should return all then just do something like:

_.sortBy(res, 'name'); // I think it's not directly name and we will need to use a function here too ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants