Skip to content

Commit 0ff57f3

Browse files
committed
allow configuration of resource categories to be for assets and / or workers. #26
1 parent 52aa177 commit 0ff57f3

23 files changed

+106
-37
lines changed

app/controllers/issue_resource_items_controller.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ class IssueResourceItemsController < ApplicationController
66
helper :resource_items
77

88
def new
9-
@categories = @project.resource_categories.sorted
109
@issue = find_issue_if_present
1110
@type = %w(Asset Human).detect{|t| t == params[:type]}
11+
@categories = @project.resource_categories.sorted
12+
@categories = @type == 'Asset' ? @categories.for_assets : @categories.for_humans
1213

1314
query = RedmineResourceManager::ResourceItemsQuery.new(
1415
project: @project, category_id: nil, issue_id: params[:issue_id],

app/controllers/resource_categories_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def destroy
4848
private
4949

5050
def resource_category_params
51-
params[:resource_category].permit :name
51+
params[:resource_category].permit :name, :for_humans, :for_assets
5252
end
5353

5454
def find_resource_category

app/models/resource_category.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,27 @@ class ResourceCategory < ActiveRecord::Base
44

55
validates :name, presence: true,
66
uniqueness: { case_sensitive: false, scope: :project_id }
7+
validate :check_usage_flags
78

89
scope :sorted, ->{ order name: :asc}
10+
scope :for_humans, -> { where for_humans: true }
11+
scope :for_assets, -> { where for_assets: true }
12+
13+
private
14+
15+
def check_usage_flags
16+
if !for_assets? and !for_humans?
17+
errors.add :base, :select_category_usage
18+
return
19+
end
20+
21+
unless new_record?
22+
if resource_items.humans.any? and !for_humans?
23+
errors.add :for_humans, :in_use
24+
end
25+
if resource_items.assets.any? and !for_assets?
26+
errors.add :for_assets, :in_use
27+
end
28+
end
29+
end
930
end

app/models/resource_item.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ class ResourceItem < ActiveRecord::Base
1010
uniqueness: { case_sensitive: false, scope: :category_id }
1111

1212
scope :sorted, ->{ order name: :asc}
13+
scope :humans, ->{ where type: 'Human' }
14+
scope :assets, ->{ where type: 'Asset' }
1315

1416
scope :like, ->(q){
1517
if q.present?

app/views/asset_resource_items/edit.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<%= title [l(:label_asset_resource_item_plural), project_asset_resource_items_path(@project)], @resource_item.name %>
22

33
<%= labelled_form_for @resource_item, url: project_asset_resource_item_path(@project, @resource_item), method: :patch do |f| %>
4-
<%= render partial: 'form', locals: { f: f } %>
4+
<%= render partial: 'form', locals: { f: f, categories: @project.resource_categories.for_assets } %>
55
<p>
66
<%= submit_tag l :button_save %>
77
</p>

app/views/asset_resource_items/new.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<%= title [l(:label_asset_resource_item_plural), project_asset_resource_items_path(@project)], l(:label_asset_resource_item_new) %>
22

33
<%= labelled_form_for @resource_item, url: project_asset_resource_items_path(@project) do |f| %>
4-
<%= render partial: 'resource_items/form', locals: { f: f } %>
4+
<%= render partial: 'resource_items/form', locals: { f: f, categories: @project.resource_categories.for_assets } %>
55
<p>
66
<%= submit_tag l :button_create %>
77
<%= submit_tag l(:button_create_and_continue), name: 'continue' %>

app/views/human_resource_items/edit.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<%= title [l(:label_human_resource_item_plural), project_human_resource_items_path(@project)], @resource_item.name %>
22

33
<%= labelled_form_for @resource_item, url: project_human_resource_item_path(@project, @resource_item), method: :patch do |f| %>
4-
<%= render partial: 'resource_items/form', locals: { f: f } %>
4+
<%= render partial: 'resource_items/form', locals: { f: f, categories: @project.resource_categories.for_humans } %>
55
<p>
66
<%= submit_tag l :button_save %>
77
</p>

app/views/human_resource_items/new.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<%= title [l(:label_human_resource_item_plural), project_human_resource_items_path(@project)], l(:label_human_resource_item_new) %>
22

33
<%= labelled_form_for @resource_item, url: project_human_resource_items_path(@project) do |f| %>
4-
<%= render partial: 'resource_items/form', locals: { f: f } %>
4+
<%= render partial: 'resource_items/form', locals: { f: f, categories: @project.resource_categories.for_humans } %>
55
<p>
66
<%= submit_tag l :button_create %>
77
<%= submit_tag l(:button_create_and_continue), name: 'continue' %>

app/views/resource_categories/_form.html.erb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@
22

33
<div class="box tabular">
44
<p><%= f.text_field :name, required: true, size: 25 %></p>
5+
<p><%= f.check_box :for_assets %></p>
6+
<p><%= f.check_box :for_humans %></p>
57
</div>
68

app/views/resource_categories/_list.html.erb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
<% if resource_categories.any? %>
22
<table class="list resource_categories">
3+
<colgroup>
4+
<col width="60%" />
5+
<col span="3" />
6+
</colgroup>
37
<thead>
48
<tr>
59
<th><%= l :label_resource_category_name %></th>
10+
<th><%= l :label_resource_category_for_assets %></th>
11+
<th><%= l :label_resource_category_for_humans %></th>
612
<th></th>
713
</tr>
814
</thead>

0 commit comments

Comments
 (0)