[vhffs-dev] [1333] Added new all-groups part (yes last commit was a long time ago but I 'm not dead)

[ Thread Index | Date Index | More vhffs.org/vhffs-dev Archives ]


Revision: 1333
Author:   beuss
Date:     2009-02-06 20:47:48 +0100 (Fri, 06 Feb 2009)

Log Message:
-----------
Added new all-groups part (yes last commit was a long time ago but I'm not dead)

Modified Paths:
--------------
    branches/vhffs-design/vhffs-api/src/Vhffs/Panel/Commons.pm
    branches/vhffs-design/vhffs-api/src/Vhffs/Panel/Group.pm
    branches/vhffs-design/vhffs-api/src/Vhffs/Panel/Public.pm
    branches/vhffs-design/vhffs-public/allgroups.pl
    branches/vhffs-design/vhffs-public/group.pl
    branches/vhffs-design/vhffs-public/groupsearch.pl
    branches/vhffs-design/vhffs-public/templates/Makefile.am

Added Paths:
-----------
    branches/vhffs-design/vhffs-public/templates/common/error.tt
    branches/vhffs-design/vhffs-public/templates/content/all-groups.tt


Modified: branches/vhffs-design/vhffs-api/src/Vhffs/Panel/Commons.pm
===================================================================
--- branches/vhffs-design/vhffs-api/src/Vhffs/Panel/Commons.pm	2009-02-01 02:27:14 UTC (rev 1332)
+++ branches/vhffs-design/vhffs-api/src/Vhffs/Panel/Commons.pm	2009-02-06 19:47:48 UTC (rev 1333)
@@ -136,6 +136,10 @@
     }
 }
 
