yvi (
yvi) wrote in
dw_dev_training2009-11-24 12:30 pm
![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
![[site community profile]](https://www.dreamwidth.org/img/comm_staff.png)
Entry tags:
Need some help: tag sorting
Since
denise asked so nicely, I might put up some questions during the next few days.
I apologize if this description is messy - I can be very bad at explaining these things.
One of the bugs I am currently stuck on is http://bugs.dwscoalition.org/show_bug.cgi?id=2012 use a tag list not a tag cloud on the subscription filter interface The goal is to change th tag cloud here: http://www.dreamwidth.org/manage/subscriptions/filters to an alphabetically sorted tag list with usage numbers. Despite my complete inability with javaScript, I managed the 'tag list with usage numbers' part fine. I am, however, stuck on the alphabetically sorted part.
It looks like sorting the tags before they reach that point might be the way to go and htdocs/tools/endpoints/general.bml might be the key to that.
get_usertags returns a "Hashref; key being tag id, value being a large hashref". It looks like hashes in perl can be sorted - is there a way to sort this hash by name? I imagine this structure looks something like:
hash{id1} = { 'name' => name1,
'usage' => usage1,
...}
hash{id2} = { 'name' => name2,
'usage' => usage2,
...}
and now I need to sort the ids by name.
There is some sorting going on in cgi-bin/LJ/S2/TagPage.pm:
But that returns a sorted array.
Any ideas?
EDIT: Okay, looks like I either need to sort the ids by name and then return both the hashref and the array and handle that in the JavaScrript portion or sort in htdocs/js/subfilters.js itself. The relevant code is in function cfUpdateTags( data ), the
![[staff profile]](https://www.dreamwidth.org/img/silk/identity/user_staff.png)
I apologize if this description is messy - I can be very bad at explaining these things.
One of the bugs I am currently stuck on is http://bugs.dwscoalition.org/show_bug.cgi?id=2012 use a tag list not a tag cloud on the subscription filter interface The goal is to change th tag cloud here: http://www.dreamwidth.org/manage/subscriptions/filters to an alphabetically sorted tag list with usage numbers. Despite my complete inability with javaScript, I managed the 'tag list with usage numbers' part fine. I am, however, stuck on the alphabetically sorted part.
It looks like sorting the tags before they reach that point might be the way to go and htdocs/tools/endpoints/general.bml might be the key to that.
} elsif ( $mode eq 'list_tags' ) { $ret{tags} = LJ::Tags::get_usertags( $u, { remote => $remote } );
get_usertags returns a "Hashref; key being tag id, value being a large hashref". It looks like hashes in perl can be sorted - is there a way to sort this hash by name? I imagine this structure looks something like:
hash{id1} = { 'name' => name1,
'usage' => usage1,
...}
hash{id2} = { 'name' => name2,
'usage' => usage2,
...}
and now I need to sort the ids by name.
There is some sorting going on in cgi-bin/LJ/S2/TagPage.pm:
my $tags = LJ::Tags::get_usertags($u, { remote => $remote }); foreach my $kwid (keys %{$tags}) { # only show tags for display next unless $tags->{$kwid}->{display}; push @taglist, LJ::S2::TagDetail($u, $kwid => $tags->{$kwid}); } @taglist = sort { $a->{name} cmp $b->{name} } @taglist;
But that returns a sorted array.
Any ideas?
EDIT: Okay, looks like I either need to sort the ids by name and then return both the hashref and the array and handle that in the JavaScrript portion or sort in htdocs/js/subfilters.js itself. The relevant code is in function cfUpdateTags( data ), the
for ( id in data.tags ) {
loop would need to be run through in order of data.tags[id].name
.
no subject
A sorted list, strictly speaking.
But yes. Because you can't sort hashes - you sort the list of keys. (Either by the key themselves, or by something based on the key, depending on what you want to accomplish.)