diff --git a/app/controllers/resource_items_controller.rb b/app/controllers/resource_items_controller.rb index 075c729..2431cdf 100644 --- a/app/controllers/resource_items_controller.rb +++ b/app/controllers/resource_items_controller.rb @@ -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 diff --git a/app/controllers/supply_items_controller.rb b/app/controllers/supply_items_controller.rb index f46f908..f3c3d35 100644 --- a/app/controllers/supply_items_controller.rb +++ b/app/controllers/supply_items_controller.rb @@ -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 diff --git a/app/models/resource_item.rb b/app/models/resource_item.rb index c6e1cd3..0f1bb56 100644 --- a/app/models/resource_item.rb +++ b/app/models/resource_item.rb @@ -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){ @@ -28,5 +29,8 @@ class ResourceItem < (defined?(ApplicationRecord) == 'constant' ? ApplicationRec all end } -end + def css_classes + "resource_item " + (active ? "active" : "inactive") + end +end diff --git a/app/models/supply_item.rb b/app/models/supply_item.rb index 6b7f993..897e43d 100644 --- a/app/models/supply_item.rb +++ b/app/models/supply_item.rb @@ -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 @@ -55,4 +56,7 @@ def unit_name end end + def css_classes + "supply_item " + (active ? "active" : "inactive") + end end diff --git a/app/views/asset_resource_items/index.html.erb b/app/views/asset_resource_items/index.html.erb index ad3047a..b11daae 100644 --- a/app/views/asset_resource_items/index.html.erb +++ b/app/views/asset_resource_items/index.html.erb @@ -22,7 +22,7 @@ <% for i in @resource_items %> - + <% if categories_present %> <%= i.category&.name %> <% end %> diff --git a/app/views/human_resource_items/index.html.erb b/app/views/human_resource_items/index.html.erb index a898570..2de260a 100644 --- a/app/views/human_resource_items/index.html.erb +++ b/app/views/human_resource_items/index.html.erb @@ -22,7 +22,7 @@ <% for i in @resource_items %> - + <% if categories_present %> <%= i.category&.name %> <% end %> diff --git a/app/views/resource_items/_form.html.erb b/app/views/resource_items/_form.html.erb index e7a2c99..f15dddc 100644 --- a/app/views/resource_items/_form.html.erb +++ b/app/views/resource_items/_form.html.erb @@ -7,6 +7,5 @@ <% if categories.any? %>

<%= f.select :category_id, categories.sorted.map{|c|[c.name, c.id]}, label: l(:field_resource_category), include_blank: true %>

<% end %> +

<%= f.check_box :active %>

- - diff --git a/app/views/supply_items/_form.html.erb b/app/views/supply_items/_form.html.erb index d8c8ed5..589f673 100644 --- a/app/views/supply_items/_form.html.erb +++ b/app/views/supply_items/_form.html.erb @@ -11,6 +11,7 @@

<%= custom_field_tag_with_label :supply_item, value %>

<% end %>

<%= f.text_area :description, label: l(:field_supply_item_description), rows: 10 %>

+

<%= f.check_box :active %>

<%= wikitoolbar_for 'supply_item_description' %> diff --git a/app/views/supply_items/_supply_item.html.erb b/app/views/supply_items/_supply_item.html.erb index 1222b1f..20e042d 100644 --- a/app/views/supply_items/_supply_item.html.erb +++ b/app/views/supply_items/_supply_item.html.erb @@ -1,4 +1,4 @@ - + <%= link_to supply_item.name, edit_project_supply_item_path(supply_item.project, supply_item) %> <%= supply_item.stock_text %>
<%= textilizable supply_item.description %>
diff --git a/assets/stylesheets/supply.css b/assets/stylesheets/supply.css index 6fd4283..fa08a26 100644 --- a/assets/stylesheets/supply.css +++ b/assets/stylesheets/supply.css @@ -7,6 +7,9 @@ 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, @@ -14,6 +17,9 @@ 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, diff --git a/db/migrate/20240516070501_add_active_fields_to_items.rb b/db/migrate/20240516070501_add_active_fields_to_items.rb new file mode 100644 index 0000000..f293c51 --- /dev/null +++ b/db/migrate/20240516070501_add_active_fields_to_items.rb @@ -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 diff --git a/lib/redmine_resource_manager/resource_items_query.rb b/lib/redmine_resource_manager/resource_items_query.rb index 9c209cf..7bbd210 100644 --- a/lib/redmine_resource_manager/resource_items_query.rb +++ b/lib/redmine_resource_manager/resource_items_query.rb @@ -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 diff --git a/lib/redmine_supply/supply_items_query.rb b/lib/redmine_supply/supply_items_query.rb index d1e646d..9ee3fd5 100644 --- a/lib/redmine_supply/supply_items_query.rb +++ b/lib/redmine_supply/supply_items_query.rb @@ -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