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 2 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
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.
28 changes: 28 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->checkForUpdate('translations');

// Register Dashboard Assets
$view->registerAssetBundle(DashboardAssets::class);
$view->registerJs('window.translationsdashboard = new Craft.Translations.Dashboard(' . Json::encode($widgetTypeInfo) . ');');
Expand All @@ -200,6 +206,28 @@ public function actionIndex()
return $this->renderTemplate('translations/_index', $variables);
}

/**
* Check for Latest Updates
* @param $pluginHandle
* @return bool
*/
public function checkForUpdate($pluginHandle): bool
{
$hasUpdate = false;

$updateData = Craft::$app->getApi()->getUpdates([]);

$updates = new UpdatesModel($updateData);

foreach ($updates->plugins as $key => $pluginUpdate) {
if ($key === $pluginHandle && $pluginUpdate->getHasReleases()) {
$hasUpdate = true;
}
}

return $hasUpdate;
}

/**
* Creates a new widget.
*
Expand Down
20 changes: 17 additions & 3 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,6 @@

</span>

<span style="padding: 0 2%"> | </span>
<span style="">
<div class="link">
<a href="https://www.surveymonkey.com/r/translationsplugin">
Expand Down Expand Up @@ -107,6 +106,21 @@
</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 class="go nowrap" href="utilities/updates"> View details
</a>
</span>
</td>
</div>
</div>
</div>
{% endif %}
sidedwards marked this conversation as resolved.
Show resolved Hide resolved
</div>
</div>

Expand Down Expand Up @@ -154,4 +168,4 @@
</div>
{% endblock %}

{% block sidebar %}{% endblock %}
{% block sidebar %}{% endblock %}