mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-02-05 22:44:22 +08:00
Merge pull request #349 from okriuchykhin/ok_SCI_783
Fix columns ordering when deleting custom fields [SCI-783]
This commit is contained in:
commit
c4ff12be51
5 changed files with 38 additions and 8 deletions
|
@ -1133,11 +1133,13 @@ function changeToEditMode() {
|
|||
var self = $(this);
|
||||
var li = self.closest('li');
|
||||
var url = li.attr('data-destroy-html-url');
|
||||
var colIndex = originalHeader.find('#' + li.attr('data-id')).index();
|
||||
|
||||
$.ajax({
|
||||
url: url,
|
||||
type: 'GET',
|
||||
dataType: 'json',
|
||||
data: {column_index: colIndex},
|
||||
success: function(data) {
|
||||
var modalBody = modal.find('.modal-body');
|
||||
|
||||
|
|
|
@ -53,7 +53,8 @@ class CustomFieldsController < ApplicationController
|
|||
format.json do
|
||||
render json: {
|
||||
html: render_to_string(
|
||||
partial: 'samples/delete_custom_field_modal_body.html.erb'
|
||||
partial: 'samples/delete_custom_field_modal_body.html.erb',
|
||||
locals: { column_index: params[:column_index] }
|
||||
)
|
||||
}
|
||||
end
|
||||
|
@ -61,9 +62,14 @@ class CustomFieldsController < ApplicationController
|
|||
end
|
||||
|
||||
def destroy
|
||||
@del_custom_field = @custom_field.dup
|
||||
respond_to do |format|
|
||||
format.json do
|
||||
if @custom_field.destroy
|
||||
SamplesTable.update_samples_table_state(
|
||||
@del_custom_field,
|
||||
params[:custom_field][:column_index]
|
||||
)
|
||||
render json: { status: :ok }
|
||||
else
|
||||
render json: { status: :unprocessable_entity }
|
||||
|
|
|
@ -18,6 +18,6 @@ class CustomField < ActiveRecord::Base
|
|||
after_create :update_samples_table_state
|
||||
|
||||
def update_samples_table_state
|
||||
SamplesTable.update_samples_table_state(self)
|
||||
SamplesTable.update_samples_table_state(self, nil)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,14 +7,35 @@ class SamplesTable < ActiveRecord::Base
|
|||
scope :find_status,
|
||||
->(org, user) { where(user: user, organization: org).pluck(:status) }
|
||||
|
||||
def self.update_samples_table_state(custom_field)
|
||||
def self.update_samples_table_state(custom_field, column_index)
|
||||
samples_table = SamplesTable.where(user: custom_field.user,
|
||||
organization: custom_field.organization)
|
||||
org_status = samples_table.first['status']
|
||||
index = org_status['columns'].count
|
||||
org_status['columns'][index] = SampleDatatable::
|
||||
SAMPLES_TABLE_DEFAULT_STATE['columns'].first
|
||||
org_status['ColReorder'] << index.to_s
|
||||
if column_index
|
||||
org_status['columns'].delete(column_index)
|
||||
org_status['columns'].keys.each do |index|
|
||||
p index
|
||||
if index.to_i > column_index.to_i
|
||||
org_status['columns'][(index.to_i - 1).to_s] =
|
||||
org_status['columns'].delete(index)
|
||||
else
|
||||
index
|
||||
end
|
||||
end
|
||||
org_status['ColReorder'].delete(column_index)
|
||||
org_status['ColReorder'].map! do |index|
|
||||
if index.to_i > column_index.to_i
|
||||
(index.to_i - 1).to_s
|
||||
else
|
||||
index
|
||||
end
|
||||
end
|
||||
else
|
||||
index = org_status['columns'].count
|
||||
org_status['columns'][index] = SampleDatatable::
|
||||
SAMPLES_TABLE_DEFAULT_STATE['columns'].first
|
||||
org_status['ColReorder'] << index.to_s
|
||||
end
|
||||
samples_table.first.update(status: org_status)
|
||||
end
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<%= bootstrap_form_for @custom_field, url: organization_custom_field_path(@organization, @custom_field, format: :json), remote: :true, method: :delete, data: { role: "destroy-custom-field-form", id: @custom_field.id } do |f| %>
|
||||
<%= f.hidden_field :column_index, value: column_index %>
|
||||
<p><%= t("samples.modal_delete_custom_field.message", cf: @custom_field.name) %></p>
|
||||
<div class="alert alert-danger" role="alert">
|
||||
<span class="glyphicon glyphicon-exclamation-sign"></span>
|
||||
|
|
Loading…
Reference in a new issue