Browse Source

Started working on the sidebar

pull/4/head
jrtechs 6 years ago
parent
commit
5d514b963e
10 changed files with 212 additions and 138 deletions
  1. +0
    -111
      includes/sidebar.html
  2. +0
    -9
      includes/sidebar.js
  3. +16
    -4
      posts/category.js
  4. +10
    -13
      posts/posts.js
  5. +7
    -0
      posts/singlePost.js
  6. +62
    -0
      sidebar/categoriesSideBar.js
  7. +70
    -0
      sidebar/popularPosts.js
  8. +11
    -0
      sidebar/sidebar.html
  9. +25
    -0
      sidebar/sidebar.js
  10. +11
    -1
      utils/sql.js

+ 0
- 111
includes/sidebar.html View File

@ -1,111 +0,0 @@
<!-- Introduction menu -->
<div class="w3-col l4">
<!-- About Card -->
<div class="w3-card w3-margin w3-margin-top">
<div class="w3-container w3-white">
<h4><b>My Name</b></h4>
<p>Just me, myself and I, exploring the universe of uknownment. I have a heart of love and a interest of lorem ipsum and mauris neque quam blog. I want to share my world with you.</p>
</div>
</div><hr>
<!-- Posts -->
<div class="w3-card w3-margin">
<div class="w3-container w3-padding">
<h4>Popular Posts</h4>
</div>
<ul class="w3-ul w3-hoverable w3-white">
<li class="w3-padding-16">
<span class="w3-large">Lorem</span><br>
<span>Sed mattis nunc</span>
</li>
<li class="w3-padding-16">
<span class="w3-large">Ipsum</span><br>
<span>Praes tinci sed</span>
</li>
<li class="w3-padding-16">
<span class="w3-large">Dorum</span><br>
<span>Ultricies congue</span>
</li>
<li class="w3-padding-16 w3-hide-medium w3-hide-small">
<span class="w3-large">Mingsum</span><br>
<span>Lorem ipsum dipsum</span>
</li>
</ul>
</div>
<hr>
<!-- Labels / tags -->
<div class="w3-card w3-margin">
<div class="w3-container w3-padding">
<h4>Tags</h4>
</div>
<div class="w3-container w3-white">
<p><span class="w3-tag w3-black w3-margin-bottom">Travel</span> <span class="w3-tag w3-light-grey w3-small w3-margin-bottom">New York</span> <span class="w3-tag w3-light-grey w3-small w3-margin-bottom">London</span>
<span class="w3-tag w3-light-grey w3-small w3-margin-bottom">IKEA</span> <span class="w3-tag w3-light-grey w3-small w3-margin-bottom">NORWAY</span> <span class="w3-tag w3-light-grey w3-small w3-margin-bottom">DIY</span>
<span class="w3-tag w3-light-grey w3-small w3-margin-bottom">Ideas</span> <span class="w3-tag w3-light-grey w3-small w3-margin-bottom">Baby</span> <span class="w3-tag w3-light-grey w3-small w3-margin-bottom">Family</span>
<span class="w3-tag w3-light-grey w3-small w3-margin-bottom">News</span> <span class="w3-tag w3-light-grey w3-small w3-margin-bottom">Clothing</span> <span class="w3-tag w3-light-grey w3-small w3-margin-bottom">Shopping</span>
<span class="w3-tag w3-light-grey w3-small w3-margin-bottom">Sports</span> <span class="w3-tag w3-light-grey w3-small w3-margin-bottom">Games</span>
</p>
</div>
</div>
<!-- END Introduction Menu -->
</div>

+ 0
- 9
includes/sidebar.js View File

@ -1,9 +0,0 @@
const utils = require('../utils/utils.js');
module.exports=
{
main: function(res, fileName)
{
return utils.include(res,"includes/sidebar.html");
}
};

+ 16
- 4
posts/category.js View File

@ -1,11 +1,23 @@
var Promise = require('promise');
const sql = require('../utils/sql');
module.exports=
{
main: function(res, fileName)
{
return new Promise(function(resolve, reject)
{
sql.getCategories().then(function(categories)
{
console.log(categories);
for(var category in categories)
{
res.write(category);
}
}).then(function())
{
resolve();
}
});
}
};

+ 10
- 13
posts/posts.js View File

