API Improve and Pages class
This commit is contained in:
parent
3058904fd2
commit
a5180135f6
@ -36,6 +36,10 @@ function editorInitialize(content) {
|
||||
initialValue: content
|
||||
});
|
||||
|
||||
// Get the tags from the content
|
||||
// When the content is setted the tags need to be setted
|
||||
_tags = parser.tags(content);
|
||||
|
||||
// Editor event change
|
||||
_editor.codemirror.on("change", function(){
|
||||
// If the content doesn't changed is not need to autosave
|
||||
@ -69,28 +73,21 @@ function editorInitialize(content) {
|
||||
});
|
||||
}
|
||||
|
||||
function editorSetContent(text) {
|
||||
// Get the tags from the content
|
||||
// When the content is setted the tags need to be setted
|
||||
_tags = parser.tags(text);
|
||||
|
||||
// Set the current content to the variable
|
||||
// This variable helps to know when the content was changed
|
||||
_content = text;
|
||||
|
||||
// Set the new content into the editor
|
||||
_editor.value(text);
|
||||
}
|
||||
|
||||
function editorGetContent() {
|
||||
return _editor.value();
|
||||
}
|
||||
|
||||
function createPage() {
|
||||
let response = ajax.createPage();
|
||||
response.then(function(key) {
|
||||
// Log
|
||||
log('createPage() => ajax.createPage => key',key);
|
||||
_key = key;
|
||||
editorInitialize('# Title \n');
|
||||
});
|
||||
}
|
||||
|
||||
// MAIN
|
||||
|
||||
// Init editor area
|
||||
editorInitialize("# Title \n");
|
||||
|
||||
$(document).ready(function() {
|
||||
showAlert("Welcome to Bludit");
|
||||
});
|
||||
|
@ -18,14 +18,14 @@ function displayTags() {
|
||||
// Init array for current tags
|
||||
_currentTags = [];
|
||||
// Remove all tags from the <ul>
|
||||
$("#currentTags").html('<li class="tagItem list-group-item tagSelected"><i class="fa fa-star-o"></i> Untagged</li>');
|
||||
$("#currentTags").html('<li class="tagItem list-group-item tagSelected" data-action="untagged"><i class="fa fa-star-o"></i> Untagged</li>');
|
||||
// Add all tags to the <ul>
|
||||
tags.forEach(function(tag) {
|
||||
_currentTags[tag.key] = tag.list;
|
||||
if (tagSelected == tag.key) {
|
||||
$("#currentTags").append('<li class="tagItem list-group-item tagSelected" data-key="'+tag.key+'"># '+tag.name+'</li>');
|
||||
$("#currentTags").append('<li class="tagItem list-group-item tagSelected" data-action="tag" data-key="'+tag.key+'"># '+tag.name+'</li>');
|
||||
} else {
|
||||
$("#currentTags").append('<li class="tagItem list-group-item" data-key="'+tag.key+'"># '+tag.name+'</li>');
|
||||
$("#currentTags").append('<li class="tagItem list-group-item" data-action="tag" data-key="'+tag.key+'"># '+tag.name+'</li>');
|
||||
}
|
||||
});
|
||||
});
|
||||
@ -39,10 +39,18 @@ $(document).ready(function() {
|
||||
$(this).addClass("tagSelected");
|
||||
// Get the tag key clicked
|
||||
let tagKey = $(this).data("key");
|
||||
let action = $(this).data("action");
|
||||
|
||||
// Log
|
||||
log('click li.tagItem => action',action);
|
||||
log('click li.tagItem => tagKey',tagKey);
|
||||
// Display pages by the tag
|
||||
displayPagesByTag(tagKey);
|
||||
|
||||
if (action=="untagged") {
|
||||
displayPagesUntagged();
|
||||
} else {
|
||||
// Display pages by the tag
|
||||
displayPagesByTag(tagKey);
|
||||
}
|
||||
});
|
||||
|
||||
// Retrive and show the tags
|
||||
@ -78,6 +86,23 @@ function displayPagesByTag(tagKey) {
|
||||
});
|
||||
}
|
||||
|
||||
function displayPagesUntagged() {
|
||||
let response = ajax.getPagesUntagged();
|
||||
response.then(function(pages) {
|
||||
// Log
|
||||
log('displayPagesUntagged() => ajax.getPagesUntagged => pages',pages);
|
||||
// Init array for current pages by tag
|
||||
_currentPages = [];
|
||||
// Remove all pages from the <ul>
|
||||
$("#currentPages").html("");
|
||||
pages.forEach(function(page) {
|
||||
_currentPages[page.key] = page;
|
||||
// Add all pages to the <ul>
|
||||
$("#currentPages").append('<li class="pageItem list-group-item" data-key="'+page.key+'"><div class="pageItemTitle">'+page.title+'</div><div class="pageItemContent">'+page.contentRaw.substring(0, 50)+'</div></li>');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Set the page selected
|
||||
function loadPage(pageKey) {
|
||||
// Check the current key if the same as the page is editing
|
||||
@ -98,7 +123,7 @@ function loadPage(pageKey) {
|
||||
content += "# "+page.title.trim()+"\n";
|
||||
}
|
||||
content += page.contentRaw;
|
||||
editorSetContent(content);
|
||||
editorInitialize(content);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -21,29 +21,27 @@ class Ajax {
|
||||
}
|
||||
}
|
||||
|
||||
createPage() {
|
||||
async createPage() {
|
||||
var url = this.apiURL+"pages";
|
||||
return fetch(url, {
|
||||
credentials: 'same-origin',
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
token: this.token,
|
||||
authentication: this.authentication
|
||||
}),
|
||||
headers: new Headers({
|
||||
'Content-Type': 'application/json'
|
||||
}),
|
||||
})
|
||||
.then(function(response) {
|
||||
return response.json();
|
||||
})
|
||||
.then(function(json) {
|
||||
try {
|
||||
const response = await fetch(url, {
|
||||
credentials: 'same-origin',
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
token: this.token,
|
||||
authentication: this.authentication
|
||||
}),
|
||||
headers: new Headers({
|
||||
'Content-Type': 'application/json'
|
||||
}),
|
||||
});
|
||||
const json = await response.json();
|
||||
return json.data.key;
|
||||
})
|
||||
.catch(err => {
|
||||
}
|
||||
catch (err) {
|
||||
console.log(err);
|
||||
return false;
|
||||
});
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
updatePage(key, title, content, tags) {
|
||||
@ -104,4 +102,25 @@ class Ajax {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async getPagesUntagged() {
|
||||
let parameters = {
|
||||
token: this.token,
|
||||
untagged: true,
|
||||
published: true,
|
||||
draft: true
|
||||
}
|
||||
let url = this.apiURL+"pages?"+$.param(parameters);
|
||||
try {
|
||||
const response = await fetch(url, {
|
||||
method: "GET"
|
||||
});
|
||||
const json = await response.json();
|
||||
return json.data;
|
||||
}
|
||||
catch (err) {
|
||||
console.log(err);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
@ -474,19 +474,19 @@ class Pages extends dbJSON {
|
||||
}
|
||||
|
||||
if ($static) {
|
||||
$list += $pages->getStaticDB();
|
||||
$list += $this->getStaticDB();
|
||||
}
|
||||
|
||||
if ($sticky) {
|
||||
$list += $pages->getStickyDB();
|
||||
$list += $this->getStickyDB();
|
||||
}
|
||||
|
||||
if ($draft) {
|
||||
$list += $pages->getDraftDB();
|
||||
$list += $this->getDraftDB();
|
||||
}
|
||||
|
||||
if ($scheduled) {
|
||||
$list += $pages->getScheduledDB();
|
||||
$list += $this->getScheduledDB();
|
||||
}
|
||||
|
||||
if ($numberOfItems==-1) {
|
||||
|
@ -296,11 +296,15 @@ class pluginAPI extends Plugin {
|
||||
private function getPages($args)
|
||||
{
|
||||
global $pages;
|
||||
$published = $args['published'];
|
||||
$static = $args['static'];
|
||||
$draft = $args['draft'];
|
||||
$sticky = $args['sticky'];
|
||||
$scheduled = $args['scheduled'];
|
||||
|
||||
// Parameters and the default values
|
||||
$published = (isset($args['published'])?$args['published']:true);
|
||||
$static = (isset($args['static'])?$args['static']:false);
|
||||
$draft = (isset($args['draft'])?$args['draft']:false);
|
||||
$sticky = (isset($args['sticky'])?$args['sticky']:false);
|
||||
$scheduled = (isset($args['scheduled'])?$args['scheduled']:false);
|
||||
$untagged = (isset($args['untagged'])?$args['untagged']:false);
|
||||
|
||||
$numberOfItems = $this->getValue('numberOfItems');
|
||||
$pageNumber = 1;
|
||||
$list = $pages->getList($pageNumber, $numberOfItems, $published, $static, $sticky, $draft, $scheduled);
|
||||
@ -315,10 +319,12 @@ class pluginAPI extends Plugin {
|
||||
try {
|
||||
// Create the page object from the page key
|
||||
$page = new Page($pageKey);
|
||||
if ($args['untagged'] && (empty($page->tags()))) {
|
||||
// Push the page to the data array for the response
|
||||
array_push($tmp['data'], $page->json($returnsArray=true));
|
||||
} else {
|
||||
if ($untagged) {
|
||||
if (empty($page->tags())) {
|
||||
// Push the page to the data array for the response
|
||||
array_push($tmp['data'], $page->json($returnsArray=true));
|
||||
}
|
||||
} else{
|
||||
array_push($tmp['data'], $page->json($returnsArray=true));
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
|
Loading…
Reference in New Issue
Block a user