[vhffs-dev] [1796] Begining of cleanup in admin lists.

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


Revision: 1796
Author:   beuss
Date:     2011-05-24 07:51:53 +0200 (Tue, 24 May 2011)
Log Message:
-----------
Begining of cleanup in admin lists.

Modified Paths:
--------------
    trunk/vhffs-api/src/Vhffs/Panel/Web.pm
    trunk/vhffs-panel/admin/web/list.pl
    trunk/vhffs-panel/templates/Makefile.am

Added Paths:
-----------
    trunk/vhffs-panel/templates/admin/misc/list.tt

Removed Paths:
-------------
    trunk/vhffs-panel/templates/admin/web/part.tmpl

Modified: trunk/vhffs-api/src/Vhffs/Panel/Web.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Panel/Web.pm	2011-05-24 05:51:44 UTC (rev 1795)
+++ trunk/vhffs-api/src/Vhffs/Panel/Web.pm	2011-05-24 05:51:53 UTC (rev 1796)
@@ -100,28 +100,23 @@
 sub search {
     my ($main, $name) = @_;
 
-    my $sql;
     my @params;
     my $webs = [];
+    my $sql = 'SELECT w.servername as label, o.state, g.groupname as owner_group, u.username as owner_user '.  
+            'FROM vhffs_httpd w '.
+            'INNER JOIN vhffs_object o ON o.object_id = w.object_id '.
+            'INNER JOIN vhffs_groups g ON g.gid = o.owner_gid '.
+            'INNER JOIN vhffs_users u ON u.uid = o.owner_uid ';
 
     if( defined $name ) {
-        $sql = 'SELECT w.servername, o.state, g.groupname  FROM vhffs_httpd w INNER JOIN vhffs_object o ON o.object_id = w.object_id INNER JOIN vhffs_groups g ON g.gid = o.owner_gid WHERE w.servername LIKE ?';
+        $sql .= 'WHERE w.servername ILIKE ? ';
         push(@params, '%'.lc($name).'%');
-    } else {
-        $sql = 'SELECT w.servername, o.state, g.groupname  FROM vhffs_httpd w INNER JOIN vhffs_object o ON o.object_id = w.object_id INNER JOIN vhffs_groups g ON g.gid = o.owner_gid';
     }
 
-    my $dbh = $main->get_db_object();
-    my $sth = $dbh->prepare($sql) or return undef;
+    $sql .= 'ORDER BY label';
 
-    return undef unless($sth->execute(@params));
-
-    while(my $w = $sth->fetchrow_hashref('NAME_lc')) {
-        $w->{state} = Vhffs::Functions::status_string_from_status_id($w->{state});
-        push(@$webs, $w);
-    }
-
-    return $webs;
+    my $dbh = $main->get_db_object();
+    return $dbh->selectall_arrayref($sql, { Slice => {} }, @params);
 }
 
 sub public_search {

Modified: trunk/vhffs-panel/admin/web/list.pl
===================================================================
--- trunk/vhffs-panel/admin/web/list.pl	2011-05-24 05:51:44 UTC (rev 1795)
+++ trunk/vhffs-panel/admin/web/list.pl	2011-05-24 05:51:53 UTC (rev 1796)
@@ -34,58 +34,27 @@
 use Locale::gettext;
 
 use lib '%VHFFS_LIB_DIR%';
-use Vhffs::Panel::Main;
+use Vhffs::Panel::Admin;
 use Vhffs::Panel::Web;
 
-my $panel = new Vhffs::Panel::Main();
-exit 0 unless $panel;
-my $session = $panel->get_session;
-exit 0 unless $session;
+my $panel = new Vhffs::Panel::Admin();
 
 my $vhffs = $panel->{'vhffs'};
-my $user = $panel->{'user'};
 my $cgi = $panel->{'cgi'};
-my $templatedir = $panel->{'templatedir'};
-my $template;
 
-if( ($user->is_moderator != 1 ) && ( $user->is_admin != 1 ) )
-{
-	$template = new HTML::Template( filename => $templatedir.'/panel/misc/simplemsg.tmpl' );
-	$template->param( MESSAGE => gettext('You are not allowed to see it') );
-}
-else
-{
-	$template = new HTML::Template( filename => $templatedir.'/panel/admin/misc/list.tmpl' );
-	my $name = $cgi->param('NAME');
+my $name = $cgi->param('NAME');
 
-	if( defined( $name ) )
-	{
-		$template->param( TITLE => gettext('Search result for').': '.$name );
-	}
-	else
-	{
-		$template->param( TITLE => gettext('List of all websites') );
-	}
+my $vars = {
+    type => 'web'
+};
 
-	$template->param( TEXT_TITLE1 => gettext('Servername') );
-	$template->param( TEXT_TITLE2 => gettext('Group') );
-	$template->param( TEXT_TITLE3 => gettext('State') );
-
-	my $webs = Vhffs::Panel::Web::search( $vhffs, $name );
-	my $web;
-	if( defined $webs )
-	{
-		my $subtemplate = new HTML::Template( filename => $templatedir.'/panel/admin/web/part.tmpl', global_vars => 1 );
-		if( $user->is_admin == 1 )  {
-			$subtemplate->param( ACTION => gettext('Edit') );
-		}  else   {
-			$subtemplate->param( ACTION => gettext('Show') );
-		}
-
-		$subtemplate->param( WEBS => $webs );
-		$template->param( LIST => $subtemplate->output );
-	}
+if( defined( $name ) ) {
+    $vars->{list_title} = sprintf( gettext('Search result for % s'), $name );
+} else {
+    $vars->{list_title} = gettext('List of all websites');
 }
 
-$panel->build( $template );
-$panel->display;
+$vars->{label_title} = gettext('Servername');
+
+$vars->{list} = Vhffs::Panel::Web::search( $vhffs, $name );
+$panel->render('admin/misc/list.tt', $vars);

Modified: trunk/vhffs-panel/templates/Makefile.am
===================================================================
--- trunk/vhffs-panel/templates/Makefile.am	2011-05-24 05:51:44 UTC (rev 1795)
+++ trunk/vhffs-panel/templates/Makefile.am	2011-05-24 05:51:53 UTC (rev 1796)
@@ -52,7 +52,6 @@
 	admin/mercurial/search.tmpl \
 	admin/user/part.tmpl \
 	admin/user/search.tmpl \
-	admin/web/part.tmpl \
 	admin/web/search.tmpl \
 	admin/cron/part.tmpl \
 	admin/cron/search.tmpl \
@@ -72,6 +71,7 @@
 	acl/form.tt \
 	acl/view.tt \
 	admin/index.tt \
+	admin/misc/list.tt \
 	admin/object/edit.tt \
 	anonymous/account_created.tt \
 	anonymous/login.tt \

Added: trunk/vhffs-panel/templates/admin/misc/list.tt
===================================================================
--- trunk/vhffs-panel/templates/admin/misc/list.tt	                        (rev 0)
+++ trunk/vhffs-panel/templates/admin/misc/list.tt	2011-05-24 05:51:53 UTC (rev 1796)
@@ -0,0 +1,28 @@
+<h1>[% list_title | html %]</h1>
+
+[% IF list.size > 0 %]
+<table>
+    <thead>
+		<tr>
+			<th>[% label_title %]</th>
+			<th>[% 'Owner user' | i18n | html %]</th>
+			<th>[% 'Owner group' | i18n | html %]</th>
+			<th>[% 'State' | i18n | html %]</th>
+            <th>[% 'Preferences' | i18n | html %]</th>
+		</tr>
+    </thead>
+    <tbody>
+[% FOREACH o IN list %]
+        <tr>
+            <td>[% o.label | html %]</td>
+            <td>[% o.owner_user | html %]</td>
+            <td>[% o.owner_group | html %]</td>
+            <td>[% o.state | stringify_status | html %]</td>
+            <td><a href="/[% type %]/prefs.pl?name=[% o.label %]">[% 'Preferences' | i18n | html %]</a></td>
+        </tr>
+[% END %]
+    </tbody>
+</table>
+[% ELSE %]
+<p>[% 'No object found' | i18n | html %]
+[% END %]

Deleted: trunk/vhffs-panel/templates/admin/web/part.tmpl
===================================================================
--- trunk/vhffs-panel/templates/admin/web/part.tmpl	2011-05-24 05:51:44 UTC (rev 1795)
+++ trunk/vhffs-panel/templates/admin/web/part.tmpl	2011-05-24 05:51:53 UTC (rev 1796)
@@ -1,16 +0,0 @@
-<TMPL_LOOP NAME="WEBS">
-<tr>
-	<td>
-		<a href="http://<TMPL_VAR ESCAPE=1 NAME="SERVERNAME">"><TMPL_VAR ESCAPE=1 NAME="SERVERNAME"></a>
-	</td>
-	<td>
-		<TMPL_VAR ESCAPE=1 NAME="GROUPNAME"> 
-	</td>
-	<td>
-		<TMPL_VAR ESCAPE=1 NAME="STATE"> 
-	</td>
-	<td>
-		<a href="/web/prefs.pl?admin_menu=1&amp;name=<TMPL_VAR ESCAPE=1 NAME="SERVERNAME">"><TMPL_VAR ESCAPE=1 NAME="ACTION"></a>
-	</td>
-</tr>
-</TMPL_LOOP>


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