mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-31 20:19:05 +08:00
Merge pull request #2779 from okriuchykhin/ok_SCI_4910
Fix rendering of RTE in API [SCI-4910]
This commit is contained in:
commit
b333700f40
7 changed files with 46 additions and 16 deletions
|
@ -3,23 +3,26 @@
|
|||
module Api
|
||||
module V1
|
||||
class ProtocolsController < BaseController
|
||||
before_action :load_team
|
||||
before_action :load_project
|
||||
before_action :load_experiment
|
||||
before_action :load_task
|
||||
include Api::V1::ExtraParams
|
||||
|
||||
before_action :load_team, :load_project, :load_experiment, :load_task
|
||||
before_action only: :show do
|
||||
load_protocol(:id)
|
||||
end
|
||||
|
||||
def index
|
||||
protocols = @task.protocols
|
||||
.page(params.dig(:page, :number))
|
||||
.per(params.dig(:page, :size))
|
||||
render jsonapi: protocols,
|
||||
each_serializer: ProtocolSerializer
|
||||
each_serializer: ProtocolSerializer, rte_rendering: render_rte?, team: @team
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def load_protocol
|
||||
@protocol = @task.protocols.find(params.require(:id))
|
||||
def show
|
||||
render jsonapi: @protocol, serializer: ProtocolSerializer,
|
||||
include: include_params,
|
||||
rte_rendering: render_rte?,
|
||||
team: @team
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -16,13 +16,15 @@ module Api
|
|||
|
||||
render jsonapi: steps, each_serializer: StepSerializer,
|
||||
include: include_params,
|
||||
rte_rendering: render_rte?
|
||||
rte_rendering: render_rte?,
|
||||
team: @team
|
||||
end
|
||||
|
||||
def show
|
||||
render jsonapi: @step, serializer: StepSerializer,
|
||||
include: include_params,
|
||||
rte_rendering: render_rte?
|
||||
rte_rendering: render_rte?,
|
||||
team: @team
|
||||
end
|
||||
|
||||
def create
|
||||
|
|
|
@ -19,11 +19,11 @@ module Api
|
|||
.page(params.dig(:page, :number))
|
||||
.per(params.dig(:page, :size))
|
||||
|
||||
render jsonapi: tasks, each_serializer: TaskSerializer, rte_rendering: render_rte?
|
||||
render jsonapi: tasks, each_serializer: TaskSerializer, rte_rendering: render_rte?, team: @team
|
||||
end
|
||||
|
||||
def show
|
||||
render jsonapi: @task, serializer: TaskSerializer, rte_rendering: render_rte?
|
||||
render jsonapi: @task, serializer: TaskSerializer, rte_rendering: render_rte?, team: @team
|
||||
end
|
||||
|
||||
def create
|
||||
|
|
|
@ -3,6 +3,10 @@
|
|||
module Api
|
||||
module V1
|
||||
class ProtocolSerializer < ActiveModel::Serializer
|
||||
include ApplicationHelper
|
||||
include ActionView::Helpers::TextHelper
|
||||
include InputSanitizeHelper
|
||||
|
||||
type :protocols
|
||||
attributes :id, :name, :authors, :description, :protocol_type
|
||||
has_many :protocol_keywords,
|
||||
|
@ -12,6 +16,17 @@ module Api
|
|||
unless: -> { object.protocol_keywords.empty? }
|
||||
has_many :steps, serializer: StepSerializer, if: -> { object.steps.any? }
|
||||
belongs_to :parent, serializer: ProtocolSerializer, if: -> { object.parent.present? }
|
||||
|
||||
def description
|
||||
if instance_options[:rte_rendering]
|
||||
custom_auto_link(object.tinymce_render(:description),
|
||||
simple_format: false,
|
||||
tags: %w(img),
|
||||
team: instance_options[:team])
|
||||
else
|
||||
object.description
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -19,7 +19,10 @@ module Api
|
|||
|
||||
def description
|
||||
if instance_options[:rte_rendering]
|
||||
custom_auto_link(object.tinymce_render(:description), simple_format: false, tags: %w(img))
|
||||
custom_auto_link(object.tinymce_render(:description),
|
||||
simple_format: false,
|
||||
tags: %w(img),
|
||||
team: instance_options[:team])
|
||||
else
|
||||
object.description
|
||||
end
|
||||
|
|
|
@ -3,6 +3,10 @@
|
|||
module Api
|
||||
module V1
|
||||
class TaskSerializer < ActiveModel::Serializer
|
||||
include ApplicationHelper
|
||||
include ActionView::Helpers::TextHelper
|
||||
include InputSanitizeHelper
|
||||
|
||||
type :tasks
|
||||
attributes :id, :name, :started_on, :due_date, :description, :state, :archived
|
||||
has_many :output_tasks, key: :outputs,
|
||||
|
@ -22,7 +26,10 @@ module Api
|
|||
|
||||
def description
|
||||
if instance_options[:rte_rendering]
|
||||
custom_auto_link(object.tinymce_render(:description), simple_format: false, tags: %w(img))
|
||||
custom_auto_link(object.tinymce_render(:description),
|
||||
simple_format: false,
|
||||
tags: %w(img),
|
||||
team: instance_options[:team])
|
||||
else
|
||||
object.description
|
||||
end
|
||||
|
|
|
@ -716,7 +716,7 @@ Rails.application.routes.draw do
|
|||
resources :task_tags, only: %i(index show),
|
||||
path: 'tags',
|
||||
as: :tags
|
||||
resources :protocols, only: %i(index) do
|
||||
resources :protocols, only: %i(index show) do
|
||||
resources :steps do
|
||||
resources :assets, only: %i(index show create), path: 'attachments'
|
||||
resources :checklists, path: 'checklists' do
|
||||
|
|
Loading…
Reference in a new issue