Skip to content

Commit

Permalink
Edit Poll
Browse files Browse the repository at this point in the history
  • Loading branch information
akiyamaSM committed Oct 2, 2017
1 parent ed9a517 commit a8876b8
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 17 deletions.
4 changes: 4 additions & 0 deletions src/Http/Controllers/PollManagerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,14 @@ public function edit(Poll $poll)
*
* @param Poll $poll
* @param Request $request
* @return \Illuminate\Http\RedirectResponse
*/
public function update(Poll $poll, Request $request)
{
PollHandler::modify($poll, $request->all());

return redirect(route('poll.index'))
->with('success', 'Your poll has been updated successfully');
}

/**
Expand Down
61 changes: 55 additions & 6 deletions src/Views/dashboard/edit.blade.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,55 @@
<div class="container">
{{ $poll->question }}
@foreach($poll->options as $option)
<h3>{{ $option->name }}</h3>
@endforeach
</div>
@extends('larapoll::layouts.app')
@section('title')
Polls- Edit
@endsection
@section('content')
<div class="container">
<ol class="breadcrumb">
<li><a href="#">Home</a></li>
<li><a href="#">Polls</a></li>
<li class="active">Edit Poll</li>
</ol>
<div class="well col-md-8 col-md-offset-2">
@if($errors->any())
<ul class="alert alert-danger">
@foreach($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
@endif
<form method="POST" action=" {{ route('poll.update', $poll->id) }}">
{{ csrf_field() }}
<!-- Question Input -->
<div class="form-group">
<label>{{ $poll->question }}</label>
</div>
<ul class="options">
@foreach($poll->options as $option)
<li>{{ $option->name }}</li>
@endforeach
</ul>

@php
$maxCheck = $poll->maxCheck;
$count_options = $poll->optionsNumber()
@endphp
<select name="count_check" class="form-control">
@for($i =1; $i<= $count_options; $i++)
<option {{ $i==$maxCheck? 'selected':'' }} >{{ $i }}</option>
@endfor
</select>

<div class="radio">
<label>
<input type="checkbox" name="close" {{ $poll->isLocked()? 'checked':'' }}> Close
</label>
</div>

<!-- Create Form Submit -->
<div class="form-group">
<input name="update" type="submit" value="Update" class="btn btn-primary form-control"/>
</div>
</form>
</div>
</div>
@endsection
4 changes: 3 additions & 1 deletion src/helpers/PollHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ public static function modify(Poll $poll, $data)
}

if(array_key_exists('close', $data)){
if($data['close']){
if(isset($data['close']) && $data['close']){
$poll->lock();
}else{
$poll->unLock();
}
}else{
$poll->unLock();
}
}
}
6 changes: 0 additions & 6 deletions tests/ManipulatesPollTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ class ManipulatesPollTest extends \TestCase
{
use DatabaseTransactions;

/** @test */
public function admin_can_see_poll_list()
{
$this->assertTrue(true);
}

/** @test */
public function admin_can_add_new_options()
{
Expand Down
7 changes: 3 additions & 4 deletions tests/PollDashboardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public function an_admin_can_modify_poll_type()
'count_check' => 2,
];
$this->post(route('poll.update', $poll->id), $options)
->assertResponseStatus(200)
->assertResponseStatus(302)
->assertEquals(2, Poll::findOrFail($poll->id)->maxCheck);
}

Expand All @@ -213,7 +213,7 @@ public function an_admin_can_close_a_poll()
];

$this->post(route('poll.update', $poll->id), $options)
->assertResponseStatus(200)
->assertResponseStatus(302)
->assertTrue(Poll::findOrFail($poll->id)->isLocked());
}

Expand All @@ -232,11 +232,10 @@ public function an_admin_can_reopen_a_closed_poll()

$this->assertTrue($poll->lock());
$options = [
'close' => 0,
];

$this->post(route('poll.update', $poll->id), $options)
->assertResponseStatus(200)
->assertResponseStatus(302)
->assertFalse(Poll::findOrFail($poll->id)->isLocked());
}

Expand Down

0 comments on commit a8876b8

Please sign in to comment.