Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show Previous version warning #1899

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 13 additions & 5 deletions src/Controller/ArticlesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1279,10 +1279,6 @@ private function articlePageArguments(Request $request, string $id, int $version
$latest = $articleVersions[count($articleVersions) - 1];
$latestVersion = $latest->getVersion();

if ($item->getVersion() < $latestVersion) {
$infoBars[] = new InfoBar('Read the <a href="'.$this->generatePath($history).'">most recent version of this article</a>.', InfoBar::TYPE_MULTIPLE_VERSIONS);
}

if ($latest instanceof ArticlePoA) {
$infoBars[] = new InfoBar('Accepted manuscript, PDF only. Full online edition to follow.');
}
Expand Down Expand Up @@ -1692,11 +1688,23 @@ private function contentAsideArguments(array $arguments) : array
}, $publicationHistory);
}

$latest = $articleVersions[count($articleVersions) - 1];
$latestVersion = $latest->getVersion();
$isNewerVersionAvailable = $item->getVersion() < $latestVersion;

return $this->convertTo($parts['item'],
ContentAside::class, [
'metrics' => $parts['metrics'],
'timeline' => $timeline,
'relatedItem' => $parts['relatedItem']
'relatedItem' => $parts['relatedItem'],
'previousVersion' => $isNewerVersionAvailable ? new ViewModel\PreviousVersionWarning(
'A newer version is available.',
new ViewModel\Link(
'Read the latest version',
$this->generatePath($history),
'Read the latest version of this article'
)
) : null
]
);
});
Expand Down
3 changes: 2 additions & 1 deletion src/ViewModel/Converter/ContentAsideConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public function convert($object, string $viewModel = null, array $context = [])
], true),
!empty($context['metrics']) ? ViewModel\ContextualData::withMetrics($context['metrics']) : null,
!empty($context['timeline']) ? ViewModel\DefinitionList::timeline($context['timeline'], null, 'Version history') : null,
$context['relatedItem'] ?? null
$context['relatedItem'] ?? null,
$context['previousVersion'] ?? null
);
}

Expand Down
8 changes: 4 additions & 4 deletions test/Controller/ArticleControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1721,11 +1721,10 @@ public function it_displays_pdf_only_info_bar_if_no_vor_available()

$this->assertSame(200, $client->getResponse()->getStatusCode());
$this->assertCount(1, $crawler->filter('.info-bar--info'));
$this->assertCount(1, $crawler->filter('.info-bar--multiple-versions'));
$this->assertContains('Accepted manuscript, PDF only. Full online edition to follow.',
array_map('trim', $crawler->filter('.info-bar--info')->extract(['_text'])));
$this->assertContains('Read the most recent version of this article.',
array_map('trim', $crawler->filter('.info-bar--multiple-versions')->extract(['_text'])));
$this->assertContains('A newer version is available.', $crawler->filter('.previous-version-warning')->text());
$this->assertContains('Read the latest version.', $crawler->filter('.previous-version-warning')->text());
}

/**
Expand Down Expand Up @@ -1845,7 +1844,8 @@ public function it_displays_previous_versions()
$crawler = $client->request('GET', $this->getPreviousVersionUrl());

$this->assertSame(200, $client->getResponse()->getStatusCode());
$this->assertContains('Read the most recent version of this article.', array_map('trim', $crawler->filter('.info-bar')->extract(['_text'])));
$this->assertContains('A newer version is available.', $crawler->filter('.previous-version-warning')->text());
$this->assertContains('Read the latest version.', $crawler->filter('.previous-version-warning')->text());
}

/**
Expand Down