1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of Gitamin. |
5
|
|
|
* |
6
|
|
|
* Copyright (C) 2015-2016 The Gitamin Team |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Gitamin\Http\Controllers\Projects; |
13
|
|
|
|
14
|
|
|
use Gitamin\Commands\Issue\AddIssueCommand; |
15
|
|
|
use Gitamin\Commands\Issue\UpdateIssueCommand; |
16
|
|
|
use Gitamin\Http\Controllers\Controller; |
17
|
|
|
use Gitamin\Models\Issue; |
18
|
|
|
use Gitamin\Models\Project; |
19
|
|
|
use GrahamCampbell\Binput\Facades\Binput; |
20
|
|
|
use Illuminate\Support\Facades\Auth; |
21
|
|
|
use Illuminate\Support\Facades\Redirect; |
22
|
|
|
use Illuminate\Support\Facades\View; |
23
|
|
|
|
24
|
|
|
class IssuesController extends Controller |
25
|
|
|
{ |
26
|
|
|
protected $active_item = 'issues'; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Display a listing of the resource. |
30
|
|
|
* |
31
|
|
|
* @return \Illuminate\Http\Response |
32
|
|
|
*/ |
33
|
|
View Code Duplication |
public function indexAction($namespace, $project_path) |
|
|
|
|
34
|
|
|
{ |
35
|
|
|
$project = Project::findByPath($namespace, $project_path); |
36
|
|
|
|
37
|
|
|
return View::make('projects.issues.index') |
38
|
|
|
->withProject($project) |
39
|
|
|
->withIssues($project->issues) |
|
|
|
|
40
|
|
|
->withActiveItem($this->active_item) |
41
|
|
|
->withPageTitle(sprintf('%s - %s', trans('dashboard.issues.issues'), $project->name)); |
|
|
|
|
42
|
|
|
} |
43
|
|
|
|
44
|
|
View Code Duplication |
public function showAction($owner_path, $project_path, $issue) |
|
|
|
|
45
|
|
|
{ |
46
|
|
|
$project = Project::findByPath($owner_path, $project_path); |
47
|
|
|
|
48
|
|
|
return View::make('projects.issues.show') |
49
|
|
|
->withProject($project) |
50
|
|
|
->withIssue($issue) |
51
|
|
|
->withPageTitle(sprintf('%s - %s', trans('dashboard.issues.issues'), $project->name)) |
|
|
|
|
52
|
|
|
->withActiveItem($this->active_item); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
View Code Duplication |
public function newAction($namespace, $project_path) |
|
|
|
|
56
|
|
|
{ |
57
|
|
|
$project = Project::findByPath($namespace, $project_path); |
58
|
|
|
|
59
|
|
|
return View::make('projects.issues.new') |
60
|
|
|
->withProject($project) |
61
|
|
|
->withPageTitle(sprintf('%s - %s', trans('dashboard.issues.issues'), $project->name)) |
|
|
|
|
62
|
|
|
->withActiveItem($this->active_item); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Show the form for creating a new resource. |
67
|
|
|
* |
68
|
|
|
* @return \Illuminate\Http\Response |
69
|
|
|
*/ |
70
|
|
View Code Duplication |
public function createAction($namespace, $project_path) |
|
|
|
|
71
|
|
|
{ |
72
|
|
|
$project = Project::findByPath($namespace, $project_path); |
73
|
|
|
$issueData = Binput::get('issue'); |
74
|
|
|
|
75
|
|
|
try { |
76
|
|
|
$issueData['author_id'] = Auth::user()->id; |
77
|
|
|
$issueData['project_id'] = $project->id; |
|
|
|
|
78
|
|
|
$issue = $this->dispatchFromArray(AddIssueCommand::class, $issueData); |
|
|
|
|
79
|
|
|
} catch (ValidationException $e) { |
|
|
|
|
80
|
|
|
return Redirect::route('projects.issue_new') |
81
|
|
|
->withInput(Binput::all()) |
82
|
|
|
->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.issues.new.failure'))) |
83
|
|
|
->withErrors($e->getMessageBag()); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
return Redirect::route('projects.issue_index', ['owner' => $namespace, 'project' => $project_path]) |
87
|
|
|
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.issues.new.success'))); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
View Code Duplication |
public function editAction($owner_path, $project_path, Issue $issue) |
|
|
|
|
91
|
|
|
{ |
92
|
|
|
$project = Project::findByPath($owner_path, $project_path); |
93
|
|
|
|
94
|
|
|
return View::make('projects.issues.edit') |
95
|
|
|
->withProject($project) |
96
|
|
|
->withIssue($issue) |
97
|
|
|
->withPageTitle(sprintf('%s - %s', trans('dashboard.issues.issues'), $project->name)) |
|
|
|
|
98
|
|
|
->withActiveItem($this->active_item); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public function updateAction($owner_path, $project_path, Issue $issue) |
102
|
|
|
{ |
103
|
|
|
$project = Project::findByPath($owner_path, $project_path); |
104
|
|
|
$issueData = Binput::get('issue'); |
105
|
|
|
|
106
|
|
|
try { |
107
|
|
|
$issueData['author_id'] = Auth::user()->id; |
108
|
|
|
$issueData['project_id'] = $project->id; |
|
|
|
|
109
|
|
|
$issueData['issue'] = $issue; |
110
|
|
|
$issue = $this->dispatchFromArray(UpdateIssueCommand::class, $issueData); |
111
|
|
|
} catch (ValidationException $e) { |
|
|
|
|
112
|
|
|
return Redirect::route('projects.issue_edit', ['owner' => $owner_path, 'project' => $project_path, 'issue' => $issue->id]) |
113
|
|
|
->withInput(Binput::all()) |
114
|
|
|
->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.issues.edit.failure'))) |
115
|
|
|
->withErrors($e->getMessageBag()); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
//Do nothing |
119
|
|
|
/* |
|
|
|
|
120
|
|
|
if ($issue->project) { |
121
|
|
|
$issue->project->update(['status' => Binput::get('project_status')]); |
122
|
|
|
} |
123
|
|
|
*/ |
124
|
|
|
|
125
|
|
|
return Redirect::route('projects.issue_edit', ['owner' => $owner_path, 'project' => $project_path, 'issue' => $issue->id]) |
126
|
|
|
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.issues.edit.success'))); |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.