Skip to content

Commit

Permalink
#30 Spent time: add filter by milestone
Browse files Browse the repository at this point in the history
  • Loading branch information
mnvx committed Jan 13, 2019
1 parent 2345408 commit 61e7ab6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
5 changes: 5 additions & 0 deletions app/Http/Controllers/TimeController.php
Expand Up @@ -6,6 +6,7 @@
use App\Http\Requests\TimeListRequest;
use App\Model\Repository\ContributorRepositoryEloquent;
use App\Model\Repository\LabelRepositoryEloquent;
use App\Model\Repository\MilestoneRepositoryEloquent;
use App\Model\Repository\ProjectRepositoryEloquent;
use App\Model\Service\Eloquent\EloquentSpentService;
use App\Providers\AppServiceProvider;
Expand Down Expand Up @@ -35,6 +36,9 @@ protected function prepareDataForIndex(FormRequest $request, array $data)
/** @var LabelRepositoryEloquent $labelRepository */
$labelRepository = app(AppServiceProvider::LABEL_REPOSITORY);

/** @var MilestoneRepositoryEloquent $milestoneRepository */
$milestoneRepository = app(AppServiceProvider::MILESTONE_REPOSITORY);

$totalTime = $this->getService()->getTotalTime($request->all());

return array_merge(
Expand All @@ -43,6 +47,7 @@ protected function prepareDataForIndex(FormRequest $request, array $data)
'authorsList' => $contributorRepository->getItemsForSelect(),
'projectsList' => $projectRepository->getItemsForSelect(),
'labelList' => $labelRepository->getItemsForSelect(null, null, 'name'),
'milestonelList' => $milestoneRepository->getItemsForSelect(null, null, 'id', 'title'),
'total' => [
'time' => $totalTime,
],
Expand Down
5 changes: 5 additions & 0 deletions app/Model/Repository/SpentRepositoryEloquent.php
Expand Up @@ -80,6 +80,11 @@ public function getListQuery(array $parameters): Builder
$query->whereRaw("issue.labels @> array[$labelsString]");
}

if ($milestoneIds = Arr::get($parameters, 'milestones'))
{
$query->whereIn('issue.milestone_id', $milestoneIds);
}

return $query;
}

Expand Down
11 changes: 11 additions & 0 deletions resources/views/gitpab/time/index_filter_form.blade.php
Expand Up @@ -68,6 +68,17 @@
])
</div>
</div>
<div class="col-md-4">
<div class="form-group">
@include('partial.form.element.select', [
'name' => 'milestones[]',
'list' => $milestonelList,
'selected' => $request->input('milestones'),
'options' => ['multiple' => 'multiple'],
'label' => __('messages.Milestones'),
])
</div>
</div>
</div>

<div class="row">
Expand Down
2 changes: 1 addition & 1 deletion resources/views/gitpab/time/index_table.blade.php
Expand Up @@ -104,6 +104,6 @@
<tr>
<td colspan="2"></td>
<td>{{ $total['time'] }}</td>
<td colspan="3"></td>
<td colspan="4"></td>
</tr>
@endsection

0 comments on commit 61e7ab6

Please sign in to comment.