Adding Asset History content manager.
This commit is contained in:
parent
17c4fdbe0c
commit
8cbf232e72
6 changed files with 352 additions and 0 deletions
|
|
@ -37,6 +37,7 @@ addGroupToAddToMatrix( $session );
|
||||||
addScreenshotTemplatesToMatrix( $session );
|
addScreenshotTemplatesToMatrix( $session );
|
||||||
surveyDoAfterTimeLimit($session);
|
surveyDoAfterTimeLimit($session);
|
||||||
surveyRemoveResponseTemplate($session);
|
surveyRemoveResponseTemplate($session);
|
||||||
|
installAssetHistory($session);
|
||||||
|
|
||||||
# Passive Analytics
|
# Passive Analytics
|
||||||
pa_installLoggingTables($session);
|
pa_installLoggingTables($session);
|
||||||
|
|
@ -91,6 +92,35 @@ sub surveyRemoveResponseTemplate {
|
||||||
print "DONE!\n" unless $quiet;
|
print "DONE!\n" unless $quiet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
sub installAssetHistory {
|
||||||
|
my $session = shift;
|
||||||
|
print "\tAdding Asset History content handler... \n" unless $quiet;
|
||||||
|
##Content Handler
|
||||||
|
my $contentHandlers = $session->config->get('contentHandlers');
|
||||||
|
if (! isIn('WebGUI::Content::Handler', @{ $contentHandlers }) ) {
|
||||||
|
my @newHandlers = ();
|
||||||
|
foreach my $handler (@{ $contentHandlers }) {
|
||||||
|
push @newHandlers, $handler;
|
||||||
|
push @newHandlers, 'WebGUI::Content::AssetHistory' if
|
||||||
|
$handler eq 'WebGUI::Content::Account';
|
||||||
|
}
|
||||||
|
$session->config->set('contentHandlers', \@newHandlers);
|
||||||
|
}
|
||||||
|
##Admin Console
|
||||||
|
$session->config->addToHash('adminConsole', 'assetHistory', {
|
||||||
|
"icon" => "assets.gif",
|
||||||
|
"groupSetting" => "groupIdAdminHistory",
|
||||||
|
"uiLevel" => 5,
|
||||||
|
"url" => "^PageUrl(\"\",op=assetHistory);",
|
||||||
|
"title" => "^International(assetHistory,Asset);"
|
||||||
|
});
|
||||||
|
##Setting for custom group
|
||||||
|
$session->setting->add('groupIdAdminHistory', 12);
|
||||||
|
print "Done.\n" unless $quiet;
|
||||||
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
sub pa_installLoggingTables {
|
sub pa_installLoggingTables {
|
||||||
my $session = shift;
|
my $session = shift;
|
||||||
print "\tInstall logging tables... ";
|
print "\tInstall logging tables... ";
|
||||||
|
|
|
||||||
|
|
@ -331,6 +331,13 @@
|
||||||
"url" : "^PageUrl(\"\",op=assetManager);",
|
"url" : "^PageUrl(\"\",op=assetManager);",
|
||||||
"title" : "^International(assets,Asset);"
|
"title" : "^International(assets,Asset);"
|
||||||
},
|
},
|
||||||
|
"assetHistory" : {
|
||||||
|
"icon" : "assets.gif",
|
||||||
|
"groupSetting" : "groupIdAdminHistory",
|
||||||
|
"uiLevel" : 5,
|
||||||
|
"url" : "^PageUrl(\"\",op=assetHistory);",
|
||||||
|
"title" : "^International(assetHistory,Asset);"
|
||||||
|
},
|
||||||
"graphics" : {
|
"graphics" : {
|
||||||
"icon" : "graphics.gif",
|
"icon" : "graphics.gif",
|
||||||
"uiLevel" : 5,
|
"uiLevel" : 5,
|
||||||
|
|
@ -895,6 +902,7 @@
|
||||||
"WebGUI::Content::AssetDiscovery",
|
"WebGUI::Content::AssetDiscovery",
|
||||||
"WebGUI::Content::AjaxI18N",
|
"WebGUI::Content::AjaxI18N",
|
||||||
"WebGUI::Content::Account",
|
"WebGUI::Content::Account",
|
||||||
|
"WebGUI::Content::AssetHistory",
|
||||||
"WebGUI::Content::Operation",
|
"WebGUI::Content::Operation",
|
||||||
"WebGUI::Content::Setup",
|
"WebGUI::Content::Setup",
|
||||||
"WebGUI::Content::Shop",
|
"WebGUI::Content::Shop",
|
||||||
|
|
|
||||||
165
lib/WebGUI/Content/AssetHistory.pm
Normal file
165
lib/WebGUI/Content/AssetHistory.pm
Normal file
|
|
@ -0,0 +1,165 @@
|
||||||
|
package WebGUI::Content::AssetHistory;
|
||||||
|
|
||||||
|
=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::AssetHistory
|
||||||
|
|
||||||
|
=head1 DESCRIPTION
|
||||||
|
|
||||||
|
Give the admins an interface to view the history of assets on their site.
|
||||||
|
|
||||||
|
=head1 SYNOPSIS
|
||||||
|
|
||||||
|
use WebGUI::Content::AssetHistory;
|
||||||
|
my $output = WebGUI::Content::AssetHistory::handler($session);
|
||||||
|
|
||||||
|
=head1 SUBROUTINES
|
||||||
|
|
||||||
|
These subroutines are available from this package:
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 handler ( session )
|
||||||
|
|
||||||
|
The content handler for this package.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub handler {
|
||||||
|
my ($session) = @_;
|
||||||
|
return undef unless ($session->form->get('op') eq 'assetHistory');
|
||||||
|
my $method = $session->form->get( 'method' )
|
||||||
|
? 'www_' . $session->form->get( 'method' )
|
||||||
|
: 'www_view'
|
||||||
|
;
|
||||||
|
|
||||||
|
# Validate the method name
|
||||||
|
if ( !__PACKAGE__->can( $method ) ) {
|
||||||
|
return "Invalid method";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return __PACKAGE__->can( $method )->( $session );
|
||||||
|
}
|
||||||
|
my $output = "";
|
||||||
|
# ...
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 www_getHistoryAsJson ( )
|
||||||
|
|
||||||
|
Servers side pagination for asset history data displayed in a YUI DataTable.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub www_getHistoryAsJson {
|
||||||
|
my ($session) = @_;
|
||||||
|
return $session->privilege->insufficient
|
||||||
|
unless $session->user->isInGroup(12);
|
||||||
|
my ($db, $form) = $session->quick(qw(db form));
|
||||||
|
my $startIndex = $form->get('startIndex') || 0;
|
||||||
|
my $numberOfResults = $form->get('results') || 25;
|
||||||
|
my %goodKeys = qw/assetId 1 url 1 username 1 dateStamp 1/;
|
||||||
|
my $sortKey = $form->get('sortKey');
|
||||||
|
$sortKey = $goodKeys{$sortKey} == 1 ? $sortKey : 'dateStamp';
|
||||||
|
my $sortDir = $form->get('sortDir');
|
||||||
|
$sortDir = lc($sortDir) eq 'desc' ? 'desc' : 'asc';
|
||||||
|
my @placeholders = ();
|
||||||
|
my $sql = <<EOSQL;
|
||||||
|
select SQL_CALC_FOUND_ROWS assetHistory.*,users.username from assetHistory join users on assetHistory.userId=users.userId
|
||||||
|
EOSQL
|
||||||
|
my $keywords = $form->get("keywords");
|
||||||
|
if ($keywords ne "") {
|
||||||
|
$db->buildSearchQuery(\$sql, \@placeholders, $keywords, [qw{url assetId username}])
|
||||||
|
}
|
||||||
|
push(@placeholders, $startIndex, $numberOfResults);
|
||||||
|
$sql .= sprintf (" order by %s limit ?,?","$sortKey $sortDir");
|
||||||
|
my %results = ();
|
||||||
|
my @records = ();
|
||||||
|
my $sth = $db->read($sql, \@placeholders);
|
||||||
|
while (my $record = $sth->hashRef) {
|
||||||
|
push(@records,$record);
|
||||||
|
}
|
||||||
|
$results{'recordsReturned'} = $sth->rows()+0;
|
||||||
|
$sth->finish;
|
||||||
|
$results{'records'} = \@records;
|
||||||
|
$results{'totalRecords'} = $db->quickScalar('select found_rows()')+0; ##Convert to numeric
|
||||||
|
$results{'startIndex'} = $startIndex;
|
||||||
|
$results{'sort'} = undef;
|
||||||
|
$results{'dir'} = $sortDir;
|
||||||
|
$session->http->setMimeType('application/json');
|
||||||
|
my $json = JSON::to_json(\%results);
|
||||||
|
return $json;
|
||||||
|
}
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 www_view
|
||||||
|
|
||||||
|
YUI DataTable for browsing asset history.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub www_view {
|
||||||
|
my $session = shift;
|
||||||
|
return $session->privilege->insufficient
|
||||||
|
unless $session->user->isInGroup(12);
|
||||||
|
##YUI specific datatable CSS
|
||||||
|
my $ac = WebGUI::AdminConsole->new( $session, "assets", {
|
||||||
|
showAdminBar => 1
|
||||||
|
} );
|
||||||
|
my ($style, $url) = $session->quick(qw(style url));
|
||||||
|
$style->setLink($url->extras('/yui/build/fonts/fonts-min.css'), {rel=>'stylesheet', type=>'text/css'});
|
||||||
|
$style->setLink($url->extras('yui/build/datatable/assets/skins/sam/datatable.css'), {rel=>'stylesheet', type => 'text/CSS'});
|
||||||
|
$style->setLink($url->extras('yui/build/paginator/assets/skins/sam/paginator.css'), {rel=>'stylesheet', type => 'text/CSS'});
|
||||||
|
$style->setScript($url->extras('/yui/build/utilities/utilities.js'), {type=>'text/javascript'});
|
||||||
|
$style->setScript($url->extras('yui/build/json/json-min.js'), {type => 'text/javascript'});
|
||||||
|
$style->setScript($url->extras('yui/build/paginator/paginator-min.js'), {type => 'text/javascript'});
|
||||||
|
$style->setScript($url->extras('yui/build/datasource/datasource-min.js'), {type => 'text/javascript'});
|
||||||
|
##YUI Datatable
|
||||||
|
$style->setScript($url->extras('yui/build/datatable/datatable-min.js'), {type => 'text/javascript'});
|
||||||
|
##WebGUI YUI AssetHistory
|
||||||
|
$style->setScript( $url->extras( 'yui-webgui/build/i18n/i18n.js' ), {type => 'text/javascript'} );
|
||||||
|
$style->setScript( $url->extras('yui-webgui/build/assetHistory/assetHistory.js'), {type => 'text/javascript'});
|
||||||
|
##Default CSS
|
||||||
|
$style->setRawHeadTags('<style type="text/css"> #paging a { color: #0000de; } #search form { display: inline; } </style>');
|
||||||
|
my $i18n=WebGUI::International->new($session);
|
||||||
|
|
||||||
|
my $output;
|
||||||
|
|
||||||
|
$output .= q|
|
||||||
|
<div class="yui-skin-sam">
|
||||||
|
<div id="search"><form id="keywordSearchForm"><input type="text" name="keywords" id="keywordsField" /><input type="submit" value="|.$i18n->get(364, 'WebGUI').q|" /></form></div>
|
||||||
|
<div id="dynamicdata"></div>
|
||||||
|
</div>
|
||||||
|
<script type="text/javascript">
|
||||||
|
YAHOO.util.Event.onDOMReady( WebGUI.AssetHistory.initManager );
|
||||||
|
</script>
|
||||||
|
|;
|
||||||
|
|
||||||
|
return $ac->render( $output );
|
||||||
|
}
|
||||||
|
|
||||||
|
1;
|
||||||
|
|
||||||
|
#vim:ft=perl
|
||||||
|
|
@ -485,6 +485,7 @@ sub definition {
|
||||||
groupIdAdminGraphics
|
groupIdAdminGraphics
|
||||||
groupIdAdminGroup
|
groupIdAdminGroup
|
||||||
groupIdAdminGroupAdmin
|
groupIdAdminGroupAdmin
|
||||||
|
groupIdAdminHistory
|
||||||
groupIdAdminHelp
|
groupIdAdminHelp
|
||||||
groupIdAdminLDAPLink
|
groupIdAdminLDAPLink
|
||||||
groupIdAdminLoginHistory
|
groupIdAdminLoginHistory
|
||||||
|
|
|
||||||
|
|
@ -1190,6 +1190,12 @@ Couldn't open %-s because %-s <br />
|
||||||
context => q{Asset Manager label, as in "locked by admin"},
|
context => q{Asset Manager label, as in "locked by admin"},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
'assetHistory' => {
|
||||||
|
message => q{Asset History},
|
||||||
|
lastUpdated => 0,
|
||||||
|
context => q{Admin Console label. Shows the history of assets in this site.},
|
||||||
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
|
||||||
142
www/extras/yui-webgui/build/assetHistory/assetHistory.js
vendored
Normal file
142
www/extras/yui-webgui/build/assetHistory/assetHistory.js
vendored
Normal file
|
|
@ -0,0 +1,142 @@
|
||||||
|
/*** The WebGUI Asset History Viewer
|
||||||
|
* Requires: YAHOO, Dom, Event
|
||||||
|
* With all due credit to Doug Bell, who wrote the AssetManager. AssetHistory
|
||||||
|
* is a blatant copy/paste/modify of it.
|
||||||
|
*/
|
||||||
|
|
||||||
|
if ( typeof WebGUI == "undefined" ) {
|
||||||
|
WebGUI = {};
|
||||||
|
}
|
||||||
|
if ( typeof WebGUI.AssetHistory == "undefined" ) {
|
||||||
|
WebGUI.AssetHistory = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------
|
||||||
|
WebGUI.AssetHistory.DefaultSortedBy ( )
|
||||||
|
*/
|
||||||
|
WebGUI.AssetHistory.DefaultSortedBy = {
|
||||||
|
"key" : "dateStamp",
|
||||||
|
"dir" : YAHOO.widget.DataTable.CLASS_ASC
|
||||||
|
};
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------
|
||||||
|
WebGUI.AssetHistory.BuildQueryString ( )
|
||||||
|
*/
|
||||||
|
WebGUI.AssetHistory.BuildQueryString = function ( state, dt ) {
|
||||||
|
var query = "startIndex=" + state.pagination.recordOffset
|
||||||
|
+ ';sortDir=' + ((state.sortedBy.dir === YAHOO.widget.DataTable.CLASS_DESC) ? "DESC" : "ASC")
|
||||||
|
+ ';results=' + state.pagination.rowsPerPage
|
||||||
|
+ ';sortKey=' + state.sortedBy.key
|
||||||
|
;
|
||||||
|
return query;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------
|
||||||
|
WebGUI.AssetHistory.formatDate ( )
|
||||||
|
Format the date the asset was modified.
|
||||||
|
*/
|
||||||
|
WebGUI.AssetHistory.formatDate = function ( elCell, oRecord, oColumn, orderNumber ) {
|
||||||
|
var actionDate = new Date( 1000 * oRecord.getData('dateStamp') );
|
||||||
|
var formattedDate = YAHOO.util.Date.format(actionDate, { format: '%x %X' });
|
||||||
|
elCell.innerHTML = formattedDate;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------
|
||||||
|
WebGUI.AssetHistory.initManager ( )
|
||||||
|
Initialize the i18n interface
|
||||||
|
*/
|
||||||
|
WebGUI.AssetHistory.initManager = function (o) {
|
||||||
|
WebGUI.AssetHistory.i18n
|
||||||
|
= new WebGUI.i18n( {
|
||||||
|
namespaces : {
|
||||||
|
'WebGUI' : [
|
||||||
|
"50",
|
||||||
|
"104",
|
||||||
|
"352"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
onpreload : {
|
||||||
|
fn : WebGUI.AssetHistory.initDataTable
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
};
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------
|
||||||
|
WebGUI.AssetHistory.initDataTable ( )
|
||||||
|
Initialize the www_manage page
|
||||||
|
*/
|
||||||
|
WebGUI.AssetHistory.initDataTable = function (o) {
|
||||||
|
var historyPaginator = new YAHOO.widget.Paginator({
|
||||||
|
containers : ['pagination'],
|
||||||
|
pageLinks : 7,
|
||||||
|
rowsPerPage : 25,
|
||||||
|
template : "<strong>{CurrentPageReport}</strong> {PreviousPageLink} {PageLinks} {NextPageLink}"
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// initialize the data source
|
||||||
|
WebGUI.AssetHistory.DataSource
|
||||||
|
= new YAHOO.util.DataSource( '?op=assetHistory;method=getHistoryAsJson;',{connTimeout:30000} );
|
||||||
|
WebGUI.AssetHistory.DataSource.responseType
|
||||||
|
= YAHOO.util.DataSource.TYPE_JSON;
|
||||||
|
WebGUI.AssetHistory.DataSource.responseSchema
|
||||||
|
= {
|
||||||
|
resultsList: 'records',
|
||||||
|
fields: [
|
||||||
|
{ key: 'assetId', parser: 'string' },
|
||||||
|
{ key: 'username', parser: 'string' },
|
||||||
|
{ key: 'dateStamp', parser: 'number' },
|
||||||
|
{ key: 'title', parser: 'string' },
|
||||||
|
{ key: 'actionTaken', parser: 'string' },
|
||||||
|
{ key: 'url', parser: 'string' }
|
||||||
|
],
|
||||||
|
metaFields: {
|
||||||
|
totalRecords: "totalRecords" // Access to value in the server response
|
||||||
|
}
|
||||||
|
};
|
||||||
|
WebGUI.AssetHistory.ColumnDefs = [ // sortable:true enables sorting
|
||||||
|
{key:"assetId", label:"assetId", sortable: true},
|
||||||
|
{key:"username", label:WebGUI.AssetHistory.i18n.get('WebGUI', '50' ), sortable: true},
|
||||||
|
{key:"dateStamp", label:WebGUI.AssetHistory.i18n.get('WebGUI', '352'), sortable: true, formatter: WebGUI.AssetHistory.formatDate},
|
||||||
|
{key:"url", label:WebGUI.AssetHistory.i18n.get('WebGUI', '104'), sortable: true},
|
||||||
|
{key:"actionTaken", label:"actionTaken"}
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
// Initialize the data table
|
||||||
|
WebGUI.AssetHistory.DataTable
|
||||||
|
= new YAHOO.widget.DataTable( 'dynamicdata',
|
||||||
|
WebGUI.AssetHistory.ColumnDefs,
|
||||||
|
WebGUI.AssetHistory.DataSource,
|
||||||
|
{
|
||||||
|
initialRequest : 'startIndex=0;results=25',
|
||||||
|
dynamicData : true,
|
||||||
|
paginator : historyPaginator,
|
||||||
|
sortedBy : WebGUI.AssetHistory.DefaultSortedBy,
|
||||||
|
generateRequest : WebGUI.AssetHistory.BuildQueryString
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
WebGUI.AssetHistory.DataTable.handleDataReturnPayload = function(oRequest, oResponse, oPayload) {
|
||||||
|
oPayload.totalRecords = oResponse.meta.totalRecords;
|
||||||
|
return oPayload;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Setup the form to submit an AJAX request back to the site.
|
||||||
|
YAHOO.util.Dom.get('keywordSearchForm').onsubmit = function () {
|
||||||
|
var state = WebGUI.AssetHistory.DataTable.getState();
|
||||||
|
state.pagination.recordOffset = 0;
|
||||||
|
WebGUI.AssetHistory.DataSource.sendRequest(
|
||||||
|
'keywords=' + YAHOO.util.Dom.get('keywordsField').value + ';startIndex=0;results=25',
|
||||||
|
{
|
||||||
|
success : WebGUI.AssetHistory.DataTable.onDataReturnInitializeTable,
|
||||||
|
scope : WebGUI.AssetHistory.DataTable, argument:state
|
||||||
|
}
|
||||||
|
);
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue