Skip to content

Commit

Permalink
Fixes #3
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelsokolov committed Nov 19, 2020
1 parent 241ce94 commit 0214f59
Show file tree
Hide file tree
Showing 6 changed files with 259 additions and 42 deletions.
39 changes: 39 additions & 0 deletions app/Http/Controllers/OutcomeController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace App\Http\Controllers;

use App\Outcome;
use App\Output;
use App\OutputUpdate;
use Carbon\Carbon;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;

class OutcomeController extends Controller
{
/**
* Update the specified resource in storage.
*
* @param Request $request
* @param int $id
* @return RedirectResponse
*/
public function update(Request $request, int $id)
{
$outcome = Outcome::find($id);
$outcome->summary = $request->summary;
$outcome->completed_on = Carbon::now();
$outcome->user_id = \Auth::user()->id;
$outcome->completed = 1;
$output_updates = array();
foreach ($request->outcome_outputs as $output) {
$output_id = Output::findorfail($output)->id;
$output_updates[$output_id]['indicator'] = Output::find($output_id)->indicator ?? 0;
$output_updates[$output_id]['value'] = OutputUpdate::where('output_id', $output_id)->get()->last()->value ?? 0;
}
$outcome->outputs = json_encode($output_updates);
$outcome->save();
return redirect()->route('project_show', $request->project);
}
}
8 changes: 8 additions & 0 deletions app/Http/Controllers/ProjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,14 @@ public function show(Project $project)
$o->valuestatus = 1;
}
}

