Class: Protocol
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Protocol
- Includes:
- Housekeeping, Shared::Citations, Shared::Documentation, Shared::IsData
- Defined in:
- app/models/protocol.rb
Overview
A Protocol is a recipe for how something is done.
Protocols are simple records, they can be Document(ed) with
external files (pdfs, text files, etc.)
Class Method Summary collapse
- .select_optimized(user_id, project_id, klass) ⇒ Object
-
.used_recently(user_id, project_id, klass) ⇒ Scope
TODO: unify, perhaps, with annotator logic, this is identical to Keyword methods.
Methods included from Shared::IsData
#errors_excepting, #full_error_messages_excepting, #identical, #is_community?, #is_destroyable?, #is_editable?, #is_in_use?, #is_in_users_projects?, #metamorphosize, #similar
Methods included from Shared::Citations
#cited?, #mark_citations_for_destruction, #nomenclature_date, #origin_citation_source_id, #reject_citations, #requires_citation?, #sources_by_topic_id
Methods included from Shared::Documentation
#document_array=, #documented?, #reject_documentation, #reject_documents
Methods included from Housekeeping
#has_polymorphic_relationship?
Methods inherited from ApplicationRecord
Class Method Details
.select_optimized(user_id, project_id, klass) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'app/models/protocol.rb', line 43 def self.select_optimized(user_id, project_id, klass) r = used_recently(user_id, project_id, klass) h = { quick: [], pinboard: Protocol.pinned_by(user_id).where(project_id: project_id).to_a, recent: [] } if r.empty? h[:quick] = Protocol.pinned_by(user_id).pinboard_inserted.where(project_id: project_id).to_a else h[:recent] = Protocol.where('"protocols"."id" IN (?)', r.first(10) ).order(:name).to_a h[:quick] = (Protocol.pinned_by(user_id).pinboard_inserted.where(project_id: project_id).to_a + Protocol.where('"protocols"."id" IN (?)', r.first(4) ).order(:name).to_a).uniq end h end |
.used_recently(user_id, project_id, klass) ⇒ Scope
TODO: unify, perhaps, with annotator logic, this is identical to Keyword methods
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/models/protocol.rb', line 24 def self.used_recently(user_id, project_id, klass) t = ProtocolRelationship.arel_table k = self.arel_table # i is a select manager i = t.project(t['protocol_id'], t['updated_at']).from(t) .where(t['updated_at'].gt( 10.weeks.ago )) .where(t['updated_by_id'].eq(user_id)) .where(t['project_id'].eq(project_id)) .order(t['updated_at'].desc) # z is a table alias z = i.as('recent_t') used_on_klass(klass).joins( Arel::Nodes::InnerJoin.new(z, Arel::Nodes::On.new(z['protocol_id'].eq(k['id']))) ).pluck(:id).uniq end |