Templates for archive, and edit story.

Added switches and URLs for adding stories.
Fixed date problems in the date_loop.
Fixed an autocommit issue with folders when there's no currently open version tag.
This commit is contained in:
Colin Kuskie 2009-03-05 00:15:20 +00:00
parent 874fad9917
commit cff0a9ae9d
5 changed files with 52 additions and 26 deletions

View file

@ -108,16 +108,14 @@ sub definition {
fieldType => 'template', fieldType => 'template',
label => $i18n->get('template'), label => $i18n->get('template'),
hoverHelp => $i18n->get('template help'), hoverHelp => $i18n->get('template help'),
filter => 'fixId',
namespace => 'StoryArchive', namespace => 'StoryArchive',
defaultValue => '', defaultValue => 'yxD5ka7XHebPLD-LXBwJqw',
}, },
storyTemplateId => { storyTemplateId => {
tab => 'display', tab => 'display',
fieldType => 'template', fieldType => 'template',
label => $i18n->get('story template'), label => $i18n->get('story template'),
hoverHelp => $i18n->get('story template help'), hoverHelp => $i18n->get('story template help'),
filter => 'fixId',
namespace => 'Story', namespace => 'Story',
defaultValue => '', defaultValue => '',
}, },
@ -126,7 +124,6 @@ sub definition {
fieldType => 'template', fieldType => 'template',
label => $i18n->get('edit story template'), label => $i18n->get('edit story template'),
hoverHelp => $i18n->get('edit story template help'), hoverHelp => $i18n->get('edit story template help'),
filter => 'fixId',
namespace => 'Story/Edit', namespace => 'Story/Edit',
defaultValue => 'E3tzZjzhmYoNlAyP2VW33Q', defaultValue => 'E3tzZjzhmYoNlAyP2VW33Q',
}, },
@ -207,7 +204,8 @@ sub getFolder {
isHidden => 1, isHidden => 1,
}); });
$newVersionTag->commit(); $newVersionTag->commit();
$oldVersionTag->setWorking(); ##Restore the old one, if it exists
$oldVersionTag->setWorking() if $oldVersionTag;
##Get a new version of the asset from the db with the correct state ##Get a new version of the asset from the db with the correct state
$folder = WebGUI::Asset->newByUrl($session, $folderUrl); $folder = WebGUI::Asset->newByUrl($session, $folderUrl);
@ -266,6 +264,8 @@ sub view {
#This is an example of debugging code to help you diagnose problems. #This is an example of debugging code to help you diagnose problems.
#WebGUI::ErrorHandler::warn($self->get("templateId")); #WebGUI::ErrorHandler::warn($self->get("templateId"));
use Data::Dumper;
$session->log->warn(Dumper $var);
return $self->processTemplate($var, undef, $self->{_viewTemplate}); return $self->processTemplate($var, undef, $self->{_viewTemplate});
} }
@ -306,16 +306,19 @@ sub viewTemplateVariables {
if ($storyDate ne $lastStoryDate) { if ($storyDate ne $lastStoryDate) {
push @{ $var->{date_loop} }, {}; push @{ $var->{date_loop} }, {};
$datePointer = $var->{date_loop}->[-1]; $datePointer = $var->{date_loop}->[-1];
$datePointer->{epochDate} = $creationDate; $datePointer->{epochDate} = $creationDay;
$datePointer->{storyLoop} = []; $datePointer->{story_loop} = [];
$lastStoryDate = $storyDate; $lastStoryDate = $storyDate;
} }
push @{$datePointer->{storyLoop}}, { push @{$datePointer->{story_loop}}, {
url => $story->getUrl, url => $story->getUrl,
title => $story->getTitle, title => $story->getTitle,
creationDate => $creationDate creationDate => $creationDate
} }
} }
$var->{addStoryUrl} = $self->getUrl('func=add;class=WebGUI::Asset::Story');
$var->{canPostStories} = $self->canPostStories;
return 1; return 1;
} }

View file

@ -165,6 +165,12 @@ our $I18N = {
lastUpdated => 0, lastUpdated => 0,
}, },
'add a story' => {
message => q|Add a Story.|,
context => q|label for the URL to add a story to the archive.|,
lastUpdated => 0,
},
}; };
1; 1;

View file

