Module: Labimotion::SegmentHelpers
- Extended by:
- Grape::API::Helpers
- Defined in:
- lib/labimotion/helpers/segment_helpers.rb
Overview
ElementHelpers
Instance Method Summary collapse
- #create_repo_klass(params, current_user) ⇒ Object
- #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_repo_klass(params, current_user) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/labimotion/helpers/segment_helpers.rb', line 65 def create_repo_klass(params, current_user) response = Labimotion::TemplateHub.fetch_identifier('SegmentKlass', params[:identifier]) attributes = response.slice('label', 'desc', 'uuid', 'identifier', 'released_at') # .except(:id, :is_active, :place, :created_by, :created_at, :updated_at) attributes['properties_template'] = response['properties_release'] attributes['place'] = ((Labimotion::SegmentKlass.all.length * 10) || 0) + 10 attributes['is_active'] = false attributes['updated_by'] = current_user.id attributes['sync_by'] = current_user.id attributes['sync_time'] = DateTime.now element_klass = Labimotion::ElementKlass.find_by(identifier: response['element_klass']['identifier']) element_klass = Labimotion::ElementKlass.find_by(name: response['element_klass']['name']) if element_klass.nil? return { error: 'ElementKlass not found' } if element_klass.nil? # el_attributes = response['element_klass'].slice('name', 'label', 'desc', 'uuid', 'identifier', 'icon_name', 'klass_prefix', 'is_generic', 'released_at') # el_attributes['properties_template'] = response['element_klass']['properties_release'] # Labimotion::ElementKlass.create!(el_attributes) attributes['element_klass_id'] = element_klass.id segment_klass = Labimotion::SegmentKlass.find_by(identifier: attributes['identifier']) if segment_klass.present? segment_klass.update!(attributes) else attributes['created_by'] = current_user.id Labimotion::SegmentKlass.create!(attributes) end rescue StandardError => e Labimotion.log_exception(e, current_user) raise e end |
#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 43 44 45 |
# 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 rescue StandardError => e Labimotion.log_exception(e, current_user) raise e 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
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/labimotion/helpers/segment_helpers.rb', line 47 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 rescue StandardError => e Labimotion.log_exception(e, current_user) raise e end |