From d17d096380a7a1ee0e43dbf383d1b9a70fd7aeab Mon Sep 17 00:00:00 2001 From: Scott Walters Date: Fri, 23 Jul 2010 09:13:55 -0400 Subject: [PATCH] StoryArchive optional sorting by title. Fwiw, this code was written a while ago but seems to have gotten misplaced. --- docs/upgrades/upgrade_7.9.9-7.9.10.pl | 25 ++++++- lib/WebGUI/Asset/Wobject/StoryArchive.pm | 19 +++++- lib/WebGUI/i18n/English/Asset_StoryArchive.pm | 24 +++++++ t/Asset/Wobject/StoryArchive.t | 67 ++++++++++++++++++- 4 files changed, 127 insertions(+), 8 deletions(-) diff --git a/docs/upgrades/upgrade_7.9.9-7.9.10.pl b/docs/upgrades/upgrade_7.9.9-7.9.10.pl index 4271a02e9..2c4d1e3e0 100644 --- a/docs/upgrades/upgrade_7.9.9-7.9.10.pl +++ b/docs/upgrades/upgrade_7.9.9-7.9.10.pl @@ -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 -------------------------------- #---------------------------------------------------------------------------- diff --git a/lib/WebGUI/Asset/Wobject/StoryArchive.pm b/lib/WebGUI/Asset/Wobject/StoryArchive.pm index c860f24e4..d5552e5d4 100644 --- a/lib/WebGUI/Asset/Wobject/StoryArchive.pm +++ b/lib/WebGUI/Asset/Wobject/StoryArchive.pm @@ -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 diff --git a/lib/WebGUI/i18n/English/Asset_StoryArchive.pm b/lib/WebGUI/i18n/English/Asset_StoryArchive.pm index 321e6e349..a6588e011 100644 --- a/lib/WebGUI/i18n/English/Asset_StoryArchive.pm +++ b/lib/WebGUI/i18n/English/Asset_StoryArchive.pm @@ -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; diff --git a/t/Asset/Wobject/StoryArchive.t b/t/Asset/Wobject/StoryArchive.t index 2268768e6..26735f716 100644 --- a/t/Asset/Wobject/StoryArchive.t +++ b/t/Asset/Wobject/StoryArchive.t @@ -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;