Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support active flag to filter supply/resource items #22

Draft
wants to merge 1 commit into
base: next
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/resource_items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def resource_class

def resource_item_params
if parameters = params[:human] || params[:asset]
parameters.permit :name, :category_id, :start_date, :end_date, :position
parameters.permit :name, :category_id, :start_date, :end_date, :position, :active
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/supply_items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def find_supply_item

def permitted_supply_item_parameters
cf_ids = [RedmineSupply.unit_cf&.id].compact.map(&:to_s)
[:name, :description, custom_field_values: cf_ids]
[:name, :description, :active, custom_field_values: cf_ids]
end

end
Expand Down
6 changes: 5 additions & 1 deletion app/models/resource_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class ResourceItem < (defined?(ApplicationRecord) == 'constant' ? ApplicationRec

acts_as_positioned :scope => [:project_id, :type]
scope :sorted, ->{ order :position }
scope :active, ->{ where(:active => true) }
scope :humans, ->{ where type: 'Human' }
scope :assets, ->{ where type: 'Asset' }
scope :filter_by_date, ->(date = Date.today){
Expand All @@ -28,5 +29,8 @@ class ResourceItem < (defined?(ApplicationRecord) == 'constant' ? ApplicationRec
all
end
}
end

def css_classes
"resource_item " + (active ? "active" : "inactive")
end
end
6 changes: 5 additions & 1 deletion app/models/supply_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class SupplyItem < (defined?(ApplicationRecord) == 'constant' ? ApplicationRecor
scope: :project_id }
validates :stock, presence: true, numericality: true

scope :sorted, ->{ order name: :asc}
scope :sorted, ->{ order name: :asc }
scope :active, ->{ where(:active => true) }

acts_as_customizable

Expand Down Expand Up @@ -55,4 +56,7 @@ def unit_name
end
end

def css_classes
"supply_item " + (active ? "active" : "inactive")
end
end
2 changes: 1 addition & 1 deletion app/views/asset_resource_items/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</thead>
<tbody>
<% for i in @resource_items %>
<tr>
<tr class="<%= i.css_classes %>">
<% if categories_present %>
<td class="category"><%= i.category&.name %>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/human_resource_items/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</thead>
<tbody>
<% for i in @resource_items %>
<tr>
<tr class="<%= i.css_classes %>">
<% if categories_present %>
<td class="category"><%= i.category&.name %>
<% end %>
Expand Down
3 changes: 1 addition & 2 deletions app/views/resource_items/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@
<% if categories.any? %>
<p><%= f.select :category_id, categories.sorted.map{|c|[c.name, c.id]}, label: l(:field_resource_category), include_blank: true %></p>
<% end %>
<p><%= f.check_box :active %></p>
</div>


1 change: 1 addition & 0 deletions app/views/supply_items/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<p><%= custom_field_tag_with_label :supply_item, value %></p>
<% end %>
<p><%= f.text_area :description, label: l(:field_supply_item_description), rows: 10 %></p>
<p><%= f.check_box :active %></p>
</div>

<%= wikitoolbar_for 'supply_item_description' %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/supply_items/_supply_item.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<tr>
<tr class="<%= supply_item.css_classes %>">
<td class="name"><%= link_to supply_item.name, edit_project_supply_item_path(supply_item.project, supply_item) %></td>
<td><%= supply_item.stock_text %></td>
<td class="description"><div><%= textilizable supply_item.description %></div></td>
Expand Down
6 changes: 6 additions & 0 deletions assets/stylesheets/supply.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,19 @@ table.list.issues td.issue_asset_resource_item_names {
white-space: normal;
}

tr.resource_item.inactive { color: #aaa; }
tr.resource_item.inactive a { color: #aaa; }

table.list.supply_items tbody td.name,
table.list.supply_items tbody td.description,
table.list.supply_item_journals tbody td.name,
table.list.resource_items tbody td.name {
text-align: left;
}

tr.supply_item.inactive { color: #aaa; }
tr.supply_item.inactive a { color: #aaa; }

/* Supply item history */

table.list.supply_item_journals tbody td.stock,
Expand Down
11 changes: 11 additions & 0 deletions db/migrate/20240516070501_add_active_fields_to_items.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class AddActiveFieldsToItems < ActiveRecord::Migration[5.2]
def self.up
add_column :supply_items, :active, :boolean, :default => true, :null => false
add_column :resource_items, :active, :boolean, :default => true, :null => false
end

def self.down
remove_column :supply_items, :active
remove_column :resource_items, :active
end
end
2 changes: 1 addition & 1 deletion lib/redmine_resource_manager/resource_items_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def total
private

def all
all = @resource_class.where(project_id: @project.id)
all = @resource_class.where(project_id: @project.id).where(active: true)
all = all.where(category_id: @category_id) if @category_id
all = all.filter_by_date if @filter_by_date
all = all.like @query if @query
Expand Down
2 changes: 1 addition & 1 deletion lib/redmine_supply/supply_items_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def total
private

def all
all = @project.supply_items
all = @project.supply_items.active
all = all.like @query if @query
all
end
Expand Down