StoryArchive optional sorting by title.

Fwiw, this code was written a while ago but seems to have gotten
misplaced.
This commit is contained in:
Scott Walters 2010-07-23 09:13:55 -04:00
parent 031309a1aa
commit d17d096380
4 changed files with 127 additions and 8 deletions

View file

@ -32,10 +32,10 @@ my $session = start(); # this line required
# upgrade functions go here
addSpamStopWordsToConfig($session);
alterStoryArchiveTable($session);
finish($session); # this line required
#----------------------------------------------------------------------------
# Describe what our function does
#sub exampleFunction {
@ -56,6 +56,25 @@ sub addSpamStopWordsToConfig {
print "DONE!\n" unless $quiet;
}
#----------------------------------------------------------------------------
# Describe what our function does
sub alterStoryArchiveTable {
my $session = shift;
print "\tAdd story sort order column to the StoryAcrhive table... " unless $quiet;
my $sth = $session->db->read('DESCRIBE `StoryArchive`');
while (my ($col) = $sth->array) {
if ($col eq 'storySortOrder') {
print "Skipped.\n" unless $quiet;
return;
}
}
$session->db->write("ALTER TABLE StoryArchive ADD COLUMN storySortOrder CHAR(22)");
print "DONE!\n" unless $quiet;
}
# -------------- DO NOT EDIT BELOW THIS LINE --------------------------------
#----------------------------------------------------------------------------

View file

@ -22,7 +22,7 @@ use WebGUI::Paginator;
use WebGUI::Keyword;
use WebGUI::Search;
use Class::C3;
use base qw/WebGUI::AssetAspect::RssFeed WebGUI::Asset::Wobject/;
use base qw/WebGUI::AssetAspect::RssFeed WebGUI::Asset::Wobject WebGUI::AssetAspect::Installable/;
use File::Path;
use constant DATE_FORMAT => '%c_%D_%y';
@ -164,6 +164,17 @@ sub definition {
label => $i18n->get('approval workflow'),
hoverHelp => $i18n->get('approval workflow help'),
},
storySortOrder => {
fieldType => "selectBox",
tab => 'display',
defaultValue => 'Chronologically',
options => {
Alphabetically => $i18n->get('alphabetically'),
Chronologically => $i18n->get('chronologically')
},
label => $i18n->get('sortAlphabeticallyChronologically'),
hoverHelp => $i18n->get('sortAlphabeticallyChronologically description'),
},
);
push(@{$definition}, {
assetName=>$i18n->get('assetName'),
@ -537,11 +548,12 @@ sub viewTemplateVariables {
$p = $search->getPaginatorResultSet($self->getUrl, $self->get('storiesPerPage'));
}
else {
$var->{mode} = 'view';
##Only return assetIds, we'll build data for the things that are actually displayed.
$var->{mode} = 'view';
my $orderBy = $self->get('storySortOrder') eq 'Alphabetically' ? 'menuTitle, lineage' : 'creationDate desc, lineage';
my $storySql = $self->getLineageSql(['descendants'],{
excludeClasses => ['WebGUI::Asset::Wobject::Folder'],
orderByClause => 'creationDate desc, lineage',
orderByClause => $orderBy,
});
my $storiesPerPage = $self->get('storiesPerPage');
if ($exporting) {
@ -551,6 +563,7 @@ sub viewTemplateVariables {
$p = WebGUI::Paginator->new($session, $self->getUrl, $storiesPerPage);
$p->setDataByQuery($storySql);
}
my $storyIds = $p->getPageData();
if (! $exporting ) {
##Pagination variables aren't useful in export mode

View file

@ -333,6 +333,30 @@ our $I18N = {
lastUpdated => 0,
},
'sortAlphabeticallyChronologically' => {
message => q|Sort Order|,
context => q|Label in the edit screen|,
lastUpdated => 1276631190,
},
'sortAlphabeticallyChronologically description' => {
message => q|Set messages to appear in order of publish date or alphabetically by title|,
context => q|Tooltip in the edit screen|,
lastUpdated => 1276631190,
},
'alphabetically' => {
message => q|Alphabetically|,
context => q|Select option in the edit screen|,
lastUpdated => 1276631190,
},
'chronologically' => {
message => q|Chronologically|,
context => q|Select option in the edit screen|,
lastUpdated => 1276631190,
},
};
1;

View file

@ -63,7 +63,7 @@ $canPostMaker->prepare({
fail => [1, $reader ],
});
my $tests = 51
my $tests = 52
+ $canPostMaker->plan
;
plan tests => 1
@ -679,7 +679,70 @@ $archive->update({ url => '/home/mystories.arch' });
is($archive->getKeywordStaticURL('bar'), '/home/mystories/keyword_bar.html', '... correct URL with file extension');
$archive->update({ url => '/home/mystories' });
}
################################################################
#
# sortOrder
#
################################################################
my $aaa_child = $archive->addChild({className => 'WebGUI::Asset::Story', title => 'Aaaa'}, @skipAutoCommit);
my $zzz_child = $archive->addChild({className => 'WebGUI::Asset::Story', title => 'Zzzz'}, @skipAutoCommit);
WebGUI::Test->addToCleanup($aaa_child);
WebGUI::Test->addToCleanup($zzz_child);
$archive->update({storiesPerPage => 25, storySortOrder => 'Alphabetically' });
$tag1 = WebGUI::VersionTag->getWorking($session);
$tag1->commit;
WebGUI::Test->addToCleanup($tag1);
$templateVars = $archive->viewTemplateVariables();
cmp_deeply (
$templateVars->{date_loop},
[
{
'story_loop' => [
{
'creationDate' => ignore(),
'deleteIcon' => ignore(),
'editIcon' => ignore(),
'url' => re('aaaa'),
'title' => 'Aaaa'
},
ignore(),
ignore(),
ignore(),
ignore(),
],
'epochDate' => ignore(),
},
{
'story_loop' => ignore(),
'epochDate' => $wgBdayMorn,
},
{
'story_loop' => ignore(),
'epochDate' => $yesterdayMorn,
},
{
'story_loop' => [
{
'creationDate' => ignore(),
'deleteIcon' => ignore(),
'editIcon' => ignore(),
'url' => re('zzzz'),
'title' => 'Zzzz'
},
],
'epochDate' => ignore(),
},
],
'viewTemplateVariables: sorted by story title'
);
} ## end SKIP block
$creationDateSth->finish;