mark: A photo of Mark kneeling on top of the Taal Volcano in the Philippines. It was a long hike. (Default)
Mark Smith ([staff profile] mark) wrote in [site community profile] changelog2009-06-14 08:20 pm

[dw-free] /manage/invitecodes usability fixes

[commit: http://hg.dwscoalition.org/dw-free/rev/7b476361b2dd]

http://bugs.dwscoalition.org/show_bug.cgi?id=1022

Usability fixes for the invite codes page.

Patch by [personal profile] afuna.

Files modified:
  • htdocs/manage/invitecodes.bml
  • htdocs/manage/invitecodes.bml.text
--------------------------------------------------------------------------------
diff -r 26ab134880c3 -r 7b476361b2dd htdocs/manage/invitecodes.bml
--- a/htdocs/manage/invitecodes.bml	Sun Jun 14 20:18:49 2009 +0000
+++ b/htdocs/manage/invitecodes.bml	Sun Jun 14 20:20:17 2009 +0000
@@ -14,7 +14,7 @@ body<=
     my $ret;
 
     if ( LJ::did_post() ) {
-        return "<?h1 $ML{'Error'} ?h1> $ML{'error.invalidform'}" unless LJ::check_form_auth;
+        return "<?h1 $ML{'Error'} ?h1> $ML{'error.invalidform'}" unless LJ::check_form_auth();
         if ( DW::InviteCodeRequests->create( userid => $remote->id, reason => $POST{reason} ) ) {
             $ret .= "<?standout $ML{'.msg.request.success'} standout?>";
         } else {
@@ -22,10 +22,55 @@ body<=
         }
     }
 
+    if ( DW::BusinessRules::InviteCodeRequests::can_request( user => $remote ) ) {
+        $ret .= "<?h2 $ML{'.form.request.header'} h2?>";
+        $ret .= "<?p $ML{'.form.request.intro'} p?>";
+        $ret .= "<div><form method='POST'>";
+        $ret .= LJ::form_auth();
+        $ret .= LJ::labelfy( 'reason', $ML{'.form.request.reason'} );
+        $ret .= LJ::html_text( { name => 'reason', id => 'reason', size => 75, maxlength => 255  } );
+        $ret .= LJ::html_submit( value => $ML{'.form.request.submit'} );
+        $ret .= "</form></div>";
+    }
+
+    if ( $GET{full} ) {
+        $ret .= "<p>" . BML::ml( '.label.viewing.full', { aopts => "href='invitecodes'" } ) . "</p>";
+    } else {
+        $ret .= "<p>" . BML::ml( '.label.viewing.partial', { aopts => "href='invitecodes?full=1'" } ) . "</p>";
+    }
+
     my @invitecodes = DW::InviteCodes->by_owner( userid => $remote->id );
+
+    my @recipient_ids;
+    foreach my $code ( @invitecodes ) {
+        push @recipient_ids, $code->recipient if $code->recipient;
+    }
+    
+    my $recipient_users = LJ::load_userids( @recipient_ids );
+
+    unless ( $GET{full} ) {
+        # filter out codes that were used over two weeks ago
+        my $two_weeks_ago = time() - ( 14 * 24 * 60 * 60 );
+        @invitecodes = grep { 
+            my $u = $recipient_users->{$_->recipient};
+            # if it's used, we should always have a recipient, but...
+            ! $_->is_used || ( $u && $u->timecreate ) > $two_weeks_ago
+        } @invitecodes;
+    }
     
     if ( @invitecodes ) {
-        $ret .= "<table class='invitecodes'><tr><th>$ML{'.header.code'}</th><th>$ML{'.header.recipient'}</th><th width='200'>$ML{'.header.sent'}</th><th>$ML{'.header.email'}</th></tr>";
+
+        # sort so that invite codes end up in this order:
+        #  - unsent and unused
+        #  - sent but unused, with earliest sent first
+        #  - used
+        @invitecodes = sort { 
+            return $a->is_used <=> $b->is_used if $a->is_used != $b->is_used;
+            return $a->timesent <=> $b->timesent;
+        } @invitecodes;
+
+
+        $ret .= "<table class='invitecodes' id='invitecodes'><tr><th>$ML{'.header.code'}</th><th>$ML{'.header.recipient'}</th><th width='200'>$ML{'.header.sent'}</th><th>$ML{'.header.email'}</th></tr>";
     
         foreach my $code ( @invitecodes ) {
             $ret .= "<tr>";
@@ -33,7 +78,7 @@ body<=
             $ret .= "<td>";
         
             if( $code->is_used ) {
-                my $u = LJ::load_userid( $code->recipient );
+                my $u = $recipient_users->{$code->recipient};
                 $ret .= $u->ljuser_display;
             } else {
                 my $create_link = ($LJ::USE_SSL ? $LJ::SSLROOT : $LJ::SITEROOT)
@@ -55,21 +100,11 @@ body<=
         }
     
         $ret .= "</table>";
+    } elsif ( $GET{full} ) {
+        $ret .= "<?p $ML{'.noinvitecodes'} p?>";
     } else {
-        $ret .= "<?p $ML{'.noinvitecodes'} p?>";
+        $ret .= "<?p $ML{'.noinvitecodes.partial'} p?>";
    }
-    
-    if ( DW::BusinessRules::InviteCodeRequests::can_request( user => $remote ) ) {
-        $ret .= "<?h2 $ML{'.form.request.header'} h2?>";
-        $ret .= "<?p $ML{'.form.request.intro'} p?>";
-        $ret .= "<div><form method='POST'>";
-        $ret .= LJ::form_auth;
-        $ret .= LJ::labelfy( 'reason', $ML{'.form.request.reason'} );
-        $ret .= LJ::html_text( { name => 'reason', id => 'reason', size => 75, maxlength => 255  } );
-        $ret .= LJ::html_submit( value => $ML{'.form.request.submit'} );
-        $ret .= "</form></div>";
-    }
-
 
     return $ret;
 } _code?>
diff -r 26ab134880c3 -r 7b476361b2dd htdocs/manage/invitecodes.bml.text
--- a/htdocs/manage/invitecodes.bml.text	Sun Jun 14 20:18:49 2009 +0000
+++ b/htdocs/manage/invitecodes.bml.text	Sun Jun 14 20:20:17 2009 +0000
@@ -9,11 +9,17 @@
 
 .form.request.submit=Request invites
 
+.label.viewing.full=Here is a full list of your invite codes. See only those which are <a [[aopts]]>unused, or used but recently sent</a>.
+
+.label.viewing.partial=Here are your unused and recently sent invite codes. See the <a [[aopts]]>full list of your invite codes</a>.
+
 .msg.request.success=Your request for new invite codes has been forwarded to site administrators for review.
 
 .msg.request.error=Your request could not go through.
 
 .noinvitecodes=You have no invite codes.
+
+.noinvitecodes.partial=You have no unused or recently sent invite codes.
 
 .header.code=Code:
 
--------------------------------------------------------------------------------