Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
openproject
Service Pack
Commits
08f76667
Verified
Commit
08f76667
authored
6 years ago
by
Tam Le
Browse files
Options
Download
Email Patches
Plain Diff
Filter backend
parent
35eef744
master
addtional_notification_email
api-fix-time-entry
dont_have_notify
feature/report-with-filter
fix/1-gitlab
fix/3-gitlab
fix/3bis-gitlab
fix/handle_when_remain_unit_is_zero
fix_run_out_mail_sent_3_times
improvement/rollback_when_logtime_exceed_remain_unit
make_notify_email_send_once_only
v1.0.5
v1.0.4
v1.0.3
v1.0.2
1 merge request
!5
WIP: SP Report with filters
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
app/controllers/assigns_controller.rb
+1
-5
app/controllers/assigns_controller.rb
app/controllers/service_packs_controller.rb
+1
-0
app/controllers/service_packs_controller.rb
app/controllers/sp_report_controller.rb
+45
-0
app/controllers/sp_report_controller.rb
app/helpers/service_pack_report.rb
+3
-3
app/helpers/service_pack_report.rb
app/helpers/service_packs_report_helper.rb
+59
-0
app/helpers/service_packs_report_helper.rb
config/routes.rb
+5
-2
config/routes.rb
with
114 additions
and
10 deletions
+114
-10
app/controllers/assigns_controller.rb
+
1
-
5
View file @
08f76667
class
AssignsController
<
ApplicationController
#layout 'admin'
before_action
:find_project_by_project_id
include
SPAssignmentManager
...
...
@@ -74,10 +74,6 @@ class AssignsController < ApplicationController
end
end
def
select_to_transfer
return
head
403
unless
@can_assign
=
User
.
current
.
allowed_to?
(
:assign_service_packs
,
@project
)
end
def
report
return
head
403
unless
User
.
current
.
allowed_to?
(
:see_assigned_service_packs
,
@project
)
if
assignment
=
assigned?
(
@project
)
...
...
This diff is collapsed.
Click to expand it.
app/controllers/service_packs_controller.rb
+
1
-
0
View file @
08f76667
...
...
@@ -23,6 +23,7 @@ class ServicePacksController < ApplicationController
# controller chooses not to get the thresholds.
# assume the service pack exists.
# TODO: make a separate action JSON only.
binding
.
pry
respond_to
do
|
format
|
format
.
json
{
# the function already converted this to json
...
...
This diff is collapsed.
Click to expand it.
app/controllers/sp_report_controller.rb
0 → 100644
+
45
-
0
View file @
08f76667
class
SpReportController
<
ApplicationController
before_action
:find_project_by_project_id
include
ServicePacksReportHelper
def
report
# json & html endpoint
# params[:service_pack, :start_date, :end_date]
spid
=
params
[
:service_pack_id
]
if
spid
.
present?
@fault
=
true
and
render_404
unless
sp
=
ServicePack
.
find_by
(
id:
spid
)
end
sql
=
query
(
service_pack:
sp
,
project:
@project
,
start_date:
params
[
:start_date
]
&
.
to_date
,
end_date:
params
[
:end_date
]
&
.
to_date
)
respond_to
do
|
format
|
format
.
html
{
# change this to debug
render
plain:
sp_available
}
format
.
json
{
render
json:
@entries
}
format
.
csv
{
# todo
}
end
end
def
proj_available
get_projects_available
.
pluck
(
:id
,
:name
)
end
def
sp_available
Assign
.
active
.
joins
(
:service_pack
)
.
where
(
project_id:
get_projects_available
.
pluck
(
:id
))
.
pluck
(
-
'service_packs.id'
,
'service_packs.name'
)
end
private
def
get_projects_available
@projects
||=
Project
.
allowed_to
(
User
.
current
,
:see_assigned_service_packs
)
end
end
\ No newline at end of file
This diff is collapsed.
Click to expand it.
app/helpers/service_pack_report.rb
+
3
-
3
View file @
08f76667
...
...
@@ -9,13 +9,13 @@ class ServicePackReport
end
end
def
query
(
project
=
nil
)
def
query
(
project
:
nil
,
date_start:
nil
,
date_end:
nil
)
sql
=
<<-
SQL
SELECT t2.spent_on, concat(t4.firstname, ' ', t4.lastname) AS user_name, t3.name AS activity_name,
t5.id AS work_package_id, t7.name AS type_name, t5.subject AS subject, t2.comments AS comment,
t1.units AS units, t2.hours AS hours,
#{
project
.
nil?
?
't6.name'
:
"'
#{
project
.
name
}
'"
}
AS project_name
FROM service_pack_entries t1
INNER
JOIN
#{
TimeEntry
.
table_name
}
t2
LEFT
JOIN
#{
TimeEntry
.
table_name
}
t2
ON t1.time_entry_id = t2.id
INNER JOIN
#{
TimeEntryActivity
.
table_name
}
t3
ON t2.activity_id = t3.id
...
...
@@ -26,7 +26,7 @@ class ServicePackReport
ON t2.work_package_id = t5.id
LEFT JOIN types t7
ON t5.type_id = t7.id
WHERE service_pack_id =
#{
@service_pack
.
id
}
WHERE
t1.
service_pack_id =
#{
@service_pack
.
id
}
#{
project
.
nil?
?
''
:
"AND t2.project_id =
#{
project
.
id
}
"
}
ORDER BY spent_on DESC
SQL
...
...
This diff is collapsed.
Click to expand it.
app/helpers/service_packs_report_helper.rb
0 → 100644
+
59
-
0
View file @
08f76667
module
ServicePacksReportHelper
def
query
(
service_pack:
nil
,
project:
nil
,
start_date:
nil
,
end_date:
nil
)
# binding.pry
proj_clause
=
<<-
SQL
SELECT t2.spent_on, concat(t4.firstname, ' ', t4.lastname) AS user_name,
t3.name AS activity_name, t5.id AS work_package_id, t5.subject AS subject,
t2.comments AS comment, t1.units AS units, t2.hours AS hours, t6.name AS type_name
SQL
query_to_sanitize
=
[
proj_clause
]
from_clause
=
<<-
SQL
FROM service_pack_entries t1
LEFT JOIN
#{
TimeEntry
.
table_name
}
t2
ON t1.time_entry_id = t2.id
INNER JOIN
#{
TimeEntryActivity
.
table_name
}
t3
ON t2.activity_id = t3.id
INNER JOIN users t4
ON t2.user_id = t4.id
LEFT JOIN
#{
WorkPackage
.
table_name
}
t5
ON t2.work_package_id = t5.id
LEFT JOIN types t6
ON t5.type_id = t6.id
SQL
where_clause
=
'WHERE 1 = 1'
dts
=
start_date
&
.
to_s
ets
=
(
end_date
&
.
next_day
)
&
.
to_s
where_clause
<<
" AND t1.created_at >= '
#{
dts
}
' "
if
dts
where_clause
<<
" AND t1.created_at < '
#{
ets
}
' "
if
ets
if
project
&
.
id
# project given?
# specific project
where_clause
<<
" AND t2.project_id =
#{
project
.
id
}
"
proj_clause
<<
-
', ? AS project_name '
query_to_sanitize
<<
project
.
name
else
# all project
from_clause
<<
-
' INNER JOIN projects t7 ON t2.project_id = t7.id '
proj_clause
<<
-
', t7.name AS project_name '
end
if
service_pack
&
.
id
# SP given?
# specific SP
where_clause
<<
" AND t1.service_pack_id =
#{
service_pack
.
id
}
"
proj_clause
<<
-
', ? AS sp_name '
query_to_sanitize
<<
service_pack
.
name
else
# all SP
from_clause
<<
-
' INNER JOIN service_packs t8 ON t1.service_pack_id = t8.id '
proj_clause
<<
-
', t8.name AS sp_name'
end
proj_clause
<<
from_clause
<<
where_clause
proj_clause
<<
-
' ORDER BY spent_on DESC '
sql
=
ActiveRecord
::
Base
.
send
(
:sanitize_sql_array
,
query_to_sanitize
)
@entries
=
ActiveRecord
::
Base
.
connection
.
exec_query
(
sql
)
sql
end
end
\ No newline at end of file
This diff is collapsed.
Click to expand it.
config/routes.rb
+
5
-
2
View file @
08f76667
# freeze_literal_string: true
OpenProject
::
Application
.
routes
.
draw
do
resources
:service_packs
do
get
'/statistics'
,
to:
'service_packs#statistics'
,
constraints:
lambda
{
|
req
|
req
.
format
==
:json
}
end
scope
"
/projects/:project_id
"
do
scope
'
/projects/:project_id
'
do
get
'/assigns'
,
to:
'assigns#show'
get
'/assigns/report'
,
to:
'assigns#report'
post
'/assigns/assign'
,
to:
'assigns#assign'
post
'/assigns/unassign'
,
to:
'assigns#unassign'
get
'/assigns/statistics'
,
to:
'assigns#statistics'
,
constraints:
lambda
{
|
req
|
req
.
format
==
:json
}
get
'/assigns/:assignment_id/transfer'
,
to:
'assigns#select_to_transfer'
,
as:
'sp_transfer'
get
'/sp_report'
,
to:
'sp_report#report'
,
as:
'sp_report'
end
end
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help