Personal blog written from scratch using Node.js, Bootstrap, and MySQL. https://jrtechs.net
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
2.5 KiB

  1. /**
  2. * Renders the admin page contents
  3. */
  4. //file IO
  5. const utils = require('../utils/utils.js');
  6. module.exports=
  7. {
  8. /**
  9. * Method calls the admin widgets it correct order
  10. *
  11. * @param request
  12. * @return {*|Promise}
  13. */
  14. main: function(request, clientAddress, templateContext, filename)
  15. {
  16. console.log("admin main called");
  17. return new Promise(function(resolve, reject)
  18. {
  19. //if logged in
  20. if(request.session && request.session.user)
  21. {
  22. console.log(filename);
  23. templateContext.loggedIn = true;
  24. utils.getPostData(request).then(function (postData)
  25. {
  26. console.log("temp 1");
  27. var page = "./adminHome.js";
  28. if(filename.includes('/downloads'))
  29. {
  30. page = "./adminDownloads.js";
  31. console.log("downloads time")
  32. }
  33. else if(filename.includes("/posts"))
  34. {
  35. page = "./posts.js";
  36. }
  37. require(page).main(postData, templateContext).then(function(template)
  38. {
  39. templateContext.adminPage = template;
  40. resolve();
  41. }).catch(function(error)
  42. {
  43. console.log(error);
  44. });
  45. // console.log(postData);
  46. // Promise.all([require("./posts/newPost.js").main(postData),
  47. // require("./category/addCategory.js").main(postData),
  48. // require("./posts/editPost.js").main(postData),
  49. // require("./downloads/adminDownloads.js").main(postData)])
  50. // .then(function(content)
  51. // {
  52. // resolve(content.join(''));
  53. // }).catch(function(error)
  54. // {
  55. // reject(error);
  56. // });
  57. });
  58. }
  59. else
  60. {
  61. require("./login/login.js").main(request, clientAddress, templateContext).then(function()
  62. {
  63. resolve();
  64. }).catch(function(err)
  65. {
  66. console.log(err);
  67. reject(err);
  68. })
  69. }
  70. });
  71. }
  72. };