mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-13 00:24:42 +08:00
add tinymce img importer and refactor input sanitize helper
This commit is contained in:
parent
3d805d529d
commit
c25df63a14
12 changed files with 36 additions and 16 deletions
1
Gemfile
1
Gemfile
|
@ -66,6 +66,7 @@ gem 'delayed_job_active_record'
|
||||||
gem 'devise-async'
|
gem 'devise-async'
|
||||||
gem 'ruby-graphviz', '~> 1.2' # Graphviz for rails
|
gem 'ruby-graphviz', '~> 1.2' # Graphviz for rails
|
||||||
gem 'tinymce-rails' # Rich text editor
|
gem 'tinymce-rails' # Rich text editor
|
||||||
|
gem 'tinymce-rails-imageupload', '~> 4.0.0.beta'
|
||||||
|
|
||||||
gem 'base62' # Used for smart annotations
|
gem 'base62' # Used for smart annotations
|
||||||
gem 'newrelic_rpm'
|
gem 'newrelic_rpm'
|
||||||
|
|
|
@ -311,6 +311,9 @@ GEM
|
||||||
tilt (2.0.1)
|
tilt (2.0.1)
|
||||||
tinymce-rails (4.5.2)
|
tinymce-rails (4.5.2)
|
||||||
railties (>= 3.1.1)
|
railties (>= 3.1.1)
|
||||||
|
tinymce-rails-imageupload (4.0.17.beta.2)
|
||||||
|
railties (>= 3.2, < 6)
|
||||||
|
tinymce-rails (~> 4.0)
|
||||||
turbolinks (2.5.3)
|
turbolinks (2.5.3)
|
||||||
coffee-rails
|
coffee-rails
|
||||||
tzinfo (1.2.2)
|
tzinfo (1.2.2)
|
||||||
|
@ -398,6 +401,7 @@ DEPENDENCIES
|
||||||
spinjs-rails
|
spinjs-rails
|
||||||
starscope
|
starscope
|
||||||
tinymce-rails
|
tinymce-rails
|
||||||
|
tinymce-rails-imageupload (~> 4.0.0.beta)
|
||||||
turbolinks
|
turbolinks
|
||||||
tzinfo-data
|
tzinfo-data
|
||||||
uglifier (>= 1.3.0)
|
uglifier (>= 1.3.0)
|
||||||
|
|
|
@ -13,14 +13,18 @@ var TinyMCE = (function() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getTinyMceAssetsUploadPath() {
|
||||||
|
return $('textarea.tinymce').attr('tiny_mce_upload_path');
|
||||||
|
}
|
||||||
|
|
||||||
// returns a public API for TinyMCE editor
|
// returns a public API for TinyMCE editor
|
||||||
return Object.freeze({
|
return Object.freeze({
|
||||||
init : function() {
|
init : function() {
|
||||||
if (typeof tinyMCE != 'undefined') {
|
if (typeof tinyMCE != 'undefined') {
|
||||||
tinyMCE.init({
|
tinyMCE.init({
|
||||||
selector: "textarea.tinymce",
|
selector: 'textarea.tinymce',
|
||||||
toolbar: ["undo redo | insert | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link | forecolor backcolor | codesample"],
|
toolbar: ["undo redo | insert | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link | forecolor backcolor | uploadimage | codesample"],
|
||||||
plugins: "link,advlist,codesample,autolink,lists,charmap,hr,anchor,searchreplace,wordcount,visualblocks,visualchars,insertdatetime,nonbreaking,save,contextmenu,directionality,paste,textcolor,colorpicker,textpattern,imagetools",
|
plugins: "uploadimage, link,advlist,codesample,autolink,lists,charmap,hr,anchor,searchreplace,wordcount,visualblocks,visualchars,insertdatetime,nonbreaking,save,contextmenu,directionality,paste,textcolor,colorpicker,textpattern,imagetools",
|
||||||
codesample_languages: [{"text":"R","value":"r"},{"text":"MATLAB","value":"matlab"},{"text":"Python","value":"python"},{"text":"JSON","value":"javascript"},{"text":"HTML/XML","value":"markup"},{"text":"JavaScript","value":"javascript"},{"text":"CSS","value":"css"},{"text":"PHP","value":"php"},{"text":"Ruby","value":"ruby"},{"text":"Java","value":"java"},{"text":"C","value":"c"},{"text":"C#","value":"csharp"},{"text":"C++","value":"cpp"}],
|
codesample_languages: [{"text":"R","value":"r"},{"text":"MATLAB","value":"matlab"},{"text":"Python","value":"python"},{"text":"JSON","value":"javascript"},{"text":"HTML/XML","value":"markup"},{"text":"JavaScript","value":"javascript"},{"text":"CSS","value":"css"},{"text":"PHP","value":"php"},{"text":"Ruby","value":"ruby"},{"text":"Java","value":"java"},{"text":"C","value":"c"},{"text":"C#","value":"csharp"},{"text":"C++","value":"cpp"}],
|
||||||
removed_menuitems: 'newdocument',
|
removed_menuitems: 'newdocument',
|
||||||
elementpath: false,
|
elementpath: false,
|
||||||
|
@ -80,7 +84,8 @@ var TinyMCE = (function() {
|
||||||
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
codesample_content_css: '<%= asset_path('highlightjs-github-theme') %>'
|
codesample_content_css: '<%= asset_path('highlightjs-github-theme') %>',
|
||||||
|
uploadimage_form_url: getTinyMceAssetsUploadPath()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -129,9 +129,8 @@ class SampleDatatable < AjaxDatatablesRails::Base
|
||||||
|
|
||||||
# Add custom attributes
|
# Add custom attributes
|
||||||
record.sample_custom_fields.each do |scf|
|
record.sample_custom_fields.each do |scf|
|
||||||
sample[@cf_mappings[scf.custom_field_id]] = custom_auto_link(scf.value,
|
sample[@cf_mappings[scf.custom_field_id]] =
|
||||||
true,
|
custom_auto_link(scf.value, simple_format: true, team: @team)
|
||||||
@team)
|
|
||||||
end
|
end
|
||||||
sample
|
sample
|
||||||
end
|
end
|
||||||
|
|
|
@ -15,14 +15,18 @@ module InputSanitizeHelper
|
||||||
ERB::Util.html_escape(text)
|
ERB::Util.html_escape(text)
|
||||||
end
|
end
|
||||||
|
|
||||||
def custom_auto_link(text, simple_format = true, org = nil, wrapper_tag = {})
|
def custom_auto_link(text, options = {})
|
||||||
|
simple_format = options.fetch(:simple_format) { true }
|
||||||
|
team = options[:team],
|
||||||
|
wrapper_tag = options.fetch(:wrapper_tag) { {} }
|
||||||
|
tags = options.fetch(:tags) { [] }
|
||||||
text = if simple_format
|
text = if simple_format
|
||||||
simple_format(sanitize_input(text), {}, wrapper_tag)
|
simple_format(sanitize_input(text), {}, wrapper_tag)
|
||||||
else
|
else
|
||||||
sanitize_input(text)
|
sanitize_input(text, tags)
|
||||||
end
|
end
|
||||||
auto_link(
|
auto_link(
|
||||||
smart_annotation_parser(text, org),
|
smart_annotation_parser(text, team),
|
||||||
link: :urls,
|
link: :urls,
|
||||||
sanitize: false,
|
sanitize: false,
|
||||||
html: { target: '_blank' }
|
html: { target: '_blank' }
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
<div class="report-element-body">
|
<div class="report-element-body">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-xs-12 text-container ql-editor">
|
<div class="col-xs-12 text-container ql-editor">
|
||||||
<%= custom_auto_link(result_text.text, false) %>
|
<%= custom_auto_link(result_text.text, simple_format: false) %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-xs-12 ql-editor">
|
<div class="col-xs-12 ql-editor">
|
||||||
<% if strip_tags(step.description).present? %>
|
<% if strip_tags(step.description).present? %>
|
||||||
<%= custom_auto_link(step.description, false) %>
|
<%= custom_auto_link(step.description, simple_format: false) %>
|
||||||
<% else %>
|
<% else %>
|
||||||
<em><%=t "projects.reports.elements.step.no_description" %></em>
|
<em><%=t "projects.reports.elements.step.no_description" %></em>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
@ -24,7 +24,9 @@
|
||||||
<li>
|
<li>
|
||||||
<input type="checkbox" disabled="disabled" <%= "checked='checked'" if item.checked %>/>
|
<input type="checkbox" disabled="disabled" <%= "checked='checked'" if item.checked %>/>
|
||||||
<span class="<%= 'checked' if item.checked %>">
|
<span class="<%= 'checked' if item.checked %>">
|
||||||
<%= custom_auto_link(item.text, true, nil, {wrapper_tag: "span"}) %>
|
<%= custom_auto_link(item.text,
|
||||||
|
simple_format: true,
|
||||||
|
wrapper_tag: { wrapper_tag: 'span'}) %>
|
||||||
</span>
|
</span>
|
||||||
</li>
|
</li>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
<div class="ql-editor">
|
<div class="ql-editor">
|
||||||
<%= custom_auto_link(result.result_text.text, false) %>
|
<%= custom_auto_link(result.result_text.text, simple_format: false) %>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
<div class="tab-pane active" role="tabpanel" id="new-step-main">
|
<div class="tab-pane active" role="tabpanel" id="new-step-main">
|
||||||
<%= f.text_field :name, label: t("protocols.steps.new.name"), placeholder: t("protocols.steps.new.name_placeholder") %>
|
<%= f.text_field :name, label: t("protocols.steps.new.name"), placeholder: t("protocols.steps.new.name_placeholder") %>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<%= f.tiny_mce_editor(:description) %>
|
<%= f.tiny_mce_editor(:description, tiny_mce_upload_path: tiny_mce_assets_path(step: @step) ) %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="tab-pane" role="tabpanel" id="new-step-checklists">
|
<div class="tab-pane" role="tabpanel" id="new-step-checklists">
|
||||||
|
|
|
@ -54,7 +54,9 @@
|
||||||
<em><%= t('protocols.steps.no_description') %></em>
|
<em><%= t('protocols.steps.no_description') %></em>
|
||||||
<% else %>
|
<% else %>
|
||||||
<div class="ql-editor">
|
<div class="ql-editor">
|
||||||
<%= custom_auto_link(step.description, false) %>
|
<%= custom_auto_link(step.description,
|
||||||
|
simple_format: false,
|
||||||
|
tags: ['img']) %>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -321,6 +321,9 @@ Rails.application.routes.draw do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# tinyMCE image uploader endpoint
|
||||||
|
post '/tinymce_assets', to: 'tiny_mce_assets#create', as: :tiny_mce_assets
|
||||||
|
|
||||||
resources :results, only: [:update, :destroy] do
|
resources :results, only: [:update, :destroy] do
|
||||||
resources :result_comments,
|
resources :result_comments,
|
||||||
path: '/comments',
|
path: '/comments',
|
||||||
|
|
Loading…
Add table
Reference in a new issue