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 self = $(this);
|
||||||
var li = self.closest('li');
|
var li = self.closest('li');
|
||||||
var url = li.attr('data-destroy-html-url');
|
var url = li.attr('data-destroy-html-url');
|
||||||
|
var colIndex = originalHeader.find('#' + li.attr('data-id')).index();
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: url,
|
url: url,
|
||||||
type: 'GET',
|
type: 'GET',
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
|
data: {column_index: colIndex},
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
var modalBody = modal.find('.modal-body');
|
var modalBody = modal.find('.modal-body');
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,8 @@ class CustomFieldsController < ApplicationController
|
||||||
format.json do
|
format.json do
|
||||||
render json: {
|
render json: {
|
||||||
html: render_to_string(
|
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
|
end
|
||||||
|
@ -61,9 +62,14 @@ class CustomFieldsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
|
@del_custom_field = @custom_field.dup
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.json do
|
format.json do
|
||||||
if @custom_field.destroy
|
if @custom_field.destroy
|
||||||
|
SamplesTable.update_samples_table_state(
|
||||||
|
@del_custom_field,
|
||||||
|
params[:custom_field][:column_index]
|
||||||
|
)
|
||||||
render json: { status: :ok }
|
render json: { status: :ok }
|
||||||
else
|
else
|
||||||
render json: { status: :unprocessable_entity }
|
render json: { status: :unprocessable_entity }
|
||||||
|
|
|
@ -18,6 +18,6 @@ class CustomField < ActiveRecord::Base
|
||||||
after_create :update_samples_table_state
|
after_create :update_samples_table_state
|
||||||
|
|
||||||
def update_samples_table_state
|
def update_samples_table_state
|
||||||
SamplesTable.update_samples_table_state(self)
|
SamplesTable.update_samples_table_state(self, nil)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,14 +7,35 @@ class SamplesTable < ActiveRecord::Base
|
||||||
scope :find_status,
|
scope :find_status,
|
||||||
->(org, user) { where(user: user, organization: org).pluck(: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,
|
samples_table = SamplesTable.where(user: custom_field.user,
|
||||||
organization: custom_field.organization)
|
organization: custom_field.organization)
|
||||||
org_status = samples_table.first['status']
|
org_status = samples_table.first['status']
|
||||||
index = org_status['columns'].count
|
if column_index
|
||||||
org_status['columns'][index] = SampleDatatable::
|
org_status['columns'].delete(column_index)
|
||||||
SAMPLES_TABLE_DEFAULT_STATE['columns'].first
|
org_status['columns'].keys.each do |index|
|
||||||
org_status['ColReorder'] << index.to_s
|
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)
|
samples_table.first.update(status: org_status)
|
||||||
end
|
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| %>
|
<%= 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>
|
<p><%= t("samples.modal_delete_custom_field.message", cf: @custom_field.name) %></p>
|
||||||
<div class="alert alert-danger" role="alert">
|
<div class="alert alert-danger" role="alert">
|
||||||
<span class="glyphicon glyphicon-exclamation-sign"></span>
|
<span class="glyphicon glyphicon-exclamation-sign"></span>
|
||||||
|
@ -9,4 +10,4 @@
|
||||||
<li><%= t("samples.modal_delete_custom_field.alert_line_2") %></li>
|
<li><%= t("samples.modal_delete_custom_field.alert_line_2") %></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
Loading…
Reference in a new issue