diff --git a/public/Scripts/controllers/aboutController.js b/public/Scripts/controllers/aboutController.js
new file mode 100644
index 0000000..ec55668
--- /dev/null
+++ b/public/Scripts/controllers/aboutController.js
@@ -0,0 +1,12 @@
+'use strict';
+
+(function(module) {
+ const aboutController = {};
+
+ aboutController.init = function(){
+ $('.tab-content').hide();
+ $('#about').show();
+ }
+
+ module.aboutController = aboutController;
+})(window);
diff --git a/public/Scripts/controllers/articleController.js b/public/Scripts/controllers/articleController.js
new file mode 100644
index 0000000..bce23bd
--- /dev/null
+++ b/public/Scripts/controllers/articleController.js
@@ -0,0 +1,14 @@
+'use strict';
+
+(function(module) {
+ const articleController = {};
+
+ articleController.init = function(){
+
+ Article.fetchAll(articleView.initIndexPage);
+ $('.tab-content').hide();
+ $('#articles').fadeIn();
+ }
+
+ module.articleController = articleController;
+})(window);
diff --git a/public/Scripts/controllers/routes.js b/public/Scripts/controllers/routes.js
new file mode 100644
index 0000000..6c98228
--- /dev/null
+++ b/public/Scripts/controllers/routes.js
@@ -0,0 +1,7 @@
+'use strict';
+
+page('/', articleController.init);
+page('/about', aboutController.init);
+
+
+page();
diff --git a/public/Scripts/article.js b/public/Scripts/models/article.js
similarity index 92%
rename from public/Scripts/article.js
rename to public/Scripts/models/article.js
index 838cd4e..7f3c095 100644
--- a/public/Scripts/article.js
+++ b/public/Scripts/models/article.js
@@ -1,7 +1,7 @@
'use strict';
-(fuction(contents){
+(fuction(contents) {
function Article (works) {
Object.keys(works).forEach(e => this[e] = works[e]);
@@ -23,8 +23,9 @@ return template(this);
};
Article.loadAll = rows => {
- rows.sort((a,b)) => (newDate(b.publishedOn)) - (newDate(a.publishedOn)));
-
+ rows.sort((a,b)) => (new Date(b.publishedOn)) - (new Date(a.publishedOn)));
+ Article.all = rows.map(ele => new Article(ele));
+};
// Article.loadAll = function(rawData) {
@@ -35,12 +36,6 @@ Article.loadAll = rows => {
// rawData.forEach(function(ele) {
// Article.all.push(new Article(ele));
-Article.all = rawData.map(function(ele){
- return new Article(ele);
- });
-};
-
-
Article.fetchAll = callback => {
$.get('/articles/all')
.then(
@@ -98,6 +93,14 @@ Article.numberWordsByAuthor = () => {
})
};
+ Article.stats = () => {
+ return {
+ numArticles: Article.all.length,
+ numWords: Article.numberWordsAll(),
+ Authors: Article.allAuthors(),
+ }
+ };
+
Article.truncateTable = callback => {
$.ajax({
url: '/articles/truncate',
diff --git a/public/Scripts/views/adminView.js b/public/Scripts/views/adminView.js
new file mode 100644
index 0000000..10b4c37
--- /dev/null
+++ b/public/Scripts/views/adminView.js
@@ -0,0 +1,15 @@
+(function() {
+ const adminView = {
+
+ initAdminPage : () => {
+ let template = Handlebars.compile($('#author-template').text());
+ Article.numberWordsByAuthor().forEach(stat => {
+ $('.author-stats').append(template(stat));
+ });
+ $('#blog-stats .articles').text(Article.all.length);
+ $('#blog-stats .words').text(Article.numberWordsAll());
+ }
+ };
+
+ Article.fetchAll(adminView.initAdminPage);
+})();
diff --git a/public/Scripts/articleView.js b/public/Scripts/views/articleView.js
similarity index 100%
rename from public/Scripts/articleView.js
rename to public/Scripts/views/articleView.js
diff --git a/public/Scripts/views/newArticle.js b/public/Scripts/views/newArticle.js
new file mode 100644
index 0000000..27f4801
--- /dev/null
+++ b/public/Scripts/views/newArticle.js
@@ -0,0 +1,30 @@
+(function() {
+ const newArticle = {};
+
+ newArticle.initNewArticlePage = function() {
+ $('.tab-content').show();
+ $('#export-field').hide();
+ $('#article-json').on('focus', function() {
+ $(this).select();
+ });
+ $('#new-form').on('change', newArticle.create);
+ };
+
+ newArticle.create = function() {
+ $('#articles').empty();
+ let formArticle = new Article({
+ title: $('#article-title').val(),
+ author: $('#article-author').val(),
+ authorUrl: $('#article-author-url').val(),
+ category: $('#article-category').val(),
+ body: $('#article-body').val(),
+ publishedOn: $('#article-published:checked').length ? new Date() : null
+ });
+ $('#articles').append(formArticle.toHtml('#article-template'));
+ $('pre code').each((i, block) => hljs.highlightBlock(block));
+ $('#export-field').show();
+ $('#article-json').val(JSON.stringify(formArticle) + ',');
+ };
+
+ newArticle.initNewArticlePage();
+})();
diff --git a/public/admin.html b/public/admin.html
new file mode 100644
index 0000000..70d1e50
--- /dev/null
+++ b/public/admin.html
@@ -0,0 +1,53 @@
+
+
+
+
+
+ My Portfolio
+
+
+
+
+
+
+
+
+
+
+
+
+ Blog Stats
+
+ Total articles:
+ Total words:
+ Author Stats
+ Details on who is writing, and how much writing they are doing...
+
+
+
+
+
+
+
+
+
+
diff --git a/public/index.html b/public/index.html
index 38b9114..e310279 100644
--- a/public/index.html
+++ b/public/index.html
@@ -32,8 +32,8 @@ {{author}}