1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Tinyissue package. |
5
|
|
|
* |
6
|
|
|
* (c) Mohamed Alsharaf <[email protected]> |
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 Tinyissue\Http\Controllers\Project; |
13
|
|
|
|
14
|
|
|
use Illuminate\Http\Request; |
15
|
|
|
use Illuminate\Http\Response; |
16
|
|
|
use Tinyissue\Form\Comment as CommentForm; |
17
|
|
|
use Tinyissue\Form\Issue as IssueForm; |
18
|
|
|
use Tinyissue\Http\Controllers\Controller; |
19
|
|
|
use Tinyissue\Http\Requests\FormRequest; |
20
|
|
|
use Tinyissue\Model\Project; |
21
|
|
|
use Tinyissue\Model\Project\Issue; |
22
|
|
|
use Tinyissue\Model\Project\Issue\Attachment; |
23
|
|
|
use Tinyissue\Model\Project\Issue\Comment; |
24
|
|
|
use Tinyissue\Model\Tag; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* IssueController is the controller class for managing request related to projects issues. |
28
|
|
|
* |
29
|
|
|
* @author Mohamed Alsharaf <[email protected]> |
30
|
|
|
*/ |
31
|
|
|
class IssueController extends Controller |
32
|
|
|
{ |
33
|
|
|
/** |
34
|
|
|
* Project issue index page (List project issues). |
35
|
|
|
* |
36
|
|
|
* @param Project $project |
37
|
|
|
* @param Issue $issue |
38
|
|
|
* @param CommentForm $form |
39
|
|
|
* |
40
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
41
|
|
|
*/ |
42
|
|
|
public function getIndex(Project $project, Issue $issue, CommentForm $form) |
43
|
|
|
{ |
44
|
|
|
$canEdit = $this->allows('update', $issue); |
45
|
|
|
$usersCanFixIssues = $canEdit && $issue->status == Issue::STATUS_OPEN ? $project->getUsersCanFixIssue() : []; |
46
|
|
|
|
47
|
|
|
// Projects should be limited to issue-modify |
48
|
|
|
$projects = null; |
49
|
|
|
if ($canEdit) { |
50
|
|
|
$projects = $this->getLoggedUser()->getProjects(); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
return view('project.issue.index', [ |
54
|
|
|
'issue' => $issue, |
55
|
|
|
'usersCanFixIssues' => $usersCanFixIssues, |
56
|
|
|
'project' => $project, |
57
|
|
|
'closed_issues_count' => $project->countClosedIssues($this->getLoggedUser()), |
58
|
|
|
'open_issues_count' => $project->countOpenIssues($this->getLoggedUser()), |
59
|
|
|
'commentForm' => $form, |
60
|
|
|
'sidebar' => 'project', |
61
|
|
|
'projects' => $projects, |
62
|
|
|
]); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Ajax: Assign new user to an issue. |
67
|
|
|
* |
68
|
|
|
* @param Issue $issue |
69
|
|
|
* @param Request $request |
70
|
|
|
* |
71
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
72
|
|
|
*/ |
73
|
|
|
public function postAssign(Issue $issue, Request $request) |
74
|
|
|
{ |
75
|
|
|
$response = [ |
76
|
|
|
'status' => $issue->updater($this->getLoggedUser())->reassign((int) $request->input('user_id'), $this->getLoggedUser()), |
77
|
|
|
]; |
78
|
|
|
|
79
|
|
|
return response()->json($response); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Ajax: save comment. |
84
|
|
|
* |
85
|
|
|
* @param Comment $comment |
86
|
|
|
* @param Request $request |
87
|
|
|
* |
88
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
89
|
|
|
*/ |
90
|
|
|
public function postEditComment(Comment $comment, Request $request) |
91
|
|
|
{ |
92
|
|
|
$body = ''; |
93
|
|
|
if ($request->has('body')) { |
94
|
|
|
$comment |
95
|
|
|
->updater($this->getLoggedUser()) |
96
|
|
|
->updateBody((string) $request->input('body')); |
97
|
|
|
$body = \Html::format($comment->comment); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
return response()->json(['text' => $body]); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* To add new comment to an issue. |
105
|
|
|
* |
106
|
|
|
* @param Project $project |
107
|
|
|
* @param Issue $issue |
108
|
|
|
* @param Comment $comment |
109
|
|
|
* @param FormRequest\Comment $request |
110
|
|
|
* |
111
|
|
|
* @return \Illuminate\Http\RedirectResponse |
112
|
|
|
*/ |
113
|
|
|
public function postAddComment(Project $project, Issue $issue, Comment $comment, FormRequest\Comment $request) |
114
|
|
|
{ |
115
|
|
|
$comment->setRelations([ |
116
|
|
|
'project' => $project, |
117
|
|
|
'issue' => $issue, |
118
|
|
|
'user' => $this->getLoggedUser(), |
119
|
|
|
]); |
120
|
|
|
$comment->updater($this->getLoggedUser())->create($request->all()); |
121
|
|
|
|
122
|
|
|
return redirect($issue->to() . '#comment' . $comment->id)->with('notice', trans('tinyissue.your_comment_added')); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Ajax: to delete a comment. |
127
|
|
|
* |
128
|
|
|
* @param Comment $comment |
129
|
|
|
* |
130
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
131
|
|
|
*/ |
132
|
|
|
public function getDeleteComment(Comment $comment) |
133
|
|
|
{ |
134
|
|
|
$comment->updater($this->getLoggedUser())->delete(); |
135
|
|
|
|
136
|
|
|
return response()->json(['status' => true]); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* New issue form. |
141
|
|
|
* |
142
|
|
|
* @param Project $project |
143
|
|
|
* @param IssueForm $form |
144
|
|
|
* |
145
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
146
|
|
|
*/ |
147
|
|
|
public function getNew(Project $project, IssueForm $form) |
148
|
|
|
{ |
149
|
|
|
return view('project.issue.new', [ |
150
|
|
|
'project' => $project, |
151
|
|
|
'form' => $form, |
152
|
|
|
'sidebar' => 'project', |
153
|
|
|
]); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* To create a new issue. |
158
|
|
|
* |
159
|
|
|
* @param Project $project |
160
|
|
|
* @param Issue $issue |
161
|
|
|
* @param FormRequest\Issue $request |
162
|
|
|
* |
163
|
|
|
* @return \Illuminate\Http\RedirectResponse |
164
|
|
|
*/ |
165
|
|
|
public function postNew(Project $project, Issue $issue, FormRequest\Issue $request) |
166
|
|
|
{ |
167
|
|
|
$issue->setRelations([ |
168
|
|
|
'project' => $project, |
169
|
|
|
'user' => $this->getLoggedUser(), |
170
|
|
|
]); |
171
|
|
|
$issue->updater($this->getLoggedUser())->create($request->all()); |
172
|
|
|
|
173
|
|
|
return redirect($issue->to())->with('notice', trans('tinyissue.issue_has_been_created')); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* Edit an existing issue form. |
178
|
|
|
* |
179
|
|
|
* @param Project $project |
180
|
|
|
* @param Issue $issue |
181
|
|
|
* @param IssueForm $form |
182
|
|
|
* |
183
|
|
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Contracts\View\Factory|\Illuminate\View\View |
184
|
|
|
*/ |
185
|
|
|
public function getEdit(Project $project, Issue $issue, IssueForm $form) |
186
|
|
|
{ |
187
|
|
|
// Cannot edit closed issue |
188
|
|
|
if ($issue->status == Issue::STATUS_CLOSED) { |
189
|
|
|
return redirect($issue->to()) |
190
|
|
|
->with('notice', trans('tinyissue.cant_edit_closed_issue')); |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
return view('project.issue.edit', [ |
194
|
|
|
'issue' => $issue, |
195
|
|
|
'project' => $project, |
196
|
|
|
'form' => $form, |
197
|
|
|
'sidebar' => 'project', |
198
|
|
|
]); |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* To update an existing issue details. |
203
|
|
|
* |
204
|
|
|
* @param Project $project |
205
|
|
|
* @param Issue $issue |
206
|
|
|
* @param FormRequest\Issue $request |
207
|
|
|
* |
208
|
|
|
* @return \Illuminate\Http\RedirectResponse |
209
|
|
|
*/ |
210
|
|
|
public function postEdit(Project $project, Issue $issue, FormRequest\Issue $request) |
211
|
|
|
{ |
212
|
|
|
// Delete the issue |
213
|
|
|
if ($request->has('delete-issue')) { |
214
|
|
|
$issue->updater($this->getLoggedUser())->delete(); |
215
|
|
|
|
216
|
|
|
return redirect($project->to())->with('notice', trans('tinyissue.issue_has_been_deleted')); |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
$issue->setRelations([ |
220
|
|
|
'project' => $project, |
221
|
|
|
'updatedBy' => $this->getLoggedUser(), |
222
|
|
|
]); |
223
|
|
|
$issue->updater($this->getLoggedUser())->update($request->all()); |
224
|
|
|
|
225
|
|
|
return redirect($issue->to()) |
226
|
|
|
->with('notice', trans('tinyissue.issue_has_been_updated')); |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
/** |
230
|
|
|
* To close or reopen an issue. |
231
|
|
|
* |
232
|
|
|
* @param Project $project |
233
|
|
|
* @param Issue $issue |
234
|
|
|
* @param int $status |
235
|
|
|
* |
236
|
|
|
* @return \Illuminate\Http\RedirectResponse |
237
|
|
|
*/ |
238
|
|
|
public function getClose(Project $project, Issue $issue, $status = 0) |
239
|
|
|
{ |
240
|
|
|
if ($status == 0) { |
241
|
|
|
$message = trans('tinyissue.issue_has_been_closed'); |
242
|
|
|
} else { |
243
|
|
|
$message = trans('tinyissue.issue_has_been_reopened'); |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
$issue->setRelation('project', $project); |
247
|
|
|
$issue->updater($this->getLoggedUser())->changeStatus($status, $this->getLoggedUser()); |
248
|
|
|
|
249
|
|
|
return redirect($issue->to()) |
250
|
|
|
->with('notice', $message); |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
/** |
254
|
|
|
* To upload an attachment file. |
255
|
|
|
* |
256
|
|
|
* @param Project $project |
257
|
|
|
* @param Attachment $attachment |
258
|
|
|
* @param Request $request |
259
|
|
|
* |
260
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
261
|
|
|
*/ |
262
|
|
|
public function postUploadAttachment(Project $project, Attachment $attachment, Request $request) |
263
|
|
|
{ |
264
|
|
|
try { |
265
|
|
|
$attachment->updater($this->getLoggedUser())->upload($request->all(), $project, $this->getLoggedUser()); |
266
|
|
|
|
267
|
|
|
$response = [ |
268
|
|
|
'upload' => [ |
269
|
|
|
[ |
270
|
|
|
'name' => $attachment->filename, |
271
|
|
|
'size' => $attachment->filesize, |
272
|
|
|
'fileId' => $attachment->id, |
273
|
|
|
], |
274
|
|
|
], |
275
|
|
|
]; |
276
|
|
|
} catch (\Exception $exception) { |
277
|
|
|
$file = $request->file('upload'); |
278
|
|
|
|
279
|
|
|
$response = [ |
280
|
|
|
'status' => false, |
281
|
|
|
'name' => $file->getClientOriginalName(), |
282
|
|
|
'error' => $exception->getMessage(), |
283
|
|
|
'trace' => $exception->getTraceAsString(), |
284
|
|
|
]; |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
return response()->json($response); |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
/** |
291
|
|
|
* Delete attachment. |
292
|
|
|
* |
293
|
|
|
* @param Project $project |
294
|
|
|
* @param Issue $issue |
295
|
|
|
* @param Attachment $attachment |
296
|
|
|
* |
297
|
|
|
* @return \Illuminate\Http\RedirectResponse |
298
|
|
|
*/ |
299
|
|
|
public function getDeleteAttachment(Project $project, Issue $issue, Attachment $attachment) |
300
|
|
|
{ |
301
|
|
|
$issue->setRelation('project', $project); |
302
|
|
|
$attachment->setRelation('issue', $issue); |
303
|
|
|
$attachment->updater($this->getLoggedUser())->delete(); |
304
|
|
|
|
305
|
|
|
return redirect($issue->to())->with('notice', trans('tinyissue.attachment_has_been_deleted')); |
306
|
|
|
} |
307
|
|
|
|
308
|
|
|
/** |
309
|
|
|
* Display an attachment file such as image. |
310
|
|
|
* |
311
|
|
|
* @param Project $project |
312
|
|
|
* @param Issue $issue |
313
|
|
|
* @param Attachment $attachment |
314
|
|
|
* @param Request $request |
315
|
|
|
* |
316
|
|
|
* @return Response |
317
|
|
|
*/ |
318
|
|
|
public function getDisplayAttachment(Project $project, Issue $issue, Attachment $attachment, Request $request) |
319
|
|
|
{ |
320
|
|
|
$issue->setRelation('project', $project); |
321
|
|
|
$attachment->setRelation('issue', $issue); |
322
|
|
|
|
323
|
|
|
return $attachment->getDisplayResponse($request); |
324
|
|
|
} |
325
|
|
|
|
326
|
|
|
/** |
327
|
|
|
* Download an attachment file. |
328
|
|
|
* |
329
|
|
|
* @param Project $project |
330
|
|
|
* @param Issue $issue |
331
|
|
|
* @param Attachment $attachment |
332
|
|
|
* |
333
|
|
|
* @return \Symfony\Component\HttpFoundation\BinaryFileResponse |
334
|
|
|
*/ |
335
|
|
|
public function getDownloadAttachment(Project $project, Issue $issue, Attachment $attachment) |
336
|
|
|
{ |
337
|
|
|
$issue->setRelation('project', $project); |
338
|
|
|
$attachment->setRelation('issue', $issue); |
339
|
|
|
|
340
|
|
|
$path = config('filesystems.disks.local.root') . '/' . config('tinyissue.uploads_dir') . '/' . $issue->project_id . '/' . $attachment->upload_token . '/' . $attachment->filename; |
341
|
|
|
|
342
|
|
|
return response()->download($path, $attachment->filename); |
343
|
|
|
} |
344
|
|
|
|
345
|
|
|
/** |
346
|
|
|
* Ajax: move an issue to another project. |
347
|
|
|
* |
348
|
|
|
* @param Issue $issue |
349
|
|
|
* @param Request $request |
350
|
|
|
* |
351
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
352
|
|
|
*/ |
353
|
|
|
public function postChangeProject(Issue $issue, Request $request) |
354
|
|
|
{ |
355
|
|
|
$issue->updater()->changeProject((int) $request->input('project_id')); |
356
|
|
|
|
357
|
|
|
return response()->json(['status' => true, 'url' => $issue->to()]); |
358
|
|
|
} |
359
|
|
|
|
360
|
|
|
/** |
361
|
|
|
* Ajax: change status of an issue. |
362
|
|
|
* |
363
|
|
|
* @param Issue $issue |
364
|
|
|
* @param Request $request |
365
|
|
|
* |
366
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
367
|
|
|
*/ |
368
|
|
|
public function postChangeKanbanTag(Issue $issue, Request $request) |
369
|
|
|
{ |
370
|
|
|
$newTag = Tag::find((int) $request->input('newtag')); |
371
|
|
|
$oldTag = Tag::find((int) $request->input('oldtag')); |
372
|
|
|
|
373
|
|
|
$issue->updater($this->getLoggedUser())->changeKanbanTag($newTag, $oldTag); |
374
|
|
|
|
375
|
|
|
return response()->json(['status' => true, 'issue' => $issue->id]); |
376
|
|
|
} |
377
|
|
|
|
378
|
|
|
/** |
379
|
|
|
* Ajax: returns comments for an issue. |
380
|
|
|
* |
381
|
|
|
* @param Project $project |
382
|
|
|
* @param Issue $issue |
383
|
|
|
* |
384
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\Vie |
385
|
|
|
*/ |
386
|
|
|
public function getIssueComments(Project $project, Issue $issue) |
387
|
|
|
{ |
388
|
|
|
$issue->setRelation('project', $project); |
389
|
|
|
$activities = $issue->getCommentActivities(); |
390
|
|
|
|
391
|
|
|
return view('project.issue.partials.activities', [ |
392
|
|
|
'no_data' => trans('tinyissue.no_comments'), |
393
|
|
|
'activities' => $activities, |
394
|
|
|
'project' => $project, |
395
|
|
|
'issue' => $issue, |
396
|
|
|
]); |
397
|
|
|
} |
398
|
|
|
|
399
|
|
|
/** |
400
|
|
|
* Ajax: returns activities for an issue excluding comments. |
401
|
|
|
* |
402
|
|
|
* @param Project $project |
403
|
|
|
* @param Issue $issue |
404
|
|
|
* |
405
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\Vie |
406
|
|
|
*/ |
407
|
|
|
public function getIssueActivity(Project $project, Issue $issue) |
408
|
|
|
{ |
409
|
|
|
$issue->setRelation('project', $project); |
410
|
|
|
$activities = $issue->getGeneralActivities(); |
411
|
|
|
|
412
|
|
|
return view('project.issue.partials.activities', [ |
413
|
|
|
'no_data' => trans('tinyissue.no_activities'), |
414
|
|
|
'activities' => $activities, |
415
|
|
|
'project' => $project, |
416
|
|
|
'issue' => $issue, |
417
|
|
|
]); |
418
|
|
|
} |
419
|
|
|
} |
420
|
|
|
|