+=head2 get_pager
+	get_pager($current_page, $total, $item_per_page, $url, $url_params)
+=cut
+
 sub get_pager {
 	my ($current_page, $total, $ipp, $slider_size, $url, $url_params) = @_;
 	my $last_page = int( ($total + $ipp - 1 ) / $ipp);

Modified: branches/vhffs-design/vhffs-api/src/Vhffs/Panel/Group.pm
===================================================================
--- branches/vhffs-design/vhffs-api/src/Vhffs/Panel/Group.pm	2009-02-01 02:27:14 UTC (rev 1332)
+++ branches/vhffs-design/vhffs-api/src/Vhffs/Panel/Group.pm	2009-02-06 19:47:48 UTC (rev 1333)
@@ -222,8 +222,12 @@
     my ($main, $letter, $starting, $count) = @_;
     my @params;
 
-    my $select_clause = 'SELECT g.gid, g.groupname, g.realname, o.description';
-    my $sql = ' FROM vhffs_groups g LEFT OUTER JOIN vhffs_users u ON u.username=g.groupname INNER JOIN vhffs_object o ON o.object_id=g.object_id WHERE o.state=? AND u.username IS NULL';
+    my $select_clause = 'SELECT g.gid, g.groupname, g.realname, o.description, owner.username as owner_name';
+    my $sql = ' FROM vhffs_groups g '.
+    	'LEFT OUTER JOIN vhffs_users u ON u.username=g.groupname '.
+    	'INNER JOIN vhffs_object o ON o.object_id=g.object_id '.
+    	'INNER JOIN vhffs_users owner ON owner.uid = o.owner_uid '.
+    	'WHERE o.state=? AND u.username IS NULL';
     push @params, Vhffs::Constants::ACTIVATED;
     if(defined $letter) {
         $sql .=  ' AND SUBSTR(g.groupname, 1, 1) = ?';

Modified: branches/vhffs-design/vhffs-api/src/Vhffs/Panel/Public.pm
===================================================================
--- branches/vhffs-design/vhffs-api/src/Vhffs/Panel/Public.pm	2009-02-01 02:27:14 UTC (rev 1332)
+++ branches/vhffs-design/vhffs-api/src/Vhffs/Panel/Public.pm	2009-02-06 19:47:48 UTC (rev 1333)
@@ -55,13 +55,25 @@
 sub render {
 	my ($self, $file, $vars) = @_;
 	
+	# TODO Should be in parent class when Template::Toolkit switch is over
 	my $create_vars = {
 		INCLUDE_PATH => $self->{templatedir}.'/public/',
 		FILTERS => {
 			i18n => \&gettext,
 			mail => sub {
 				return Vhffs::Functions::obfuscate_email($self->{vhffs}, $_[0]);
-			}
+			},
+			# Format filter accept only one argument
+			# pretty_print can 'sprintf' anything, use it as
+			# [% '%s is €%d' | pretty_print(article, price)]
+			pretty_print => [sub {
+				my $context = shift;
+				my @args = @_;
+				return sub {
+					my $format = shift;
+					return sprintf($format, @args);
+				}
+			}, 1]
 		}
 	};
 	

Modified: branches/vhffs-design/vhffs-public/allgroups.pl
===================================================================
--- branches/vhffs-design/vhffs-public/allgroups.pl	2009-02-01 02:27:14 UTC (rev 1332)
+++ branches/vhffs-design/vhffs-public/allgroups.pl	2009-02-06 19:47:48 UTC (rev 1333)
@@ -33,28 +33,21 @@
 use utf8;
 
 use POSIX qw(locale_h);
-use CGI;
 use locale;
 use Locale::gettext;
 
 use lib '%VHFFS_LIB_DIR%';
 use Vhffs::Panel::Commons;
 use Vhffs::Panel::Group;
-use Vhffs::Panel::Main;
-use Vhffs::Panel::Template;
+use Vhffs::Panel::Public;
 
-my $panel = new Vhffs::Panel::Main();
-exit 0 unless $panel;
+my $panel = new Vhffs::Panel::Public();
+my $vhffs = $panel->{vhffs};
+my $cgi = $panel->{cgi};
 
-my $vhffs = $panel->{'vhffs'};
-my $cgi = $panel->{'cgi'};
-my $templatedir = $panel->{'templatedir'};
-
-$panel->check_public();
-
 my $letter = $cgi->param('letter');
 my $used_letters = Vhffs::Panel::Group::get_used_letters($vhffs);
-$letter = $used_letters->[0]{letter} unless(defined $letter || !defined $used_letters->[0]);
+$letter = $used_letters->[0]{letter} unless(defined $letter || !defined $used_letters->[0]{letter});
 undef $letter if( $letter eq 'all');
 
 my $page = $cgi->param('page');
@@ -62,17 +55,14 @@
 my $per_page_count = 10;
 
 my $result = Vhffs::Panel::Group::get_groups_starting_with( $vhffs , $letter, ($page - 1) *  $per_page_count, $per_page_count);
-my $template = new Vhffs::Panel::Template( filename => $templatedir."/public/groupslist.tmpl", die_on_bad_params => 0, loop_context_vars => 1 );
+my $pager = Vhffs::Panel::Commons::get_pager($page, $result->{total_count}, $per_page_count, 5, $panel->{url}, {
+	'letter' => defined($letter) ? $letter : 'all'
+});
 
-my $hostname = $vhffs->get_config->get_host_name;
+my $vars = {
+	pager => $pager,
+	groups => $result->{data},
+	letters => $used_letters
+};
 
-Vhffs::Panel::Commons::paginate($template, $page, $result->{total_count}, $per_page_count, { letter => (defined($letter) ? $letter : 'all') });
-
-$template->param( URL_PANEL => $vhffs->get_config->get_panel->{'url'} );
-$template->param( TEXT_TITLE => sprintf( gettext("All groups on %s") , $hostname ) );
-$template->param( LETTERS => $used_letters );
-$template->param( ALL => gettext('All') );
-$template->param( GROUPS => $result->{data} );
-
-$panel->light( $template );
-$panel->display;
+$panel->render('content/all-groups.tt', $vars);

Modified: branches/vhffs-design/vhffs-public/group.pl
===================================================================
--- branches/vhffs-design/vhffs-public/group.pl	2009-02-01 02:27:14 UTC (rev 1332)
+++ branches/vhffs-design/vhffs-public/group.pl	2009-02-06 19:47:48 UTC (rev 1333)
@@ -47,8 +47,23 @@
 my $config = $vhffs->get_config();
 
 my $groupname = $cgi->param('name');
+
+unless(defined $groupname) {
+	$panel->render('common/error.tt', {
+		message => gettext('CGI Error')
+	});
+	exit(0);
+}
+
 my $group = Vhffs::Group::get_by_groupname($panel->{vhffs}, $groupname);
-# TODO undefined groupname or group not found.
+
+unless(defined $group) {
+	$panel->render('common/error.tt', {
+		message => gettext('Group not found')
+	});
+	exit(0);
+}
+
 my $tag_categories = $group->get_tags(Vhffs::Constants::TAG_VISIBILITY_PUBLIC); 
 
 my $vars = {

Modified: branches/vhffs-design/vhffs-public/groupsearch.pl
===================================================================
--- branches/vhffs-design/vhffs-public/groupsearch.pl	2009-02-01 02:27:14 UTC (rev 1332)
+++ branches/vhffs-design/vhffs-public/groupsearch.pl	2009-02-06 19:47:48 UTC (rev 1333)
@@ -72,10 +72,16 @@
 my $page = defined($cgi->param('page')) ? int($cgi->param('page')) : 1;
 
 my ($groups, $count) = Vhffs::Panel::Group::public_search($panel->{vhffs}, $groupname, $description, \@included_tags_ids, \@excluded_tags_ids, $page - 1);
+
+if(scalar(@$groups) == 0) {
+	$panel->render('common/error.tt', {
+		message => gettext('No group found')
+	});
+	exit(0);
+}
+
 my $pager = Vhffs::Panel::Commons::get_pager($page, $count, 10, 5, $panel->{url}, { groupname => $groupname, description => $description, included_tags => \@included_tags_ids, excluded_tags => \@excluded_tags_ids});
 
-# TODO No group found
-
 my $vars = {
 	groups => $groups,
 	gs_title => gettext( 'Search results' ),

Modified: branches/vhffs-design/vhffs-public/templates/Makefile.am
===================================================================
--- branches/vhffs-design/vhffs-public/templates/Makefile.am	2009-02-01 02:27:14 UTC (rev 1332)
+++ branches/vhffs-design/vhffs-public/templates/Makefile.am	2009-02-06 19:47:48 UTC (rev 1333)
@@ -1,7 +1,9 @@
 publictemplatesdir = @TEMPLATESDIR@/public
 nobase_dist_publictemplates_DATA = \
 	banner.tmpl \
+	common/error.tt \
 	common/pager.tt \
+	content/all-groups.tt \
 	content/last-groups.tt \
 	content/group-details.tt \
 	content/groupsearch-form.tt \

Added: branches/vhffs-design/vhffs-public/templates/common/error.tt
===================================================================
--- branches/vhffs-design/vhffs-public/templates/common/error.tt	                        (rev 0)
+++ branches/vhffs-design/vhffs-public/templates/common/error.tt	2009-02-06 19:47:48 UTC (rev 1333)
@@ -0,0 +1 @@
+<p class="error">[% message %]</p>
\ No newline at end of file

Added: branches/vhffs-design/vhffs-public/templates/content/all-groups.tt
===================================================================
--- branches/vhffs-design/vhffs-public/templates/content/all-groups.tt	                        (rev 0)
+++ branches/vhffs-design/vhffs-public/templates/content/all-groups.tt	2009-02-06 19:47:48 UTC (rev 1333)
@@ -0,0 +1,16 @@
+<div class="all-groups">
+<h1>[% 'All groups' | i18n %]</h1>
+[% INCLUDE common/pager.tt pager=pager%]
+
+<div class="pages-tabs">
+[<a href="/allgroups.pl?letter=all">[% 'All' | i18n%]</a>]
+[% title_str = '%s (%d groups)' | i18n %]
+[% FOREACH l = letters %]
+[<a href="/allgroups.pl?letter=[% l.letter %]" title="[% title_str | pretty_print(l.letter, l.count) %]">[% l.letter %]</a>]&nbsp;
+[% END %]
+</div>
+
+[% FOREACH g = groups %]
+[% INCLUDE 'parts/group-general.tt' %]
+[% END %]
+</div>


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/