Skip to content

Commit

Permalink
Add review cta and improve UI
Browse files Browse the repository at this point in the history
  • Loading branch information
zaxbux committed May 8, 2020
1 parent bfd545a commit e5f2237
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 30 deletions.
17 changes: 17 additions & 0 deletions Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,29 @@ public function boot() {
],
]);
}

// Show "review me" callout if not hidden
if (!Settings::get('_review_hidden')) {
$widget->addFields([
'_review_hidden' => [
'type' => 'partial',
'path' => '$/zaxbux/gmailmailerdriver/partials/_review.htm',
],
]);
}
});

\App::extend('swift.transport', function (\Illuminate\Mail\TransportManager $manager) {
return $manager->extend(self::MODE_GMAIL, function () {
return new GmailTransport();
});
});

Settings::extend(function($model) {
$model->bindEvent('model.beforeSave', function() use ($model) {
// Convert hidden input value to boolean
$model->setSettingsValue('_review_hidden', $model->getSettingsValue('_review_hidden', false) ? true : false);
});
});
}
}
4 changes: 4 additions & 0 deletions lang/en/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
'label' => 'Error!',
'comment' => 'There was a problem with granting access to the Gmail API. Please create new credentials and try again. Check the error log for more information.',
],
'review' => [
'header' => 'Did you find this plugin useful?',
'link' => 'Rate it and leave a review!',
]
],
'widgets' => [
'authorizationstatus' => [
Expand Down
43 changes: 21 additions & 22 deletions models/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,39 @@
use October\Rain\Database\Model;
use Zaxbux\GmailMailerDriver\Classes\GoogleAPI;

class Settings extends Model
{
class Settings extends Model {
const TOKEN_FIELD = 'token';
const CONFIG_FIELD = 'credentials';

public $implement = ['System.Behaviors.SettingsModel'];
public $settingsCode = 'zaxbux_gmailmailerdriver_settings';
public $settingsFields = 'fields.yaml';
public $implement = ['System.Behaviors.SettingsModel'];
public $settingsCode = 'zaxbux_gmailmailerdriver_settings';
public $settingsFields = 'fields.yaml';

public $attachOne = [
public $attachOne = [
'credentials' => [
'System\\Models\\File',
'public' => false,
'delete' => true,
],
];

/**
* Revoke the token with Google before deleting the credentials
*/
public function resetDefault() {
try {
$googleAPI = new GoogleAPI();

if ($googleAPI->isAuthorized()) {
// Revoke authorization with Google
if ($googleAPI->client->revokeToken($googleAPI->client->getAccessToken())) {
Log::info('Gmail Mailer Driver: Auth token revoked');
}
/**
* Revoke the token with Google before deleting the credentials
*/
public function resetDefault() {
try {
$googleAPI = new GoogleAPI();

if ($googleAPI->isAuthorized()) {
// Revoke authorization with Google
if ($googleAPI->client->revokeToken($googleAPI->client->getAccessToken())) {
Log::info('Gmail Mailer Driver: Auth token revoked');
}
} catch (\Exception $ex) {
Log::alert($ex);
}

parent::resetDefault();
} catch (\Exception $ex) {
Log::alert($ex);
}

parent::resetDefault();
}
}
14 changes: 6 additions & 8 deletions models/settings/fields.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
fields:
_auth_redirect_uri:
type: partial
path: $/zaxbux/gmailmailerdriver/partials/_auth_redirect_uri.htm

credentials:
type: fileupload
label: zaxbux.gmailmailerdriver::lang.settings.field.credentials.label
comment: zaxbux.gmailmailerdriver::lang.settings.field.credentials.comment
commentHtml: true
span: left
type: fileupload
span: full
mode: file
fileTypes: json
useCaption: false
_auth_redirect_uri:
label: zaxbux.gmailmailerdriver::lang.settings.field.auth_redirect_uri.label
comment: zaxbux.gmailmailerdriver::lang.settings.field.auth_redirect_uri.comment
span: right
type: text
readOnly: true
4 changes: 4 additions & 0 deletions partials/_auth_redirect_uri.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<style>#Form-field-Settings-_auth_redirect_uri {background-color: #fff!important; color: #385478; cursor: text; }</style>
<label for="Form-field-Settings-_auth_redirect_uri"><?=e(trans('zaxbux.gmailmailerdriver::lang.settings.field.auth_redirect_uri.label'))?></label>
<input type="text" id="Form-field-Settings-_auth_redirect_uri" value="<?=$value?>" class="form-control" autocomplete="off" readonly onfocus="this.select();" onmouseup="return false;">
<p class="help-block"><?=e(trans('zaxbux.gmailmailerdriver::lang.settings.field.auth_redirect_uri.comment'))?></p>
18 changes: 18 additions & 0 deletions partials/_review.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<div class="callout callout-info no-icon" data-review-callout>
<button type="button" class="close" data-dismiss="callout" aria-hidden="true">&times;</button>
<div class="header">
<h3><?=e(trans('zaxbux.gmailmailerdriver::lang.partials.review.header'));?></h3>
</div>
<div class="content">
<p><a href="https://octobercms.com/plugin/zaxbux-gmailmailerdriver#reviews" target="_blank" rel="noopener"><i class="icon-star"></i> <?=e(trans('zaxbux.gmailmailerdriver::lang.partials.review.link'));?></a></p>
</div>
</div>
<input type="hidden" name="Settings[_review_hidden]">
<script type="application/javascript">
$(document).on('close.oc.callout', function(e) {
console.log(e);
if (e.target.hasAttribute('data-review-callout')) {
$('input[name="Settings[_review_hidden]"]').val('1');
}
});
</script>

0 comments on commit e5f2237

Please sign in to comment.