2017-06-30 21:20:27 +08:00
|
|
|
class ProtocolLinkedChildrenDatatable < CustomDatatable
|
2016-07-21 19:11:15 +08:00
|
|
|
def_delegator :@view, :link_to
|
|
|
|
def_delegator :@view, :protocols_my_module_path
|
|
|
|
|
|
|
|
def initialize(view, protocol, user, controller)
|
|
|
|
super(view)
|
|
|
|
@protocol = protocol
|
|
|
|
@user = user
|
|
|
|
@controller = controller
|
|
|
|
end
|
|
|
|
|
|
|
|
def sortable_columns
|
|
|
|
@sortable_columns ||= [
|
2016-08-24 23:22:16 +08:00
|
|
|
'Protocol.id'
|
2016-07-21 19:11:15 +08:00
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
def sortable_displayed_columns
|
|
|
|
@sortable_displayed_columns ||= [
|
2016-08-24 23:22:16 +08:00
|
|
|
'0'
|
2016-07-21 19:11:15 +08:00
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
def searchable_columns
|
|
|
|
@searchable_columns ||= []
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
# Returns json of current linked children (already paginated)
|
|
|
|
def data
|
|
|
|
records.map do |record|
|
|
|
|
{
|
2016-08-24 23:22:16 +08:00
|
|
|
'DT_RowId' => record.id,
|
|
|
|
'1' => record_html(record)
|
2016-07-21 19:11:15 +08:00
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Query database for records (this will be later paginated and filtered)
|
|
|
|
# after that "data" function will return json
|
|
|
|
def get_raw_records
|
|
|
|
records =
|
|
|
|
Protocol
|
2016-08-24 23:22:16 +08:00
|
|
|
.joins(my_module: { experiment: :project })
|
|
|
|
.includes(my_module: { experiment: :project })
|
|
|
|
.references(my_module: { experiment: :project })
|
|
|
|
.where(protocol_type: Protocol.protocol_types[:linked])
|
|
|
|
.where(parent: @protocol)
|
2016-07-21 19:11:15 +08:00
|
|
|
records.distinct
|
|
|
|
end
|
|
|
|
|
|
|
|
# Helper methods
|
|
|
|
|
|
|
|
def record_html(record)
|
2016-08-24 23:22:16 +08:00
|
|
|
res = ''
|
2016-07-21 19:11:15 +08:00
|
|
|
res += "<ol class='breadcrumb'>"
|
2018-05-22 22:55:58 +08:00
|
|
|
res += "<li><span class='fas fa-folder'></span> "
|
2016-07-21 19:11:15 +08:00
|
|
|
res += @controller.render_to_string(
|
2016-08-24 23:22:16 +08:00
|
|
|
partial: 'search/results/partials/project_text.html.erb',
|
|
|
|
locals: { project: record.my_module.experiment.project }
|
2016-07-21 19:11:15 +08:00
|
|
|
)
|
2016-08-24 23:22:16 +08:00
|
|
|
res += '</li>'
|
2018-03-30 23:03:44 +08:00
|
|
|
res += "<li><i class='fas fa-flask'></i> "
|
2016-08-24 23:22:16 +08:00
|
|
|
res += @controller.render_to_string(
|
|
|
|
partial: 'search/results/partials/experiment_text.html.erb',
|
|
|
|
locals: { experiment: record.my_module.experiment }
|
|
|
|
)
|
|
|
|
res += '</li>'
|
2018-07-09 19:13:44 +08:00
|
|
|
res += "<li><span class='fas fa-credit-card'></span> "
|
2016-07-21 19:11:15 +08:00
|
|
|
res += @controller.render_to_string(
|
2016-08-24 23:22:16 +08:00
|
|
|
partial: 'search/results/partials/my_module_text.html.erb',
|
2016-07-21 19:11:15 +08:00
|
|
|
locals: { my_module: record.my_module, link_to_page: :protocols }
|
|
|
|
)
|
2016-08-24 23:22:16 +08:00
|
|
|
res += '</li>'
|
|
|
|
res += '</ol>'
|
2016-07-21 19:11:15 +08:00
|
|
|
res
|
|
|
|
end
|
|
|
|
end
|