Refactoring the button into a partial

This commit is contained in:
maximest-pierre 2018-04-09 21:46:04 -04:00 committed by Maxime St-Pierre
parent 77a8ea52f7
commit 42a59116f6
4 changed files with 74 additions and 49 deletions

View file

@ -29,28 +29,18 @@ class DownloadActions extends Actions
public static function executeGet()
{
$osChoices = OS::getAll();
$os = static::guessOs();
if ($os && isset($osChoices[$os]))
{
$os = static::guessOS();
if(isset($os) && isset($osChoices[$os])){
list($uri, $osTitle, $osIcon, $buttonLabel, $analyticsLabel) = $osChoices[$os];
$release = GitHub::getAppRelease();
$asset = GitHub::getAppAsset($os);
return ['download/get', [
'analyticsLabel' => $analyticsLabel,
'buttonLabel' => $buttonLabel,
'downloadUrl' => $asset ? $asset['browser_download_url'] : null,
'isAuto' => Request::getParam('auto'),
'os' => $os,
'osTitle' => $osTitle,
'osIcon' => $osIcon,
'releaseTimestamp' => $release ? strtotime($release['created_at']) : null,
'size' => $asset ? $asset['size'] / ( 1024 * 1024 ) : 0, //bytes -> MB
'version' => $release ? $release['name'] : null,
]];
$asset = Github::getAppAsset($os);
$param = ['osTitle' => $osTitle, 'osIcon' => $osIcon, 'os' => $os, 'downloadUrl' => $asset ? $asset['browser_download_url'] : null];
return ['download/get', $param];
}
else{
return ['download/get-no-os'];
}
return ['download/get-no-os'];
}
public static function prepareListPartial(array $vars)
@ -113,4 +103,32 @@ class DownloadActions extends Actions
return $email;
}
public static function prepareDownloadButtonPartial(array $vars)
{
$osChoices = OS::getAll();
$os = static::guessOS();
if ($os && isset($osChoices[$os])) {
list($uri, $osTitle, $osIcon, $buttonLabel, $analyticsLabel) = $osChoices[$os];
$release = Github::getAppRelease();
$asset = Github::getAppAsset($os);
$vars = $vars + [
'analyticsLabel' => $analyticsLabel,
'buttonLabel' => $buttonLabel,
'downloadUrl' => $asset ? $asset['browser_download_url'] : null,
'os' => $os,
'osTitle' => $osTitle,
'osIcon' => $osIcon,
'releaseTimestamp' => $release ? strtotime($release['created_at']) : null,
'size' => $asset ? $asset['size'] / (1024 * 1024) : 0, //bytes -> MB
'version' => $release ? $release['name'] : null,
'isAuto' => Request::getParam('auto'),
];
}
return $vars;
}
}

View file

@ -0,0 +1,32 @@
<?php if ($downloadUrl): ?>
<a class="btn-<?php echo $buttonStyle?> btn-large"
download
href="<?php echo $downloadUrl ?>"
id="get-download-btn"
data-facebook-track="1"
data-analytics-category="Sign Up"
data-analytics-action="Download"
data-analytics-label="<?php echo $analyticsLabel ?>"
><?php echo $buttonLabel ?></a>
<?php if ($isAuto): ?>
<?php js_start() ?>
var anchor = document.getElementById('get-download-btn');
ga('send', 'event', anchor.getAttribute('data-analytics-category'), anchor.getAttribute('data-analytics-action'), anchor.getAttribute('data-analytics-label'));
setTimeout(function() { window.location = anchor.getAttribute('href'); }, 500);
<?php js_end() ?>
<?php endif ?>
<br/>
<span class="meta"> Latest Version :
<?php echo $version ?>, Download Size :
<?php echo number_format($size, 1) ?> MB,
built on <?php echo date('F d', $releaseTimestamp) ?>
at <?php echo date('H:i:s', $releaseTimestamp) ?> UTC
</span>
<div class="meta">
<?php if ($os === OS::OS_LINUX): ?>
{{download.works}}
<?php endif ?>
</div>
<?php else: ?>
<a href="/get" class="btn-primary btn-large spacer1">Download LBRY</a><BR>
<?php endif ?>

View file

@ -2,7 +2,6 @@
<?php Response::addMetaImage(Request::getHostAndProto() . '/img/lbry-ui.png') ?>
<?php NavActions::setNavUri('/get') ?>
<?php echo View::render('nav/_header', ['isDark' => false]) ?>
<main class="column-fluid">
<div class="span7">
<div class="cover cover-dark cover-dark-grad content content-stretch content-dark">
@ -15,35 +14,12 @@
</p>
<div class="text-center">
<p>
<a class="btn-alt btn-large"
download
href="<?php echo $downloadUrl ?>"
id="get-download-btn"
data-facebook-track="1"
data-analytics-category="Sign Up"
data-analytics-action="Download"
data-analytics-label="<?php echo $analyticsLabel ?>"
><?php echo $buttonLabel ?></a>
<?php if ($isAuto): ?>
<?php js_start() ?>
var anchor = document.getElementById('get-download-btn');
ga('send', 'event', anchor.getAttribute('data-analytics-category'), anchor.getAttribute('data-analytics-action'), anchor.getAttribute('data-analytics-label'));
setTimeout(function() { window.location = anchor.getAttribute('href'); }, 500);
<?php js_end() ?>
<?php endif ?>
<br/>
<span class="meta"> Latest Version :
<?php echo $version ?>, Download Size :
<?php echo number_format($size, 1) ?> MB,
built on <?php echo date('F d', $releaseTimestamp) ?>
at <?php echo date('H:i:s', $releaseTimestamp) ?>
</span>
<?php echo View::Render('download/_downloadButton', ['buttonStyle'=>'alt',])?>
<div class="meta">
Like source code? Go <a href="https://github.com/lbryio/lbry-app" class="link-primary">here</a>.<P><P>
</div>
</p>
<div class="meta">
<?php if ($os === OS::OS_LINUX): ?>
{{download.works}}
<?php endif ?>
Like source code? Go <a href="https://github.com/lbryio/lbry-app" class="link-primary">here</a>.<P><P>
<img src="https://spee.ch/5a3e08d52dd2d7cb1c63a480b45dea8b4679cf01/lbryget-gif-mastertest.gif" />
</div>
</div>

View file

@ -15,7 +15,6 @@
<h3 class="cover-subtitle cover-title-flat">Hollywood films, college lessons, amazing streamers and more are on the first media network ruled by <em>you</em>.</h3>
</div>
<div class="spacer2 text-center">
<a href="/get" class="btn-primary btn-large spacer1">Download LBRY</a><BR>
</div>
<?php echo View::render('download/_downloadButton', ['buttonStyle' => 'primary',])?>
</div>
</main>