rfe #12016: add more functionality to story_loop
This commit is contained in:
parent
61245baaaa
commit
82c6c58958
3 changed files with 66 additions and 21 deletions
|
|
@ -1,4 +1,5 @@
|
|||
7.10.7
|
||||
- rfe #12016: add more functionality to story_loop
|
||||
- Added a Preview button the the Template asset's edit page
|
||||
- fixed #12009: Export JS errors in IE7
|
||||
- added #11968: use the language override in the registration form (Jukka Raimovaara / Mentalhouse Oy)
|
||||
|
|
|
|||
|
|
@ -193,32 +193,43 @@ sub viewTemplateVariables {
|
|||
rowsPerPage => $numberOfStories,
|
||||
});
|
||||
my $storyIds = $p->getPageData();
|
||||
$var->{story_loop} = [];
|
||||
|
||||
my $icon = $session->icon;
|
||||
my $userUiLevel = $session->user->profileField("uiLevel");
|
||||
my $uiLevels = $session->config->get('assetToolbarUiLevel');
|
||||
my $i18n = WebGUI::International->new($session);
|
||||
my $url = $session->url;
|
||||
|
||||
##Only build objects for the assets that we need
|
||||
STORY: foreach my $storyId (@{ $storyIds }) {
|
||||
my $story = WebGUI::Asset->new($session, $storyId->{assetId}, $storyId->{className}, $storyId->{revisionDate});
|
||||
next STORY unless $story;
|
||||
my $storyVars = {
|
||||
url => ( $exporting
|
||||
? $story->getUrl
|
||||
: $session->url->append($self->getUrl, 'func=viewStory;assetId='.$storyId->{assetId}) ),
|
||||
title => $story->getTitle,
|
||||
creationDate => $story->get('creationDate'),
|
||||
};
|
||||
if ($story->canEdit && $userUiLevel >= $uiLevels->{delete} && !$exporting) {
|
||||
$storyVars->{deleteIcon} = $icon->delete('func=delete', $story->get('url'), $i18n->get(43));
|
||||
$var->{story_loop} = [
|
||||
map {
|
||||
my $v = $_->viewTemplateVariables;
|
||||
if ($exporting) {
|
||||
$v->{url} = $_->getUrl;
|
||||
}
|
||||
else {
|
||||
my $params = "func=viewStory;assetId=$v->{assetId}";
|
||||
my $rawUrl = $v->{url};
|
||||
$v->{url} = $url->append($self->getUrl, $params);
|
||||
if ($v->{canEdit}) {
|
||||
if ($userUiLevel >= $uiLevels->{delete}) {
|
||||
$v->{deleteIcon} = $icon->delete('func=delete', $rawUrl, $i18n->get(43));
|
||||
}
|
||||
if ($userUiLevel >= $uiLevels->{edit}) {
|
||||
$v->{editIcon} = $icon->edit('func=edit', $rawUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
$v;
|
||||
}
|
||||
if ($story->canEdit && $userUiLevel >= $uiLevels->{edit} && !$exporting) {
|
||||
$storyVars->{editIcon} = $icon->edit('func=edit', $story->get('url'));
|
||||
grep { $_ }
|
||||
map {
|
||||
WebGUI::Asset->new(
|
||||
$session, @{ $_ }{ qw( assetId className revisionDate ) }
|
||||
)
|
||||
}
|
||||
push @{$var->{story_loop}}, $storyVars;
|
||||
}
|
||||
@{ $storyIds }
|
||||
];
|
||||
|
||||
if (@{ $storyIds }) {
|
||||
my $topStoryData = $storyIds->[0];
|
||||
|
|
|
|||
|
|
@ -92,6 +92,39 @@ addToCleanup($versionTag);
|
|||
#
|
||||
################################################################
|
||||
|
||||
# When it's okay that the variables we get will have extra keys and
|
||||
# values beyond what we're checking for, we'll use this function.
|
||||
sub cmp_variable_loop {
|
||||
my ($got, $expected, $name) = @_;
|
||||
local $Test::Builder::Level = $Test::Builder::Level + 1;
|
||||
my $sg = @$got;
|
||||
my $se = @$expected;
|
||||
unless (@$got == @$expected) {
|
||||
fail($name);
|
||||
diag(<<EOM);
|
||||
Arrayrefs are not the same length.
|
||||
got : $sg
|
||||
expect : $se
|
||||
EOM
|
||||
return 0;
|
||||
}
|
||||
|
||||
my $failed;
|
||||
for my $i (0..$#$got) {
|
||||
my $g = $got->[$i];
|
||||
my $e = $expected->[$i];
|
||||
my ($ok, $stack) = Test::Deep::cmp_details($g, superhashof($e));
|
||||
unless ($ok) {
|
||||
unless ($failed) {
|
||||
fail($name);
|
||||
$failed = 1;
|
||||
}
|
||||
diag(Test::Deep::deep_diag($stack));
|
||||
}
|
||||
}
|
||||
return $failed ? 0 : pass($name);
|
||||
}
|
||||
|
||||
my $templateVars;
|
||||
$templateVars = $topic->viewTemplateVariables();
|
||||
|
||||
|
|
@ -104,7 +137,7 @@ cmp_deeply(
|
|||
}),
|
||||
'viewTemplateVars: RSS and Atom feed template variables'
|
||||
);
|
||||
cmp_deeply(
|
||||
cmp_variable_loop(
|
||||
$templateVars->{story_loop},
|
||||
[
|
||||
{
|
||||
|
|
@ -132,7 +165,7 @@ ok(! $templateVars->{standAlone}, 'viewTemplateVars: not in standalone mode');
|
|||
|
||||
$topic->{_standAlone} = 1;
|
||||
$templateVars = $topic->viewTemplateVariables();
|
||||
cmp_deeply(
|
||||
cmp_variable_loop(
|
||||
$templateVars->{story_loop},
|
||||
[
|
||||
{
|
||||
|
|
@ -239,7 +272,7 @@ $topic->update({
|
|||
storiesShort => 3,
|
||||
});
|
||||
$templateVars = $topic->viewTemplateVariables;
|
||||
cmp_deeply(
|
||||
cmp_variable_loop(
|
||||
$templateVars->{story_loop},
|
||||
[
|
||||
{
|
||||
|
|
@ -321,7 +354,7 @@ $topic->update( { storySortOrder => 'Alphabetically' } );
|
|||
|
||||
$templateVars = $topic->viewTemplateVariables();
|
||||
|
||||
cmp_deeply(
|
||||
cmp_variable_loop(
|
||||
[
|
||||
{
|
||||
title => $templateVars->{topStoryTitle},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue