Helpful Docs to read before posting: (All Docs) | Config Docs | General FAQ | Mailing List Sending FAQ | Error FAQ

change sort order of 'switch' listing?

How do I configure...

change sort order of 'switch' listing?

Postby themice » Fri Oct 15, 2010 7:45 pm

Greetings,
I have a bunch of lists within 1 install of Pro DaDa. Within any list control panel in the upper left there's a drop down to choose another list and switch quickly to it. Very handy but when I switch between a few lists the order seems to change (randomly?) and it's hard to locate the list I want.

So is there any way (i.e. in the code in a specific file) to modify the sort order of that list so it's the same all the time. For me I think an alpha sorted list would work best.

Thx for any help. --Marc
themice
 
Posts: 44
Joined: Mon Mar 10, 2008 7:52 pm

Re: change sort order of 'switch' listing?

Postby justin » Sat Oct 16, 2010 9:58 am

It should actually already be in alphabetical order, based on the list name - can you provide some screen shots showing this to not work as we're both expecting?
User avatar
justin
 
Posts: 4577
Joined: Wed Feb 13, 2008 8:41 pm
Location: Denver, CO

Re: change sort order of 'switch' listing?

Postby themice » Sat Oct 16, 2010 11:26 am

Just emailed you a screenshot - take a look. I'm using Pro DaDa 4.0.4 I believe for this install. I've been a user of DaDa for a number of years and I don't remember the list ever staying in alpha order on any version I've used in the past (but my memory isn't always reliable :-). Thx.
themice
 
Posts: 44
Joined: Mon Mar 10, 2008 7:52 pm

Re: change sort order of 'switch' listing?

Postby justin » Sat Oct 16, 2010 7:42 pm

I got the screenshot - thanks.

Can you let me know what backend you're using? Is it either the default backend, or the SQL backend?
User avatar
justin
 
Posts: 4577
Joined: Wed Feb 13, 2008 8:41 pm
Location: Denver, CO

Re: change sort order of 'switch' listing?

Postby justin » Sat Oct 16, 2010 8:40 pm

There's certainly something weird going on, here. I'm looking at it, and I'll soon file a bug report. Thanks for bringing this to my attention.
User avatar
justin
 
Posts: 4577
Joined: Wed Feb 13, 2008 8:41 pm
Location: Denver, CO

Re: change sort order of 'switch' listing?

Postby justin » Sun Oct 17, 2010 2:56 pm

I've done some work in getting this straightened out, after filling out the bug report - it should work for 4.0.4, if you want to give it a go, although I still didn't experience anything like the mess of stuff you had.

If you want, you can probably try to do some surgery, and transplant the, available_lists() subroutine from this version of dada/DADA/App/Guts.pm and put it in your copy (make a backup, first)

http://github.com/justingit/dada-mail/b ... pp/Guts.pm

Here it is,

Code: Select all
sub available_lists {

    my %args = (
        -As_Ref => 0,
        -In_Order => 0,
        -Dont_Die => 0,
        -dbi_handle => undef,
        -clear_cache => 0,
        @_,
    );

    my $in_order = $args{-In_Order};
    my $want_ref = $args{-As_Ref};
    my @dbs = ();
    my @available_lists = ();
    my $present_list = undef;

    require DADA::MailingList::Settings;
    $DADA::MailingList::Settings::dbi_obj = $args{-dbi_handle};

# BUGFIX: 2222381 3.0.0 - DADA::App::Guts::available_lists() needs caching
# https://sourceforge.net/tracker2/?func=detail&aid=2222381&group_id=13002&atid=113002
#
# Caching.
    if ( $args{-clear_cache} == 1 ) {

        # This is completely over the top, but...
        foreach ( keys %$cache ) {
            $cache->{$_} = undef;
            delete( $cache->{$_} );
        }
        $cache = undef;
        $cache = {};
    }
    if ( $in_order == 1 ) {
        if ( exists( $cache->{available_lists_in_order} ) ) {

            #$ic++; carp "CACHE! $ic++";
            $want_ref == "1"
              ? return $cache->{available_lists_in_order}
              : return @{ $cache->{available_lists_in_order} };
        }
    }
    else {
        if ( exists( $cache->{available_lists} ) ) {

            #$ic++; carp "CACHE! $ic++";
            $want_ref == "1"
              ? return $cache->{available_lists}
              : return @{ $cache->{available_lists} };
        }
    }

    # /Caching.

    # DEV: This is really bad form - do not emulate!

    if ( $DADA::Config::SETTINGS_DB_TYPE =~ /SQL/i ) {

        ######################################################################
        my $dbi_handle;


        require DADA::App::DBIHandle;
        $dbi_handle = DADA::App::DBIHandle->new;
        my $dbh = $dbi_handle->dbh_obj;
        ######################################################################

        my $query = 'SELECT DISTINCT list from '
          . $DADA::Config::SQL_PARAMS{settings_table};

        if ( $in_order == 1 ) {
            $query .= ' ORDER BY list ASC';
        }

        my $sth = $dbh->prepare($query);
        eval { $sth->execute() or croak; };

# BUGFIX:
# 2219954 3.0.0 - Guts.pm sub available_lists param, -Dont_Die broken
# https://sourceforge.net/tracker2/?func=detail&aid=2219954&group_id=13002&atid=113002
        if ($@) {
            if ( $args{-Dont_Die} == 1 ) {
                carp $DBI::errstr;
                $want_ref == "1" ? return [] : return ();
            }
            else {
                croak $DBI::errstr;
            }
        }
        else {

            while ( ( my $l ) = $sth->fetchrow_array ) {
                push( @available_lists, $l );
            }
            $sth->finish;
        }

    }
    else {

 
        my $path = $DADA::Config::FILES;
        $path = make_safer($path);
        $path =~ /(.*)/;
        $path = $1;

        if ( opendir( LISTS, $DADA::Config::FILES ) ) {
            while ( defined( $present_list = readdir LISTS ) ) {
                next if $present_list =~ /^\.\.?$/;
                $present_list =~ s(^.*/)();
                next if $present_list !~ /^mj-.*$/;

                $present_list =~ s/mj-//;
                $present_list =~ s/(\.dir|\.pag|\.db)$//;
                $present_list =~ s/(\.list|\.template)$//;

                next if $present_list eq "";

                if ( defined($present_list)
                    && $present_list ne ""
                    && $present_list !~ m/^\s+$/ )
                {
                    push( @dbs, $present_list );
                }
            } #/while

            foreach my $all_those (@dbs) {
                if ( $all_those !~ m/\-archive.*|\-schedules.*/ ) {
                    push( @available_lists, $all_those );
                }
            }

            #give me just one occurence of each name
            my %seen = ();
            my @unique = grep { !$seen{$_}++ } @available_lists;

            my @clean_unique;

            foreach (@unique) {
                if ( defined($_)
                    && $_ ne ""
                    && $_ !~ m/^\s+$/ )
                {
                    push( @clean_unique, $_ );
                }

            }
@available_lists = @clean_unique;
        }
        else {

            # DON'T rely on this...
            if ( $args{-Dont_Die} == 1 ) {
                $want_ref == "1" ? return [] : return ();
            }
            else {
                croak(
"$DADA::Config::PROGRAM_NAME $DADA::Config::VER error, please MAKE SURE that '$path' is a directory (NOT a file) and that Dada Mail has enough permissions to write into this directory: $!"
                );

            }
        }

    }

    if ( $in_order == 1 ) {

         my $labels = {};
         foreach my $l (@available_lists) {
             my $ls =
               DADA::MailingList::Settings->new( { -list => $l } );
             my $li = $ls->get;
             $labels->{$l} = $li->{list_name};
         }
         @available_lists =
           sort { uc( $labels->{$a} ) cmp uc( $labels->{$b} ) }
           keys %$labels;
$cache->{available_lists_in_order} = \@available_lists;
         $cache->{available_lists} = \@available_lists;
     }
else {
$cache->{available_lists} = \@available_lists;
}
     #$nc++; carp "not CACHED! $nc";
     $want_ref == "1" ? return \@available_lists : return @available_lists;

}


It passes all my tests, but I haven't thoroughly tested everything.



User avatar
justin
 
Posts: 4577
Joined: Wed Feb 13, 2008 8:41 pm
Location: Denver, CO

Re: change sort order of 'switch' listing?

Postby themice » Sun Mar 18, 2012 8:20 am

UPDATE: I just upgraded to pro dada 4.9.1 (I think I was using 4.0.2) and my drop down list for selecting a list is still not showing in any order (just a bunch of random list names) like before. Any ideas? Thanks!
themice
 
Posts: 44
Joined: Mon Mar 10, 2008 7:52 pm

Re: change sort order of 'switch' listing?

Postby justin » Sun Mar 18, 2012 12:48 pm

Can you post a screenshot?
User avatar
justin
 
Posts: 4577
Joined: Wed Feb 13, 2008 8:41 pm
Location: Denver, CO

Re: change sort order of 'switch' listing?

Postby themice » Sun Mar 18, 2012 5:28 pm

sure... I'm also going to try a fresh install of 4.9.1 and create a few lists and see if they are in any order.


Image
themice
 
Posts: 44
Joined: Mon Mar 10, 2008 7:52 pm

Re: change sort order of 'switch' listing?

Postby justin » Sun Mar 18, 2012 9:21 pm

Can you also tell me what backend you're using (Default, MySQL, etc) ?
User avatar
justin
 
Posts: 4577
Joined: Wed Feb 13, 2008 8:41 pm
Location: Denver, CO

Next

Return to Configuring Dada Mail

Who is online

Users browsing this forum: Google Adsense [Bot], RRKG and 1 guest

Loading