-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathorder_helper.rb
181 lines (154 loc) · 6.36 KB
/
order_helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# frozen_string_literal: true
# Copyright (c) 2006-2017, Puzzle ITC GmbH. This file is part of
# PuzzleTime and licensed under the Affero General Public License version 3
# or later. See the COPYING file at the top-level directory or at
# https://github.com/puzzle/puzzletime.
module OrderHelper
def order_team_enumeration(order)
list = order.team_members.to_a
if list.size > 2
linked_employee_enumeration(list.take(2)) + ', …'.html_safe
else
linked_employee_enumeration(list)
end
end
def linked_employee_enumeration(employees)
safe_join(employees, ', ') { |e| link_to(e, e) }
end
def order_contacts_enumeration(order)
list = order.contacts.to_a
contacts = safe_join(list.take(2), ', ')
contacts << ', …'.html_safe if list.size > 2
contacts
end
def order_target_rating_icon(rating, options = {})
options[:style] ||= 'font-size: 20px;'
add_css_class(options, rating)
picon(order_target_icon_key(rating), options)
end
def order_target_icon(target)
return unless target
order_target_rating_icon(
target.rating,
title: target.comment? ? simple_format(target.comment).gsub('"', '"') : nil,
data: { toggle: :tooltip }
)
end
def order_target_icon_key(rating)
case rating
when 'green' then 'disk'
when 'orange' then 'triangle'
when 'red' then 'square'
end
end
def format_order_status_style(status)
content_tag(:span, status.name, class: "label label-#{status.style}")
end
def format_target_scope_icon(scope)
icon(scope.icon)
end
def format_order_crm_key(order)
crm_order_link(order)
end
def format_order_billability(value)
content_tag(:span, f(value), class: order_report_billability_class(value))
end
def format_order_average_rate(value)
content_tag(:span, f(value), class: order_report_average_rate_class(value))
end
def format_order_additional_crm_orders(order)
simple_list(order.additional_crm_orders.map(&method(:crm_order_link)))
end
def format_major_chance(order)
return if order.nil?
content_tag(:span, safe_join(risk_icons(order.major_chance, OrderChance.sti_name)),
style: 'font-size: 20px;',
title: uncertainties_tooltip(order, OrderChance.sti_name),
data: { toggle: :tooltip })
end
def format_major_risk(order)
return if order.nil?
content_tag(:span, safe_join(risk_icons(order.major_risk, OrderRisk.sti_name)),
style: 'font-size: 20px;',
title: uncertainties_tooltip(order, OrderRisk.sti_name),
data: { toggle: :tooltip })
end
def glyphicons
%w[asterisk plus euro minus cloud envelope pencil glass music search heart star star-empty
user film th-large th th-list ok remove zoom-in zoom-out off signal cog trash home file
time road download-alt download upload inbox play-circle repeat refresh list-alt lock flag
headphones volume-off volume-down volume-up qrcode barcode tag tags book bookmark print
camera font bold italic text-height text-width align-left align-center align-right
align-justify list indent-left indent-right facetime-video picture map-marker adjust tint
edit share check move step-backward fast-backward backward play pause stop forward
fast-forward step-forward eject chevron-left chevron-right plus-sign minus-sign remove-sign
ok-sign question-sign info-sign screenshot remove-circle ok-circle ban-circle arrow-left
arrow-right arrow-up arrow-down share-alt resize-full resize-small exclamation-sign gift
leaf fire eye-open eye-close warning-sign plane calendar random comment magnet chevron-up
chevron-down retweet shopping-cart folder-close folder-open resize-vertical
resize-horizontal hdd bullhorn bell certificate thumbs-up thumbs-down hand-right hand-left
hand-up hand-down circle-arrow-right circle-arrow-left circle-arrow-up circle-arrow-down
globe wrench tasks filter briefcase fullscreen dashboard paperclip heart-empty link phone
pushpin usd gbp sort sort-by-alphabet sort-by-alphabet-alt sort-by-order sort-by-order-alt
sort-by-attributes sort-by-attributes-alt unchecked expand collapse-down collapse-up log-in
flash log-out new-window record save open saved import export send floppy-disk floppy-saved
floppy-remove floppy-save floppy-open credit-card transfer cutlery header compressed
earphone phone-alt tower stats sd-video hd-video subtitles sound-stereo sound-dolby
sound-5-1 sound-6-1 sound-7-1 copyright-mark registration-mark cloud-download cloud-upload
tree-conifer tree-deciduous]
end
def choosable_order_options
managed_orders = current_user.managed_orders.where(work_items: { closed: false }).list.minimal
order_option(@order, true) + safe_join(managed_orders) { |o| order_option(o) }
end
def order_option(order, selected = false)
return unless order
json = { id: order.id,
name: order.name,
path_shortnames: order.path_shortnames }
content_tag(:option,
order.label_verbose,
value: order.id,
selected:,
data: { data: json.to_json })
end
def order_report_billability_class(value)
config = Settings.reports.orders.billability
if value >= config.green
'green'
elsif value >= config.orange
'orange'
else
'red'
end
end
def order_report_average_rate_class(value)
config = Settings.reports.orders.average_rate
if value >= config.green
'green'
elsif value >= config.yellow
'yellow'
elsif value >= config.orange
'orange'
else
'red'
end
end
def uncertainties_tooltip(order, uncertainty_type)
uncertainties = uncertainties_grouped_by_risk(order, uncertainty_type)
%i[high medium low]
.select { |risk| uncertainties.key?(risk) }
.reduce('') do |result, risk|
title = t("activerecord.attributes.order_uncertainty/risks.#{risk}")
names = uncertainties[risk].map { |u| "<li>#{h(u.name)}</li>" }.join
result + "<h5>#{title}:</h5><ul class=\"list-unstyled\">#{names}</ul>"
end
end
def uncertainties_grouped_by_risk(order, uncertainty_type)
order.order_uncertainties
.to_a
.select { |u| u.type == uncertainty_type }
.sort_by(&:risk_value)
.group_by(&:risk)
end
end