Commit 1cbaf3c8 by Tấn Trần Thanh

done daily report

parent 55e9704c
Pipeline #1579 canceled with stages
in 0 seconds
...@@ -3,11 +3,38 @@ require 'csv' ...@@ -3,11 +3,38 @@ require 'csv'
class WorkflowReportController < ApplicationController class WorkflowReportController < ApplicationController
before_action :authorize_global before_action :authorize_global
before_action :require_xhr_request, only: :export before_action :require_xhr_request, only: :export
LEADER_IDS = [172, 229, 271, 142, 6]
def index def index
@team_options = $workflow_report_config['teams'].map { |team| team.keys() } @team_options = $workflow_report_config['teams'].map { |team| team.keys() }
end end
def index_daily_report
@team_options = Project.visible.sorted.active
end
def show_daily_report
project_id = Project.find_by(name: params[:team]).id
users_by_role = Project.find(project_id).users_by_role
result = []
users_by_role.each { |key, _value| users_by_role.delete(key) if key.is_a?(Role) && (key.name == 'Manager' || key.name == 'JP' || key.name == 'TeamLead') }
users_by_role.keys.each do |role|
users_by_role[role].each do |u|
if !LEADER_IDS.include?(u.id)
result << { id: u.id, fullname: "#{u.firstname} #{u.lastname}" }
end
end
end
report = {}
result.each do |item|
report[item[:fullname]] = WorkflowReportTimeEntries.query_time_entry(item[:id])
end
respond_to do |format|
format.js { render 'build_report', locals: { report: report, display_hour: params[:display_hour] } }
end
end
def export def export
thead = ['root_id', 'project', 'subject', 'target_version', ' created_on ', 'closed_on ', 'due_date ', ' status ', 'Estimated_hours (*final version) ', 'Actual time', 'Diff', 'Estimated_hours (*Initial version)', thead = ['root_id', 'project', 'subject', 'target_version', ' created_on ', 'closed_on ', 'due_date ', ' status ', 'Estimated_hours (*final version) ', 'Actual time', 'Diff', 'Estimated_hours (*Initial version)',
'Number of estimation changes', 'Note of estimation changes', '1. Requirement', '2. Design', '3. Coding', '4. Testing', '5. Bug fixing', '6. Release', 'Others', '1. Requirement', '2. Design', '3. Coding', 'Number of estimation changes', 'Note of estimation changes', '1. Requirement', '2. Design', '3. Coding', '4. Testing', '5. Bug fixing', '6. Release', 'Others', '1. Requirement', '2. Design', '3. Coding',
...@@ -17,7 +44,7 @@ class WorkflowReportController < ApplicationController ...@@ -17,7 +44,7 @@ class WorkflowReportController < ApplicationController
result = fetch_data(project_ids, params[:year].to_i, params[:month].to_i, column_number: thead.size) result = fetch_data(project_ids, params[:year].to_i, params[:month].to_i, column_number: thead.size)
respond_to do |format| respond_to do |format|
format.js { render 'build_table', locals: {result: result, thead: thead} } format.js { render 'build_table', locals: { result: result, thead: thead } }
end end
end end
......
module WorkflowReportHelper
def build_report(entrie)
done_ratio = entrie.issue.done_ratio
github_issue_id = entrie.issue.subject.match(/.*(#\d+).*/)[1] rescue "##{entrie.issue.id}"
text = "#{entrie.project.name}#{github_issue_id}: #{entrie.activity.name} - #{entrie.comments}"
text.concat(" (#{done_ratio}%)") if done_ratio > 0
text
end
end
class WorkflowReportTimeEntries < TimeEntry
scope :query_time_entry, ->(user_id) {
where("#{TimeEntry.table_name}.user_id = ? AND #{TimeEntry.table_name}.spent_on BETWEEN ? AND ?", user_id, DateTime.current.beginning_of_day - 9.hours, DateTime.current.end_of_day - 9.hours).
joins(:activity, :project).
references(:issue => [:tracker, :status]).
includes(:issue => [:tracker, :status, :assigned_to, :priority]).
order("#{TimeEntry.table_name}.spent_on DESC, #{Project.table_name}.name ASC, #{Tracker.table_name}.position ASC, #{Issue.table_name}.id ASC")
}
end
\ No newline at end of file
- display_hour = display_hour.to_boolean if display_hour.is_a?(String)
p = "*Daily Report #{Date.current.strftime("%Y-%m-%d")}*"
- report.each_with_index do |(username, entries), index|
- total_time = entries.reduce(0) { |acc, entrie| acc + entrie.hours }
.mt-10 class=("bg-danger" if total_time < 8)
span = "#{(index + 1).to_s}. #{username} #{'(' +total_time.to_s + 'h)' if display_hour}"
- entries.each do |entrie|
div
span &nbsp;&nbsp;
- #{build_report(entrie)}
- if display_hour
span = " (#{entrie.hours} h)"
h3 Report
ul
li = link_to 'Workflow Report', workflow_report_path
li = link_to 'Daily Report', workflow_report_daily_path
\ No newline at end of file
<% display_hour = display_hour || false %>
$("#daily_report").html("<%= escape_javascript(render partial: 'daily_report', locals: { report: report, display_hour: display_hour } ) %>")
= stylesheet_link_tag 'style', plugin: 'workflow_report' = stylesheet_link_tag 'style', plugin: 'workflow_report'
= javascript_include_tag(:application, :plugin => 'workflow_report') = javascript_include_tag(:application, :plugin => 'workflow_report')
= content_for :sidebar do
= render 'side_content'
fieldset.box.tabular fieldset.box.tabular
legend legend
| EXPORT WORKFLOW | EXPORT WORKFLOW
......
= stylesheet_link_tag 'style', plugin: 'workflow_report'
= javascript_include_tag(:application, :plugin => 'workflow_report')
= content_for :sidebar do
= render 'side_content'
fieldset.box.tabular
legend
| DAILY REPORT
= form_tag workflow_report_daily_export_path, method: :get, remote: true, id: 'export-form' do
p
= label :team, 'Team'
= select_tag :team, options_for_select(@team_options), { prompt: "Select team" }
p
= label :display_hour, 'Display hour'
= check_box_tag :display_hour, '1', true
= submit_tag 'export', id: 'export'
#daily_report
...@@ -3,6 +3,10 @@ ...@@ -3,6 +3,10 @@
height: 100vh; height: 100vh;
} }
#daily_report {
min-height: 80vh;
}
table { table {
display: inline-block; display: inline-block;
table-layout: fixed; table-layout: fixed;
...@@ -26,6 +30,10 @@ table { ...@@ -26,6 +30,10 @@ table {
z-index: 1; z-index: 1;
} }
.mt-10 {
margin-top: 10px;
}
.green { .green {
background-color: #92ce92; background-color: #92ce92;
} }
......
...@@ -3,3 +3,5 @@ ...@@ -3,3 +3,5 @@
get 'workflow_report', to: 'workflow_report#index' get 'workflow_report', to: 'workflow_report#index'
get 'workflow_report/export', to: 'workflow_report#export' get 'workflow_report/export', to: 'workflow_report#export'
get 'workflow_report/daily', to: 'workflow_report#index_daily_report'
get 'workflow_report/daily/export', to: 'workflow_report#show_daily_report'
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment