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; |
13
|
|
|
|
14
|
|
|
use Illuminate\Http\Request; |
15
|
|
|
use Tinyissue\Form\Project as Form; |
16
|
|
|
use Tinyissue\Form\GlobalIssue as IssueForm; |
17
|
|
|
use Tinyissue\Http\Requests\FormRequest; |
18
|
|
|
use Tinyissue\Model\Project; |
19
|
|
|
use Tinyissue\Model\User; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* ProjectsController is the controller class for managing request related to projects. |
23
|
|
|
* |
24
|
|
|
* @author Mohamed Alsharaf <[email protected]> |
25
|
|
|
*/ |
26
|
|
|
class ProjectsController extends Controller |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* Display list of active/archived projects. |
30
|
|
|
* |
31
|
|
|
* @param int $status |
32
|
|
|
* |
33
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
34
|
|
|
*/ |
35
|
6 |
|
public function getIndex($status = Project::STATUS_OPEN) |
36
|
|
|
{ |
37
|
6 |
|
$viewData = []; |
38
|
6 |
|
if (!$this->auth->guest()) { |
39
|
3 |
|
$projects = $this->getLoggedUser()->projectsWithCountOpenIssues($status)->get(); |
40
|
3 |
|
if ($status) { |
41
|
3 |
|
$countActive = $projects->count(); |
42
|
3 |
|
$countArchived = $this->getLoggedUser()->projectsWithCountOpenIssues(Project::STATUS_ARCHIVED)->count(); |
43
|
|
|
} else { |
44
|
2 |
|
$countActive = $this->getLoggedUser()->projectsWithCountOpenIssues(Project::STATUS_OPEN)->count(); |
45
|
2 |
|
$countArchived = $projects->count(); |
46
|
|
|
} |
47
|
3 |
|
$viewData['projects'] = $this->getLoggedUser()->projects()->get(); |
48
|
|
|
} else { |
49
|
3 |
|
$viewData['sidebar'] = 'public'; |
50
|
3 |
|
$project = new Project(); |
51
|
3 |
|
$projects = $project->projectsWithOpenIssuesCount($status, Project::PRIVATE_NO)->get(); |
52
|
3 |
|
if ($status) { |
53
|
3 |
|
$countActive = $projects->count(); |
54
|
3 |
|
$countArchived = $project->projectsWithOpenIssuesCount(Project::STATUS_ARCHIVED, Project::PRIVATE_NO)->count(); |
55
|
|
|
} else { |
56
|
|
|
$countActive = $project->projectsWithOpenIssuesCount(Project::STATUS_OPEN, Project::PRIVATE_NO)->count(); |
57
|
|
|
$countArchived = $projects->count(); |
58
|
|
|
} |
59
|
3 |
|
$user = new User(); |
60
|
3 |
|
$viewData['activeUsers'] = $user->activeUsers(); |
61
|
|
|
} |
62
|
6 |
|
$viewData['content_projects'] = $projects; |
63
|
6 |
|
$viewData['active'] = $status === Project::STATUS_OPEN ? 'active' : 'archived'; |
64
|
6 |
|
$viewData['active_count'] = $countActive; |
65
|
6 |
|
$viewData['archived_count'] = $countArchived; |
66
|
|
|
|
67
|
6 |
|
return view('projects.index', $viewData); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Add new project form. |
72
|
|
|
* |
73
|
|
|
* @param Form $form |
74
|
|
|
* |
75
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
76
|
|
|
*/ |
77
|
1 |
|
public function getNew(Form $form) |
78
|
|
|
{ |
79
|
1 |
|
return view('projects.new', [ |
80
|
1 |
|
'form' => $form, |
81
|
1 |
|
'projects' => $this->getLoggedUser()->projects()->get(), |
82
|
|
|
]); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* To create a new project. |
87
|
|
|
* |
88
|
|
|
* @param Project $project |
89
|
|
|
* @param FormRequest\Project $request |
90
|
|
|
* |
91
|
|
|
* @return \Illuminate\Http\RedirectResponse |
92
|
|
|
*/ |
93
|
1 |
|
public function postNew(Project $project, FormRequest\Project $request) |
94
|
|
|
{ |
95
|
1 |
|
$project->createProject($request->all()); |
96
|
|
|
|
97
|
1 |
|
return redirect($project->to()); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Ajax: Calculate the progress of user projects. |
102
|
|
|
* |
103
|
|
|
* @param Request $request |
104
|
|
|
* @param Project $project |
105
|
|
|
* |
106
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
107
|
|
|
*/ |
108
|
1 |
|
public function postProgress(Request $request, Project $project) |
109
|
|
|
{ |
110
|
|
|
// Get all projects with count of closed and opened issues |
111
|
1 |
|
$projects = $project->projectsWithCountIssues((array) $request->input('ids')); |
112
|
|
|
|
113
|
|
|
// The project progress Html and value |
114
|
1 |
|
$progress = $projects->transform(function (Project $project) { |
115
|
1 |
|
$progress = $project->getProgress(); |
116
|
1 |
|
$view = view('partials/progress', ['text' => $progress . '%', 'progress' => $progress])->render(); |
117
|
|
|
|
118
|
|
|
return [ |
119
|
1 |
|
'id' => $project->id, |
120
|
|
|
'progress' => [ |
121
|
1 |
|
'html' => $view, |
122
|
1 |
|
'value' => $progress, |
123
|
|
|
], |
124
|
|
|
]; |
125
|
1 |
|
})->lists('progress', 'id')->all(); |
126
|
|
|
|
127
|
1 |
|
return response()->json(['status' => true, 'progress' => $progress]); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Add new issue form. |
132
|
|
|
* |
133
|
|
|
* @param IssueForm $form |
134
|
|
|
* |
135
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
136
|
|
|
*/ |
137
|
1 |
|
public function getNewIssue(IssueForm $form) |
138
|
|
|
{ |
139
|
1 |
|
return view('projects.new-issue', [ |
140
|
1 |
|
'form' => $form, |
141
|
1 |
|
'projects' => $this->getLoggedUser()->projects()->get(), |
142
|
|
|
]); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* To create a new issue. |
147
|
|
|
* |
148
|
|
|
* @param Project\Issue $issue |
149
|
|
|
* @param FormRequest\GlobalIssue $request |
150
|
|
|
* |
151
|
|
|
* @return \Illuminate\Http\RedirectResponse |
152
|
|
|
*/ |
153
|
1 |
|
public function postNewIssue(Project\Issue $issue, FormRequest\GlobalIssue $request) |
154
|
|
|
{ |
155
|
1 |
|
$project = Project::find((int) $request->input('project')); |
156
|
|
|
|
157
|
1 |
|
$issue->setRelation('project', $project); |
158
|
1 |
|
$issue->setRelation('user', $this->getLoggedUser()); |
159
|
1 |
|
$issue->createIssue([ |
160
|
1 |
|
'title' => $request->input('title'), |
161
|
1 |
|
'body' => $request->input('body'), |
162
|
1 |
|
'tag_type' => $request->input('tag_type'), |
163
|
1 |
|
'upload_token' => $request->input('upload_token'), |
164
|
1 |
|
'assigned_to' => (int) $project->default_assignee, |
165
|
1 |
|
'time_quote' => 0, |
166
|
|
|
]); |
167
|
|
|
|
168
|
1 |
|
return redirect($issue->to()) |
169
|
1 |
|
->with('notice', trans('tinyissue.issue_has_been_created')); |
170
|
|
|
} |
171
|
|
|
} |
172
|
|
|
|