@ -2,17 +2,15 @@ const utils = require('../utils/utils.js');
const sql = require('../utils/sql');
var Promise = require('promise');
var renderSideBar = function(res, requestURL)
{
return new Promise(function(resolve, reject)
{
require("../includes/sidebar.js").main(res, requestURL).then(function()
{
resolve();
})
});
};
/**
* Function responsible for calling the appropriate sql requests to query
* database and serve correct blog post
*
* @param res the result sent to the client
* @param requestURL url requested from client
* @return {*|Promise} returns a resolved promise to preserve execution order
*/
var renderPost = function(res, requestURL)
{
return new Promise(function(resolve, reject)
@ -25,7 +23,6 @@ var renderPost = function(res, requestURL)
{
sql.getPost(requestURL).then(function(post)
{
console.log("a " + post);
if(post != 0)
{
return require("../posts/singlePost.js").renderPost(res, post);
@ -50,7 +47,7 @@ var renderPost = function(res, requestURL)
module.exports=
{
/**
* Function which parses a url and displays appropriate post
* Calls posts and sidebar modules to render blog contents in order
*
* @param res
* @param fileName request url
@ -61,7 +58,7 @@ module.exports=
{
renderPost(res, requestURL).then(function()
{
return renderSideBar(res, requestURL);
return require("../sidebar/sidebar.js").main(res)
}).then(function ()
{
resolve();

+ 7
- 0
posts/singlePost.js View File

@ -4,6 +4,13 @@ var Promise = require('promise');
module.exports=
{
/**
* renderPost() displays a single blog post in it's entirety
*
* @param res result sent to user
* @param post sql data about the blog post
* @return {*|Promise}
*/
renderPost: function(res, post)
{
return new Promise(function (resolve, reject)

+ 62
- 0
sidebar/categoriesSideBar.js View File

@ -0,0 +1,62 @@
const Promise = require('promise');
const sql = require('../utils/sql');
module.exports=
{
/**
* Responsible for querying the database and displaying all
* categories that the blog has in the sidebar
*
* @param res
* @return {*|Promise}
*/
main: function(res)
{
return new Promise(function(resolve, reject)
{
res.write("<div class=\"w3-col l4\">");
sql.getCategories().then(function(categories)
{
console.log(categories[0].name);
console.log("cool beans");
// for(var category in categories)
// {
// console.log(category);
// res.write(category.name);
// }
res.write("</div>");
resolve();
})
});
}
};
/*
<!-- Labels / tags -->
<div class="w3-card w3-margin">
<div class="w3-container w3-padding">
<h4>Tags</h4>
</div>
<div class="w3-container w3-white">
<p><span class="w3-tag w3-black w3-margin-bottom">Travel</span> <span class="w3-tag w3-light-grey w3-small w3-margin-bottom">New York</span> <span class="w3-tag w3-light-grey w3-small w3-margin-bottom">London</span>
<span class="w3-tag w3-light-grey w3-small w3-margin-bottom">IKEA</span> <span class="w3-tag w3-light-grey w3-small w3-margin-bottom">NORWAY</span> <span class="w3-tag w3-light-grey w3-small w3-margin-bottom">DIY</span>
<span class="w3-tag w3-light-grey w3-small w3-margin-bottom">Ideas</span> <span class="w3-tag w3-light-grey w3-small w3-margin-bottom">Baby</span> <span class="w3-tag w3-light-grey w3-small w3-margin-bottom">Family</span>
<span class="w3-tag w3-light-grey w3-small w3-margin-bottom">News</span> <span class="w3-tag w3-light-grey w3-small w3-margin-bottom">Clothing</span> <span class="w3-tag w3-light-grey w3-small w3-margin-bottom">Shopping</span>
<span class="w3-tag w3-light-grey w3-small w3-margin-bottom">Sports</span> <span class="w3-tag w3-light-grey w3-small w3-margin-bottom">Games</span>
</p>
</div>
</div>
*/

+ 70
- 0
sidebar/popularPosts.js View File

@ -0,0 +1,70 @@
const Promise = require('promise');
module.exports=
{
main: function(res)
{
return new Promise(function(resolve, reject)
{
res.write("Popular posts");
resolve();
})
}
};
/*
<!-- Posts -->
<div class="w3-card w3-margin">
<div class="w3-container w3-padding">
<h4>Popular Posts</h4>
</div>
<ul class="w3-ul w3-hoverable w3-white">
<li class="w3-padding-16">
<span class="w3-large">Lorem</span><br>
<span>Sed mattis nunc</span>
</li>
<li class="w3-padding-16">
<span class="w3-large">Ipsum</span><br>
<span>Praes tinci sed</span>
</li>
<li class="w3-padding-16">
<span class="w3-large">Dorum</span><br>
<span>Ultricies congue</span>
</li>
<li class="w3-padding-16 w3-hide-medium w3-hide-small">
<span class="w3-large">Mingsum</span><br>
<span>Lorem ipsum dipsum</span>
</li>
</ul>
</div>
<hr>
*/

+ 11
- 0
sidebar/sidebar.html View File

@ -0,0 +1,11 @@
<div class="w3-card w3-margin w3-margin-top">
<div class="w3-container w3-white">
<h4><b>My Name</b></h4>
<p>Just me, myself and I, exploring the universe of uknownment. I have a heart of love and a interest of lorem ipsum and mauris neque quam blog. I want to share my world with you.</p>
</div>
</div><hr>

+ 25
- 0
sidebar/sidebar.js View File

@ -0,0 +1,25 @@
const utils = require('../utils/utils.js');
var Promise = require('promise');
module.exports=
{
main: function(res)
{
return new Promise(function(resolve, reject)
{
res.write("<div class=\"w3-col l4\">");
utils.include(res,"sidebar/sidebar.html").then(function()
{
return require("../sidebar/popularPosts.js").main(res);
}).then(function()
{
return require("../sidebar/categoriesSideBar.js").main(res);
}).then(function()
{
res.write("</div>");
resolve();
});
})
}
};

+ 11
- 1
utils/sql.js View File

@ -35,7 +35,7 @@ var fetch = function(sqlStatement)
console.log(err);
reject();
}
console.log("sql statement method");
console.log(result);
resolve(result);
});
});
@ -107,5 +107,15 @@ module.exports=
});
});
},
/**
* Function used to retrieve all categories when making the sidebar
*
* @return {Promise<Response> | * | Array}
*/
getCategories: function()
{
var q = "select * from categories";
return fetch(q);
}
};

Loading…
Cancel
Save