Browse Source

Updated database and sidebar to display pinned posts.

pull/43/head
jrtechs 6 years ago
parent
commit
288a973929
4 changed files with 65 additions and 0 deletions
  1. +21
    -0
      blog/sidebar.js
  2. +2
    -0
      docs/sqlConfig.md
  3. +12
    -0
      templates/blog/sideBar.html
  4. +30
    -0
      utils/sql.js

+ 21
- 0
blog/sidebar.js View File

@ -45,6 +45,26 @@ const getInformationForCategories = function(templateContext)
}; };
const getInformationForPinnedPosts = function(templateContext)
{
return new Promise(function(resolve, reject)
{
sql.getPinnedPosts().then(function(posts)
{
posts.forEach(function(p)
{
p.url = '/' + p.category + '/' + p.url;
});
templateContext.pinnedPosts = posts;
resolve();
}).catch(function(error)
{
reject(error);
})
});
};
module.exports= module.exports=
{ {
main: function(templateContext) main: function(templateContext)
@ -53,6 +73,7 @@ module.exports=
{ {
Promise.all([includes.fetchTemplate(TEMPLATE_FILE), Promise.all([includes.fetchTemplate(TEMPLATE_FILE),
getInformationForRecentPosts(templateContext), getInformationForRecentPosts(templateContext),
getInformationForPinnedPosts(templateContext),
getInformationForCategories(templateContext)]) getInformationForCategories(templateContext)])
.then(function(content) .then(function(content)
{ {

+ 2
- 0
docs/sqlConfig.md View File

@ -29,9 +29,11 @@ picture_url varchar(100) not null,
published datetime not null, published datetime not null,
name varchar(100) not null, name varchar(100) not null,
url varchar(100) not null, url varchar(100) not null,
pinned BIT,
primary key(post_id) primary key(post_id)
); );
ALTER TABLE posts ADD pinned BIT;
create table downloads( create table downloads(
download_id mediumint unsigned not null AUTO_INCREMENT, download_id mediumint unsigned not null AUTO_INCREMENT,

+ 12
- 0
templates/blog/sideBar.html View File

@ -34,3 +34,15 @@
</div> </div>
<br> <br>
<div class="container">
<div class="list-group">
<a href="#" class="list-group-item list-group-item-action flex-column align-items-start active">
<h5 class="mb-1">Pinned Posts</h5>
</a>
{for pinnedPost in pinnedPosts}
<a class="list-group-item" href='{pinnedPost.url}'>{pinnedPost.name}<br></a>
{/for}
</div>
</div>
<br>

+ 30
- 0
utils/sql.js View File

@ -235,6 +235,36 @@ module.exports=
}, },
getPinnedPosts: function()
{
return new Promise(function(resolve, reject)
{
var q = "select name,url, category_id from posts where pinned=1 order " +
"by post_id desc limit 10";
console.log(q);
fetch(q).then(function (sqlPosts) {
var promises = [];
sqlPosts.forEach(function (post) {
promises.push(new Promise(function (res, rej) {
var getCategory = "select url from categories where " +
"category_id='" + post.category_id + "'";
fetch(getCategory).then(function (urls) {
var obj = new Object();
obj.name = post.name;
obj.url = post.url;
obj.category = urls[0].url;
res(obj);
});
}));
});
Promise.all(promises).then(function (goodies) {
resolve(goodies);
});
});
});
},
/** /**
* TODO * TODO
* @returns {*|Promise} * @returns {*|Promise}

Loading…
Cancel
Save