diff --git a/app/controllers/resource_items_controller.rb b/app/controllers/resource_items_controller.rb index 15e1398..6f20ca1 100644 --- a/app/controllers/resource_items_controller.rb +++ b/app/controllers/resource_items_controller.rb @@ -8,7 +8,7 @@ class ResourceItemsController < ApplicationController def index @resource_items = resource_class.where(project_id: @project.id) .includes(:category).references(:category) - .order("#{ResourceCategory.table_name}.name ASC, #{ResourceItem.table_name}.name ASC") + .sorted end def edit @@ -44,9 +44,20 @@ def update resource_item_params, item: @resource_item, project: @project ) if r.item_saved? - redirect_to_index + respond_to do |format| + format.html { + flash[:notice] = l(:notice_successful_update) + redirect_to_index + } + format.js { head 200 } + end else - render 'edit' + respond_to do |format| + format.html { + render 'edit' + } + format.js { head 422 } + end end end @@ -78,7 +89,7 @@ def resource_class def resource_item_params if parameters = params[:human] || params[:asset] - parameters.permit :name, :category_id, :start_date, :end_date + parameters.permit :name, :category_id, :start_date, :end_date, :position end end diff --git a/app/models/resource_item.rb b/app/models/resource_item.rb index 216fe47..f3e0335 100644 --- a/app/models/resource_item.rb +++ b/app/models/resource_item.rb @@ -12,7 +12,8 @@ class ResourceItem < ActiveRecord::Base validates :start_date, :date => true validates :end_date, :date => true - scope :sorted, ->{ order name: :asc} + acts_as_positioned :scope => [:project_id, :type] + scope :sorted, ->{ order :position } scope :humans, ->{ where type: 'Human' } scope :assets, ->{ where type: 'Asset' } scope :filter_by_date, ->(date = Date.today){ diff --git a/app/views/asset_resource_items/index.html.erb b/app/views/asset_resource_items/index.html.erb index 5b4d1b2..ad3047a 100644 --- a/app/views/asset_resource_items/index.html.erb +++ b/app/views/asset_resource_items/index.html.erb @@ -29,7 +29,10 @@
<%= l :label_no_data %>
<% end %> +<%= javascript_tag do %> + $(function() { + $("table.resource_items tbody").positionedItems({ + scroll: false, + sort: function (event, ui) { + ui.helper.css({'top': ui.position.top + $(window).scrollTop() + 'px'}); + }, + }); + }); +<% end %> diff --git a/app/views/human_resource_items/index.html.erb b/app/views/human_resource_items/index.html.erb index 34eb36a..a898570 100644 --- a/app/views/human_resource_items/index.html.erb +++ b/app/views/human_resource_items/index.html.erb @@ -29,7 +29,10 @@<%= l :label_no_data %>
<% end %> +<%= javascript_tag do %> + $(function() { + $("table.resource_items tbody").positionedItems({ + scroll: false, + sort: function (event, ui) { + ui.helper.css({'top': ui.position.top + $(window).scrollTop() + 'px'}); + }, + }); + }); +<% end %> diff --git a/db/migrate/20210325123542_add_position_to_resource_items.rb b/db/migrate/20210325123542_add_position_to_resource_items.rb new file mode 100644 index 0000000..cafdfdd --- /dev/null +++ b/db/migrate/20210325123542_add_position_to_resource_items.rb @@ -0,0 +1,5 @@ +class AddPositionToResourceItems < ActiveRecord::Migration[5.2] + def change + add_column :resource_items, :position, :integer, default: 0 + end +end diff --git a/lib/redmine_resource_manager/save_resource_item.rb b/lib/redmine_resource_manager/save_resource_item.rb index 9ae217e..8e16db0 100644 --- a/lib/redmine_resource_manager/save_resource_item.rb +++ b/lib/redmine_resource_manager/save_resource_item.rb @@ -17,13 +17,15 @@ def initialize(params, resource_class: nil, def call - if category_id = @params[:category_id].presence - @item.category = @project.resource_categories.find category_id - end + # if category_id = @params[:category_id].presence + # @item.category = @project.resource_categories.find category_id + # end @item.project = @project - @item.name = @params[:name] - @item.start_date = @params[:start_date] - @item.end_date = @params[:end_date] + @item.attributes = @params + # @item.name = @params[:name] + # @item.start_date = @params[:start_date] + # @item.end_date = @params[:end_date] + # @item.position = @params[:position] return Result.new item_saved: @item.save, item: @item