|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* GitScrum v0.1. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Renato Marinho <[email protected]> |
|
6
|
|
|
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace GitScrum\Http\Controllers; |
|
10
|
|
|
|
|
11
|
|
|
use Illuminate\Http\Request; |
|
12
|
|
|
use GitScrum\Http\Requests\IssueRequest; |
|
13
|
|
|
use GitScrum\Models\Sprint; |
|
14
|
|
|
use GitScrum\Models\UserStory; |
|
15
|
|
|
use GitScrum\Models\Issue; |
|
16
|
|
|
use GitScrum\Models\Organization; |
|
17
|
|
|
use GitScrum\Models\IssueType; |
|
18
|
|
|
use GitScrum\Models\ConfigStatus; |
|
19
|
|
|
use GitScrum\Models\ConfigIssueEffort; |
|
20
|
|
|
use Carbon\Carbon; |
|
21
|
|
|
use Auth; |
|
22
|
|
|
|
|
23
|
|
|
class IssueController extends Controller |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* Display a listing of the resource. |
|
27
|
|
|
* |
|
28
|
|
|
* @return \Illuminate\Http\Response |
|
29
|
|
|
*/ |
|
30
|
|
|
public function index($slug) |
|
31
|
|
|
{ |
|
32
|
|
|
if ($slug) { |
|
33
|
|
|
$sprint = Sprint::slug($slug) |
|
34
|
|
|
->with('issues.user') |
|
35
|
|
|
->with('issues.users') |
|
36
|
|
|
->with('issues.commits') |
|
37
|
|
|
->with('issues.statuses') |
|
38
|
|
|
->with('issues.status') |
|
39
|
|
|
->with('issues.comments') |
|
40
|
|
|
->with('issues.attachments') |
|
41
|
|
|
->with('issues.type') |
|
42
|
|
|
->first(); |
|
43
|
|
|
|
|
44
|
|
|
$issues = $sprint->issues; |
|
45
|
|
|
} else { |
|
46
|
|
|
$sprint = null; |
|
47
|
|
|
$issues = Auth::user()->issues; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
$issues = $issues->sortBy('position')->groupBy('config_status_id'); |
|
51
|
|
|
|
|
52
|
|
|
$configStatus = ConfigStatus::type('issue')->get(); |
|
53
|
|
|
|
|
54
|
|
|
if (!is_null($sprint) && !count($sprint)) { |
|
55
|
|
|
return redirect()->route('sprints.index'); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
//get all stories from this product with an open issue |
|
59
|
|
|
//@TODO make sure stories are managable by user |
|
60
|
|
|
$userStoriesIds = UserStory::select(['user_stories.id', 'user_stories.config_priority_id']) |
|
61
|
|
|
->where('user_stories.product_backlog_id', $sprint->product_backlog_id) |
|
62
|
|
|
->join('issues', function ($join) { |
|
63
|
|
|
$join->on('user_stories.id', '=', 'issues.user_story_id') |
|
64
|
|
|
->where('issues.config_status_id', 1); |
|
65
|
|
|
}) |
|
66
|
|
|
->groupBy(['user_stories.id', 'user_stories.config_priority_id']) |
|
67
|
|
|
->orderBy('user_stories.config_priority_id') |
|
68
|
|
|
->orderBy('user_stories.id') |
|
69
|
|
|
->get(); |
|
70
|
|
|
$openUserStories = []; |
|
71
|
|
|
foreach ($userStoriesIds as $oneUserStoryId) { |
|
72
|
|
|
$openUserStory = UserStory::find($oneUserStoryId->id); |
|
73
|
|
|
$openUserStory->load(['issues' => function($query) { |
|
74
|
|
|
$query->where('config_status_id',1) |
|
75
|
|
|
->whereNull('sprint_id'); |
|
76
|
|
|
}, 'issues.type']); |
|
77
|
|
|
if ($openUserStory->issues->count() > 0) { |
|
78
|
|
|
$openUserStory->load('priority'); |
|
79
|
|
|
$openUserStories[] = $openUserStory; |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
return view('issues.index') |
|
|
|
|
|
|
84
|
|
|
->with('sprint', $sprint) |
|
85
|
|
|
->with('issues', $issues) |
|
86
|
|
|
->with('configStatus', $configStatus) |
|
87
|
|
|
->with('openUserStories', $openUserStories); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
public function create($slug_sprint = null, $slug_user_story = null, $parent_id = null) |
|
|
|
|
|
|
91
|
|
|
{ |
|
92
|
|
|
$issue_types = IssueType::where('enabled', 1) |
|
93
|
|
|
->orderby('position', 'ASC') |
|
94
|
|
|
->get(); |
|
95
|
|
|
|
|
96
|
|
|
$issue_efforts = ConfigIssueEffort::where('enabled', 1) |
|
97
|
|
|
->orderby('position', 'ASC') |
|
98
|
|
|
->get(); |
|
99
|
|
|
|
|
100
|
|
|
$userStory = $productBacklogs = null; |
|
101
|
|
|
|
|
102
|
|
|
if ((is_null($slug_sprint) || !$slug_sprint) && $slug_user_story) { |
|
103
|
|
|
$userStory = UserStory::slug($slug_user_story)->first(); |
|
104
|
|
|
$productBacklogs = Auth::user()->productBacklogs($userStory->product_backlog_id); |
|
105
|
|
|
$usersByOrganization = Organization::find($userStory->productBacklog->organization_id)->users; |
|
106
|
|
|
} elseif ($slug_sprint) { |
|
107
|
|
|
$usersByOrganization = Organization::find(Sprint::slug($slug_sprint)->first() |
|
108
|
|
|
->productBacklog->organization_id)->users; |
|
109
|
|
|
} else { |
|
110
|
|
|
$issue = Issue::find($parent_id); |
|
111
|
|
|
$productBacklogs = $issue->product_backlog_id; |
|
112
|
|
|
$usersByOrganization = Organization::find($issue->productBacklog->organization_id)->users; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
return view('issues.create') |
|
|
|
|
|
|
116
|
|
|
->with('productBacklogs', $productBacklogs) |
|
117
|
|
|
->with('userStory', $userStory) |
|
118
|
|
|
->with('slug', $slug_sprint) |
|
119
|
|
|
->with('parent_id', $parent_id) |
|
120
|
|
|
->with('issue_types', $issue_types) |
|
121
|
|
|
->with('issue_efforts', $issue_efforts) |
|
122
|
|
|
->with('usersByOrganization', $usersByOrganization) |
|
123
|
|
|
->with('action', 'Create'); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
public function store(IssueRequest $request) |
|
127
|
|
|
{ |
|
128
|
|
|
$issue = Issue::create($request->all()); |
|
129
|
|
|
|
|
130
|
|
|
if (is_array($request->members)) { |
|
|
|
|
|
|
131
|
|
|
$issue->users()->sync($request->members); |
|
|
|
|
|
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
return redirect()->route('issues.show', ['slug' => $issue->slug]) |
|
|
|
|
|
|
135
|
|
|
->with('success', trans('Congratulations! The Issue has been created with successfully')); |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
public function show($slug) |
|
|
|
|
|
|
139
|
|
|
{ |
|
140
|
|
|
$issue = Issue::slug($slug) |
|
141
|
|
|
->with('sprint') |
|
142
|
|
|
->with('type') |
|
143
|
|
|
->with('configEffort') |
|
144
|
|
|
->with('labels') |
|
145
|
|
|
->first(); |
|
146
|
|
|
|
|
147
|
|
|
$usersByOrganization = Organization::find($issue->productBacklog->organization_id)->users; |
|
148
|
|
|
|
|
149
|
|
|
return view('issues.show') |
|
|
|
|
|
|
150
|
|
|
->with('issue', $issue) |
|
151
|
|
|
->with('usersByOrganization', $usersByOrganization); |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
public function edit($slug) |
|
|
|
|
|
|
155
|
|
|
{ |
|
156
|
|
|
$issue = Issue::slug($slug)->first(); |
|
157
|
|
|
|
|
158
|
|
|
$issue_types = IssueType::where('enabled', 1) |
|
159
|
|
|
->orderby('position', 'ASC') |
|
160
|
|
|
->get(); |
|
161
|
|
|
|
|
162
|
|
|
$issue_efforts = ConfigIssueEffort::where('enabled', 1) |
|
163
|
|
|
->orderby('position', 'ASC') |
|
164
|
|
|
->get(); |
|
165
|
|
|
|
|
166
|
|
|
$usersByOrganization = Organization::find($issue->productBacklog->organization_id)->users; |
|
167
|
|
|
|
|
168
|
|
|
$productBacklogs = Auth::user()->productBacklogs($issue->productBacklog->id, false); |
|
169
|
|
|
|
|
170
|
|
|
return view('issues.edit') |
|
|
|
|
|
|
171
|
|
|
->with('productBacklogs', $productBacklogs) |
|
172
|
|
|
->with('userStory', $issue->userStory) |
|
173
|
|
|
->with('slug', isset($issue->sprint->slug) ? $issue->sprint->slug : null) |
|
174
|
|
|
->with('issue_types', $issue_types) |
|
175
|
|
|
->with('issue_efforts', $issue_efforts) |
|
176
|
|
|
->with('usersByOrganization', $usersByOrganization) |
|
177
|
|
|
->with('issue', $issue) |
|
178
|
|
|
->with('action', 'Edit'); |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
public function update(IssueRequest $request, $slug) |
|
182
|
|
|
{ |
|
183
|
|
|
$issue = Issue::slug($slug)->first(); |
|
184
|
|
|
|
|
185
|
|
|
$issue->update($request->all()); |
|
186
|
|
|
|
|
187
|
|
|
if (is_array($request->members)) { |
|
|
|
|
|
|
188
|
|
|
$issue->users()->sync($request->members); |
|
|
|
|
|
|
189
|
|
|
} |
|
190
|
|
|
|
|
191
|
|
|
return back() |
|
192
|
|
|
->with('success', trans('Congratulations! The Issue has been edited with successfully')); |
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
public function statusUpdate(Request $request, $slug = null, int $status = 0) |
|
196
|
|
|
{ |
|
197
|
|
|
|
|
198
|
|
|
if (!isset($request->status_id)) { |
|
199
|
|
|
$request->status_id = $status; |
|
200
|
|
|
} |
|
201
|
|
|
$status = ConfigStatus::find($request->status_id); |
|
202
|
|
|
|
|
203
|
|
|
if ($request->ajax()) { |
|
204
|
|
|
$position = 1; |
|
205
|
|
|
|
|
206
|
|
|
try { |
|
207
|
|
|
foreach (json_decode($request->json) as $id) { |
|
208
|
|
|
$issue = Issue::find($id); |
|
209
|
|
|
if (empty($issue->sprint_id) && !empty($request->sprint_id)) { |
|
210
|
|
|
$issue->assignToSprint($request->sprint_id); |
|
211
|
|
|
} |
|
212
|
|
|
$updateSuccess = $issue->updateStatusAndPosition($request->status_id, $status, $position); |
|
213
|
|
|
++$position; |
|
214
|
|
|
} |
|
215
|
|
|
|
|
216
|
|
|
return response()->json([ |
|
217
|
|
|
'success' => $updateSuccess, |
|
|
|
|
|
|
218
|
|
|
]); |
|
219
|
|
|
} catch (\Exception $e) { |
|
220
|
|
|
return response()->json([ |
|
221
|
|
|
'success' => false, |
|
222
|
|
|
]); |
|
223
|
|
|
} |
|
224
|
|
|
} else { |
|
225
|
|
|
$issue = Issue::slug($slug)->firstOrFail(); |
|
226
|
|
|
$issue->updateStatusAndPosition($request->status_id, $status); |
|
227
|
|
|
|
|
228
|
|
|
return back()->with('success', trans('Updated successfully')); |
|
229
|
|
|
} |
|
230
|
|
|
} |
|
231
|
|
|
|
|
232
|
|
|
public function destroy(Request $request) |
|
233
|
|
|
{ |
|
234
|
|
|
$issue = Issue::slug($request->slug)->firstOrFail(); |
|
235
|
|
|
|
|
236
|
|
|
if (isset($issue->userStory)) { |
|
237
|
|
|
$redirect = redirect()->route('user_stories.show', ['slug' => $issue->userStory->slug]); |
|
238
|
|
|
} else { |
|
239
|
|
|
$redirect = redirect()->route('sprints.show', ['slug' => $issue->sprint->slug]); |
|
240
|
|
|
} |
|
241
|
|
|
|
|
242
|
|
|
$issue->delete(); |
|
243
|
|
|
|
|
244
|
|
|
return $redirect; |
|
245
|
|
|
} |
|
246
|
|
|
|
|
247
|
|
|
public function removeFromSprint($slug) |
|
248
|
|
|
{ |
|
249
|
|
|
$issue = Issue::slug($slug)->firstOrFail(); |
|
250
|
|
|
$sprintSlug = $issue->sprint->slug; |
|
251
|
|
|
$issue->removeFromSprint(); |
|
252
|
|
|
return redirect()->route('issues.index', ['slug' => $sprintSlug]); |
|
253
|
|
|
} |
|
254
|
|
|
} |
|
255
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: