From 0764a54fcd5b23ccfde890d6d44758130b6b4bf9 Mon Sep 17 00:00:00 2001 From: Darien Lombardi Date: Sun, 29 Nov 2015 18:52:23 -0800 Subject: [PATCH] rearrange profile view. new info layout and profile picture centering --- public/css/app.css | 30 +++- public/html/general/home.html | 7 +- public/html/general/nav.html | 2 +- public/html/users/profile.html | 110 +++++++++---- public/js/all.js | 149 ++++++++++-------- public/js/all.min.js | 2 +- src/javascripts/controllers/composeCtrl.js | 61 ++++--- src/javascripts/controllers/homeCtrl.js | 42 ++--- .../controllers/notificationsCtrl.js | 1 + src/javascripts/controllers/profileCtrl.js | 14 +- src/javascripts/controllers/threadCtrl.js | 1 + src/javascripts/controllers/topicCtrl.js | 1 + src/javascripts/controllers/usersCtrl.js | 45 +++--- src/javascripts/module.js | 2 +- src/stylesheets/_nav.scss | 2 +- src/stylesheets/_profile.scss | 31 ++++ src/stylesheets/_universal.scss | 4 + src/templates/general/compose.html | 46 ++++-- src/templates/general/home.html | 7 +- src/templates/general/nav.html | 2 +- src/templates/users/profile.html | 110 +++++++++---- views/index.ejs | 4 +- 22 files changed, 432 insertions(+), 241 deletions(-) diff --git a/public/css/app.css b/public/css/app.css index fa29ace..5661bb9 100644 --- a/public/css/app.css +++ b/public/css/app.css @@ -6866,6 +6866,31 @@ hr { .right { margin-left: 10px; } +#profilePicture { + display: block; + width: 150px; + height: 150px; + border-radius: 50%; + margin: 0 auto; + margin-top: 30px; } + +#info { + background-color: #f7f7f7; + padding: 10px; } + +#contact { + margin-bottom: 10px; + padding: 10px; + background-color: white; } + #contact li { + margin-top: 10px; } + +#stats { + padding: 10px; + background-color: white; } + #stats li { + margin-top: 10px; } + #navContainer { border-top: 3px solid #B92B27; } @@ -6907,7 +6932,7 @@ quora-title { background-color: #D54d4A; color: white; } -#profilePicture { +#navPicture { height: 25px; width: 25px; border-radius: 50%; } @@ -7061,3 +7086,6 @@ button { .buttons .dislikeBtn:hover { background-color: #797979; } + +.sweet-alert fieldset { + display: none; } diff --git a/public/html/general/home.html b/public/html/general/home.html index 8f8f71f..76ef00f 100644 --- a/public/html/general/home.html +++ b/public/html/general/home.html @@ -6,14 +6,13 @@
-

Topics

Subscriptions

-

Random Topics

+

Topics

{{post.title}}

-

{{post.author.username}} {{post.author.work}}

+

{{post.author.username}} {{post.author.work}}

tags: {{post.tags}}

@@ -70,7 +69,7 @@

{{post.title}}

-
{{comment.author.username}}
+
{{comment.author.username}}

diff --git a/public/html/general/nav.html b/public/html/general/nav.html index daa9817..24e84cb 100644 --- a/public/html/general/nav.html +++ b/public/html/general/nav.html @@ -26,7 +26,7 @@

Quora

  • Home
  • Compose
  • {{newNotifications.length}} Notifications
  • -
  • {{currentUser.username}}
  • +
  • {{currentUser.username}}
  • Login
  • Logout
  • diff --git a/public/html/users/profile.html b/public/html/users/profile.html index 7d49e84..ffe4092 100644 --- a/public/html/users/profile.html +++ b/public/html/users/profile.html @@ -1,45 +1,89 @@ -
    -
    - Profile Picture -
    +
    +
    + +

    {{user.username}}

    - - - - - + + +
    -
    {{user.about}}

    - - -
    - Feed Here of all user activity? +
    +
    +
    +
      +
    • email: {{user.email}}
    • +
    • home: {{user.home}}
    • +
    • work: {{user.work}}
    • +
    • about: {{user.about}}
    • +
    +
    +
    +
      +
    • posts: {{user.posts.length}}
    • +
    • followers: {{user.followers.length}}
    • +
    • following: {{user.following.length}}
    • +
    • views: {{user.views}}
    • +
    +
    +
    -
    -
    -
    -
    -

    Posts

    - {{user.likes}} likes
    - {{user.views}} views -

    -
    -

    Activity

    - {{user.followers}} followers
    - {{user.following}} following + + +
    +
    +
    + +
    +

    answered • {{post.topic.name}}

    +
    +
    +

    unanswered • {{post.topic.name}}

    +
    +

    {{post.title}}

    +

    {{post.author.username}} {{post.author.work}}

    +

    +

    tags: {{post.tags}}

    + + + + + Comments {{post.comments.length}} + Comments {{post.comments.length}} +
    +
    +
    +
    +
    +
    +
    + +
    +
    + +
    +
    +
    +
    +
    +
    + +
    {{comment.author.username}}
    +

    + + + + +
    +
    +
    +
    +
    - - {{user.posts.length}} posts -
    -
    I can answer questions about...
    -
      -
    • {{user.knowledge.topic.name}}
    • -
    diff --git a/public/js/all.js b/public/js/all.js index 086ee65..c0f7d18 100644 --- a/public/js/all.js +++ b/public/js/all.js @@ -1,6 +1,6 @@ 'use strict'; -var app = angular.module('quora', ['ui.router', 'infinite-scroll', 'hc.marked', "oitozero.ngSweetAlert", "ngFileUpload"]); +var app = angular.module('quora', ['ui.router', 'infinite-scroll', 'hc.marked', "ngFileUpload"]); app.constant('tokenStorageKey', 'my-token'); @@ -66,21 +66,6 @@ app.config(["$stateProvider", "$locationProvider", "$urlRouterProvider", "marked $urlRouterProvider.otherwise('/'); }]); -"use strict"; - -app.directive('ngEnter', function () { - return function (scope, element, attrs) { - element.bind("keydown keypress", function (event) { - if (event.which === 13) { - scope.$apply(function () { - scope.$eval(attrs.ngEnter); - }); - - event.preventDefault(); - } - }); - }; -}); 'use strict'; app.controller('composeCtrl', function ($scope, $http, $location, $state, auth, postFactory, topicFactory) { @@ -93,14 +78,15 @@ app.controller('composeCtrl', function ($scope, $http, $location, $state, auth, (function init() { topicFactory.getTopics().success(function (topics) { $scope.topics = topics; - console.log(topics); }).error(function (err) { console.log("error: ", err); }); var questionObject = { postType: "question" }; - $scope.topQuestion = postFactory.getSortedPosts(questionObject)[0]; + postFactory.getSortedPosts(questionObject).success(function (questions) { + $scope.topQuestion = questions[0]; + }); })(); $scope.addTopicToPost = function (topic) { @@ -111,22 +97,31 @@ app.controller('composeCtrl', function ($scope, $http, $location, $state, auth, }, 50); }; - $scope.submitQuestion = function (question, selectedTopic) { - var questionObject = { - author: currentUser._id, - title: question.title, - tags: question.tags, - content: question.content, - topic: selectedTopic, - postType: "question", - token: auth.getToken() - }; - console.log(questionObject); - postFactory.createPost(questionObject).success(function (data) { - $location.path('thread/' + data._id + ''); - }).error(function (err) { - console.log(err); - }); + $scope.submitQuestion = function (isValid, question, selectedTopic) { + if (isValid) { + var questionObject = { + author: currentUser._id, + title: question.title, + tags: question.tags, + content: question.content, + topic: selectedTopic, + postType: "question", + token: auth.getToken() + }; + postFactory.createPost(questionObject).success(function (data) { + $location.path('thread/' + data._id + ''); + }).error(function (err) { + console.log(err); + }); + } else { + swal({ + title: "Invalid Form", + text: "Incorrect Inputs", + timer: 2000, + type: "error", + confirmButtonColor: "#B92B27" + }); + } }; $scope.submitTopic = function (topic) { @@ -164,6 +159,7 @@ app.controller('homeCtrl', function ($scope, $state, postFactory, userFactory, t $scope.topicFeed; var currentUser = auth.currentUser(); $scope.loggedIn = auth.isLoggedIn(); + $(document).foundation(); if (!$scope.loggedIn) { $state.go("users.login"); @@ -273,12 +269,7 @@ app.controller('homeCtrl', function ($scope, $state, postFactory, userFactory, t pid: $scope.posts[index]._id }; postFactory.getSortedComments(sortingObject).success(function (posts) { - if (currentUser) { - postFactory.formatPosts(posts, currentUser); - $scope.comments = posts; - } else { - $scope.comments = posts; - } + $scope.comments = posts; }); }; @@ -287,23 +278,19 @@ app.controller('homeCtrl', function ($scope, $state, postFactory, userFactory, t }; $scope.submitComment = function (comment, post) { - if (!$scope.loggedIn) { - $rootScope.isNotLoggedIn(); - } else { - var commentObject = { - content: comment, - author: currentUser._id, - responseTo: post._id, - postType: "comment", - token: auth.getToken() - }; - postFactory.createPost(commentObject).success(function (post) { - $scope.comments.push(post); - }).error(function (err) { - console.log("failed to submit comment"); - console.error(err); - }); - } + var commentObject = { + content: comment, + author: currentUser._id, + responseTo: post._id, + postType: "comment", + token: auth.getToken() + }; + postFactory.createPost(commentObject).success(function (post) { + $scope.comments.push(post); + }).error(function (err) { + console.log("failed to submit comment"); + console.error(err); + }); }; $scope.deletePost = function (post, $index) { @@ -329,12 +316,10 @@ app.controller('homeCtrl', function ($scope, $state, postFactory, userFactory, t $scope.$on('filteredByTags', function (event, posts) { $scope.posts = posts; }); - $scope.$on("loggedOut", function () { $scope.loggedIn = auth.isLoggedIn(); $scope.getPosts(); }); - $scope.$on("loggedIn", function () { $scope.loggedIn = auth.isLoggedIn(); }); @@ -345,6 +330,7 @@ app.controller('notificationsCtrl', function ($scope, $http, auth, userFactory, $scope.currentUser = auth.currentUser(); $scope.newNotifications; $scope.oldNotifications; + $(document).foundation(); ($scope.getNotifications = function () { $scope.newNotifications = []; @@ -373,9 +359,18 @@ app.controller('notificationsCtrl', function ($scope, $http, auth, userFactory, }); 'use strict'; -app.controller('profileCtrl', function ($scope, $state, auth) { - +app.controller('profileCtrl', function ($scope, $stateParams, $state, auth, userFactory) { $(document).foundation(); + $scope.currentUser = false; + $scope.followed = false; + userFactory.getUser($stateParams.user).success(function (user) { + if (user._id === auth.currentUser()._id) { + $scope.currentUser = true; + } + user.followers.indexOf(auth.currentUser()._id) !== -1 ? $scope.followed = true : $scope.followed = false; + $scope.user = user; + }); + $scope.$emit("getNotifications"); $scope.$emit("notHome"); }); @@ -385,6 +380,7 @@ app.controller('threadCtrl', function ($scope, $state, auth, postFactory, $rootS $scope.displayAnswerForm = false; var currentUser = auth.currentUser(); $scope.loggedIn = auth.isLoggedIn(); + $(document).foundation(); $scope.answers; $scope.comments; @@ -581,6 +577,7 @@ app.controller('topicCtrl', function ($scope, $state, $stateParams, topicFactory $scope.posts; $scope.topic; $scope.subscribed = false; + $(document).foundation(); (function getTopicPosts() { topicFactory.getTopic($stateParams.topic).success(function (topic) { @@ -798,7 +795,7 @@ app.controller('usersCtrl', function ($scope, $state, auth, userFactory, postFac $state.go('home'); }).error(function (err) { swal({ - title: "Input Not Valid", + title: "Input Not Valid??", text: "Either the username or password was entered incorrectly", timer: 2000, type: "error", @@ -818,18 +815,17 @@ app.controller('usersCtrl', function ($scope, $state, auth, userFactory, postFac password: $scope.password } }); - file.upload.then(function (response) { - auth.saveToken(response.data.token); + file.upload.then(function (res) { + auth.saveToken(res.data.token); $scope.$emit('login'); $timeout(function () { - file.result = response.data; + file.result = res.data; $state.go('home'); }); - }, function (response) { - if (response.status > 0) $scope.errorMsg = response.status + ': ' + response.data; + }, function (res) { + if (res.status > 0) $scope.errorMsg = res.status + ': ' + res.data; }, function (evt) { - // Math.min is to fix IE which reports 200% sometimes file.progress = Math.min(100, parseInt(100.0 * evt.loaded / evt.total)); }); }; @@ -837,7 +833,7 @@ app.controller('usersCtrl', function ($scope, $state, auth, userFactory, postFac $scope.logout = function () { auth.logout(); $scope.$emit('logout'); - $state.go('home'); + $state.go('users.login'); }; $scope.filterByTag = function (tag) { @@ -885,6 +881,21 @@ app.controller('usersCtrl', function ($scope, $state, auth, userFactory, postFac }); }); }); +"use strict"; + +app.directive('ngEnter', function () { + return function (scope, element, attrs) { + element.bind("keydown keypress", function (event) { + if (event.which === 13) { + scope.$apply(function () { + scope.$eval(attrs.ngEnter); + }); + + event.preventDefault(); + } + }); + }; +}); 'use strict'; app.factory('auth', function ($window, $http, tokenStorageKey) { diff --git a/public/js/all.min.js b/public/js/all.min.js index 8128c95..b678b2e 100644 --- a/public/js/all.min.js +++ b/public/js/all.min.js @@ -1 +1 @@ -"use strict";var app=angular.module("quora",["ui.router","infinite-scroll","hc.marked","oitozero.ngSweetAlert","ngFileUpload"]);app.constant("tokenStorageKey","my-token"),app.filter("unsafe",function(t){return function(o){return t.trustAsHtml(o)}}).run(function(t,o){t.$on("logout",function(){t.$broadcast("loggedOut")}),t.$on("login",function(){t.$broadcast("loggedIn")}),t.$on("tag posts",function(o,e){t.$broadcast("filteredByTags",e)}),t.$on("getNotifications",function(o,e){t.$broadcast("notifications",e)}),t.$on("notHome",function(){t.$broadcast("removeTagFilter")}),t.$on("inHome",function(){t.$broadcast("addTagFilter")}),t.isNotLoggedIn=function(){swal({title:"Not Logged In!",text:"You must be logged in to complete this action.",showCancelButton:!0,confirmButtonColor:"#B92B27",confirmButtonText:"Go to Login?",closeOnConfirm:!1,imageUrl:"../assets/Tied_Hands-100.png"},function(){swal({title:"Redirecting!",type:"success",timer:750,showConfirmButton:!1}),o.go("users.login")})}}),app.config(["$stateProvider","$locationProvider","$urlRouterProvider","markedProvider",function(t,o,e,n){o.html5Mode(!0).hashPrefix("!"),n.setOptions({gfm:!0,tables:!0,highlight:function(t,o){return o?hljs.highlight(o,t,!0).value:hljs.highlightAuto(t).value}}),t.state("home",{url:"/",templateUrl:"/html/general/home.html",controller:"homeCtrl"}).state("thread",{url:"/thread/:thread?",templateUrl:"/html/general/thread.html",controller:"threadCtrl"}).state("compose",{url:"/compose",templateUrl:"/html/general/compose.html",controller:"composeCtrl"}).state("topic",{url:"/topics/:topic?",templateUrl:"/html/general/topic.html",controller:"topicCtrl"}).state("users",{"abstract":!0,templateUrl:"/html/users/users.html"}).state("users.login",{url:"/login",templateUrl:"/html/users/form.html",controller:"usersCtrl"}).state("users.notifications",{url:"/notifications",templateUrl:"/html/users/notifications.html",controller:"notificationsCtrl"}).state("users.profile",{url:"/profile/:user?",templateUrl:"/html/users/profile.html",controller:"profileCtrl"}),e.otherwise("/")}]),app.directive("ngEnter",function(){return function(t,o,e){o.bind("keydown keypress",function(o){13===o.which&&(t.$apply(function(){t.$eval(e.ngEnter)}),o.preventDefault())})}}),app.controller("composeCtrl",function(t,o,e,n,s,i,r){var c=s.currentUser();$(document).foundation(),t.topics=[],t.selectedTopic,t.toggleDropdown=!1,function(){r.getTopics().success(function(o){t.topics=o,console.log(o)}).error(function(t){console.log("error: ",t)});var o={postType:"question"};t.topQuestion=i.getSortedPosts(o)[0]}(),t.addTopicToPost=function(o){t.selectedTopic=o.name,t.toggleDropdown=!0,window.setTimeout(function(){t.toggleDropdown=!1},50)},t.submitQuestion=function(t,o){var n={author:c._id,title:t.title,tags:t.tags,content:t.content,topic:o,postType:"question",token:s.getToken()};console.log(n),i.createPost(n).success(function(t){e.path("thread/"+t._id)}).error(function(t){console.log(t)})},t.submitTopic=function(o){console.log("SUBMIT POST FUNCTION STARTS");var e={name:o.name,about:o.about,token:s.getToken()};r.createTopic(e).success(function(o){t.topics.push(o),swal({title:"Success!",text:"You've made a new Topic!",timer:750,showConfirmButton:!1}),n.go("compose")}).error(function(t){swal({title:"Error!",text:"Missing fields!",showConfirmButton:!0})})},t.$emit("notHome"),t.$emit("getNotifications")}),app.controller("homeCtrl",function(t,o,e,n,s,i,r,c,u){t.posts,t.topicFeed;var l=i.currentUser();t.loggedIn=i.isLoggedIn(),t.loggedIn||o.go("users.login"),t.getPosts=function(o){t.posts=[],t.topicFeed=[];var i={postType:"question",sortingMethod:o};e.getSortedPosts(i).success(function(o){t.posts=o}),s.get7Topics().success(function(o){t.topicFeed=o}),n.getUser(l._id).success(function(o){t.subscriptions=o.subscriptions})},t.getPosts("likes"),t.sortLikes=function(){$(".filter").removeClass("active"),$("#likes").addClass("active"),t.getPosts("likes")},t.sortDislikes=function(){$(".filter").removeClass("active"),$("#dislikes").addClass("active"),t.getPosts("dislikes")},t.sortOldest=function(){$(".filter").removeClass("active"),$("#oldest").addClass("active"),t.getPosts("oldest")},t.sortNewest=function(){$(".filter").removeClass("active"),$("#newest").addClass("active"),t.getPosts("newest")},t.sortSubscriptions=function(){$(".filter").removeClass("active"),$("#subscriptions").addClass("active"),e.subscriptionsPosts(l._id).success(function(o){t.posts=o})},t.togglePostLike=function(o,n){var s=void 0,r=void 0;s="post"===o?t.posts:t.comments,r=s[n].liked?"unlike":"like";var c={pid:s[n]._id,uid:l._id,type:r,token:i.getToken()};e.changeStats(c).success(function(t){"like"===r?(s[n].likes+=1,s[n].liked=!0):(s[n].likes-=1,s[n].liked=!1)})},t.togglePostDislike=function(o,n){var s=void 0,r=void 0;s="post"===o?t.posts:t.comments,r=s[n].disliked?"undo":"dislike";var c={pid:s[n]._id,uid:l._id,type:r,token:i.getToken()};e.changeStats(c).success(function(t){"dislike"===r?(s[n].dislikes+=1,s[n].disliked=!0):(s[n].dislikes-=1,s[n].disliked=!1)})},t.showComments=function(o){t.posts[o].showComments=!0;var n=(t.posts[o].comments,{sortingMethod:"likes",pid:t.posts[o]._id});e.getSortedComments(n).success(function(o){l?(e.formatPosts(o,l),t.comments=o):t.comments=o})},t.hideComments=function(o){t.posts[o].showComments=!1},t.submitComment=function(o,n){if(t.loggedIn){var s={content:o,author:l._id,responseTo:n._id,postType:"comment",token:i.getToken()};e.createPost(s).success(function(o){t.comments.push(o)}).error(function(t){console.log("failed to submit comment"),console.error(t)})}else u.isNotLoggedIn()},t.deletePost=function(o,n){e.deletePost(o._id).success(function(o){switch(o.postType){case"comment":t.comments.splice(n,1);break;case"question":t.posts.splice(n,1)}}).error(function(t){console.log("failed at deletePost function "),console.error(t)})},t.$emit("getNotifications"),t.$emit("inHome"),t.$on("filteredByTags",function(o,e){t.posts=e}),t.$on("loggedOut",function(){t.loggedIn=i.isLoggedIn(),t.getPosts()}),t.$on("loggedIn",function(){t.loggedIn=i.isLoggedIn()})}),app.controller("notificationsCtrl",function(t,o,e,n,s,i){t.currentUser=e.currentUser(),t.newNotifications,t.oldNotifications,(t.getNotifications=function(){t.newNotifications=[],t.oldNotifications=[];var o={uid:t.currentUser._id};n.getNotifs(o).success(function(e){t.newNotifications=e.notifications.filter(function(t){return!t.seen}),t.oldNotifications=e.notifications.filter(function(t){return t.seen}),n.clearNotifs(o).success(function(t){console.log("user: ",t)}).error(function(t){console.log("error: ",t)})}).error(function(t){console.log("error: ",t)})})(),t.$emit("notHome")}),app.controller("profileCtrl",function(t,o,e){$(document).foundation(),t.$emit("getNotifications"),t.$emit("notHome")}),app.controller("threadCtrl",function(t,o,e,n,s,i){t.displayAnswerForm=!1;var r=e.currentUser();t.loggedIn=e.isLoggedIn(),t.answers,t.comments,t.question,(t.getPost=function(){n.getPost(i.thread).success(function(o){t.question=o,t.topic=o.topic,t.comments=o.comments;var e={sortingMethod:"likes",pid:o._id};n.getSortedAnswers(e).success(function(o){t.answers=o})}).error(function(t){console.log(t)})})(),t.submitAnswer=function(o,s){var i={content:o,author:r._id,responseTo:s._id,postType:"answer",token:e.getToken()};n.createPost(i).success(function(o){t.answers.push(o)}).error(function(t){console.log("error: ",t)})},t.toggleAnswerLike=function(o){if(t.loggedIn){var i;i=t.answers[o].liked?"unlike":"like";var c={pid:t.answers[o]._id,uid:r._id,type:i,token:e.getToken()};n.changeStats(c).success(function(e){"like"===i?(t.answers[o].likes+=1,t.answers[o].liked=!0):(t.answers[o].likes-=1,t.answers[o].liked=!1)}).error(function(t){console.log("error: ",t)})}else s.isNotLoggedIn()},t.toggleAnswerDislike=function(o){if(t.loggedIn){var i;i=t.answers[o].disliked?"undo":"dislike";var c={pid:t.answers[o]._id,uid:r._id,type:i,token:e.getToken()};n.changeStats(c).success(function(e){"dislike"===i?(t.answers[o].dislikes+=1,t.answers[o].disliked=!0):(t.answers[o].dislikes-=1,t.answers[o].disliked=!1)}).error(function(t){console.log("error: ",t)})}else s.isNotLoggedIn()},t.toggleCommentLike=function(o){if(t.loggedIn){var i;i=t.comments[o].liked?"unlike":"like";var c={pid:t.comments[o]._id,uid:r._id,type:i,token:e.getToken()};n.changeStats(c).success(function(e){"like"===i?(t.comments[o].likes+=1,t.comments[o].liked=!0):(t.comments[o].likes-=1,t.comments[o].liked=!1)}).error(function(t){console.log("error: ",t)})}else s.isNotLoggedIn()},t.toggleCommentDislike=function(o){if(t.loggedIn){var i;i=t.comments[o].disliked?"undo":"dislike";var c={pid:t.comments[o]._id,uid:r._id,type:i,token:e.getToken()};n.changeStats(c).success(function(e){"dislike"===i?(t.comments[o].dislikes+=1,t.comments[o].disliked=!0):(t.comments[o].dislikes-=1,t.comments[o].disliked=!1)}).error(function(t){console.log("error: ",t)})}else s.isNotLoggedIn()},t.showComments=function(){var o={sortingMethod:"likes",pid:t.posts[index]._id};n.getSortedComments(o).success(function(o){r?(n.formatPosts(o,r),t.comments=o):t.comments=o})},t.submitComment=function(o,i){if(console.log(i),t.loggedIn){var c={content:o,author:r._id,responseTo:i._id,postType:"comment",token:e.getToken()};n.createPost(c).success(function(o){t.comments.push(o)}).error(function(t){console.log("error: ",t)})}else s.isNotLoggedIn()},t.loadMore=function(){for(var o=t.comments[t.comments.length-1],e=8,n=1;e>=n;n++)console.log("count is "+n),t.comments.push(o+"")},t.$emit("notHome"),t.$emit("getNotifications")}),app.controller("topicCtrl",function(t,o,e,n,s,i,r,c){var u=s.currentUser();t.loggedIn=s.isLoggedIn(),t.posts,t.topic,t.subscribed=!1,function(){n.getTopic(e.topic).success(function(o){console.log("TOPIC: ",o),o.subscribers.forEach(function(o){o===u._id?t.subscribed=!0:t.subscribed=!1}),t.topic=o,r.formatPosts(o.posts,u),t.posts=o.posts}).error(function(t){console.log("error: ",t)})}(),t.subscribe=function(){var o={uid:u._id,topic:e.topic};console.log(o),i.subscribe(o).success(function(o){t.subscribed=!0}).error(function(t){console.log("error: ",t)})},t.unsubscribe=function(){var o={uid:u._id,topic:e.topic};i.unsubscribe(o).success(function(o){t.subscribed=!1}).error(function(t){console.log("error: ",t)})},t.togglePostLike=function(o){if(t.loggedIn){var e;e=t.posts[o].liked?"unlike":"like";var n={pid:t.posts[o]._id,uid:u._id,type:e,token:s.getToken()};r.changeStats(n).success(function(n){"like"===e?(t.posts[o].likes+=1,t.posts[o].liked=!0):(t.posts[o].likes-=1,t.posts[o].liked=!1)}).error(function(t){console.log("error: ",t)})}else c.isNotLoggedIn()},t.togglePostDislike=function(o){if(t.loggedIn){var e;e=t.posts[o].disliked?"undo":"dislike";var n={pid:t.posts[o]._id,uid:u._id,type:e,token:s.getToken()};r.changeStats(n).success(function(n){"dislike"===e?(t.posts[o].dislikes+=1,t.posts[o].disliked=!0):(t.posts[o].dislikes-=1,t.posts[o].disliked=!1)}).error(function(t){console.log("error: ",t)})}else c.isNotLoggedIn()},t.toggleCommentLike=function(o){if(t.loggedIn){var e;e=t.comments[o].liked?"unlike":"like";var n={pid:t.comments[o]._id,uid:u._id,type:e,token:s.getToken()};r.changeStats(n).success(function(n){"like"===e?(t.comments[o].likes+=1,t.comments[o].liked=!0):(t.comments[o].likes-=1,t.comments[o].liked=!1)}).error(function(t){console.log("error: ",t)})}else c.isNotLoggedIn()},t.toggleCommentDislike=function(o){if(t.loggedIn){var e;e=t.comments[o].disliked?"undo":"dislike";var n={pid:t.comments[o]._id,uid:u._id,type:e,token:s.getToken()};r.changeStats(n).success(function(n){"dislike"===e?(t.comments[o].dislikes+=1,t.comments[o].disliked=!0):(t.comments[o].dislikes-=1,t.comments[o].disliked=!1)}).error(function(t){console.log("error: ",t)})}else c.isNotLoggedIn()},t.showComments=function(o){t.posts[o].showComments=!0;var e=(t.posts[o].comments,{sortingMethod:"likes",pid:t.posts[o]._id});r.getSortedComments(e).success(function(o){r.formatPosts(o,u),console.log(o),t.comments=o})},t.hideComments=function(o){t.posts[o].showComments=!1},t.submitComment=function(o,e){if(t.loggedIn){var n={content:o,author:u._id,responseTo:e._id,postType:"comment",token:s.getToken()};r.createPost(n).success(function(o){t.comments.push(o),console.log(o)}).error(function(t){console.log("error: ",t)})}else c.isNotLoggedIn()},t.$emit("notHome"),t.$emit("getNotifications"),t.$on("loggedOut",function(){t.loggedIn=s.isLoggedIn()}),t.$on("loggedIn",function(){t.loggedIn=s.isLoggedIn()})}),app.controller("usersCtrl",function(t,o,e,n,s,i,r,c){t.Login=!1,t.tagFilter=!0,t.loggedIn=e.isLoggedIn(),t.currentUser=e.currentUser(),t.newNotifications=[],(t.switchState=function(){t.Login=!t.Login,t.Login?t.currentState="Create Account":t.currentState="Go to Login",t.Login?t.formState="Login":t.formState="Register"})(),t.login=function(n,s){var i={username:n,password:s};e.login(i).success(function(e){t.$emit("login"),o.go("home")}).error(function(t){swal({title:"Input Not Valid",text:"Either the username or password was entered incorrectly",timer:2e3,type:"error",confirmButtonColor:"#B92B27"})})},t.register=function(n){n.upload=r.upload({url:"auth/register",data:{file:n,username:t.username,email:t.email,fullName:t.fullName,password:t.password}}),n.upload.then(function(s){e.saveToken(s.data.token),t.$emit("login"),c(function(){n.result=s.data,o.go("home")})},function(o){o.status>0&&(t.errorMsg=o.status+": "+o.data)},function(t){n.progress=Math.min(100,parseInt(100*t.loaded/t.total))})},t.logout=function(){e.logout(),t.$emit("logout"),o.go("home")},t.filterByTag=function(o){s.getPostsByTag(o).success(function(o){t.$emit("tag posts",o)}).error(function(t){console.log("error: ",t)})},t.$on("removeTagFilter",function(){t.tagFilter=!1}),t.$on("addTagFilter",function(){t.tagFilter=!0}),t.$on("notifications",function(){n.getUser(t.currentUser._id).success(function(o){t.picture=e.loggedInUser.picture,t.newNotifications=o.notifications.filter(function(t){return!t.seen})}).error(function(t){console.log("error: ",t)})}),t.$on("loggedOut",function(){t.loggedIn=e.isLoggedIn(),t.notifications=[]}),t.$on("loggedIn",function(){t.loggedIn=e.isLoggedIn(),t.currentUser=e.currentUser(),n.getUser(t.currentUser._id).success(function(o){t.picture=e.loggedInUser.picture,t.newNotifications=o.notifications.filter(function(t){return!t.seen})}).error(function(t){console.log("error: ",t)})})}),app.factory("auth",function(t,o,e){var n={};return n.loggedInUser,n.saveToken=function(o){t.localStorage[e]=o},n.getToken=function(){return t.localStorage[e]},n.isLoggedIn=function(){var o=n.getToken();if(o){var e=JSON.parse(t.atob(o.split(".")[1]));return e.exp>Date.now()/1e3}return!1},n.currentUser=function(){if(n.isLoggedIn()){var e=n.getToken(),s=JSON.parse(t.atob(e.split(".")[1]));return o.get("/users/"+s._id).then(function(t){n.loggedInUser=t.data})["catch"](function(t){console.log("err",t)}),s}},n.register=function(t){return o.post("/auth/register",t).success(function(t){n.saveToken(t.token)})},n.login=function(t){return o.post("/auth/login",t).success(function(t){n.saveToken(t.token)})},n.logout=function(){t.localStorage.removeItem(e)},n}),app.factory("postFactory",function(t,o,e){var n={};return n.createPost=function(t){return o.post("/posts/add",t)},n.deletePost=function(t){return o["delete"]("/posts/delete/"+t)},n.changeStats=function(t){return o.put("/posts/changeStats",t)},n.getPost=function(t){return o.get("/posts/"+t)},n.editPost=function(t){return o.put("/posts/edit",t)},n.getPostsByTag=function(t){return o.get("/posts/sorted/user/topic/tag/"+t+"/postType/").success(function(t){return n.formatPosts(t,e.currentUser()),t})},n.getPostsByTopic=function(t){return o.get("/posts/sorted/user/topic/"+t+"/tag/postType/").success(function(t){return n.formatPosts(t,e.currentUser()),t})},n.getSortedPosts=function(t){return o.get("/posts/sorted/"+t.sortingMethod+"/user/topic/tag/postType/"+t.postType).success(function(t){return n.formatPosts(t,e.currentUser()),t})},n.subscriptionsPosts=function(t){return o.get("/posts/sorted/user/"+t+"/topic/tag/postType/").success(function(t){return n.formatPosts(t,e.currentUser()),t})},n.getSortedComments=function(t){return o.get("/posts/sortedComments/"+t.sortingMethod+"/post/"+t.pid).success(function(t){return n.formatPosts(t,e.currentUser()),t})},n.getSortedAnswers=function(t){return o.get("/posts/sortedComments/"+t.sortingMethod+"/post/"+t.pid).success(function(t){return n.formatPosts(t,e.currentUser()),t})},n.formatLikedPosts=function(t,o){t.map(function(t){return t.likers.forEach(function(e){if(e.toString()===o._id.toString()){var n=t;return n.liked=!0,n}return t})}),t.map(function(t){return t.dislikers.forEach(function(e){if(e.toString()===o._id.toString()){var n=t;return n.disliked=!0,n}return t})})},n.formatTags=function(t){t.map(function(o){console.log(t);var e="";return o.tags.forEach(function(t){e+=t+", "}),o.tags=e,o})},n.formatUserPosts=function(t,o){t.map(function(t){t.author._id.toString()===o._id.toString()?t.userPost=!0:t.userPost=!1})},n.formatPosts=function(t,o){return n.formatLikedPosts(t,o),n.formatUserPosts(t,o),n.formatTags(t),t},n}),app.factory("topicFactory",function(t,o){var e={};return e.getTopics=function(){return o.get("/topics/allTopics")},e.subscribedTopics=function(){return o.get("/topics/allTopics")},e.get7Topics=function(){return o.get("/topics/limit7")},e.getTopic=function(t){return o.get("/topics/topic/"+t)},e.createTopic=function(t){return o.post("/topics/add",t)},e.deleteTopic=function(t){return o["delete"]("/topics/delete",t)},e}),app.factory("userFactory",function(t,o){var e={};return e.getUser=function(t){return o.get("/users/"+t)},e.getNotifs=function(t){return o.get("/users/notifications/"+t.uid)},e.clearNotifs=function(t){return o.post("/users/clearNotifications",t)},e.addKnowledge=function(t){return o.post("/users/addKnowledge",t)},e.updateInfo=function(t){return o.put("/users/updateInfo",t)},e.follow=function(t){return o.post("/users/follow",t)},e.unfollow=function(t){return o.put("/users/unfollow",t)},e.subscribe=function(t){return o.post("/users/subscribe",t)},e.unsubscribe=function(t){return o.put("/users/unsubscribe",t)},e}); \ No newline at end of file +"use strict";var app=angular.module("quora",["ui.router","infinite-scroll","hc.marked","ngFileUpload"]);app.constant("tokenStorageKey","my-token"),app.filter("unsafe",function(t){return function(o){return t.trustAsHtml(o)}}).run(function(t,o){t.$on("logout",function(){t.$broadcast("loggedOut")}),t.$on("login",function(){t.$broadcast("loggedIn")}),t.$on("tag posts",function(o,e){t.$broadcast("filteredByTags",e)}),t.$on("getNotifications",function(o,e){t.$broadcast("notifications",e)}),t.$on("notHome",function(){t.$broadcast("removeTagFilter")}),t.$on("inHome",function(){t.$broadcast("addTagFilter")}),t.isNotLoggedIn=function(){swal({title:"Not Logged In!",text:"You must be logged in to complete this action.",showCancelButton:!0,confirmButtonColor:"#B92B27",confirmButtonText:"Go to Login?",closeOnConfirm:!1,imageUrl:"../assets/Tied_Hands-100.png"},function(){swal({title:"Redirecting!",type:"success",timer:750,showConfirmButton:!1}),o.go("users.login")})}}),app.config(["$stateProvider","$locationProvider","$urlRouterProvider","markedProvider",function(t,o,e,n){o.html5Mode(!0).hashPrefix("!"),n.setOptions({gfm:!0,tables:!0,highlight:function(t,o){return o?hljs.highlight(o,t,!0).value:hljs.highlightAuto(t).value}}),t.state("home",{url:"/",templateUrl:"/html/general/home.html",controller:"homeCtrl"}).state("thread",{url:"/thread/:thread?",templateUrl:"/html/general/thread.html",controller:"threadCtrl"}).state("compose",{url:"/compose",templateUrl:"/html/general/compose.html",controller:"composeCtrl"}).state("topic",{url:"/topics/:topic?",templateUrl:"/html/general/topic.html",controller:"topicCtrl"}).state("users",{"abstract":!0,templateUrl:"/html/users/users.html"}).state("users.login",{url:"/login",templateUrl:"/html/users/form.html",controller:"usersCtrl"}).state("users.notifications",{url:"/notifications",templateUrl:"/html/users/notifications.html",controller:"notificationsCtrl"}).state("users.profile",{url:"/profile/:user?",templateUrl:"/html/users/profile.html",controller:"profileCtrl"}),e.otherwise("/")}]),app.controller("composeCtrl",function(t,o,e,n,s,i,r){var c=s.currentUser();$(document).foundation(),t.topics=[],t.selectedTopic,t.toggleDropdown=!1,function(){r.getTopics().success(function(o){t.topics=o}).error(function(t){console.log("error: ",t)});var o={postType:"question"};i.getSortedPosts(o).success(function(o){t.topQuestion=o[0]})}(),t.addTopicToPost=function(o){t.selectedTopic=o.name,t.toggleDropdown=!0,window.setTimeout(function(){t.toggleDropdown=!1},50)},t.submitQuestion=function(t,o,n){if(t){var r={author:c._id,title:o.title,tags:o.tags,content:o.content,topic:n,postType:"question",token:s.getToken()};i.createPost(r).success(function(t){e.path("thread/"+t._id)}).error(function(t){console.log(t)})}else swal({title:"Invalid Form",text:"Incorrect Inputs",timer:2e3,type:"error",confirmButtonColor:"#B92B27"})},t.submitTopic=function(o){console.log("SUBMIT POST FUNCTION STARTS");var e={name:o.name,about:o.about,token:s.getToken()};r.createTopic(e).success(function(o){t.topics.push(o),swal({title:"Success!",text:"You've made a new Topic!",timer:750,showConfirmButton:!1}),n.go("compose")}).error(function(t){swal({title:"Error!",text:"Missing fields!",showConfirmButton:!0})})},t.$emit("notHome"),t.$emit("getNotifications")}),app.controller("homeCtrl",function(t,o,e,n,s,i,r,c,u){t.posts,t.topicFeed;var l=i.currentUser();t.loggedIn=i.isLoggedIn(),$(document).foundation(),t.loggedIn||o.go("users.login"),t.getPosts=function(o){t.posts=[],t.topicFeed=[];var i={postType:"question",sortingMethod:o};e.getSortedPosts(i).success(function(o){t.posts=o}),s.get7Topics().success(function(o){t.topicFeed=o}),n.getUser(l._id).success(function(o){t.subscriptions=o.subscriptions})},t.getPosts("likes"),t.sortLikes=function(){$(".filter").removeClass("active"),$("#likes").addClass("active"),t.getPosts("likes")},t.sortDislikes=function(){$(".filter").removeClass("active"),$("#dislikes").addClass("active"),t.getPosts("dislikes")},t.sortOldest=function(){$(".filter").removeClass("active"),$("#oldest").addClass("active"),t.getPosts("oldest")},t.sortNewest=function(){$(".filter").removeClass("active"),$("#newest").addClass("active"),t.getPosts("newest")},t.sortSubscriptions=function(){$(".filter").removeClass("active"),$("#subscriptions").addClass("active"),e.subscriptionsPosts(l._id).success(function(o){t.posts=o})},t.togglePostLike=function(o,n){var s=void 0,r=void 0;s="post"===o?t.posts:t.comments,r=s[n].liked?"unlike":"like";var c={pid:s[n]._id,uid:l._id,type:r,token:i.getToken()};e.changeStats(c).success(function(t){"like"===r?(s[n].likes+=1,s[n].liked=!0):(s[n].likes-=1,s[n].liked=!1)})},t.togglePostDislike=function(o,n){var s=void 0,r=void 0;s="post"===o?t.posts:t.comments,r=s[n].disliked?"undo":"dislike";var c={pid:s[n]._id,uid:l._id,type:r,token:i.getToken()};e.changeStats(c).success(function(t){"dislike"===r?(s[n].dislikes+=1,s[n].disliked=!0):(s[n].dislikes-=1,s[n].disliked=!1)})},t.showComments=function(o){t.posts[o].showComments=!0;var n=(t.posts[o].comments,{sortingMethod:"likes",pid:t.posts[o]._id});e.getSortedComments(n).success(function(o){t.comments=o})},t.hideComments=function(o){t.posts[o].showComments=!1},t.submitComment=function(o,n){var s={content:o,author:l._id,responseTo:n._id,postType:"comment",token:i.getToken()};e.createPost(s).success(function(o){t.comments.push(o)}).error(function(t){console.log("failed to submit comment"),console.error(t)})},t.deletePost=function(o,n){e.deletePost(o._id).success(function(o){switch(o.postType){case"comment":t.comments.splice(n,1);break;case"question":t.posts.splice(n,1)}}).error(function(t){console.log("failed at deletePost function "),console.error(t)})},t.$emit("getNotifications"),t.$emit("inHome"),t.$on("filteredByTags",function(o,e){t.posts=e}),t.$on("loggedOut",function(){t.loggedIn=i.isLoggedIn(),t.getPosts()}),t.$on("loggedIn",function(){t.loggedIn=i.isLoggedIn()})}),app.controller("notificationsCtrl",function(t,o,e,n,s,i){t.currentUser=e.currentUser(),t.newNotifications,t.oldNotifications,$(document).foundation(),(t.getNotifications=function(){t.newNotifications=[],t.oldNotifications=[];var o={uid:t.currentUser._id};n.getNotifs(o).success(function(e){t.newNotifications=e.notifications.filter(function(t){return!t.seen}),t.oldNotifications=e.notifications.filter(function(t){return t.seen}),n.clearNotifs(o).success(function(t){console.log("user: ",t)}).error(function(t){console.log("error: ",t)})}).error(function(t){console.log("error: ",t)})})(),t.$emit("notHome")}),app.controller("profileCtrl",function(t,o,e,n,s){$(document).foundation(),t.currentUser=!1,t.followed=!1,s.getUser(o.user).success(function(o){o._id===n.currentUser()._id&&(t.currentUser=!0),-1!==o.followers.indexOf(n.currentUser()._id)?t.followed=!0:t.followed=!1,t.user=o}),t.$emit("getNotifications"),t.$emit("notHome")}),app.controller("threadCtrl",function(t,o,e,n,s,i){t.displayAnswerForm=!1;var r=e.currentUser();t.loggedIn=e.isLoggedIn(),$(document).foundation(),t.answers,t.comments,t.question,(t.getPost=function(){n.getPost(i.thread).success(function(o){t.question=o,t.topic=o.topic,t.comments=o.comments;var e={sortingMethod:"likes",pid:o._id};n.getSortedAnswers(e).success(function(o){t.answers=o})}).error(function(t){console.log(t)})})(),t.submitAnswer=function(o,s){var i={content:o,author:r._id,responseTo:s._id,postType:"answer",token:e.getToken()};n.createPost(i).success(function(o){t.answers.push(o)}).error(function(t){console.log("error: ",t)})},t.toggleAnswerLike=function(o){if(t.loggedIn){var i;i=t.answers[o].liked?"unlike":"like";var c={pid:t.answers[o]._id,uid:r._id,type:i,token:e.getToken()};n.changeStats(c).success(function(e){"like"===i?(t.answers[o].likes+=1,t.answers[o].liked=!0):(t.answers[o].likes-=1,t.answers[o].liked=!1)}).error(function(t){console.log("error: ",t)})}else s.isNotLoggedIn()},t.toggleAnswerDislike=function(o){if(t.loggedIn){var i;i=t.answers[o].disliked?"undo":"dislike";var c={pid:t.answers[o]._id,uid:r._id,type:i,token:e.getToken()};n.changeStats(c).success(function(e){"dislike"===i?(t.answers[o].dislikes+=1,t.answers[o].disliked=!0):(t.answers[o].dislikes-=1,t.answers[o].disliked=!1)}).error(function(t){console.log("error: ",t)})}else s.isNotLoggedIn()},t.toggleCommentLike=function(o){if(t.loggedIn){var i;i=t.comments[o].liked?"unlike":"like";var c={pid:t.comments[o]._id,uid:r._id,type:i,token:e.getToken()};n.changeStats(c).success(function(e){"like"===i?(t.comments[o].likes+=1,t.comments[o].liked=!0):(t.comments[o].likes-=1,t.comments[o].liked=!1)}).error(function(t){console.log("error: ",t)})}else s.isNotLoggedIn()},t.toggleCommentDislike=function(o){if(t.loggedIn){var i;i=t.comments[o].disliked?"undo":"dislike";var c={pid:t.comments[o]._id,uid:r._id,type:i,token:e.getToken()};n.changeStats(c).success(function(e){"dislike"===i?(t.comments[o].dislikes+=1,t.comments[o].disliked=!0):(t.comments[o].dislikes-=1,t.comments[o].disliked=!1)}).error(function(t){console.log("error: ",t)})}else s.isNotLoggedIn()},t.showComments=function(){var o={sortingMethod:"likes",pid:t.posts[index]._id};n.getSortedComments(o).success(function(o){r?(n.formatPosts(o,r),t.comments=o):t.comments=o})},t.submitComment=function(o,i){if(console.log(i),t.loggedIn){var c={content:o,author:r._id,responseTo:i._id,postType:"comment",token:e.getToken()};n.createPost(c).success(function(o){t.comments.push(o)}).error(function(t){console.log("error: ",t)})}else s.isNotLoggedIn()},t.loadMore=function(){for(var o=t.comments[t.comments.length-1],e=8,n=1;e>=n;n++)console.log("count is "+n),t.comments.push(o+"")},t.$emit("notHome"),t.$emit("getNotifications")}),app.controller("topicCtrl",function(t,o,e,n,s,i,r,c){var u=s.currentUser();t.loggedIn=s.isLoggedIn(),t.posts,t.topic,t.subscribed=!1,$(document).foundation(),function(){n.getTopic(e.topic).success(function(o){console.log("TOPIC: ",o),o.subscribers.forEach(function(o){o===u._id?t.subscribed=!0:t.subscribed=!1}),t.topic=o,r.formatPosts(o.posts,u),t.posts=o.posts}).error(function(t){console.log("error: ",t)})}(),t.subscribe=function(){var o={uid:u._id,topic:e.topic};console.log(o),i.subscribe(o).success(function(o){t.subscribed=!0}).error(function(t){console.log("error: ",t)})},t.unsubscribe=function(){var o={uid:u._id,topic:e.topic};i.unsubscribe(o).success(function(o){t.subscribed=!1}).error(function(t){console.log("error: ",t)})},t.togglePostLike=function(o){if(t.loggedIn){var e;e=t.posts[o].liked?"unlike":"like";var n={pid:t.posts[o]._id,uid:u._id,type:e,token:s.getToken()};r.changeStats(n).success(function(n){"like"===e?(t.posts[o].likes+=1,t.posts[o].liked=!0):(t.posts[o].likes-=1,t.posts[o].liked=!1)}).error(function(t){console.log("error: ",t)})}else c.isNotLoggedIn()},t.togglePostDislike=function(o){if(t.loggedIn){var e;e=t.posts[o].disliked?"undo":"dislike";var n={pid:t.posts[o]._id,uid:u._id,type:e,token:s.getToken()};r.changeStats(n).success(function(n){"dislike"===e?(t.posts[o].dislikes+=1,t.posts[o].disliked=!0):(t.posts[o].dislikes-=1,t.posts[o].disliked=!1)}).error(function(t){console.log("error: ",t)})}else c.isNotLoggedIn()},t.toggleCommentLike=function(o){if(t.loggedIn){var e;e=t.comments[o].liked?"unlike":"like";var n={pid:t.comments[o]._id,uid:u._id,type:e,token:s.getToken()};r.changeStats(n).success(function(n){"like"===e?(t.comments[o].likes+=1,t.comments[o].liked=!0):(t.comments[o].likes-=1,t.comments[o].liked=!1)}).error(function(t){console.log("error: ",t)})}else c.isNotLoggedIn()},t.toggleCommentDislike=function(o){if(t.loggedIn){var e;e=t.comments[o].disliked?"undo":"dislike";var n={pid:t.comments[o]._id,uid:u._id,type:e,token:s.getToken()};r.changeStats(n).success(function(n){"dislike"===e?(t.comments[o].dislikes+=1,t.comments[o].disliked=!0):(t.comments[o].dislikes-=1,t.comments[o].disliked=!1)}).error(function(t){console.log("error: ",t)})}else c.isNotLoggedIn()},t.showComments=function(o){t.posts[o].showComments=!0;var e=(t.posts[o].comments,{sortingMethod:"likes",pid:t.posts[o]._id});r.getSortedComments(e).success(function(o){r.formatPosts(o,u),console.log(o),t.comments=o})},t.hideComments=function(o){t.posts[o].showComments=!1},t.submitComment=function(o,e){if(t.loggedIn){var n={content:o,author:u._id,responseTo:e._id,postType:"comment",token:s.getToken()};r.createPost(n).success(function(o){t.comments.push(o),console.log(o)}).error(function(t){console.log("error: ",t)})}else c.isNotLoggedIn()},t.$emit("notHome"),t.$emit("getNotifications"),t.$on("loggedOut",function(){t.loggedIn=s.isLoggedIn()}),t.$on("loggedIn",function(){t.loggedIn=s.isLoggedIn()})}),app.controller("usersCtrl",function(t,o,e,n,s,i,r,c){t.Login=!1,t.tagFilter=!0,t.loggedIn=e.isLoggedIn(),t.currentUser=e.currentUser(),t.newNotifications=[],(t.switchState=function(){t.Login=!t.Login,t.Login?t.currentState="Create Account":t.currentState="Go to Login",t.Login?t.formState="Login":t.formState="Register"})(),t.login=function(n,s){var i={username:n,password:s};e.login(i).success(function(e){t.$emit("login"),o.go("home")}).error(function(t){swal({title:"Input Not Valid??",text:"Either the username or password was entered incorrectly",timer:2e3,type:"error",confirmButtonColor:"#B92B27"})})},t.register=function(n){n.upload=r.upload({url:"auth/register",data:{file:n,username:t.username,email:t.email,fullName:t.fullName,password:t.password}}),n.upload.then(function(s){e.saveToken(s.data.token),t.$emit("login"),c(function(){n.result=s.data,o.go("home")})},function(o){o.status>0&&(t.errorMsg=o.status+": "+o.data)},function(t){n.progress=Math.min(100,parseInt(100*t.loaded/t.total))})},t.logout=function(){e.logout(),t.$emit("logout"),o.go("users.login")},t.filterByTag=function(o){s.getPostsByTag(o).success(function(o){t.$emit("tag posts",o)}).error(function(t){console.log("error: ",t)})},t.$on("removeTagFilter",function(){t.tagFilter=!1}),t.$on("addTagFilter",function(){t.tagFilter=!0}),t.$on("notifications",function(){n.getUser(t.currentUser._id).success(function(o){t.picture=e.loggedInUser.picture,t.newNotifications=o.notifications.filter(function(t){return!t.seen})}).error(function(t){console.log("error: ",t)})}),t.$on("loggedOut",function(){t.loggedIn=e.isLoggedIn(),t.notifications=[]}),t.$on("loggedIn",function(){t.loggedIn=e.isLoggedIn(),t.currentUser=e.currentUser(),n.getUser(t.currentUser._id).success(function(o){t.picture=e.loggedInUser.picture,t.newNotifications=o.notifications.filter(function(t){return!t.seen})}).error(function(t){console.log("error: ",t)})})}),app.directive("ngEnter",function(){return function(t,o,e){o.bind("keydown keypress",function(o){13===o.which&&(t.$apply(function(){t.$eval(e.ngEnter)}),o.preventDefault())})}}),app.factory("auth",function(t,o,e){var n={};return n.loggedInUser,n.saveToken=function(o){t.localStorage[e]=o},n.getToken=function(){return t.localStorage[e]},n.isLoggedIn=function(){var o=n.getToken();if(o){var e=JSON.parse(t.atob(o.split(".")[1]));return e.exp>Date.now()/1e3}return!1},n.currentUser=function(){if(n.isLoggedIn()){var e=n.getToken(),s=JSON.parse(t.atob(e.split(".")[1]));return o.get("/users/"+s._id).then(function(t){n.loggedInUser=t.data})["catch"](function(t){console.log("err",t)}),s}},n.register=function(t){return o.post("/auth/register",t).success(function(t){n.saveToken(t.token)})},n.login=function(t){return o.post("/auth/login",t).success(function(t){n.saveToken(t.token)})},n.logout=function(){t.localStorage.removeItem(e)},n}),app.factory("postFactory",function(t,o,e){var n={};return n.createPost=function(t){return o.post("/posts/add",t)},n.deletePost=function(t){return o["delete"]("/posts/delete/"+t)},n.changeStats=function(t){return o.put("/posts/changeStats",t)},n.getPost=function(t){return o.get("/posts/"+t)},n.editPost=function(t){return o.put("/posts/edit",t)},n.getPostsByTag=function(t){return o.get("/posts/sorted/user/topic/tag/"+t+"/postType/").success(function(t){return n.formatPosts(t,e.currentUser()),t})},n.getPostsByTopic=function(t){return o.get("/posts/sorted/user/topic/"+t+"/tag/postType/").success(function(t){return n.formatPosts(t,e.currentUser()),t})},n.getSortedPosts=function(t){return o.get("/posts/sorted/"+t.sortingMethod+"/user/topic/tag/postType/"+t.postType).success(function(t){return n.formatPosts(t,e.currentUser()),t})},n.subscriptionsPosts=function(t){return o.get("/posts/sorted/user/"+t+"/topic/tag/postType/").success(function(t){return n.formatPosts(t,e.currentUser()),t})},n.getSortedComments=function(t){return o.get("/posts/sortedComments/"+t.sortingMethod+"/post/"+t.pid).success(function(t){return n.formatPosts(t,e.currentUser()),t})},n.getSortedAnswers=function(t){return o.get("/posts/sortedComments/"+t.sortingMethod+"/post/"+t.pid).success(function(t){return n.formatPosts(t,e.currentUser()),t})},n.formatLikedPosts=function(t,o){t.map(function(t){return t.likers.forEach(function(e){if(e.toString()===o._id.toString()){var n=t;return n.liked=!0,n}return t})}),t.map(function(t){return t.dislikers.forEach(function(e){if(e.toString()===o._id.toString()){var n=t;return n.disliked=!0,n}return t})})},n.formatTags=function(t){t.map(function(o){console.log(t);var e="";return o.tags.forEach(function(t){e+=t+", "}),o.tags=e,o})},n.formatUserPosts=function(t,o){t.map(function(t){t.author._id.toString()===o._id.toString()?t.userPost=!0:t.userPost=!1})},n.formatPosts=function(t,o){return n.formatLikedPosts(t,o),n.formatUserPosts(t,o),n.formatTags(t),t},n}),app.factory("topicFactory",function(t,o){var e={};return e.getTopics=function(){return o.get("/topics/allTopics")},e.subscribedTopics=function(){return o.get("/topics/allTopics")},e.get7Topics=function(){return o.get("/topics/limit7")},e.getTopic=function(t){return o.get("/topics/topic/"+t)},e.createTopic=function(t){return o.post("/topics/add",t)},e.deleteTopic=function(t){return o["delete"]("/topics/delete",t)},e}),app.factory("userFactory",function(t,o){var e={};return e.getUser=function(t){return o.get("/users/"+t)},e.getNotifs=function(t){return o.get("/users/notifications/"+t.uid)},e.clearNotifs=function(t){return o.post("/users/clearNotifications",t)},e.addKnowledge=function(t){return o.post("/users/addKnowledge",t)},e.updateInfo=function(t){return o.put("/users/updateInfo",t)},e.follow=function(t){return o.post("/users/follow",t)},e.unfollow=function(t){return o.put("/users/unfollow",t)},e.subscribe=function(t){return o.post("/users/subscribe",t)},e.unsubscribe=function(t){return o.put("/users/unsubscribe",t)},e}); \ No newline at end of file diff --git a/src/javascripts/controllers/composeCtrl.js b/src/javascripts/controllers/composeCtrl.js index 27b61e5..2989c6c 100644 --- a/src/javascripts/controllers/composeCtrl.js +++ b/src/javascripts/controllers/composeCtrl.js @@ -12,22 +12,24 @@ app.controller('composeCtrl', function($scope, $http, $location, $state, auth, p (function init(){ topicFactory.getTopics() - .success(function(topics){ + .success(topics => { $scope.topics = topics; - console.log(topics); }) - .error(function(err){ + .error(err => { console.log("error: ", err) }) var questionObject = { postType: "question" } - $scope.topQuestion = postFactory.getSortedPosts(questionObject)[0]; + postFactory.getSortedPosts(questionObject) + .success(questions => { + $scope.topQuestion = questions[0]; + }) })(); - $scope.addTopicToPost = function(topic){ + $scope.addTopicToPost = (topic) => { $scope.selectedTopic = topic.name; $scope.toggleDropdown = true; window.setTimeout(function(){ @@ -35,27 +37,36 @@ app.controller('composeCtrl', function($scope, $http, $location, $state, auth, p }, 50); } - $scope.submitQuestion = function(question, selectedTopic){ - var questionObject = { - author: currentUser._id, - title: question.title, - tags: question.tags, - content: question.content, - topic: selectedTopic, - postType: "question", - token: auth.getToken() + $scope.submitQuestion = (isValid, question, selectedTopic) => { + if(isValid){ + var questionObject = { + author: currentUser._id, + title: question.title, + tags: question.tags, + content: question.content, + topic: selectedTopic, + postType: "question", + token: auth.getToken() + } + postFactory.createPost(questionObject) + .success(data => { + $location.path('thread/'+data._id+''); + }) + .error(err => { + console.log(err); + }) + } else { + swal({ + title: "Invalid Form", + text: "Incorrect Inputs", + timer: 2000, + type: "error", + confirmButtonColor: "#B92B27" + }); } - console.log(questionObject); - postFactory.createPost(questionObject) - .success(function(data){ - $location.path('thread/'+data._id+''); - }) - .error(function(err){ - console.log(err); - }) }; - $scope.submitTopic = function(topic){ + $scope.submitTopic = (topic) => { console.log("SUBMIT POST FUNCTION STARTS"); var topicObject = { name: topic.name, @@ -63,7 +74,7 @@ app.controller('composeCtrl', function($scope, $http, $location, $state, auth, p token: auth.getToken() } topicFactory.createTopic(topicObject) - .success(function(topic){ + .success(topic => { $scope.topics.push(topic); swal({ title: "Success!", @@ -73,7 +84,7 @@ app.controller('composeCtrl', function($scope, $http, $location, $state, auth, p }); $state.go("compose"); }) - .error(function(err){ + .error(err => { swal({ title: "Error!", text: "Missing fields!", diff --git a/src/javascripts/controllers/homeCtrl.js b/src/javascripts/controllers/homeCtrl.js index a75730a..64376fc 100644 --- a/src/javascripts/controllers/homeCtrl.js +++ b/src/javascripts/controllers/homeCtrl.js @@ -6,6 +6,7 @@ app.controller('homeCtrl', function($scope, $state, postFactory, userFactory, to $scope.topicFeed; let currentUser = auth.currentUser(); $scope.loggedIn = auth.isLoggedIn(); + $(document).foundation(); if(!$scope.loggedIn){ $state.go("users.login"); @@ -122,12 +123,7 @@ app.controller('homeCtrl', function($scope, $state, postFactory, userFactory, to } postFactory.getSortedComments(sortingObject) .success(posts => { - if(currentUser){ - postFactory.formatPosts(posts, currentUser) - $scope.comments = posts; - } else { - $scope.comments = posts; - } + $scope.comments = posts; }) } @@ -136,25 +132,21 @@ app.controller('homeCtrl', function($scope, $state, postFactory, userFactory, to } $scope.submitComment = (comment, post) => { - if(!$scope.loggedIn){ - $rootScope.isNotLoggedIn(); - } else { - var commentObject = { - content: comment, - author: currentUser._id, - responseTo: post._id, - postType: "comment", - token: auth.getToken() - } - postFactory.createPost(commentObject) - .success(post => { - $scope.comments.push(post); - }) - .error(err => { - console.log("failed to submit comment"); - console.error(err); - }) + var commentObject = { + content: comment, + author: currentUser._id, + responseTo: post._id, + postType: "comment", + token: auth.getToken() } + postFactory.createPost(commentObject) + .success(post => { + $scope.comments.push(post); + }) + .error(err => { + console.log("failed to submit comment"); + console.error(err); + }) } $scope.deletePost = (post, $index) => { @@ -182,12 +174,10 @@ app.controller('homeCtrl', function($scope, $state, postFactory, userFactory, to $scope.$on('filteredByTags', function(event, posts){ $scope.posts = posts; }) - $scope.$on("loggedOut", function(){ $scope.loggedIn = auth.isLoggedIn(); $scope.getPosts(); }) - $scope.$on("loggedIn", function(){ $scope.loggedIn = auth.isLoggedIn(); }) diff --git a/src/javascripts/controllers/notificationsCtrl.js b/src/javascripts/controllers/notificationsCtrl.js index b6c7570..48171a9 100644 --- a/src/javascripts/controllers/notificationsCtrl.js +++ b/src/javascripts/controllers/notificationsCtrl.js @@ -6,6 +6,7 @@ app.controller('notificationsCtrl', function($scope, $http, auth, userFactory, p $scope.currentUser = auth.currentUser(); $scope.newNotifications; $scope.oldNotifications; + $(document).foundation(); ($scope.getNotifications = function(){ $scope.newNotifications = []; diff --git a/src/javascripts/controllers/profileCtrl.js b/src/javascripts/controllers/profileCtrl.js index 08dabd0..70f737f 100644 --- a/src/javascripts/controllers/profileCtrl.js +++ b/src/javascripts/controllers/profileCtrl.js @@ -1,9 +1,19 @@ 'use strict'; -app.controller('profileCtrl', function($scope, $state, auth){ - +app.controller('profileCtrl', function($scope, $stateParams, $state, auth, userFactory){ $(document).foundation(); + $scope.currentUser = false; + $scope.followed = false; + userFactory.getUser($stateParams.user) + .success(user => { + if(user._id === auth.currentUser()._id){ + $scope.currentUser = true; + } + user.followers.indexOf(auth.currentUser()._id) !== -1 ? $scope.followed = true : $scope.followed = false; + $scope.user = user; + }) + $scope.$emit("getNotifications"); $scope.$emit("notHome"); }); diff --git a/src/javascripts/controllers/threadCtrl.js b/src/javascripts/controllers/threadCtrl.js index c3e2638..82fd2ad 100644 --- a/src/javascripts/controllers/threadCtrl.js +++ b/src/javascripts/controllers/threadCtrl.js @@ -4,6 +4,7 @@ app.controller('threadCtrl', function($scope, $state, auth, postFactory, $rootSc $scope.displayAnswerForm = false; var currentUser = auth.currentUser(); $scope.loggedIn = auth.isLoggedIn(); + $(document).foundation(); $scope.answers; $scope.comments; diff --git a/src/javascripts/controllers/topicCtrl.js b/src/javascripts/controllers/topicCtrl.js index 0f8238d..10603b0 100644 --- a/src/javascripts/controllers/topicCtrl.js +++ b/src/javascripts/controllers/topicCtrl.js @@ -7,6 +7,7 @@ app.controller('topicCtrl', function($scope, $state, $stateParams, topicFactory, $scope.posts; $scope.topic; $scope.subscribed = false; + $(document).foundation(); (function getTopicPosts(){ topicFactory.getTopic($stateParams.topic) diff --git a/src/javascripts/controllers/usersCtrl.js b/src/javascripts/controllers/usersCtrl.js index 595a6c2..858dcd7 100644 --- a/src/javascripts/controllers/usersCtrl.js +++ b/src/javascripts/controllers/usersCtrl.js @@ -7,23 +7,23 @@ app.controller('usersCtrl', function($scope, $state, auth, userFactory, postFact $scope.currentUser = auth.currentUser(); $scope.newNotifications = []; - ($scope.switchState = function(){ + ($scope.switchState = () => { $scope.Login = !$scope.Login; $scope.Login ? $scope.currentState = "Create Account" : $scope.currentState = "Go to Login" $scope.Login ? $scope.formState = "Login" : $scope.formState = "Register" })(); - $scope.login = function(username, password) { - var user = { + $scope.login = (username, password) => { + let user = { username: username, password: password } - auth.login(user).success(function(data){ + auth.login(user).success(data => { $scope.$emit('login'); $state.go('home'); - }).error(function(err){ + }).error(err => { swal({ - title: "Input Not Valid", + title: "Input Not Valid??", text: "Either the username or password was entered incorrectly", timer: 2000, type: "error", @@ -33,7 +33,7 @@ app.controller('usersCtrl', function($scope, $state, auth, userFactory, postFact }; - $scope.register = function(file) { + $scope.register = (file) => { file.upload = Upload.upload({ url: 'auth/register', data: { @@ -44,35 +44,34 @@ app.controller('usersCtrl', function($scope, $state, auth, userFactory, postFact password: $scope.password }, }); - file.upload.then(function (response) { - auth.saveToken(response.data.token); + file.upload.then(res => { + auth.saveToken(res.data.token); $scope.$emit('login'); - $timeout(function () { - file.result = response.data; + $timeout(function() { + file.result = res.data; $state.go('home'); }); - }, function (response) { - if (response.status > 0) - $scope.errorMsg = response.status + ': ' + response.data; + }, function (res) { + if (res.status > 0) + $scope.errorMsg = res.status + ': ' + res.data; }, function (evt) { - // Math.min is to fix IE which reports 200% sometimes file.progress = Math.min(100, parseInt(100.0 * evt.loaded / evt.total)); }); } - $scope.logout = function(){ + $scope.logout = () => { auth.logout(); $scope.$emit('logout'); - $state.go('home'); + $state.go('users.login'); } - $scope.filterByTag = function(tag){ + $scope.filterByTag = (tag) => { postFactory.getPostsByTag(tag) - .success(function(posts){ + .success(posts => { $scope.$emit('tag posts', posts); }) - .error(function(err){ + .error(err => { console.log("error: ", err); }) } @@ -93,7 +92,7 @@ app.controller('usersCtrl', function($scope, $state, auth, userFactory, postFact return !notif.seen; }) }) - .error(function(err){ + .error(err => { console.log("error: ", err) }) }) @@ -107,13 +106,13 @@ app.controller('usersCtrl', function($scope, $state, auth, userFactory, postFact $scope.loggedIn = auth.isLoggedIn(); $scope.currentUser = auth.currentUser(); userFactory.getUser($scope.currentUser._id) - .success(function(user){ + .success(user => { $scope.picture = auth.loggedInUser.picture; $scope.newNotifications = user.notifications.filter(function(notif){ return !notif.seen; }) }) - .error(function(err){ + .error(err => { console.log("error: ", err) }) }) diff --git a/src/javascripts/module.js b/src/javascripts/module.js index 582b6e9..2718cd9 100644 --- a/src/javascripts/module.js +++ b/src/javascripts/module.js @@ -1,6 +1,6 @@ 'use strict'; -var app = angular.module('quora', ['ui.router', 'infinite-scroll', 'hc.marked', "oitozero.ngSweetAlert", "ngFileUpload"]); +var app = angular.module('quora', ['ui.router', 'infinite-scroll', 'hc.marked', "ngFileUpload"]); app.constant('tokenStorageKey', 'my-token'); diff --git a/src/stylesheets/_nav.scss b/src/stylesheets/_nav.scss index 13cfe64..a846fcf 100644 --- a/src/stylesheets/_nav.scss +++ b/src/stylesheets/_nav.scss @@ -49,7 +49,7 @@ quora-title { color: white; } -#profilePicture{ +#navPicture{ height: 25px; width: 25px; border-radius: 50%; diff --git a/src/stylesheets/_profile.scss b/src/stylesheets/_profile.scss index a1b3fdd..ca32ca8 100644 --- a/src/stylesheets/_profile.scss +++ b/src/stylesheets/_profile.scss @@ -31,3 +31,34 @@ hr { .right{ margin-left: 10px; } + +#profilePicture{ + display: block; + width: 150px; + height: 150px; + border-radius: 50%; + margin: 0 auto; + margin-top: 30px; +} + +#info{ + background-color: $quora-hover-grey; + padding: 10px; +} + +#contact{ + margin-bottom: 10px; + padding: 10px; + background-color: white; + li{ + margin-top: 10px; + } +} + +#stats{ + padding: 10px; + background-color: white; + li{ + margin-top: 10px; + } +} diff --git a/src/stylesheets/_universal.scss b/src/stylesheets/_universal.scss index 8bfab2c..ad92789 100644 --- a/src/stylesheets/_universal.scss +++ b/src/stylesheets/_universal.scss @@ -31,3 +31,7 @@ button{ .buttons .dislikeBtn:hover{ background-color: #797979; } + +.sweet-alert fieldset{ + display: none; +} diff --git a/src/templates/general/compose.html b/src/templates/general/compose.html index b3549ef..7683f00 100644 --- a/src/templates/general/compose.html +++ b/src/templates/general/compose.html @@ -5,21 +5,39 @@
    -
    Ask a question
    +
    +
    Ask a question
    - - - -
    - - - - -
    +
    + + +

    title not long enough

    +
    +
    + + +

    content not long enough

    +
    +
    + + +

    content not long enough

    +
    +
    + +
    + +

    content not long enough

    + + + +
    +
    +
    diff --git a/src/templates/general/home.html b/src/templates/general/home.html index 8f8f71f..76ef00f 100644 --- a/src/templates/general/home.html +++ b/src/templates/general/home.html @@ -6,14 +6,13 @@
    -

    Topics

    Subscriptions

    -

    Random Topics

    +

    Topics

    {{post.title}}

    -

    {{post.author.username}} {{post.author.work}}

    +

    {{post.author.username}} {{post.author.work}}

    tags: {{post.tags}}

    @@ -70,7 +69,7 @@

    {{post.title}}

    -
    {{comment.author.username}}
    +
    {{comment.author.username}}

    diff --git a/src/templates/general/nav.html b/src/templates/general/nav.html index daa9817..24e84cb 100644 --- a/src/templates/general/nav.html +++ b/src/templates/general/nav.html @@ -26,7 +26,7 @@

    Quora

  • Home
  • Compose
  • {{newNotifications.length}} Notifications
  • -
  • {{currentUser.username}}
  • +
  • {{currentUser.username}}
  • Login
  • Logout
  • diff --git a/src/templates/users/profile.html b/src/templates/users/profile.html index 7d49e84..ffe4092 100644 --- a/src/templates/users/profile.html +++ b/src/templates/users/profile.html @@ -1,45 +1,89 @@ -
    -
    - Profile Picture -
    +
    +
    + +

    {{user.username}}

    - - - - - + + +
    -
    {{user.about}}

    - - -
    - Feed Here of all user activity? +
    +
    +
    +
      +
    • email: {{user.email}}
    • +
    • home: {{user.home}}
    • +
    • work: {{user.work}}
    • +
    • about: {{user.about}}
    • +
    +
    +
    +
      +
    • posts: {{user.posts.length}}
    • +
    • followers: {{user.followers.length}}
    • +
    • following: {{user.following.length}}
    • +
    • views: {{user.views}}
    • +
    +
    +
    -
    -
    -
    -
    -

    Posts

    - {{user.likes}} likes
    - {{user.views}} views -

    -
    -

    Activity

    - {{user.followers}} followers
    - {{user.following}} following + + +
    +
    +
    + +
    +

    answered • {{post.topic.name}}

    +
    +
    +

    unanswered • {{post.topic.name}}

    +
    +

    {{post.title}}

    +

    {{post.author.username}} {{post.author.work}}

    +

    +

    tags: {{post.tags}}

    + + + + + Comments {{post.comments.length}} + Comments {{post.comments.length}} +
    +
    +
    +
    +
    +
    +
    + +
    +
    + +
    +
    +
    +
    +
    +
    + +
    {{comment.author.username}}
    +

    + + + + +
    +
    +
    +
    +
    - - {{user.posts.length}} posts -
    -
    I can answer questions about...
    -
      -
    • {{user.knowledge.topic.name}}
    • -
    diff --git a/views/index.ejs b/views/index.ejs index 6d19590..81591b7 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -7,7 +7,7 @@ - + @@ -34,10 +34,10 @@ - +