mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-06 13:14:29 +08:00
refactor
This commit is contained in:
parent
ed24448817
commit
5b58824ec0
7 changed files with 31 additions and 23 deletions
2
Gemfile
2
Gemfile
|
@ -65,7 +65,7 @@ gem 'aws-sdk-v1'
|
||||||
gem 'delayed_job_active_record'
|
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', '~> 4.5.7' # Rich text editor
|
||||||
|
|
||||||
gem 'base62' # Used for smart annotations
|
gem 'base62' # Used for smart annotations
|
||||||
gem 'newrelic_rpm'
|
gem 'newrelic_rpm'
|
||||||
|
|
|
@ -20,11 +20,13 @@ var TinyMCE = (function() {
|
||||||
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 | customimageuploader | codesample"],
|
toolbar: ["undo redo | insert | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link | forecolor backcolor | customimageuploader | codesample"],
|
||||||
plugins: "customimageuploader,link,advlist,codesample,autolink,lists,charmap,hr,anchor,searchreplace,wordcount,visualblocks,visualchars,insertdatetime,nonbreaking,save,contextmenu,directionality,paste,textcolor,colorpicker,textpattern,imagetools",
|
plugins: "customimageuploader,link,advlist,codesample,autolink,lists,charmap,hr,anchor,searchreplace,wordcount,visualblocks,visualchars,insertdatetime,nonbreaking,save,contextmenu,directionality,paste,textcolor,colorpicker,textpattern",
|
||||||
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',
|
||||||
|
object_resizing: false,
|
||||||
elementpath: false,
|
elementpath: false,
|
||||||
default_link_target: "_blank",
|
forced_root_block: false,
|
||||||
|
default_link_target: '_blank',
|
||||||
target_list: [
|
target_list: [
|
||||||
{title: 'New page', value: '_blank'},
|
{title: 'New page', value: '_blank'},
|
||||||
{title: 'Same page', value: '_self'}
|
{title: 'Same page', value: '_self'}
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
onclick: insertImage,
|
onclick: insertImage,
|
||||||
subtype: 'primary'},
|
subtype: 'primary'},
|
||||||
{text: "<%= I18n.t 'general.cancel' %>",
|
{text: "<%= I18n.t 'general.cancel' %>",
|
||||||
onclick: ed.windowManager.close}
|
onclick: editor.windowManager.close}
|
||||||
],
|
],
|
||||||
}, {
|
}, {
|
||||||
plugin_url: url
|
plugin_url: url
|
||||||
|
@ -42,11 +42,11 @@
|
||||||
|
|
||||||
iframe = win.find('iframe')[0];
|
iframe = win.find('iframe')[0];
|
||||||
form = createElement('form', {
|
form = createElement('form', {
|
||||||
action: ed.getParam('customimageuploader_form_url',
|
action: editor.getParam('customimageuploader_form_url',
|
||||||
'<%= Rails.application
|
'<%= Rails.application
|
||||||
.routes
|
.routes
|
||||||
.url_helpers
|
.url_helpers
|
||||||
.tiny_mce_assets_path %>'),
|
.tiny_mce_assets_path %>'),
|
||||||
target: iframe._id,
|
target: iframe._id,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
enctype: 'multipart/form-data',
|
enctype: 'multipart/form-data',
|
||||||
|
@ -67,17 +67,17 @@
|
||||||
form.appendChild(createElement('input',
|
form.appendChild(createElement('input',
|
||||||
{type: 'hidden',
|
{type: 'hidden',
|
||||||
name: 'object_type',
|
name: 'object_type',
|
||||||
value: $(ed.getElement())
|
value: $(editor.getElement())
|
||||||
.data('object-type')}));
|
.data('object-type')}));
|
||||||
form.appendChild(createElement('input',
|
form.appendChild(createElement('input',
|
||||||
{type: 'hidden',
|
{type: 'hidden',
|
||||||
name: 'object_id',
|
name: 'object_id',
|
||||||
value: $(ed.getElement())
|
value: $(editor.getElement())
|
||||||
.data('object-id')}));
|
.data('object-id')}));
|
||||||
form.appendChild(createElement('input',
|
form.appendChild(createElement('input',
|
||||||
{type: 'hidden',
|
{type: 'hidden',
|
||||||
name: 'hint',
|
name: 'hint',
|
||||||
value: ed.getParam('uploadimage_hint', '')}));
|
value: editor.getParam('uploadimage_hint', '')}));
|
||||||
|
|
||||||
var el = win.getEl();
|
var el = win.getEl();
|
||||||
var body = document.getElementById(el.id + '-body');
|
var body = document.getElementById(el.id + '-body');
|
||||||
|
@ -157,11 +157,11 @@
|
||||||
if(json['error']) {
|
if(json['error']) {
|
||||||
handleError(json['error']['message']);
|
handleError(json['error']['message']);
|
||||||
} else {
|
} else {
|
||||||
ed.execCommand('mceInsertContent', false, buildHTML(json));
|
editor.execCommand('mceInsertContent', false, buildHTML(json));
|
||||||
ed.windowManager.close();
|
editor.windowManager.close();
|
||||||
}
|
}
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
// hack that get's the server error message
|
// hack that gets the server error message
|
||||||
var error_json = JSON.parse($(ret).text());
|
var error_json = JSON.parse($(ret).text());
|
||||||
handleError(error_json['error'][0]);
|
handleError(error_json['error'][0]);
|
||||||
}
|
}
|
||||||
|
@ -177,8 +177,12 @@
|
||||||
function handleError(error) {
|
function handleError(error) {
|
||||||
var message = win.find('.error')[0].getEl();
|
var message = win.find('.error')[0].getEl();
|
||||||
|
|
||||||
if(message)
|
if(message) {
|
||||||
message.getElementsByTagName('p')[0].innerHTML = ed.translate(error);
|
message
|
||||||
|
.getElementsByTagName('p')[0]
|
||||||
|
.innerHTML = editor.translate(error);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function createElement(element, attributes) {
|
function createElement(element, attributes) {
|
||||||
|
|
|
@ -32,6 +32,7 @@ class ResultTextsController < ApplicationController
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@result_text = ResultText.new(result_params[:result_text_attributes])
|
@result_text = ResultText.new(result_params[:result_text_attributes])
|
||||||
|
# gerate a tag that replaces img tag in database
|
||||||
@result_text.text = parse_tiny_mce_asset_to_token(@result_text.text)
|
@result_text.text = parse_tiny_mce_asset_to_token(@result_text.text)
|
||||||
@result = Result.new(
|
@result = Result.new(
|
||||||
user: current_user,
|
user: current_user,
|
||||||
|
@ -42,8 +43,8 @@ class ResultTextsController < ApplicationController
|
||||||
@result.last_modified_by = current_user
|
@result.last_modified_by = current_user
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
if (@result.save and @result_text.save) then
|
if (@result.save and @result_text.save)
|
||||||
# link tiny_mce_assets to the result text
|
# link tiny_mce_assets to the text result
|
||||||
link_tiny_mce_assets(@result_text.text, @result_text)
|
link_tiny_mce_assets(@result_text.text, @result_text)
|
||||||
|
|
||||||
result_annotation_notification
|
result_annotation_notification
|
||||||
|
|
|
@ -164,7 +164,7 @@ class StepsController < ApplicationController
|
||||||
table.last_modified_by = current_user unless table.new_record?
|
table.last_modified_by = current_user unless table.new_record?
|
||||||
table.team = current_team
|
table.team = current_team
|
||||||
end
|
end
|
||||||
|
|
||||||
# gerate a tag that replaces img tag in databases
|
# gerate a tag that replaces img tag in databases
|
||||||
@step.description = parse_tiny_mce_asset_to_token(
|
@step.description = parse_tiny_mce_asset_to_token(
|
||||||
params[:step][:description],
|
params[:step][:description],
|
||||||
|
|
|
@ -103,6 +103,8 @@ module ApplicationHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
def smart_annotation_parser(text, team = nil)
|
def smart_annotation_parser(text, team = nil)
|
||||||
|
# sometimes happens that the "team" param gets wrong data: "{nil, []}"
|
||||||
|
# so we have to check if the "team" param is kind of Team object
|
||||||
team = nil unless team.is_a? Team
|
team = nil unless team.is_a? Team
|
||||||
new_text = smart_annotation_filter_resources(text)
|
new_text = smart_annotation_filter_resources(text)
|
||||||
new_text = smart_annotation_filter_users(new_text, team)
|
new_text = smart_annotation_filter_users(new_text, team)
|
||||||
|
|
|
@ -6,5 +6,4 @@ namespace :tiny_mce_asset do
|
||||||
'result_text_id IS ? AND created_at < ?',
|
'result_text_id IS ? AND created_at < ?',
|
||||||
nil, nil, 7.days.ago)
|
nil, nil, 7.days.ago)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue