mirror of
https://github.com/getgrav/grav-plugin-admin.git
synced 2025-11-04 20:36:03 +01:00
Fixes #1766 - support 3rd party dashboard widgets
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
1. [](#improved)
|
1. [](#improved)
|
||||||
* Improved delete button UI [#1769](https://github.com/getgrav/grav-plugin-admin/issues/1769)
|
* Improved delete button UI [#1769](https://github.com/getgrav/grav-plugin-admin/issues/1769)
|
||||||
|
* Ability to configure display of 3rd party dashboard widgets [#1766](https://github.com/getgrav/grav-plugin-admin/issues/1766)
|
||||||
1. [](#bugfix)
|
1. [](#bugfix)
|
||||||
* Fixed administrator user creation when `Flex Users` is enabled
|
* Fixed administrator user creation when `Flex Users` is enabled
|
||||||
* Fixed minor button alignment in FF [#1760](https://github.com/getgrav/grav-plugin-admin/issues/1760)
|
* Fixed minor button alignment in FF [#1760](https://github.com/getgrav/grav-plugin-admin/issues/1760)
|
||||||
|
|||||||
44
admin.php
44
admin.php
@@ -376,11 +376,27 @@ class AdminPlugin extends Plugin
|
|||||||
*/
|
*/
|
||||||
public function onAdminDashboard()
|
public function onAdminDashboard()
|
||||||
{
|
{
|
||||||
$this->grav['twig']->plugins_hooked_dashboard_widgets_top[] = ['template' => 'dashboard-maintenance'];
|
$lang = $this->grav['language'];
|
||||||
$this->grav['twig']->plugins_hooked_dashboard_widgets_top[] = ['template' => 'dashboard-statistics'];
|
$this->grav['twig']->plugins_hooked_dashboard_widgets_top[] = [
|
||||||
$this->grav['twig']->plugins_hooked_dashboard_widgets_top[] = ['template' => 'dashboard-notifications'];
|
'name' => $lang->translate('PLUGIN_ADMIN.MAINTENANCE'),
|
||||||
$this->grav['twig']->plugins_hooked_dashboard_widgets_top[] = ['template' => 'dashboard-feed'];
|
'template' => 'dashboard-maintenance',
|
||||||
$this->grav['twig']->plugins_hooked_dashboard_widgets_main[] = ['template' => 'dashboard-pages'];
|
];
|
||||||
|
$this->grav['twig']->plugins_hooked_dashboard_widgets_top[] = [
|
||||||
|
'name' => $lang->translate('PLUGIN_ADMIN.STATISTICS'),
|
||||||
|
'template' => 'dashboard-statistics',
|
||||||
|
];
|
||||||
|
$this->grav['twig']->plugins_hooked_dashboard_widgets_top[] = [
|
||||||
|
'name' => $lang->translate('PLUGIN_ADMIN.NOTIFICATIONS'),
|
||||||
|
'template' => 'dashboard-notifications',
|
||||||
|
];
|
||||||
|
$this->grav['twig']->plugins_hooked_dashboard_widgets_top[] = [
|
||||||
|
'name' => $lang->translate('PLUGIN_ADMIN.NEWS_FEED'),
|
||||||
|
'template' => 'dashboard-feed',
|
||||||
|
];
|
||||||
|
$this->grav['twig']->plugins_hooked_dashboard_widgets_main[] = [
|
||||||
|
'name' => $lang->translate('PLUGIN_ADMIN.LATEST_PAGE_UPDATES'),
|
||||||
|
'template' => 'dashboard-pages',
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -393,12 +409,13 @@ class AdminPlugin extends Plugin
|
|||||||
*/
|
*/
|
||||||
public function onAdminTools(Event $event)
|
public function onAdminTools(Event $event)
|
||||||
{
|
{
|
||||||
|
$lang = $this->grav['language'];
|
||||||
$event['tools'] = array_merge($event['tools'], [
|
$event['tools'] = array_merge($event['tools'], [
|
||||||
'backups' => [['admin.maintenance', 'admin.super'], $this->grav['language']->translate('PLUGIN_ADMIN.BACKUPS')],
|
'backups' => [['admin.maintenance', 'admin.super'], $lang->translate('PLUGIN_ADMIN.BACKUPS')],
|
||||||
'scheduler' => [['admin.super'], $this->grav['language']->translate('PLUGIN_ADMIN.SCHEDULER')],
|
'scheduler' => [['admin.super'], $lang->translate('PLUGIN_ADMIN.SCHEDULER')],
|
||||||
'logs' => [['admin.super'], $this->grav['language']->translate('PLUGIN_ADMIN.LOGS')],
|
'logs' => [['admin.super'], $lang->translate('PLUGIN_ADMIN.LOGS')],
|
||||||
'reports' => [['admin.super'], $this->grav['language']->translate('PLUGIN_ADMIN.REPORTS')],
|
'reports' => [['admin.super'], $lang->translate('PLUGIN_ADMIN.REPORTS')],
|
||||||
'direct-install' => [['admin.super'], $this->grav['language']->translate('PLUGIN_ADMIN.DIRECT_INSTALL')],
|
'direct-install' => [['admin.super'], $lang->translate('PLUGIN_ADMIN.DIRECT_INSTALL')],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return $event;
|
return $event;
|
||||||
@@ -613,13 +630,12 @@ class AdminPlugin extends Plugin
|
|||||||
return $bc <=> $ac;
|
return $bc <=> $ac;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Gather Plugin-hooked dashboard items
|
||||||
|
$this->grav->fireEvent('onAdminDashboard');
|
||||||
|
|
||||||
switch ($this->template) {
|
switch ($this->template) {
|
||||||
case 'dashboard':
|
case 'dashboard':
|
||||||
$twig->twig_vars['popularity'] = $this->popularity;
|
$twig->twig_vars['popularity'] = $this->popularity;
|
||||||
|
|
||||||
// Gather Plugin-hooked dashboard items
|
|
||||||
$this->grav->fireEvent('onAdminDashboard');
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ sidebar:
|
|||||||
size: auto
|
size: auto
|
||||||
dashboard:
|
dashboard:
|
||||||
days_of_stats: 7
|
days_of_stats: 7
|
||||||
widgets:
|
widgets_display:
|
||||||
dashboard-maintenance: true
|
dashboard-maintenance: true
|
||||||
dashboard-statistics: true
|
dashboard-statistics: true
|
||||||
dashboard-notifications: true
|
dashboard-notifications: true
|
||||||
|
|||||||
@@ -361,65 +361,11 @@ form:
|
|||||||
title: Dashboard
|
title: Dashboard
|
||||||
underline: true
|
underline: true
|
||||||
|
|
||||||
widgets.dashboard-maintenance:
|
widgets_display:
|
||||||
type: toggle
|
type: widgets
|
||||||
label: Maintenance Widget
|
label: Widget Display Status
|
||||||
highlight: 1
|
|
||||||
default: 1
|
|
||||||
options:
|
|
||||||
1: PLUGIN_ADMIN.ENABLED
|
|
||||||
0: PLUGIN_ADMIN.DISABLED
|
|
||||||
validate:
|
validate:
|
||||||
type: bool
|
type: array
|
||||||
help: Display dashboard maintenance widget
|
|
||||||
|
|
||||||
widgets.dashboard-statistics:
|
|
||||||
type: toggle
|
|
||||||
label: Statistics Widget
|
|
||||||
highlight: 1
|
|
||||||
default: 1
|
|
||||||
options:
|
|
||||||
1: PLUGIN_ADMIN.ENABLED
|
|
||||||
0: PLUGIN_ADMIN.DISABLED
|
|
||||||
validate:
|
|
||||||
type: bool
|
|
||||||
help: Display dashboard statistics widget
|
|
||||||
|
|
||||||
widgets.dashboard-notifications:
|
|
||||||
type: toggle
|
|
||||||
label: Notifications Feed Widget
|
|
||||||
highlight: 1
|
|
||||||
default: 1
|
|
||||||
options:
|
|
||||||
1: PLUGIN_ADMIN.ENABLED
|
|
||||||
0: PLUGIN_ADMIN.DISABLED
|
|
||||||
validate:
|
|
||||||
type: bool
|
|
||||||
help: Display dashboard notifications feed widget
|
|
||||||
|
|
||||||
widgets.dashboard-feed:
|
|
||||||
type: toggle
|
|
||||||
label: News Feed Widget
|
|
||||||
highlight: 1
|
|
||||||
default: 1
|
|
||||||
options:
|
|
||||||
1: PLUGIN_ADMIN.ENABLED
|
|
||||||
0: PLUGIN_ADMIN.DISABLED
|
|
||||||
validate:
|
|
||||||
type: bool
|
|
||||||
help: Display dashboard news feed widget
|
|
||||||
|
|
||||||
widgets.dashboard-pages:
|
|
||||||
type: toggle
|
|
||||||
label: Latest Pages Widget
|
|
||||||
highlight: 1
|
|
||||||
default: 1
|
|
||||||
options:
|
|
||||||
1: PLUGIN_ADMIN.ENABLED
|
|
||||||
0: PLUGIN_ADMIN.DISABLED
|
|
||||||
validate:
|
|
||||||
type: bool
|
|
||||||
help: Display dashboard latest pages widget
|
|
||||||
|
|
||||||
Notifications:
|
Notifications:
|
||||||
type: section
|
type: section
|
||||||
|
|||||||
@@ -37,7 +37,7 @@
|
|||||||
<div id="admin-dashboard">
|
<div id="admin-dashboard">
|
||||||
{% if grav.twig.plugins_hooked_dashboard_widgets_top %}
|
{% if grav.twig.plugins_hooked_dashboard_widgets_top %}
|
||||||
{% for widget in grav.twig.plugins_hooked_dashboard_widgets_top %}
|
{% for widget in grav.twig.plugins_hooked_dashboard_widgets_top %}
|
||||||
{% if attribute(config.plugins.admin.widgets, widget.template) == true %}
|
{% if attribute(config.plugins.admin.widgets_display, widget.template)|string in ['1', 'true'] %}
|
||||||
<div class="dashboard-item-flex">
|
<div class="dashboard-item-flex">
|
||||||
{% include 'partials/' ~ widget.template ~ '.html.twig' %}
|
{% include 'partials/' ~ widget.template ~ '.html.twig' %}
|
||||||
</div>
|
</div>
|
||||||
@@ -50,7 +50,7 @@
|
|||||||
{% block content %}
|
{% block content %}
|
||||||
{%- if grav.twig.plugins_hooked_dashboard_widgets_main -%}
|
{%- if grav.twig.plugins_hooked_dashboard_widgets_main -%}
|
||||||
{%- for widget in grav.twig.plugins_hooked_dashboard_widgets_main -%}
|
{%- for widget in grav.twig.plugins_hooked_dashboard_widgets_main -%}
|
||||||
{%- if attribute(config.plugins.admin.widgets, widget.template) == true %}
|
{% if attribute(config.plugins.admin.widgets_display, widget.template)|string in ['1', 'true'] %}
|
||||||
{% include 'partials/' ~ widget.template ~ '.html.twig' %}
|
{% include 'partials/' ~ widget.template ~ '.html.twig' %}
|
||||||
{% endif -%}
|
{% endif -%}
|
||||||
{%- endfor -%}
|
{%- endfor -%}
|
||||||
@@ -61,7 +61,7 @@
|
|||||||
<div id="admin-dashboard">
|
<div id="admin-dashboard">
|
||||||
{%- if grav.twig.plugins_hooked_dashboard_widgets_bottom -%}
|
{%- if grav.twig.plugins_hooked_dashboard_widgets_bottom -%}
|
||||||
{%- for widget in grav.twig.plugins_hooked_dashboard_widgets_bottom -%}
|
{%- for widget in grav.twig.plugins_hooked_dashboard_widgets_bottom -%}
|
||||||
{%- if attribute(config.plugins.admin.widgets, widget.template) == true %}
|
{% if attribute(config.plugins.admin.widgets_display, widget.template)|string in ['1', 'true'] %}
|
||||||
{% include 'partials/' ~ widget.template ~ '.html.twig' %}
|
{% include 'partials/' ~ widget.template ~ '.html.twig' %}
|
||||||
{% endif -%}
|
{% endif -%}
|
||||||
{%- endfor -%}
|
{%- endfor -%}
|
||||||
|
|||||||
61
themes/grav/templates/forms/fields/widgets/widgets.html.twig
Normal file
61
themes/grav/templates/forms/fields/widgets/widgets.html.twig
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
{#{% extends "forms/field.html.twig" %}#}
|
||||||
|
|
||||||
|
{% import _self as macro %}
|
||||||
|
|
||||||
|
{% macro spanToggle(input, length) %}
|
||||||
|
{% set space = repeat(' ', (length - input|length) / 2) %}
|
||||||
|
{{ (space ~ input ~ space)|raw }}
|
||||||
|
{% endmacro %}
|
||||||
|
|
||||||
|
{% macro outputWidget(widget) %}
|
||||||
|
|
||||||
|
{% endmacro %}
|
||||||
|
|
||||||
|
{% set widgets = grav.twig.plugins_hooked_dashboard_widgets_top|array|merge(grav.twig.plugins_hooked_dashboard_widgets_main|array)|merge(grav.twig.plugins_hooked_dashboard_widgets_bottom|array) %}
|
||||||
|
{% set widgets_display = grav.config.plugins.admin.widgets_display %}
|
||||||
|
|
||||||
|
{% for widget in widgets %}
|
||||||
|
{% set widget_name = widget.name|default(widget.template|titleize) %}
|
||||||
|
{% set widget_id = widget.template %}
|
||||||
|
{% set widget_value = widgets_display[widget_id]|string in ['1', 'true'] ? 'true' : 'false' %}
|
||||||
|
{% set name = 'data['~field.name~']['~widget_id~']' %}
|
||||||
|
|
||||||
|
<div class="block block-toggle">
|
||||||
|
<div class="form-field grid">
|
||||||
|
<div class="form-label block size-1-3">
|
||||||
|
<label>
|
||||||
|
<span>{{ widget_name }} Widget</span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div class="form-data block size-2-3" data-grav-field="toggle" data-grav-default="1">
|
||||||
|
<div class="switch-toggle switch-grav medium switch-2">
|
||||||
|
|
||||||
|
{% set options = { true: 'PLUGIN_ADMIN.ENABLED', false: 'PLUGIN_ADMIN.DISABLED' } %}
|
||||||
|
|
||||||
|
{% set maxLen = 0 %}
|
||||||
|
{% for value, text in options %}
|
||||||
|
{% set translation = grav.twig.twig.filters['tu'] is defined ? text|tu : text|t %}
|
||||||
|
{% set maxLen = max(translation|length, maxLen) %}
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
{% for key, text in options %}
|
||||||
|
{% set id = "toggle_" ~ field.name ~ "." ~ widget_id ~ '.' ~ key %}
|
||||||
|
{% set translation = (grav.twig.twig.filters['tu'] is defined ? text|tu : text|t)|trim %}
|
||||||
|
|
||||||
|
<input type="radio"
|
||||||
|
value="{{ key }}"
|
||||||
|
id="{{ id }}"
|
||||||
|
name="{{ name }}"
|
||||||
|
class="{{ 'true' == '' ~ key ? 'highlight' : '' }}"
|
||||||
|
{% if key|string == widget_value|string %}
|
||||||
|
checked="checked"
|
||||||
|
{% endif %}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<label for="{{ id }}">{{ (macro.spanToggle(translation, maxLen)|trim)|raw }}</label>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
Reference in New Issue
Block a user