diff --git a/app/controllers/analytics.js b/app/controllers/analytics.js
index ceb3a3f5..81d4a2c3 100644
--- a/app/controllers/analytics.js
+++ b/app/controllers/analytics.js
@@ -4,44 +4,8 @@ const Tweet = mongoose.model("Tweet");
const qs = require('querystring')
const url = require('url')
-exports.index = (req, res) => {
- const page = (req.param("page") > 0 ? req.param("page") : 1) - 1;
- const perPage = 10;
- const options = {
- perPage: perPage,
- page: page
- };
- let analytics, pageViews, tweetCount, pagination;
-
- Analytics.list(options)
- .then(result => {
- analytics = result;
- return Analytics.count();
- })
- .then(result => {
- pageViews = result;
- pagination = createPagination(req, Math.ceil(pageViews / perPage), page+1)
- return Tweet.countTotalTweets()
- })
- .then(result => {
- tweetCount = result;
- res.render("analytics/analytics", {
- title: "List of users",
- analytics: analytics,
- pageViews: pageViews,
- tweetCount: tweetCount,
- pagination: pagination,
- pages: Math.ceil(pageViews / perPage)
- });
- })
- .catch(error => {
- console.log(error);
- return res.render("500");
- });
-};
-
-function createPagination (req, pages, page) {
+exports.createPagination = (req, pages, page) => {
let params = qs.parse(url.parse(req.url).query);
let str = '';
let pageNumberClass;
@@ -67,7 +31,7 @@ function createPagination (req, pages, page) {
if (page > 2) {
str += '
1';
if (page > 3) {
- str += '...';
+ str += '...';
}
}
// Determine how many pages to show after the current page index
@@ -112,3 +76,42 @@ function createPagination (req, pages, page) {
// Return the pagination string to be outputted in the pug templates
return str;
}
+
+
+exports.index = (req, res) => {
+ let createPagination = exports.createPagination;
+ const page = (req.param("page") > 0 ? req.param("page") : 1) - 1;
+ const perPage = 10;
+ const options = {
+ perPage: perPage,
+ page: page
+ };
+
+ let analytics, pageViews, tweetCount, pagination;
+
+ Analytics.list(options)
+ .then(result => {
+ analytics = result;
+ return Analytics.count();
+ })
+ .then(result => {
+ pageViews = result;
+ pagination = createPagination(req, Math.ceil(pageViews / perPage), page+1)
+ return Tweet.countTotalTweets()
+ })
+ .then(result => {
+ tweetCount = result;
+ res.render("analytics/analytics", {
+ title: "List of users",
+ analytics: analytics,
+ pageViews: pageViews,
+ tweetCount: tweetCount,
+ pagination: pagination,
+ pages: Math.ceil(pageViews / perPage),
+ });
+ })
+ .catch(error => {
+ console.log(error);
+ return res.render("500");
+ });
+};
diff --git a/app/controllers/tweets.js b/app/controllers/tweets.js
index 8ab7db30..73d19675 100644
--- a/app/controllers/tweets.js
+++ b/app/controllers/tweets.js
@@ -1,4 +1,5 @@
// ## Tweet Controller
+const createPagination = require('./analytics').createPagination;
const mongoose = require("mongoose");
const Tweet = mongoose.model("Tweet");
const Analytics = mongoose.model("Analytics");
@@ -47,7 +48,7 @@ exports.create = (req, res) => {
tweet.user = req.user;
tweet.uploadAndSave({}, err => {
if (err) {
- res.render("500");
+ res.render("500", {error: err});
} else {
res.redirect("/");
}
@@ -70,7 +71,7 @@ exports.update = (req, res) => {
tweet = _.extend(tweet, {"body": req.body.tweet});
tweet.uploadAndSave({}, (err) => {
if (err) {
- return res.render("500");
+ return res.render("500", {error: err});
}
res.redirect("/");
});
@@ -91,20 +92,23 @@ exports.destroy = (req, res) => {
exports.index = (req, res) => {
logAnalytics(req);
const page = (req.param("page") > 0 ? req.param("page") : 1) - 1;
+ const perPage = 10;
const options = {
- perPage: 10,
+ perPage: perPage,
page: page
};
let followingCount = req.user.following.length;
let followerCount = req.user.followers.length;
- let tweets, tweetCount, analytics;
+ let tweets, tweetCount, pageViews, analytics;
Tweet.list(options)
.then(result => {
tweets = result;
- return Tweet.countUserTweets(req.user._id)
+ return Tweet.countTotalTweets()
})
.then(result => {
tweetCount = result;
+ pageViews = result;
+ pagination = createPagination(req, Math.ceil(pageViews/ perPage), page+1);
return Analytics.list({ perPage: 15 })
})
.then(result => {
@@ -115,8 +119,10 @@ exports.index = (req, res) => {
analytics: analytics,
page: page + 1,
tweetCount: tweetCount,
+ pagination: pagination,
followerCount: followerCount,
- followingCount: followingCount
+ followingCount: followingCount,
+ pages: Math.ceil(pageViews / perPage),
});
})
.catch(error => {
diff --git a/app/models/tweets.js b/app/models/tweets.js
index ec8056f7..82e89d2a 100644
--- a/app/models/tweets.js
+++ b/app/models/tweets.js
@@ -9,11 +9,11 @@ const setTags = tags => tags.split(",");
// Tweet Schema
const TweetSchema = new Schema({
- body: { type: String, default: "", trim: true },
+ body: { type: String, default: "", trim: true, maxlength: 140},
user: { type: Schema.ObjectId, ref: "User" },
comments: [
{
- body: { type: String, default: "" },
+ body: { type: String, default: "", maxlength: 140},
user: { type: Schema.ObjectId, ref: "User" },
commenterName: { type: String, default: "" },
createdAt: { type: Date, default: Date.now }
diff --git a/app/views/500.pug b/app/views/500.pug
index 6d1f6638..e0c81b35 100644
--- a/app/views/500.pug
+++ b/app/views/500.pug
@@ -8,7 +8,7 @@ block main
block content
#error-message-box
#error-stack-trace
- pre
+ pre.pre-scrollable
code!=error
diff --git a/app/views/tweets/index.pug b/app/views/tweets/index.pug
index c2ab0f72..b8a09dd5 100644
--- a/app/views/tweets/index.pug
+++ b/app/views/tweets/index.pug
@@ -44,6 +44,12 @@ block content
include ../analytics/recent-visits
.col-xl-6.col-lg-8.second-column
include tweets
+ - if (pages > 1)
+ nav(aria-label='Page navigation example').pagination-container
+ ul.pagination
+ != pagination
+
+
.col-xl-3.col-lg-4.third-column
.recent-visits.col-xs-6.col-md-12
include ../analytics/recent-visits
diff --git a/app/views/tweets/tweets.pug b/app/views/tweets/tweets.pug
index 1627f1ba..5ef41f5b 100644
--- a/app/views/tweets/tweets.pug
+++ b/app/views/tweets/tweets.pug
@@ -2,7 +2,8 @@ each tweet in tweets
.tweet(data-tweetId = tweet._id)
.row
.col-1
- img(class='tweet-image', src=tweet.user.github.avatar_url)
+ - if (tweet.user.github !== undefined)
+ img(class='tweet-image', src=tweet.user.github.avatar_url)
.col-11.tweet-description
span.name-date-group
span.name
diff --git a/app/views/users/profile.pug b/app/views/users/profile.pug
index 1f04a42d..2a0787c4 100644
--- a/app/views/users/profile.pug
+++ b/app/views/users/profile.pug
@@ -4,13 +4,16 @@ block content
.row#profile-page
.col-lg-4
.profile-summary
- img(class="profile-image", src=user.github.avatar_url)
+ - if (user.github !== undefined)
+ img(class="profile-image", src=user.github.avatar_url)
div.user-info
span.profile-handle
- a(href=user.github.html_url, target='_blank') @#{user.github.login}
+ - if (user.github !== undefined)
+ a(href=user.github.html_url, target='_blank') @#{user.github.login}
ul
- li Github followers: #{user.github.followers}
- li Public repositories: #{user.github.public_repos}
+ - if (user.github !== undefined)
+ li Github followers: #{user.github.followers}
+ li Public repositories: #{user.github.public_repos}
.row
.col-12.user-stats
ul
diff --git a/public/css/style.css b/public/css/style.css
index 1e306ace..6171bb16 100755
--- a/public/css/style.css
+++ b/public/css/style.css
@@ -579,3 +579,21 @@ footer{
/*Extra large devices (large desktops)*/
/*No media query since the extra-large breakpoint has no upper bound on its width*/
+
+pre {
+ white-space: pre-wrap; /* css-3 */
+ white-space: -moz-pre-wrap; /* Mozilla, since 1999 */
+ white-space: -pre-wrap; /* Opera 4-6 */
+ white-space: -o-pre-wrap; /* Opera 7 */
+ word-wrap: break-word; /* Internet Explorer 5.5+ */
+}
+
+pre code {
+ color: black;
+}
+
+#error-stack-trace {
+ background: yellow;
+ padding: 20px;
+ margin-top: 20px;
+}
\ No newline at end of file