Skip to content

Commit c3b062c

Browse files
committed
adds assets / people issue query columns #25
1 parent 0ff57f3 commit c3b062c

File tree

6 files changed

+65
-23
lines changed

6 files changed

+65
-23
lines changed

app/models/issue_resource_item.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@ class IssueResourceItem < ActiveRecord::Base
22
belongs_to :issue
33
belongs_to :resource_item
44

5+
scope :sorted, ->{
6+
includes(:resource_item).order("#{ResourceItem.table_name}.name ASC")
7+
}
8+
59
# breaks the nested assignment :()
610
# validates :issue, presence: true
711
validates :resource_item, presence: true
12+
813
end
14+

config/locales/en.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ en:
1717
field_supply_item_stock: Stock
1818
field_supply_item_stock_change: Stock change
1919
field_supply_item_stock_change_comment: Comment
20+
field_issue_asset_resource_item_names: Assets
21+
field_issue_human_resource_item_names: People
2022
field_issue_supply_item_names: Supply Items
2123
label_add_issue_resource_items: Add
2224
label_resource_category_for_assets: For assets

lib/redmine_resource_manager/issue_patch.rb

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,35 @@ def self.apply
1515
if: ->(issue, user){ user.allowed_to?(:manage_issue_resources,
1616
issue.project) }
1717

18-
def issue_human_resource_items
19-
issue_resource_items.includes(:resource_item)
20-
.where(resource_items: { type: 'Human'})
21-
end
22-
23-
def issue_asset_resource_items
24-
issue_resource_items.includes(:resource_item)
25-
.where(resource_items: { type: 'Asset'})
26-
end
27-
28-
def resource_items_by_type
29-
{
30-
'asset' => resource_items.where(type: 'Asset'),
31-
'human' => resource_items.where(type: 'Human')
32-
}
33-
end
34-
3518
end
36-
3719
end
3820
end
3921

22+
23+
def issue_human_resource_item_names
24+
IssueResourceItemsPresenter.new(issue_human_resource_items).to_s
25+
end
26+
def issue_asset_resource_item_names
27+
IssueResourceItemsPresenter.new(issue_asset_resource_items).to_s
28+
end
29+
30+
def issue_human_resource_items
31+
issue_resource_items.includes(:resource_item)
32+
.where(resource_items: { type: 'Human'})
33+
end
34+
35+
def issue_asset_resource_items
36+
issue_resource_items.includes(:resource_item)
37+
.where(resource_items: { type: 'Asset'})
38+
end
39+
40+
def resource_items_by_type
41+
{
42+
'asset' => resource_items.where(type: 'Asset'),
43+
'human' => resource_items.where(type: 'Human')
44+
}
45+
end
46+
4047
end
4148
end
4249

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
module RedmineResourceManager
2+
class IssueResourceItemsPresenter < RedmineSupply::Presenter
3+
def initialize(scope)
4+
@scope = scope.sorted
5+
end
6+
7+
def call
8+
@scope.to_a.map{|ri| issue_resource_item_tag ri}
9+
end
10+
11+
def to_s
12+
call.join ", ".html_safe
13+
end
14+
15+
private
16+
17+
def issue_resource_item_tag(issue_resource_item)
18+
h issue_resource_item.resource_item.name
19+
end
20+
21+
end
22+
end

lib/redmine_supply/patches/issue_patch.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ def self.apply
99

1010
has_many :issue_supply_items
1111

12-
def issue_supply_item_names
13-
IssueSupplyItemsPresenter.new(issue_supply_items).to_s
14-
end
15-
1612
accepts_nested_attributes_for :issue_supply_items
1713

1814
safe_attributes 'issue_supply_items_attributes',
@@ -24,6 +20,10 @@ def issue_supply_item_names
2420
end
2521
end
2622

23+
def issue_supply_item_names
24+
IssueSupplyItemsPresenter.new(issue_supply_items).to_s
25+
end
26+
2727
def issue_supply_items_attributes=(attributes = [])
2828
# remove items with zero quantity. existing items with zero quantity are
2929
# destroyed as well

lib/redmine_supply/patches/issue_query_patch.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,16 @@ def available_columns
1515
@available_columns << QueryColumn.new(:issue_supply_item_names)
1616
end
1717

18+
if User.current.allowed_to?(:view_issue_resources, project, global: true)
19+
@available_columns << QueryColumn.new(:issue_human_resource_item_names)
20+
@available_columns << QueryColumn.new(:issue_asset_resource_item_names)
21+
end
22+
1823
@available_columns
1924
end
2025

2126
def add_supply_items(a)
22-
a | [:issue_supply_items]
27+
a | %i(issue_supply_items issue_resource_items)
2328
end
2429

2530
def issues(options={})

0 commit comments

Comments
 (0)