Skip to content

Commit

Permalink
Do not attempt to fetch any notification if settings are disabled (fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
w00fz committed Mar 17, 2017
1 parent 2bdd38e commit bd8369f
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 25 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# v1.3.0
## XX/XX/2017

1. [](#improved)
* Do not attempt to fetch any notification if settings are disabled [#942](https://github.com/getgrav/grav-plugin-admin/issues/942)

# v1.3.0-rc.1
## 03/13/2017

Expand Down
51 changes: 29 additions & 22 deletions themes/grav/app/updates/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import $ from 'jquery';
import { config } from 'grav-config';
import request from '../utils/request';

const canFetchNotifications = () => config.notifications;

class Notifications {

showNotificationInFeed(notification, index) {
Expand All @@ -28,7 +30,7 @@ class Notifications {
break;
}

var hidden = '';
let hidden = '';
if (index > 9) {
hidden = ' hidden ';
}
Expand Down Expand Up @@ -167,8 +169,11 @@ class Notifications {

// Grav.default.Notifications.fetch()
fetch({ locations = [], refresh = false } = {}) {
var that = this;
if (!canFetchNotifications()) {
return false;
}

let that = this;
let feed = $('#notifications');
let loader = feed.find('.widget-loader');
let content = feed.find('.widget-content > ul');
Expand All @@ -177,13 +182,13 @@ class Notifications {
loader.show();
content.hide();

var processNotifications = function processNotifications(response) {
var notifications = response.notifications;
let processNotifications = function processNotifications(response) {
let notifications = response.notifications;

$('#notifications').find('.widget-content > ul').empty();

if (notifications) {
var index = 0;
let index = 0;

notifications.forEach(function(notification, i) {
notification.closeButton = `<a href="#" data-notification-action="hide-notification" data-notification-id="${notification.id}" class="close hide-notification"><i class="fa fa-close"></i></a>`;
Expand Down Expand Up @@ -234,7 +239,7 @@ class Notifications {
}
});
}).fail(function() {
var widget = $('#notifications .widget-content');
let widget = $('#notifications .widget-content');
widget
.find('.widget-loader')
.find('div').remove();
Expand All @@ -252,27 +257,29 @@ class Notifications {
}
}

var notifications = new Notifications();
let notifications = new Notifications();
export default notifications;

notifications.fetch();
if (canFetchNotifications()) {
notifications.fetch();

$(document).on('click', '[data-notification-action="hide-notification"]', (event) => {
let notification_id = $(event.target).parents('.hide-notification').data('notification-id');
$(document).on('click', '[data-notification-action="hide-notification"]', (event) => {
let notification_id = $(event.target).parents('.hide-notification').data('notification-id');

let url = `${config.base_url_relative}/notifications.json/task${config.param_sep}hideNotification/notification_id${config.param_sep}${notification_id}`;
let url = `${config.base_url_relative}/notifications.json/task${config.param_sep}hideNotification/notification_id${config.param_sep}${notification_id}`;

request(url, { method: 'post' }, () => {});
request(url, { method: 'post' }, () => {});

$(event.target).parents('.single-notification').hide();
});
$(event.target).parents('.single-notification').hide();
});

$(document).on('click', '[data-notification-action="show-all-notifications"]', (event) => {
$('#notifications .show-all').hide();
$('#notifications .hidden').removeClass('hidden');
});
$(document).on('click', '[data-notification-action="show-all-notifications"]', (event) => {
$('#notifications .show-all').hide();
$('#notifications .hidden').removeClass('hidden');
});

$(document).on('click', '[data-refresh="notifications"]', (event) => {
event.preventDefault();
notifications.fetch({ locations: ['feed'], refresh: true });
});
$(document).on('click', '[data-refresh="notifications"]', (event) => {
event.preventDefault();
notifications.fetch({ locations: ['feed'], refresh: true });
});
}
6 changes: 3 additions & 3 deletions themes/grav/js/admin.min.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions themes/grav/templates/partials/javascript-config.html.twig
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% if authorize(['admin.login', 'admin.super']) %}
{% set notifications = (config.plugins.admin.widgets['dashboard-notifications'] or config.plugins.admin.notifications.dashboard or config.plugins.admin.notifications.plugins or config.plugins.admin.notifications.themes) ? 1 : 0 %}
<script type="text/javascript">
window.GravAdmin = window.GravAdmin || {};
window.GravAdmin.config = {
Expand All @@ -14,6 +15,7 @@
admin_nonce: '{{ admin.getNonce }}',
language: '{{ grav.user.language|default('en') }}',
pro_enabled: '{{ config.plugins["admin-pro"].enabled }}',
notifications: {{ notifications }},
local_notifications: '{{ config.system.local_notifications|default(false) }}',
site: {
delimiter: '{{ config.site.summary.delimiter|default('===') }}'
Expand Down

0 comments on commit bd8369f

Please sign in to comment.