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 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
12 changes: 10 additions & 2 deletions src/assetbundles/src/js/OrderIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,17 @@ Craft.Translations.OrderIndex = Garnish.Base.extend(
}
}

var UpdateNotification = localStorage.getItem(Craft.username+"UpdateNotification");
if(UpdateNotification == null || UpdateNotification == "false") {
if (document.getElementById("update-notice")) {
document.getElementById("update-notice").style.display = "block";
}
}

$(document).on("click", ".close-notice", function() {
$("#trial-notice").fadeOut();
localStorage.setItem(Craft.username+"PaidNotification", "true");
var that = $(this);
$("#"+that.data('id')).fadeOut();
localStorage.setItem(Craft.username+that.data('key'), "true");
})

$(document).on("click", ".translations-restore-order", function() {
Expand Down
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
*
* @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
25 changes: 22 additions & 3 deletions src/templates/_index.twig
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@
<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>
<a class="right icon delete close-notice" data-id="trial-notice" data-key="PaidNotification" title="Close" style="margin-top: -1%; padding-left: 1%; font-size: 1.2rem"></a>

{% 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 @@ -109,6 +109,25 @@
</div>
</div>
</div>
{% if updates %}
<div class="item" id="update-notice" style="padding-bottom: 10px; display: none; width: calc(100% - 0px)">
<div data-title="Notice" style="">
<div class="front" style="position: relative;">
<div class="pane notice-pane">
<a class="right icon delete close-notice" data-id="update-notice" data-key="UpdateNotification" 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" href="utilities/updates"> View details
</a>
</span>
</td>
</div>
</div>
</div>
</div>
</div>
{% endif %}

<div id="translations-dashboard" style="visibility:hidden;">
{% for widget in widgets %}
Expand Down