foreach ($project->outcomes as $outcome) {
if ($outcome->outputs) {
$outcome->outputs = json_decode($outcome->outputs, true);
} else {
$outcome->outputs = array();
}
}
$project->dates = $this->project_dates($project);
$project->projectstart = !$activities->isEmpty() ? Activity::where('project_id', $project->id)->orderBy('start', 'asc')->first()->start->format('d/m/Y') : null;
$project->projectend = !$activities->isEmpty() ? Activity::where('project_id', $project->id)->orderBy('end', 'desc')->first()->end->format('d/m/Y') : null;
Expand Down
2 changes: 1 addition & 1 deletion app/Outcome.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class Outcome extends Model
{
protected $dates = ['start', 'end'];
protected $fillable = ['name', 'summary', 'outputs', 'completed', 'project_id', 'user_id'];
protected $fillable = ['name', 'summary', 'outputs', 'completed', 'completed_on', 'project_id', 'user_id'];

public function project()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public function up()
$table->id();
$table->string('name');
$table->boolean('completed')->nullable();
$table->date('completed_on')->nullable();
$table->mediumText('summary')->nullable();
$table->string('outputs')->nullable();
$table->foreignId('project_id')->constrained();
Expand Down
250 changes: 209 additions & 41 deletions resources/views/project/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,49 +33,210 @@
@endif
</table>

@if ($project->pending_updates()->count())
<div class="alert alert-info" role="alert">
@if ($project->pending_updates()->count() > 1)
There are {{$project->pending_updates()->count()}} pending updates.
@else There is 1 pending update @endif
<a href="/project/{{$project->id}}/updates">Check it out.</a>
</div>
@endif
<div class="my-3">
<p><a class="btn btn-light" data-toggle="collapse" href="#project_updates" role="button" aria-expanded="false"
aria-controls="project_updates">Project updates @if ($project->pending_updates()->count()) <span
class="badge badge-info">{{$project->pending_updates()->count()}}</span><span class="sr-only">pending updates</span> @endif
</a></p>
@if($project->pending_updates()->count())
<div class="collapse" id="project_updates">
<div class="card card-body">
@foreach ($project->pending_updates()->all() as $index => $pu)
<p>#{{$index+1}} created on {{$pu->created_at->format('d/m/Y')}} by {{ Auth::user()->name }}
@if($pu->status == 'draft') <span class="badge badge-danger">Draft</span>
@elseif($pu->status == 'submitted') <span
class="badge badge-warning">Pending approval</span>
@elseif($pu->status == 'approved') <span class="badge badge-success">Approved</span>
@endif<br/>
@if($pu->summary){{$pu->summary}} @else No summary provided @endif
<br/>
@if ($pu->status == 'draft')
<a href="/project/update/{{$pu->id}}/edit"
class="btn btn-outline-secondary btn-sm">Edit <i class="fas fa-info-circle"></i></a>
<a href="/project/update/{{$pu->id}}/delete"
class="btn btn-outline-secondary btn-sm"
onclick="return confirm('Are you sure you want to delete this update?');">Delete
<i class="fas fa-trash-alt"></i></a>
@endif
<a href="/project/update/{{$pu->id}}" class="btn btn-outline-secondary btn-sm">Show
<i class="fas fa-info-circle"></i></a>
@if ($pu->status != 'draft')
<a href="/project/update/{{$pu->id}}/review" class="btn btn-outline-secondary btn-sm">Review
<i class="fas fa-highlighter"></i></a>
@endif
<p/>
@endforeach
</div>
</div>
@endif
</div>

@if (!$activities->isEmpty())
<h5 class="my-4">Activities</h5>
<table class="table">
@foreach ($activities as $index => $a)
<tr id="activity-{{$a->id}}">
<td class="collapsed link">@if($a->comments)<i class="fas fa-caret-square-right mr-2"></i><i
class="fas fa-caret-square-down d-none"></i>@endif{{$a->title}}</td>
@if($a->status == 1)
<td class="status inprogress">In progress {{$a->statusdate}}</td>
@elseif($a->status == 2)
<td class="status delayed">Delayed {{$a->statusdate}}</td>
@elseif($a->status == 3)
<td class="status done">Done {{$a->statusdate}}</td>
@elseif($a->status == 0)
<td class="status">Not started</td>
@endif
</tr>
@if ($a->comments)
<tr id="activity-{{$a->id}}" class="d-none update">
<td colspan="2">
<table class="table">
@foreach ($a->comments as $puindex => $comment)
<tr>
<td>@if (!$project->cumulative)<b>Update {{$puindex}}</b>
: @endif {!! $comment !!}</td>
</tr>
@endforeach
</table>
</td>
</tr>
<div class="my-3">
<p><a class="btn btn-light" data-toggle="collapse" href="#project_activities" role="button"
aria-expanded="false"
aria-controls="project_activities">Project activities</a></p>

<div class="collapse" id="project_activities">
<div class="card card-body">
@if (!$activities->isEmpty())
<table class="table">
@foreach ($activities as $index => $a)
<tr id="activity-{{$a->id}}">
<td class="collapsed link">@if($a->comments)<i
class="fas fa-caret-square-right mr-2"></i><i
class="fas fa-caret-square-down d-none"></i>@endif{{$a->title}}</td>
@if($a->status == 1)
<td class="status inprogress">In progress {{$a->statusdate}}</td>
@elseif($a->status == 2)
<td class="status delayed">Delayed {{$a->statusdate}}</td>
@elseif($a->status == 3)
<td class="status done">Done {{$a->statusdate}}</td>
@elseif($a->status == 0)
<td class="status">Not started</td>
@endif
</tr>
@if ($a->comments)
<tr id="activity-{{$a->id}}" class="d-none update">
<td colspan="2">
<table class="table">
@foreach ($a->comments as $puindex => $comment)
<tr>
<td>@if (!$project->cumulative)<b>Update {{$puindex}}</b>
: @endif {!! $comment !!}</td>
</tr>
@endforeach
</table>
</td>
</tr>
@endif
@endforeach
</table>
@endif
@endforeach
</table>
@endif
</div>
</div>
</div>

<div class="my-3">
<p><a class="btn btn-light" data-toggle="collapse" href="#project_outcomes" role="button" aria-expanded="false"
aria-controls="project_outcomes">Project outcomes</a></p>
<div class="collapse" id="project_outcomes">
<div class="card card-body">
<ul class="list-group">
@foreach($project->outcomes as $outcome)
@if ($outcome->completed)
<li class="list-group-item">{{$outcome->name}} <a href="#" class="badge badge-success"
data-toggle="modal"
data-target="#outcome_completed"
data-outcome="{{$outcome->name}}"
data-id="{{ $outcome->id }}">Completed
on {{$outcome->completed_on}}</a></li>

<div class="modal fade" id="outcome_completed" tabindex="-1" role="dialog"
aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Outcome
completion: {{$outcome->name}}</h5>
<button type="button" class="close" data-dismiss="modal"
aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<div class="form-group">
<p>Completed on {{$outcome->completed_on}}</p>
</div>
<div class="form-group">
<label for="summary" class="col-form-label">Completion
description:</label>
<p class="form-control" id="summary"
name="summary">{{$outcome->summary}}</p>
</div>
<div class="form-group">
<label for="summary" class="col-form-label">Outputs status:</label>
@foreach($outcome->outputs as $output_id => $output)
<p>Output: {{$output['indicator']}} Value: {{$output['value']}}</p>
@endforeach
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">
Close
</button>
</div>
</div>
</div>
</div>
@else
<li class="list-group-item">{{$outcome->name}} <a href="#" class="badge badge-primary"
data-toggle="modal"
data-target="#outcome_completion"
data-outcome="{{$outcome->name}}"
data-id="{{ $outcome->id }}">Mark as
complete</a>
</li>
<div class="modal fade" id="outcome_completion" tabindex="-1" role="dialog"
aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<form action="{{ route('outcome_update', $outcome) }}" method="POST">
@method('PUT')
@csrf
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Outcome
completion: {{$outcome->name}}</h5>
<button type="button" class="close" data-dismiss="modal"
aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<form>
<!--
<div class="form-group">
<label for="completion_date"
class="col-form-label">Completed on:</label>
<input type="date" class="form-control" id="completion-date">
</div>
-->
<input name="project" value="{{$project->id}}" hidden>
<div class="form-group col-md-3 px-0">
<label for="project_area">Outputs covered</label><br>
<div class="col-md-4 py-2">
<select name="outcome_outputs[]" id="outcome_outputs"
class="custom-select"
multiple="multiple" required>
@foreach($outputs as $output)
<option value="{{$output->id}}" {{ old('output_id') == $output->id || in_array($output->id, $outcome->outputs) ? 'selected':''}}>{{$output->indicator}}</option>
@endforeach
</select>
</div>
</div>
<div class="form-group">
<label for="summary" class="col-form-label">Completion
description:</label>
<textarea class="form-control" id="summary" name="summary"
placeholder="Describe the outcome completion summary"></textarea>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">
Close
</button>
<input class="btn btn-primary" value="Save" type="submit">
</div>
</div>
</form>
</div>
</div>
@endif
@endforeach
</ul>
</div>
</div>
</div>

@if (!$outputs->isEmpty())
<h5 class="my-4">Outputs</h5>
Expand Down Expand Up @@ -118,6 +279,13 @@ class="fas fa-caret-square-down d-none"></i>@endif{{$a->title}}</td>
$(this).children('.fas').toggleClass('fa-caret-square-right fa-caret-square-down');
$(this).toggleClass('expanded collapsed');
});
$(document).ready(function () {
$('#outcome_outputs').multiselect({
templates: {
li: '<li><a href="javascript:void(0);"><label class="pl-2"></label></a></li>'
}
});
});
</script>

@endsection
Loading

0 comments on commit 0214f59

Please sign in to comment.