From 5d514b963e6582a461974e65ec263963e764b8e4 Mon Sep 17 00:00:00 2001 From: jrtechs Date: Mon, 22 Jan 2018 23:07:33 -0500 Subject: [PATCH] Started working on the sidebar --- includes/sidebar.html | 111 ----------------------------------- includes/sidebar.js | 9 --- posts/category.js | 20 +++++-- posts/posts.js | 23 ++++---- posts/singlePost.js | 7 +++ sidebar/categoriesSideBar.js | 62 +++++++++++++++++++ sidebar/popularPosts.js | 70 ++++++++++++++++++++++ sidebar/sidebar.html | 11 ++++ sidebar/sidebar.js | 25 ++++++++ utils/sql.js | 12 +++- 10 files changed, 212 insertions(+), 138 deletions(-) delete mode 100644 includes/sidebar.html delete mode 100644 includes/sidebar.js create mode 100644 sidebar/categoriesSideBar.js create mode 100644 sidebar/popularPosts.js create mode 100644 sidebar/sidebar.html create mode 100644 sidebar/sidebar.js diff --git a/includes/sidebar.html b/includes/sidebar.html deleted file mode 100644 index 7dd02bf..0000000 --- a/includes/sidebar.html +++ /dev/null @@ -1,111 +0,0 @@ - -
- - - -
- - - -
- -

My Name

- -

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.

- -
- -

- - - - - -
- -
- -

Popular Posts

- -
- -
    - -
  • - - - Lorem
    - - Sed mattis nunc - -
  • - -
  • - - - Ipsum
    - - Praes tinci sed - -
  • - -
  • - - - Dorum
    - - Ultricies congue - -
  • - -
  • - - - - Mingsum
    - - Lorem ipsum dipsum - -
  • - -
- -
- -
- - - - - -
- -
- -

Tags

- -
- -
- -

Travel New York London - - IKEA NORWAY DIY - - Ideas Baby Family - - News Clothing Shopping - - Sports Games - -

- -
- -
- - - - - -
\ No newline at end of file diff --git a/includes/sidebar.js b/includes/sidebar.js deleted file mode 100644 index 6e3ae48..0000000 --- a/includes/sidebar.js +++ /dev/null @@ -1,9 +0,0 @@ -const utils = require('../utils/utils.js'); - -module.exports= -{ - main: function(res, fileName) - { - return utils.include(res,"includes/sidebar.html"); - } -}; \ No newline at end of file diff --git a/posts/category.js b/posts/category.js index 98876bb..9c8154e 100644 --- a/posts/category.js +++ b/posts/category.js @@ -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(); + } + }); } }; \ No newline at end of file diff --git a/posts/posts.js b/posts/posts.js index a2cbf4e..57a4c4e 100644 --- a/posts/posts.js +++ b/posts/posts.js @@ -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(); diff --git a/posts/singlePost.js b/posts/singlePost.js index 96de4f1..d5d8d57 100644 --- a/posts/singlePost.js +++ b/posts/singlePost.js @@ -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) diff --git a/sidebar/categoriesSideBar.js b/sidebar/categoriesSideBar.js new file mode 100644 index 0000000..b63c679 --- /dev/null +++ b/sidebar/categoriesSideBar.js @@ -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("
"); + 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("
"); + resolve(); + }) + }); + } + }; + +/* + + +
+ +
+ +

Tags

+ +
+ +
+ +

Travel New York London + + IKEA NORWAY DIY + + Ideas Baby Family + + News Clothing Shopping + + Sports Games + +

+ +
+ +
+ */ \ No newline at end of file diff --git a/sidebar/popularPosts.js b/sidebar/popularPosts.js new file mode 100644 index 0000000..e6f5bdf --- /dev/null +++ b/sidebar/popularPosts.js @@ -0,0 +1,70 @@ +const Promise = require('promise'); + +module.exports= + { + main: function(res) + { + return new Promise(function(resolve, reject) + { + res.write("Popular posts"); + resolve(); + }) + } + }; + +/* + + +
+ +
+ +

Popular Posts

+ +
+ + + +
+ +
+ */ \ No newline at end of file diff --git a/sidebar/sidebar.html b/sidebar/sidebar.html new file mode 100644 index 0000000..a4cb471 --- /dev/null +++ b/sidebar/sidebar.html @@ -0,0 +1,11 @@ +
+ +
+ +

My Name

+ +

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.

+ +
+ +

\ No newline at end of file diff --git a/sidebar/sidebar.js b/sidebar/sidebar.js new file mode 100644 index 0000000..ed6b39f --- /dev/null +++ b/sidebar/sidebar.js @@ -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("
"); + + 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("
"); + resolve(); + }); + }) + } +}; \ No newline at end of file diff --git a/utils/sql.js b/utils/sql.js index 8c849bb..7b3a314 100644 --- a/utils/sql.js +++ b/utils/sql.js @@ -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 | * | Array} + */ + getCategories: function() + { + var q = "select * from categories"; + return fetch(q); } }; \ No newline at end of file