Module: Labimotion::SegmentHelpers
- Extended by:
- Grape::API::Helpers
- Defined in:
- lib/labimotion/helpers/segment_helpers.rb
Overview
ElementHelpers
Instance Method Summary collapse
- #create_segment_klass(current_user, params) ⇒ Object
- #klass_list(el_klass, is_active = false) ⇒ Object
- #update_segment_klass(current_user, params) ⇒ Object
Instance Method Details
#create_segment_klass(current_user, params) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/labimotion/helpers/segment_helpers.rb', line 16 def create_segment_klass(current_user, params) place = params[:place] begin place = place.to_i if place.present? && place.to_i == place.to_f rescue StandardError place = 100 end uuid = SecureRandom.uuid template = { uuid: uuid, layers: {}, select_options: {} } attributes = declared(params, include_missing: false) attributes[:properties_template]['uuid'] = uuid if attributes[:properties_template].present? template = (attributes[:properties_template].presence || template) template['eln'] = Chemotion::Application.config.version template['labimotion'] = Labimotion::VERSION template['klass'] = 'SegmentKlass' attributes.merge!(properties_template: template, element_klass: @klass, created_by: current_user.id, place: place) attributes[:is_active] = false attributes[:uuid] = uuid attributes[:released_at] = DateTime.now attributes[:properties_release] = attributes[:properties_template] klass = Labimotion::SegmentKlass.create!(attributes) klass.reload klass.create_klasses_revision(current_user.id) klass end |
#klass_list(el_klass, is_active = false) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/labimotion/helpers/segment_helpers.rb', line 9 def klass_list(el_klass, is_active=false) scope = SegmentKlass.all scope = scope.where(is_active: is_active) if is_active.present? && is_active == true scope = scope.joins(:element_klass).where(klass_element: params[:element], is_active: true) if el_klass.present? scope.order('place') || [] end |
#update_segment_klass(current_user, params) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/labimotion/helpers/segment_helpers.rb', line 44 def update_segment_klass(current_user, params) segment = fetch_klass('SegmentKlass', params[:id]) place = params[:place] begin place = place.to_i if place.present? && place.to_i == place.to_f rescue StandardError place = 100 end attributes = declared(params, include_missing: false) attributes.delete(:id) attributes[:place] = place segment&.update!(attributes) segment end |