Do not attempt to fetch any notification if settings are disabled (fixes #942)

This commit is contained in:
Djamil Legato
2017-03-17 07:58:29 -07:00
parent 2bdd38e542
commit bd8369fde9
4 changed files with 40 additions and 25 deletions

View File

@@ -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

View File

@@ -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) {
@@ -28,7 +30,7 @@ class Notifications {
break;
}
var hidden = '';
let hidden = '';
if (index > 9) {
hidden = ' hidden ';
}
@@ -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');
@@ -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>`;
@@ -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();
@@ -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 });
});
}

File diff suppressed because one or more lines are too long

View File

@@ -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 = {
@@ -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('===') }}'