mirror of
https://github.com/getgrav/grav-plugin-admin.git
synced 2025-11-02 03:16:11 +01:00
@@ -9,6 +9,7 @@ use Grav\Common\Themes;
|
||||
use Grav\Common\Uri;
|
||||
use Grav\Common\Data;
|
||||
use Grav\Common\Page;
|
||||
use Grav\Common\Page\Collection;
|
||||
use Grav\Common\User\User;
|
||||
|
||||
class AdminController
|
||||
@@ -265,6 +266,43 @@ class AdminController
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function taskFilterPages()
|
||||
{
|
||||
$data = $this->post;
|
||||
|
||||
$flags = !empty($data['flags']) ? array_map('strtolower', explode(',', $data['flags'])) : [];
|
||||
$queries = !empty($data['query']) ? explode(',', $data['query']) : [];
|
||||
|
||||
$collection = $this->grav['pages']->all();
|
||||
|
||||
if (count($flags)) {
|
||||
if (in_array('modular', $flags))
|
||||
$collection = $collection->modular();
|
||||
|
||||
if (in_array('visible', $flags))
|
||||
$collection = $collection->visible();
|
||||
|
||||
if (in_array('routable', $flags))
|
||||
$collection = $collection->routable();
|
||||
}
|
||||
|
||||
if (!empty($queries)) {
|
||||
foreach ($collection as $page) {
|
||||
foreach ($queries as $query) {
|
||||
$query = trim($query);
|
||||
|
||||
// $page->content();
|
||||
if (stripos($page->getRawContent(), $query) === false && stripos($page->title(), $query) === false) {
|
||||
$collection->remove($page);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->admin->json_response = ['success', 'Pages filtered'];
|
||||
$this->admin->collection = $collection;
|
||||
}
|
||||
|
||||
protected function taskListmedia()
|
||||
{
|
||||
$page = $this->admin->page(true);
|
||||
|
||||
7
pages/admin/pages-filter.md
Normal file
7
pages/admin/pages-filter.md
Normal file
@@ -0,0 +1,7 @@
|
||||
---
|
||||
title: Pages Filter
|
||||
|
||||
access:
|
||||
admin.pages: true
|
||||
admin.super: true
|
||||
---
|
||||
@@ -14,10 +14,71 @@ $(function(){
|
||||
|
||||
// selectize
|
||||
$('input.page-filter').selectize({
|
||||
delimiter: ',',
|
||||
create: false
|
||||
maxItems: null,
|
||||
valueField: 'flag',
|
||||
labelField: 'flag',
|
||||
searchField: ['flag'],
|
||||
options: [
|
||||
{flag: 'Modular'},
|
||||
{flag: 'Visible'},
|
||||
{flag: 'Routable'}
|
||||
],
|
||||
});
|
||||
|
||||
var startFilterPages = function () {
|
||||
|
||||
$('input[name="page-search"]').focus();
|
||||
var flags = $('input[name="page-filter"]').val(),
|
||||
query = $('input[name="page-search"]').val();
|
||||
|
||||
if (!flags.length && !query.length) {
|
||||
return finishFilterPages([], true);
|
||||
}
|
||||
|
||||
GravAjax({
|
||||
dataType: 'json',
|
||||
method: 'POST',
|
||||
url: GravAdmin.config.base_url_relative + '/pages-filter.json/task:filterPages',
|
||||
data: {
|
||||
flags: flags,
|
||||
query: query
|
||||
},
|
||||
success: function (result, status) {
|
||||
finishFilterPages(result.results);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var finishFilterPages = function (pages, reset) {
|
||||
var items = $('[data-nav-id]');
|
||||
|
||||
items.removeClass('search-match');
|
||||
|
||||
if (reset) {
|
||||
items.addClass('search-match');
|
||||
} else {
|
||||
pages.forEach(function (id) {
|
||||
var match = items.filter('[data-nav-id="' + id + '"]');
|
||||
match.addClass('search-match');
|
||||
match.find('[data-nav-id]').addClass('search-match');
|
||||
match.parents('[data-nav-id]').addClass('search-match');
|
||||
});
|
||||
}
|
||||
|
||||
items.each(function (key, item) {
|
||||
if ($(item).hasClass('search-match')) {
|
||||
$(item).show();
|
||||
} else {
|
||||
$(item).hide();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// selectize
|
||||
$('input[name="page-search"]').on('input', startFilterPages);
|
||||
$('input[name="page-filter"]').on('change', startFilterPages);
|
||||
|
||||
|
||||
// auto generate folder based on title
|
||||
// on user input on folder, autogeneration stops
|
||||
// if user empties the folder, autogeneration restarts
|
||||
|
||||
5
themes/grav/templates/pages-filter.json.twig
Normal file
5
themes/grav/templates/pages-filter.json.twig
Normal file
@@ -0,0 +1,5 @@
|
||||
{"status":{{admin.json_response[0]|json_encode}}, "results":[
|
||||
{%- for search_result in admin.collection -%}
|
||||
{{- search_result.route|json_encode -}}{{ not loop.last ? ',' }}
|
||||
{%- endfor -%}
|
||||
]}
|
||||
@@ -45,7 +45,7 @@
|
||||
(p.routable ? 'Routable • ' : 'Not Routable • ') ~
|
||||
(p.visible ? 'Visible • ' : 'Not Visible • ') %}
|
||||
|
||||
<li class="page-item">
|
||||
<li class="page-item" data-nav-id="{{ p.route }}">
|
||||
<div class="row">
|
||||
<span {{ p.children(0).count > 0 ? 'data-toggle="children"' : ''}} data-hint="{{ description|trim(' • ') }}" class="hint--bottom">
|
||||
<i class="page-icon fa fa-fw fa-circle-o {{ p.children(0).count > 0 ? 'children-closed' : ''}} {{ p.modular ? 'modular' : (not p.routable ? 'not-routable' : (not p.visible ? 'not-visible' : (not p.page ? 'folder' : ''))) }}"></i>
|
||||
@@ -131,7 +131,7 @@
|
||||
{% else %}
|
||||
<form id="page-filtering">
|
||||
<div class="page-filters">
|
||||
<input type="text" placeholder="Add Filters" class="page-filter" value="Routable,Visible,Modular" name="page-filter" />
|
||||
<input type="text" placeholder="Add Filters" class="page-filter" name="page-filter" />
|
||||
</div>
|
||||
<div class="page-search">
|
||||
<input type="text" placeholder="Search Pages" name="page-search" />
|
||||
|
||||
@@ -60,7 +60,7 @@
|
||||
{% if plugin.keywords %}
|
||||
<tr>
|
||||
<td>Keywords:</td>
|
||||
<td>{{ plugin.keywords }}</td>
|
||||
<td>{{ plugin.keywords|join(', ') }}</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% if plugin.license %}
|
||||
|
||||
Reference in New Issue
Block a user