diff --git a/app/assets/javascripts/samples/sample_types_groups.js b/app/assets/javascripts/samples/sample_types_groups.js index 52a9ce3d1..66961969b 100644 --- a/app/assets/javascripts/samples/sample_types_groups.js +++ b/app/assets/javascripts/samples/sample_types_groups.js @@ -125,6 +125,7 @@ initSampleGroupColor(); appendCarretToColorPickerDropdown(); editSampleGroupColor(); + editSampleGroupForm(); }).bind('ajax:error', function(ev, error) { $(this).clearFormErrors(); var msg = $.parseJSON(error.responseText); diff --git a/app/controllers/sample_groups_controller.rb b/app/controllers/sample_groups_controller.rb index 6619d939d..62b558055 100644 --- a/app/controllers/sample_groups_controller.rb +++ b/app/controllers/sample_groups_controller.rb @@ -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 diff --git a/app/controllers/sample_types_controller.rb b/app/controllers/sample_types_controller.rb index 7fec2d470..f726ebf6c 100644 --- a/app/controllers/sample_types_controller.rb +++ b/app/controllers/sample_types_controller.rb @@ -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 diff --git a/app/models/sample_group.rb b/app/models/sample_group.rb index bee48b668..698fa6393 100644 --- a/app/models/sample_group.rb +++ b/app/models/sample_group.rb @@ -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 diff --git a/app/models/sample_type.rb b/app/models/sample_type.rb index aa2b6b137..399d2290e 100644 --- a/app/models/sample_type.rb +++ b/app/models/sample_type.rb @@ -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 diff --git a/app/views/sample_groups/index.html.erb b/app/views/sample_groups/index.html.erb index e8b0bc0af..fa191f2dd 100644 --- a/app/views/sample_groups/index.html.erb +++ b/app/views/sample_groups/index.html.erb @@ -32,7 +32,7 @@ <% end %> - <% @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 } %>