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

New release notification on dashboard #175

Merged
merged 3 commits into from
Jun 10, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions src/assetbundles/src/img/right-arrow.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions src/controllers/WidgetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
use acclaro\translations\services\repository\FileRepository;
use acclaro\translations\services\repository\SiteRepository;
use acclaro\translations\assetbundles\RecentlyModifiedAssets;
use craft\models\Updates as UpdatesModel;

// Widget Classes
use acclaro\translations\widgets\News;
Expand Down Expand Up @@ -116,6 +117,8 @@ public function actionIndex()
}
}

$pluginHandle = "translations";

$view = $this->getView();
$namespace = $view->getNamespace();

Expand Down Expand Up @@ -183,6 +186,9 @@ public function actionIndex()
}
}

// Check For Plugin Updates
$variables['updates'] = $this->hasUpdate($pluginHandle);

// Register Dashboard Assets
$view->registerAssetBundle(DashboardAssets::class);
$view->registerJs('window.translationsdashboard = new Craft.Translations.Dashboard(' . Json::encode($widgetTypeInfo) . ');');
Expand Down Expand Up @@ -474,6 +480,25 @@ public function actionGetRecentlyModified($limit = 0)
// Public Methods
// =========================================================================

/**
* Check for Latest Updates
*
* @return bool
*/
public function hasUpdate($pluginHandle): bool
{
$hasUpdate = false;
try {
$pluginInfo = Craft::$app->getPlugins()->getPluginInfo($pluginHandle);

$hasUpdate = $pluginInfo['upgradeAvailable'];
} catch (\Throwable $th) {
Craft::warning("Error getting plugin updates", $pluginHandle);
return $hasUpdate;
}

return $hasUpdate;
}
/**
* Returns all available widget type classes.
*
Expand Down
20 changes: 18 additions & 2 deletions src/templates/_index.twig
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@

{% set plugin = craft.app.plugins.getPlugin('translations', false) %}

<div class="body" style="width:100%; text-align: center">
<div class="body" style="width:100%; text-align: center; display: flex; align-items: center; flex-direction: column;">
<td style="text-align:center;">
<span>
{% if licenseStatus == 'valid' %}
Expand All @@ -77,7 +77,7 @@

</span>

<span style="padding: 0 2%"> | </span>
<span style="padding: 0 2%"> </span>
sidedwards marked this conversation as resolved.
Show resolved Hide resolved
<span style="">
<div class="link">
<a href="https://www.surveymonkey.com/r/translationsplugin">
Expand Down Expand Up @@ -107,6 +107,22 @@
</div>
</div>
</div>
{% if updates %}
<div class="front" style="position: relative;">
<div class="pane notice-pane">
<a class="right icon delete close-notice" title="Close" style="margin-top: -1%; padding-left: 1%; font-size: 1.2rem"></a>
<div class="body" style="width:100%; text-align: center; display: flex; align-items: center; flex-direction: column;">
<td style="text-align:center;">
<span>There is an update available for Translations.
<a href="utilities/updates"> View details
</a>
<img src="{{ baseAssetsUrl ~ '/img/right-arrow.svg' }}" height="15px" style="vertical-align: middle"/>
</span>
</td>
</div>
</div>
</div>
{% endif %}
</div>
</div>

Expand Down