Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion controllers/Home.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}
24 changes: 23 additions & 1 deletion public/assets/js/app.js
Original file line number Diff line number Diff line change
@@ -1 +1,23 @@
angular.module('CodeReviewApp', []);
angular.module('CodeReviewApp', [])
.directive('post', [function(){
return {
restrict: 'A',
replace: true,
transclude: true,
template: '<a ng-href="/posts/{{postid}}">' +
'<div class="post__user" ng-click="toggleCollapse()">{{username}}</div>' +
'<div class="post" ng-class="{\'post--collapsed\': collapsed}"></div>' +
'</a>',
scope: {
postid: '@',
username: '@'
},
controller: ['$scope', function($scope){
$scope.collapsed = true;

$scope.toggleCollapse = function(){
$scope.collapsed = !$scope.collapsed;
};
}]
}
}]);
10 changes: 10 additions & 0 deletions public/assets/scss/app.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.post{
transition: max-height 0.4s;
max-height: none;
overflow: hidden;
border-radius: 4px;

&--collapsed{
max-height: 0px;
}
}
11 changes: 11 additions & 0 deletions public/template.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@
</head>
<body>

<div class="header" ng-include="/header.html"></div>

<div class="content">
<? foreach($posts as $post){?>
<post post-id="<?=$post->post_id?>" user-name="<?=$post->user->name?>">
<?=$post->html?>
</post>
<? } ?>
</div>

<div class="footer" ng-include="/footer.html"></div>

<script src="{{ elixir('js/' . $app . '.js') }}"></script>
</body>
Expand Down