@ -70,12 +70,15 @@ my $class = 'WebGUI::Asset::Wobject::StoryArchive';
my $loaded = use_ok($class); my $loaded = use_ok($class);
my $storage; my $storage;
my $versionTag;
SKIP: { SKIP: {
skip "Unable to load module $class", $tests unless $loaded; skip "Unable to load module $class", $tests unless $loaded;
$archive = WebGUI::Asset->getDefault($session)->addChild({className => $class}); $archive = WebGUI::Asset->getDefault($session)->addChild({className => $class, title => 'My Stories', url => '/home/mystories'});
$versionTag = WebGUI::VersionTag->getWorking($session);
$versionTag->commit;
isa_ok($archive, 'WebGUI::Asset::Wobject::StoryArchive', 'created StoryArchive'); isa_ok($archive, 'WebGUI::Asset::Wobject::StoryArchive', 'created StoryArchive');
@ -155,9 +158,15 @@ is($folder->getFirstChild->getTitle, 'First Story', '... and it is the correct c
# #
################################################################ ################################################################
my $oldFolder = $archive->getFolder(997966800); my $wgBday = 997966800;
my $tomorrow = time()+24*3600; my $oldFolder = $archive->getFolder($wgBday);
my $tomorrow = time()+24*3600;
my $newFolder = $archive->getFolder($tomorrow); my $newFolder = $archive->getFolder($tomorrow);
my ($wgBdayMorn,undef) = $session->datetime->dayStartEnd($wgBday);
my ($tomorrowMorn,undef) = $session->datetime->dayStartEnd($tomorrow);
my $story = $oldFolder->addChild({ className => 'WebGUI::Asset::Story', title => 'WebGUI is released'}); my $story = $oldFolder->addChild({ className => 'WebGUI::Asset::Story', title => 'WebGUI is released'});
$session->db->write('update asset set creationDate=997966800 where assetId=?',[$story->getId]); $session->db->write('update asset set creationDate=997966800 where assetId=?',[$story->getId]);
$story = $newFolder->addChild({ className => 'WebGUI::Asset::Story', title => "There's always tomorrow" }); $story = $newFolder->addChild({ className => 'WebGUI::Asset::Story', title => "There's always tomorrow" });
@ -174,26 +183,28 @@ KEY: foreach my $key (keys %{ $templateVars }) {
cmp_deeply( cmp_deeply(
$templateVars, $templateVars,
{ {
date_loop => [ canPostStories => 0,
addStoryUrl => '/home/mystories?func=add;class=WebGUI::Asset::Story',
date_loop => [
{ {
epochDate => 997966800, epochDate => $wgBdayMorn,
storyLoop => [ { story_loop => [ {
creationDate => 997966800, creationDate => $wgBday,
url => '/home/untitled/august_16_2001/webgui-is-released', url => '/home/mystories/august_16_2001/webgui-is-released',
title => 'WebGUI is released', title => 'WebGUI is released',
}, ], }, ],
}, },
{ {
epochDate => ignore(), epochDate => ignore(),
storyLoop => [ { story_loop => [ {
creationDate => ignore(), creationDate => ignore(),
url => re('first-story'), url => re('first-story'),
title => 'First Story', title => 'First Story',
}, ], }, ],
}, },
{ {
epochDate => $tomorrow, epochDate => $tomorrowMorn,
storyLoop => [{ story_loop => [{
creationDate => $tomorrow, creationDate => $tomorrow,
url => re('theres-always-tomorrow'), url => re('theres-always-tomorrow'),
title => "There's always tomorrow", title => "There's always tomorrow",
@ -209,6 +220,7 @@ $folder->addChild({ className => 'WebGUI::Asset::Story', title => 'Story 3'});
$folder->addChild({ className => 'WebGUI::Asset::Story', title => 'Story 4'}); $folder->addChild({ className => 'WebGUI::Asset::Story', title => 'Story 4'});
$archive->update({storiesPerPage => 3}); $archive->update({storiesPerPage => 3});
$session->user({userId => 3});
$templateVars = {}; $templateVars = {};
$archive->viewTemplateVariables($templateVars); $archive->viewTemplateVariables($templateVars);
@ -217,21 +229,24 @@ KEY: foreach my $key (keys %{ $templateVars }) {
delete $templateVars->{$key}; delete $templateVars->{$key};
} }
cmp_deeply( cmp_deeply(
$templateVars, $templateVars,
{ {
date_loop => [ canPostStories => 1,
addStoryUrl => '/home/mystories?func=add;class=WebGUI::Asset::Story',
date_loop => [
{ {
epochDate => 997966800, epochDate => $wgBdayMorn,
storyLoop => [ { story_loop => [ {
creationDate => 997966800, creationDate => $wgBday,
url => '/home/untitled/august_16_2001/webgui-is-released', url => '/home/mystories/august_16_2001/webgui-is-released',
title => 'WebGUI is released', title => 'WebGUI is released',
}, ], }, ],
}, },
{ {
epochDate => ignore(), epochDate => ignore(),
storyLoop => [ story_loop => [
{ {
creationDate => ignore(), creationDate => ignore(),
url => re('first-story'), url => re('first-story'),
@ -258,7 +273,9 @@ END {
if (defined $archive and ref $archive eq $class) { if (defined $archive and ref $archive eq $class) {
$archive->purge; $archive->purge;
} }
WebGUI::VersionTag->getWorking($session)->rollback; if ($versionTag) {
$versionTag->rollback;
}
foreach my $user ($editor, $reporter, $reader) { foreach my $user ($editor, $reporter, $reader) {
$user->delete if defined $user; $user->delete if defined $user;
} }