Browse Source

Finished upgrading to the template engine with the use next page nav bar.

pull/41/head
jrtechs 5 years ago
parent
commit
6e68672bb6
5 changed files with 51 additions and 38 deletions
  1. +2
    -2
      admin/admin.js
  2. +2
    -1
      blog/category.js
  3. +7
    -2
      blog/homePage.js
  4. +18
    -32
      blog/renderNextBar.js
  5. +22
    -1
      templates/blog/blogMain.html

+ 2
- 2
admin/admin.js View File

@ -44,9 +44,9 @@ module.exports=
page = "./adminDownloads.js";
console.log("downloads time")
}
else if(filename.includes("/blog"))
else if(filename.includes("/posts"))
{
page = "./blog.js";
page = "./posts.js";
}
require(page).main(postData, templateContext).then(function(template)

+ 2
- 1
blog/category.js View File

@ -26,7 +26,8 @@ module.exports=
sql.getPostsFromCategory(splitURL[2]).then(function(posts)
{
blogBodyRenderer.renderBatchOfPosts(requestURL, posts, page, 5, templateContext).then(function()
Promise.all([blogBodyRenderer.renderBatchOfPosts(requestURL, posts, page, 5, templateContext),
require('./renderNextBar').main(requestURL, page, 5, posts.length, templateContext)]).then(function()
{
resolve();
});

+ 7
- 2
blog/homePage.js View File

@ -13,11 +13,16 @@ module.exports=
main: function(requestURL, request, templateContext)
{
var page = request.query.page;
return new Promise(function(resolve, reject)
{
sql.getRecentPostSQL().then(function(posts)
sql.getAllPosts().then(function(posts)
{
resolve(blogPostRenderer.renderBatchOfPosts(requestURL, posts, page, 5, templateContext));
Promise.all([blogPostRenderer.renderBatchOfPosts(requestURL, posts, page, 5, templateContext),
require('./renderNextBar').main(requestURL, page, 5, posts.length, templateContext)]).then(function()
{
resolve();
});
}).catch(function(error)
{
reject(error);

+ 18
- 32
blog/renderNextBar.js View File

@ -24,43 +24,29 @@ module.exports=
* @param totalPosts -- total amount of blog in the category
* @returns {Promise} promise which renders the buttons
*/
main: function(baseURL, currentPage, postsPerPage, totalPosts)
main: function(baseURL, currentPage, postsPerPage, totalPosts, templateContext)
{
return new Promise(function(resolve, reject)
{
if(!isValidPage(currentPage, postsPerPage, totalPosts))
{
reject("Invalid Page");
}
var nextPage = currentPage + 1;
var previousPage = currentPage - 1;
if(typeof currentPage == "undefined")
currentPage = 1;
currentPage = Number(currentPage);
var olderPosts = "";
var newerPosts = "";
if(!isValidPage(currentPage, postsPerPage, totalPosts))
{
reject("Invalid Page");
}
if (isValidPage(previousPage, postsPerPage, totalPosts))
{
newerPosts = "<button class=\"btn btn-secondary btn-lg " +
"w3-padding-large w3-white w3-border\" onclick=\"location.href='" +
baseURL + "?page=" + previousPage +
"'\"><b>Newer Posts &raquo;</b></button>";
}
var nextPage = currentPage + 1;
var previousPage = currentPage - 1;
if (isValidPage(nextPage, postsPerPage, totalPosts))
{
olderPosts = "<button class=\"btn btn-secondary btn-lg " +
"w3-padding-large w3-white w3-border\" onclick=\"location.href='" +
baseURL + "?page=" + nextPage +
"'\"><b>Older Posts &raquo;</b></button>";
}
if (isValidPage(previousPage, postsPerPage, totalPosts))
{
templateContext.newPostsURL = baseURL + "?page=" + previousPage;
}
resolve(" <div class=\"row\">\n" +
" <div class=\"col-6\">" + newerPosts + "</div>\n" +
" <div class=\"col-6\"><span class=\"float-right\">" + olderPosts + "</span></div>\n" +
" <br><br></div>");
})
if (isValidPage(nextPage, postsPerPage, totalPosts))
{
templateContext.oldPostsURL = baseURL + "?page=" + nextPage
}
}
};

+ 22
- 1
templates/blog/blogMain.html View File

@ -20,7 +20,8 @@
</div>
</div>
<br><br>
<br>
<br>
{else}
<div class="row p-lg-0">
<h1 class="align-content-center">Page Not Found</h1>
@ -30,6 +31,26 @@
</div>
<br><br>
{/for}
<div class="row">
<div class="col-6">
{if newPostsURL}
<button class="btn btn-secondary btn-l" onclick="location.href='{newPostsURL}'">
<b>Older Posts &raquo;</b>
</button>
{/if}
</div>
<div class="col-6">
{if oldPostsURL}
<span class="float-right">
<button class="btn btn-secondary btn-l" onclick="location.href='{oldPostsURL}'">
<b>Older Posts &raquo;</b>
</button>
</span>
{/if}
</div>
</div>
<br>
</div>
<div class="col-md-4 col-4">
{>sideBar}

Loading…
Cancel
Save