diff --git a/controllers/Home.php b/controllers/Home.php index 139f6cfe..8f255e1b 100644 --- a/controllers/Home.php +++ b/controllers/Home.php @@ -3,9 +3,33 @@ namespace Latchel; use Controller; +use Post; +use User; +use Comment; class HomeController extends Controller{ public function index(){ - return view('template'); + $posts = $this->getPosts('home'); + + return view('template', ['posts' = $posts]); + } + + public static function getPosts($slug){ + $posts = Post::where('slug', '=', $slug)->get(); + + foreach($posts as &$post){ + $post->user = User::find($post->user_id); + } + + foreach($posts as &$post){ + $post->comments = Comment::where('post_id', '=', $post->post_id)->get(); + + foreach($post->comments as &$comment){ + $comment->user = User::find($comment->user_id); + } + } + + return $posts; } + } \ No newline at end of file diff --git a/public/assets/js/app.js b/public/assets/js/app.js index 2c56c50f..00423b21 100644 --- a/public/assets/js/app.js +++ b/public/assets/js/app.js @@ -1 +1,23 @@ -angular.module('CodeReviewApp', []); \ No newline at end of file +angular.module('CodeReviewApp', []) + .directive('post', [function(){ + return { + restrict: 'A', + replace: true, + transclude: true, + template: '' + + '
{{username}}
' + + '
' + + '
', + scope: { + postid: '@', + username: '@' + }, + controller: ['$scope', function($scope){ + $scope.collapsed = true; + + $scope.toggleCollapse = function(){ + $scope.collapsed = !$scope.collapsed; + }; + }] + } + }]); diff --git a/public/assets/scss/app.scss b/public/assets/scss/app.scss index e69de29b..7bdb7f8f 100644 --- a/public/assets/scss/app.scss +++ b/public/assets/scss/app.scss @@ -0,0 +1,10 @@ +.post{ + transition: max-height 0.4s; + max-height: none; + overflow: hidden; + border-radius: 4px; + + &--collapsed{ + max-height: 0px; + } +} diff --git a/public/template.blade.php b/public/template.blade.php index c58124ea..17cb7925 100644 --- a/public/template.blade.php +++ b/public/template.blade.php @@ -12,6 +12,17 @@ +
+ +
+ + + html?> + + +
+ +