initial commit: new admin console

This commit is contained in:
Doug Bell 2010-04-01 16:52:21 -05:00
parent 743e57c8ae
commit 8f4024a4b2
3 changed files with 285 additions and 0 deletions

170
lib/WebGUI/Admin.pm Normal file
View file

@ -0,0 +1,170 @@
package WebGUI::Admin;
# The new WebGUI Admin console
use Moose;
use namespace::autoclean;
has 'session' => (
is => 'ro',
isa => 'WebGUI::Session',
required => 1,
);
#----------------------------------------------------------------------
sub getAdminPluginTemplateVars {
my $self = shift;
my $session = $self->session;
my ( $user, $url, $setting ) = $session->quick(qw(user url setting));
my $functions = $session->config->get("adminConsole");
my %processed; # title => attributes
# process the raw information from the config file
foreach my $funcId ( keys %{$functions} ) {
my $funcDef = $functions->{$funcId};
my $var = {};
# If we have a class name, we've got a new WebGUI::Admin::Plugin
if ( $funcDef->{className} ) {
my $plugin = $funcDef->{className}->new( $session, $funcId, $funcDef );
$var = {
title => $plugin->getTitle,
icon => $plugin->getIcon,
'icon.small' => $plugin->getIconSmall,
url => $plugin->getUrl,
canUse => $plugin->canUse,
};
}
# Don't know what we have (old admin console functions)
else {
# make title
my $title = $functions->{$function}{title};
WebGUI::Macro::process( $session, \$title );
# determine if the user can use this thing
my $canUse = 0;
if ( defined $functions->{$function}{group} ) {
$canUse = $user->isInGroup( $functions->{$function}{group} );
}
elsif ( defined $functions->{$function}{groupSetting} ) {
$canUse = $user->isInGroup( $setting->get( $functions->{$function}{groupSetting} ) );
}
if ( $functions->{$function}{uiLevel} > $user->profileField("uiLevel") ) {
$canUse = 0;
}
# build the attributes
$var = {
title => $title,
icon => $url->extras( "/adminConsole/" . $functions->{$function}{icon} ),
'icon.small' => $url->extras( "adminConsole/small/" . $functions->{$function}{icon} ),
url => $functions->{$function}{url},
canUse => $canUse,
};
} ## end else [ if ( $funcDef->{className...})]
# build the list of processed items
$processed{$title} = $var;
} ## end foreach my $funcId ( keys %...)
#sort the functions alphabetically
return [ map { $processed{$_} } sort keys %processed ];
} ## end sub getAdminFunctionTemplateVars
#----------------------------------------------------------------------
=head2 getClipboardTemplateVars
=cut
sub getClipboardTemplateVars {
my ( $self ) = @_;
my $session = $self->session;
my $vars = [];
my $clipboardItems = $session->asset->getAssetsInClipboard(1);
}
#----------------------------------------------------------------------
=head2 getNewContentTemplateVars
=cut
sub getNewContentTemplateVars {
my ( $self ) = @_;
my $session = $self->session;
my ( $user ) = $session->quick(qw( user ));
my $vars = [];
}
#----------------------------------------------------------------------
=head2 getVersionTagTemplateVars
=cut
sub getVersionTagTemplateVars {
my ( $self ) = @_;
my $session = $self->session;
my ( $user ) = $session->quick(qw( user ));
my $vars = [];
my $working = WebGUI::VersionTag->getWorking( $session, "nocreate" );
my $tags = WebGUI::VersionTag->getOpenTags($session);
if ( @$tags ) {
next unless $user->isInGroup( $tag->get("groupToUse") );
push @$vars, {
name => $tag->get("name"),
isWorking => ( $working && $working->getId eq $tag->getId ) ? 1 : 0,
joinUrl => $tag->getJoinUrl,
editUrl => $tag->getEditUrl,
};
}
return $vars;
}
#----------------------------------------------------------------------
=head2 www_view ( session )
Show the main Admin console wrapper
=cut
sub www_view {
my ($self) = @_;
my $session = $self->session;
my ( $user, $url ) = $session->quick(qw{ user url });
my $var;
$var->{backToSiteUrl} = $url->page;
# Add vars for AdminBar
$var->{adminPlugins} = $self->getAdminPluginTemplateVars;
$var->{versionTags} = $self->getVersionTagTemplateVars;
$var->{clipboardAssets} = $self->getClipboardTemplateVars;
$var->{newContentTabs} = $self->getNewContentTemplateVars;
# Add vars for current user
$var->{username} = $user->username;
$var->{profileUrl} = $user->getProfileUrl;
$var->{logoutUrl} = $url->page("op=auth;method=logout");
# Add vars for current version tag
if ( my $tag = WebGUI::VersionTag->getWorking( $session, "nocreate" ) ) {
$var->{tagName} = $tag->get("name");
$var->{publishUrl} = ""; #TODO
$var->{leaveUrl} = ""; #TODO
}
# Use the template in our __DATA__ block
# Use the blank style
return $output;
} ## end sub www_view
1;

View file

@ -0,0 +1,67 @@
package WebGUI::Content::Admin;
=head1 LEGAL
-------------------------------------------------------------------
WebGUI is Copyright 2001-2009 Plain Black Corporation.
-------------------------------------------------------------------
Please read the legal notices (docs/legal.txt) and the license
(docs/license.txt) that came with this distribution before using
this software.
-------------------------------------------------------------------
http://www.plainblack.com info@plainblack.com
-------------------------------------------------------------------
=cut
use strict;
=head1 NAME
Package WebGUI::Content::Admin
=head1 DESCRIPTION
The WebGUI Admin Console
=head1 SUBROUTINES
These subroutines are available from this package:
=cut
#-------------------------------------------------------------------
=head2 handler ( session )
Handle every op=admin request
1) Try to run the Admin Console plugin requested
2) Show the Admin Console wrapper
=cut
sub handler {
my ($session) = @_;
if ( $session->form->get("op") eq "admin" ) {
if ( $session->form->get("plugin") ) {
# Load the requested plugin if necessary
# Default page is "view"
# Pass control to the right page
}
else {
my $admin = WebGUI::Admin->new( $session );
return $admin->www_view;
}
}
return;
}
1;
#vim:ft=perl
__DATA__

View file

@ -322,6 +322,41 @@ sub getAssets {
#-------------------------------------------------------------------
=head2 getCommitUrl ( )
Get the URL to commit this version tag. Will check settings to see
if commit comments are on or off
=cut
sub getCommitUrl {
my ( $self ) = @_;
my $session = $self->session;
my ( $url ) = $session->quick(qw( url ));
if ($session->setting->get("skipCommitComments")) {
return $url->page("op=commitVersionTagConfirm;tagId=".$self->getId);
}
else {
return $url->page("op=commitVersionTag;tagId=".$self->getId);
}
}
#-------------------------------------------------------------------
=head2 getEditUrl ( )
Get the URL to edit this version tag
=cut
sub getEditUrl {
my ( $self ) = @_;
return $self->session->url->page( "op=editVersionTag;tagId=".$self->getId );
}
#-------------------------------------------------------------------
=head2 getId ( )
Returns the ID of this version tag.
@ -335,6 +370,19 @@ sub getId {
#-------------------------------------------------------------------
=head2 getJoinUrl ( )
Get the URL to join this version tag
=cut
sub getJoinUrl {
my ( $self ) = @_;
return $self->session->url->page( "op=setWorkingVersionTag;tagId=".$self->getId );
}
#-------------------------------------------------------------------
=head2 getOpenTags ( session )
Returns an array reference containing all the open version tag objects. This is a class method.