Skip to content

Commit 7c9bf5f

Browse files
author
Shawn McCool
committed
add rudimentary thread editing
1 parent f0b438b commit 7c9bf5f

File tree

7 files changed

+96
-14
lines changed

7 files changed

+96
-14
lines changed

app/controllers/ForumController.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,12 @@ public function postCreateThread()
9595

9696
return $this->redirectAction('ForumController@getThread', [$commentSlug]);
9797
}
98+
99+
public function getEditThread($threadId)
100+
{
101+
$thread = $this->comments->requireForumThreadById($threadId);
102+
$tags = $this->tags->getAllForForum();
103+
104+
$this->view('forum.editthread', compact('thread', 'tags'));
105+
}
98106
}

app/domain/Lio/Comments/Comment.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ public function updateChildCount()
6666
}
6767
}
6868

69+
public function hasTag($tagId)
70+
{
71+
return $this->tags->contains($tagId);
72+
}
73+
6974
public function isMainComment()
7075
{
7176
if(! $this->parent_id) return true;

app/domain/Lio/Comments/CommentRepository.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,15 @@ public function getForumCreateForm()
6060
{
6161
return new ForumCreateForm;
6262
}
63+
64+
public function requireForumThreadById($id)
65+
{
66+
$model = $this->model->where('id', '=', $id)->where('type', '=', COMMENT::TYPE_FORUM)->first();
67+
68+
if ( ! $model) {
69+
throw new EntityNotFoundException;
70+
}
71+
72+
return $model;
73+
}
6374
}

app/routes.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
Route::get('forum', 'ForumController@getIndex');
3939
Route::get('forum/create-thread', ['before' => 'auth', 'uses' => 'ForumController@getCreateThread']);
4040
Route::post('forum/create-thread', ['before' => 'auth', 'uses' => 'ForumController@postCreateThread']);
41+
Route::get('forum/edit-thread/{threadId}', ['before' => 'auth', 'uses' => 'ForumController@getEditThread']);
4142
Route::get('forum/{slug}', ['before' => 'handle_slug', 'uses' => 'ForumController@getThread']);
4243
Route::post('forum/{slug}', ['before' => 'auth|handle_slug', 'uses' => 'ForumController@postThread']);
4344

app/views/auth/signup.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
@section('content')
44
<section class="auth woops">
5-
<h1>Woops!</h1>
5+
<h1>Whoops!</h1>
66
<p>You'll need an account in order to do whatever you just tried to do. No problem, just authenticate through GitHub and you're done.</p>
77
<a class="button full" href="{{ action('AuthController@getLogin') }}">Login with GitHub</a>
88
</section>

app/views/forum/_comment.blade.php

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,27 @@
33
<a href="{{ $comment->author->profileUrl }}">{{ $comment->author->thumbnail }}</a>
44
</div>
55
<div class="content">
6-
@if($comment->id == $thread->id)
6+
@if($comment->title)
77
<h1>{{ $comment->title }}</h1>
8+
@endif
9+
@if($comment->id == $thread->id)
810
<div class="tags">Tags: {{ $comment->tags->getTagList() }}</div>
9-
{{ $comment->body }}
10-
<ul class="meta">
11-
<li><i class="icon-time"></i> {{ $comment->created_ago }}</li>
12-
<li><i class="icon-user"></i><a href="{{ $comment->author->profileUrl }}"> {{ $comment->author->name }}</a></li>
13-
</ul>
14-
@else
15-
{{ $comment->body }}
16-
<ul class="meta">
17-
<li><i class="icon-time"></i>&nbsp;{{ $comment->created_ago }}</li>
18-
<li><i class="icon-user"></i>&nbsp;<a href="{{ $comment->author->profileUrl }}">{{ $comment->author->name }}</a></li>
19-
<li><i class="icon-link"></i>&nbsp;<a href="{{ $comment->commentUrl }}">Share</a></li>
20-
</ul>
2111
@endif
12+
13+
{{ $comment->body }}
14+
15+
<ul class="meta">
16+
<li><i class="icon-time"></i>&nbsp;{{ $comment->created_ago }}</li>
17+
<li><i class="icon-user"></i>&nbsp;<a href="{{ $comment->author->profileUrl }}">{{ $comment->author->name }}</a></li>
18+
@if($comment->id == $thread->id)
19+
<li><i class="icon-link"></i>&nbsp;<a href="{{ $comment->forumThreadUrl }}">Thread Link</a></li>
20+
@else
21+
<li><i class="icon-link"></i>&nbsp;<a href="{{ $comment->commentUrl }}">Reply Link</a></li>
22+
@endif
23+
24+
@if(Auth::user() && $comment->id == $thread->id && $comment->author_id == Auth::user()->id)
25+
<li><i class="icon-link"></i>&nbsp;<a href="{{ action('ForumController@getEditThread', [$comment->id]) }}">Edit</a></li>
26+
@endif
27+
</ul>
2228
</div>
2329
</div>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{{ Form::model($thread->resource) }}
2+
<fieldset>
3+
<legend>Create Thread</legend>
4+
5+
<div class="row">
6+
<div class="">
7+
{{ Form::label('title', 'Title') }}
8+
{{ Form::text('title', null, ['placeholder' => 'Title']) }}
9+
{{ $errors->first('title', '<small class="error">:message</small>') }}
10+
</div>
11+
</div>
12+
13+
<div class="row">
14+
<div class="">
15+
{{ Form::label('body', 'Thread') }}
16+
<div id="markdown_editor"></div>
17+
{{ Form::textarea('body', null, ['id' => '_markdown_textarea', 'style' => 'display: none;']) }}
18+
{{ $errors->first('body', '<small class="error">:message</small>') }}
19+
</div>
20+
</div>
21+
22+
<div class="row">
23+
@if($tags->count() > 0)
24+
<h3>Describe your post with up to 3 tags</h3>
25+
{{ $errors->first('tags', '<small class="error">:message</small>') }}
26+
<ul class="tags">
27+
@foreach($tags as $tag)
28+
<li>
29+
<label>
30+
{{ Form::checkbox("tags[{$tag->id}]", $tag->id, isset($thread) ? $thread->hasTag($tag->id) : null) }} <span title="{{ $tag->description }}">{{ $tag->name }}</span>
31+
</label> - {{ $tag->description }}
32+
</li>
33+
@endforeach
34+
</ul>
35+
@endif
36+
</div>
37+
38+
<div class="row">
39+
{{ Form::button('Save', ['type' => 'submit', 'class' => 'button']) }}
40+
</div>
41+
42+
</fieldset>
43+
44+
{{ Form::close() }}
45+
46+
@include('layouts._markdown_editor')
47+
48+
@section('scripts')
49+
@parent
50+
<script src="{{ asset('javascripts/forums.js') }}"></script>
51+
@stop

0 commit comments

Comments
 (0)