mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-31 20:19:05 +08:00
refactor sample types/groups [fixes SCI-700]
This commit is contained in:
parent
83aae59eed
commit
7725374c42
6 changed files with 20 additions and 36 deletions
|
@ -125,6 +125,7 @@
|
|||
initSampleGroupColor();
|
||||
appendCarretToColorPickerDropdown();
|
||||
editSampleGroupColor();
|
||||
editSampleGroupForm();
|
||||
}).bind('ajax:error', function(ev, error) {
|
||||
$(this).clearFormErrors();
|
||||
var msg = $.parseJSON(error.responseText);
|
||||
|
|
|
@ -119,15 +119,11 @@ class SampleGroupsController < ApplicationController
|
|||
def load_vars_nested
|
||||
@organization = Organization.find_by_id(params[:organization_id])
|
||||
|
||||
unless @organization
|
||||
render_404
|
||||
end
|
||||
render_404 unless @organization
|
||||
end
|
||||
|
||||
def check_create_permissions
|
||||
unless can_create_sample_type_in_organization(@organization)
|
||||
render_403
|
||||
end
|
||||
render_403 unless can_create_sample_type_in_organization(@organization)
|
||||
end
|
||||
|
||||
def sample_group_params
|
||||
|
|
|
@ -1,18 +1,7 @@
|
|||
class SampleTypesController < ApplicationController
|
||||
before_action :load_vars_nested, only: [:create,
|
||||
:index,
|
||||
:edit,
|
||||
:update,
|
||||
:sample_type_element,
|
||||
:destroy,
|
||||
:destroy_confirmation]
|
||||
before_action :load_vars_nested
|
||||
before_action :check_create_permissions
|
||||
before_action :set_sample_type, only: [:edit,
|
||||
:update,
|
||||
:destroy,
|
||||
:sample_type_element,
|
||||
:destroy,
|
||||
:destroy_confirmation]
|
||||
before_action :set_sample_type, except: [:create, :index]
|
||||
|
||||
def create
|
||||
@sample_type = SampleType.new(sample_type_params)
|
||||
|
@ -65,9 +54,9 @@ class SampleTypesController < ApplicationController
|
|||
def update
|
||||
@sample_type.update_attributes(sample_type_params)
|
||||
|
||||
if @sample_type.save
|
||||
respond_to do |format|
|
||||
format.json do
|
||||
respond_to do |format|
|
||||
format.json do
|
||||
if @sample_type.save
|
||||
render json: {
|
||||
html: render_to_string(
|
||||
partial: 'sample_type.html.erb',
|
||||
|
@ -75,11 +64,7 @@ class SampleTypesController < ApplicationController
|
|||
organization: @organization }
|
||||
)
|
||||
}
|
||||
end
|
||||
end
|
||||
else
|
||||
respond_to do |format|
|
||||
format.json do
|
||||
else
|
||||
render json: @sample_type.errors,
|
||||
status: :unprocessable_entity
|
||||
end
|
||||
|
@ -130,15 +115,11 @@ class SampleTypesController < ApplicationController
|
|||
def load_vars_nested
|
||||
@organization = Organization.find_by_id(params[:organization_id])
|
||||
|
||||
unless @organization
|
||||
render_404
|
||||
end
|
||||
render_404 unless @organization
|
||||
end
|
||||
|
||||
def check_create_permissions
|
||||
unless can_create_sample_type_in_organization(@organization)
|
||||
render_403
|
||||
end
|
||||
render_403 unless can_create_sample_type_in_organization(@organization)
|
||||
end
|
||||
|
||||
def set_sample_type
|
||||
|
|
|
@ -10,7 +10,11 @@ class SampleGroup < ActiveRecord::Base
|
|||
validates :organization, presence: true
|
||||
|
||||
belongs_to :created_by, foreign_key: 'created_by_id', class_name: 'User'
|
||||
belongs_to :last_modified_by, foreign_key: 'last_modified_by_id', class_name: 'User'
|
||||
belongs_to :last_modified_by,
|
||||
foreign_key: 'last_modified_by_id',
|
||||
class_name: 'User'
|
||||
belongs_to :organization, inverse_of: :sample_groups
|
||||
has_many :samples, inverse_of: :sample_groups
|
||||
|
||||
scope :sorted, -> { order(name: :asc) }
|
||||
end
|
||||
|
|
|
@ -7,7 +7,9 @@ class SampleType < ActiveRecord::Base
|
|||
validates :organization, presence: true
|
||||
|
||||
belongs_to :created_by, foreign_key: 'created_by_id', class_name: 'User'
|
||||
belongs_to :last_modified_by, foreign_key: 'last_modified_by_id', class_name: 'User'
|
||||
belongs_to :last_modified_by,
|
||||
foreign_key: 'last_modified_by_id',
|
||||
class_name: 'User'
|
||||
belongs_to :organization, inverse_of: :sample_types
|
||||
has_many :samples, inverse_of: :sample_types
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
</div>
|
||||
<% end %>
|
||||
</li>
|
||||
<% @sample_groups.each do |sample_group| %>
|
||||
<% @sample_groups.sorted.each do |sample_group| %>
|
||||
<%= render partial: 'sample_group',
|
||||
locals: { sample_group: sample_group,
|
||||
organization: current_organization } %>
|
||||
|
|
Loading…
Reference in a new issue