Autosave tab, and autosave type for pages

This commit is contained in:
Diego Najar 2019-05-24 19:00:22 +02:00
parent c3cccaf42d
commit 68407ad75e
7 changed files with 61 additions and 15 deletions

View File

@ -40,6 +40,7 @@ $drafts = $pages->getDraftDB(true);
$scheduled = $pages->getScheduledDB(true);
$static = $pages->getStaticDB(true);
$sticky = $pages->getStickyDB(true);
$autosave = $pages->getAutosaveDB(true);
// If the user is an Author filter the content he/she can edit
if (checkRole(array('author'), false)) {

View File

@ -44,7 +44,7 @@ EOF;
}
if (isset($args['icon'])) {
return '<a '.$options.'><span class="fa fa-'.$args['icon'].'" style="font-size: 0.7em;"></span> '.$args['title'].'</a>';
return '<a '.$options.'><span class="fa fa-'.$args['icon'].'"></span>'.$args['title'].'</a>';
}
return '<a '.$options.'>'.$args['title'].'</a>';

View File

@ -10,6 +10,7 @@ function table($type) {
global $scheduled;
global $static;
global $sticky;
global $autosave;
if ($type=='published') {
$list = $published;
@ -51,6 +52,8 @@ function table($type) {
echo '</p>';
return false;
}
} elseif ($type=='autosave') {
$list = $autosave;
}
echo '
@ -180,8 +183,13 @@ function table($type) {
<a class="nav-link" id="scheduled-tab" data-toggle="tab" href="#scheduled" role="tab"><?php $L->p('Scheduled') ?> <?php if (count($scheduled)>0) { echo '<span class="badge badge-danger">'.count($scheduled).'</span>'; } ?></a>
</li>
<li class="nav-item">
<a class="nav-link" id="draft-tab" data-toggle="tab" href="#draft" role="tab"><?php $L->p('Draft') ?> <?php if (count($drafts)>0) { echo '<span class="badge badge-danger">'.count($drafts).'</span>'; } ?></a>
<a class="nav-link" id="draft-tab" data-toggle="tab" href="#draft" role="tab"><?php $L->p('Draft') ?></a>
</li>
<?php if (!empty($autosave)): ?>
<li class="nav-item">
<a class="nav-link" id="autosave-tab" data-toggle="tab" href="#autosave" role="tab"><?php $L->p('Autosave') ?></a>
</li>
<?php endif; ?>
</ul>
<div class="tab-content">
<!-- TABS PAGES -->
@ -222,12 +230,11 @@ function table($type) {
<script>
$(document).ready(function() {
var searchXHR;
var searchList;
var searchArray;
$("#search").autoComplete({
minChars: 3,
source: function(term, response) {
try { searchXHR.abort(); } catch(e){}
searchXHR = $.getJSON(HTML_PATH_ADMIN_ROOT+"ajax/content-list",
searchXHR = $.getJSON(HTML_PATH_ADMIN_ROOT+"ajax/content-get-list",
{
published: true,
static: true,
@ -237,19 +244,19 @@ function table($type) {
query: term
},
function(data) {
searchList = data;
searchArray = data;
var matches = [];
for (var title in data) {
matches.push(title);
for (var key in data) {
matches.push(key);
}
response(matches);
});
},
renderItem: function (item, search) {
var key = searchList[item];
var title = searchArray[item]['title'];
html = '<div class="search-suggestion">';
html += '<div class="search-suggestion-item">'+item+'</div>';
html += '<div class="search-suggestion-options"><a href="<?php echo DOMAIN_ADMIN ?>edit-content/'+key+'">Edit</a> <a target="_blank" class="ml-2" href="<?php echo DOMAIN_PAGES ?>'+key+'"">Visit</a></div>';
html += '<div class="search-suggestion-item">'+title+'</div>';
html += '<div class="search-suggestion-options"><a href="<?php echo DOMAIN_ADMIN ?>edit-content/'+item+'">Edit</a> <a target="_blank" class="ml-2" href="<?php echo DOMAIN_PAGES ?>'+item+'"">Visit</a></div>';
html += '</div>';
return html;
}
@ -276,6 +283,13 @@ function table($type) {
<div class="tab-pane" id="draft" role="tabpanel">
<?php table('draft'); ?>
</div>
<!-- TABS AUTOSAVE -->
<?php if (!empty($autosave)): ?>
<div class="tab-pane" id="autosave" role="tabpanel">
<?php table('autosave'); ?>
</div>
<?php endif; ?>
</div>
<!-- Modal for delete page -->

View File

@ -1,6 +1,19 @@
<?php defined('BLUDIT') or die('Bludit CMS.');
header('Content-Type: application/json');
/*
| Search for pages that have in the title the string $query and returns the array of pages
|
| @_GET['published'] boolean True to search in published database
| @_GET['static'] boolean True to search in static database
| @_GET['sticky'] boolean True to search in sticky database
| @_GET['scheduled'] boolean True to search in scheduled database
| @_GET['draft'] boolean True to search in draft database
| @_GET['query'] string Text to search in the title
|
| @return array
*/
// $_GET
// ----------------------------------------------------------------------------
$published = empty($_GET['published']) ? false:true;
@ -24,7 +37,7 @@ foreach ($pagesKey as $pageKey) {
$page = new Page($pageKey);
$lowerTitle = Text::lowercase($page->title());
if (Text::stringContains($lowerTitle, $query)) {
$tmp[$page->title()] = $page->key();
$tmp[$page->key()] = $page->json(true);
}
} catch (Exception $e) {
// continue

View File

@ -8,6 +8,7 @@ header('Content-Type: application/json');
| @_POST['title'] string Page title
| @_POST['content'] string Page content
| @_POST['uuid'] string Page uuid
| @_POST['uuid'] string Page type, by default is draft
|
| @return array
*/
@ -17,6 +18,7 @@ header('Content-Type: application/json');
$title = isset($_POST['title']) ? $_POST['title'] : false;
$content = isset($_POST['content']) ? $_POST['content'] : false;
$uuid = isset($_POST['uuid']) ? $_POST['uuid'] : false;
$type = isset($_POST['type']) ? $_POST['type'] : 'draft';
// ----------------------------------------------------------------------------
// Check UUID
@ -30,7 +32,7 @@ $page = array(
'slug'=>$uuid,
'title'=>$title,
'content'=>$content,
'type'=>'draft'
'type'=>$type
);
// Get the page key by the UUID

View File

@ -13,7 +13,8 @@ class bluditAjax {
'tokenCSRF': tokenCSRF,
'uuid': "autosave-" + uuid,
'title': title,
'content': content
'content': content,
'type': 'autosave'
}),
});
const json = await response.json();

View File

@ -8,7 +8,7 @@ class Pages extends dbJSON {
'description'=>'',
'username'=>'',
'tags'=>array(),
'type'=>'published', // published, static, draft, sticky, scheduled
'type'=>'published', // published, static, draft, sticky, scheduled, autosave
'date'=>'',
'dateModified'=>'',
'position'=>0,
@ -411,6 +411,21 @@ class Pages extends dbJSON {
return $tmp;
}
// Returns an array with a list of keys/database of autosave pages
public function getAutosaveDB($onlyKeys=true)
{
$tmp = $this->db;
foreach ($tmp as $key=>$fields) {
if($fields['type']!='autosave') {
unset($tmp[$key]);
}
}
if ($onlyKeys) {
return array_keys($tmp);
}
return $tmp;
}
// Returns an array with a list of keys/database of scheduled pages
public function getScheduledDB($onlyKeys=true)
{