diff --git a/Gemfile.lock b/Gemfile.lock index e52990e2a..d30eb7bc4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -19,6 +19,7 @@ PATH rails GEM + remote: https://rubygems.org/ remote: https://rubygems.org/ specs: actionmailer (3.2.13) @@ -61,6 +62,10 @@ GEM xpath (~> 1.0.0) childprocess (0.5.3) ffi (~> 1.0, >= 1.0.11) + climate_control (0.0.3) + activesupport (>= 3.0) + cocaine (0.5.4) + climate_control (>= 0.0.3, < 1.0) coderay (1.0.9) coffee-rails (3.2.2) coffee-script (>= 2.2.0) @@ -74,12 +79,16 @@ GEM fastercsv (1.5.0) ffi (1.9.3-x86-mingw32) hike (1.2.3) + htmlentities (4.3.2) i18n (0.6.1) journey (1.0.4) jquery-rails (2.0.3) railties (>= 3.1.0, < 5.0) thor (~> 0.14) json (1.8.0) + kaminari (0.16.1) + actionpack (>= 3.0.0) + activesupport (>= 3.0.0) mail (2.5.4) mime-types (~> 1.16) treetop (~> 1.4.8) @@ -91,6 +100,11 @@ GEM mysql2 (0.3.11-x86-mingw32) net-ldap (0.3.1) nokogiri (1.5.11-x86-mingw32) + paperclip (3.5.4) + activemodel (>= 3.0.0) + activesupport (>= 3.0.0) + cocaine (~> 0.5.3) + mime-types polyglot (0.3.3) rack (1.4.5) rack-cache (1.2) @@ -98,6 +112,8 @@ GEM rack-openid (1.3.1) rack (>= 1.1.0) ruby-openid (>= 2.1.8) + rack-raw-upload (1.1.1) + multi_json rack-ssl (1.3.3) rack rack-test (0.6.2) @@ -120,6 +136,14 @@ GEM rake (10.3.2) rdoc (3.12.2) json (~> 1.4) + rich (1.4.6) + jquery-rails + kaminari + mime-types + paperclip + rack-raw-upload + rails (>= 3.2.0) + sass-rails rmagick (2.13.2) ruby-openid (2.1.8) rubyzip (1.1.4) @@ -170,15 +194,19 @@ DEPENDENCIES coderay (~> 1.0.6) coffee-rails (~> 3.2.1) fastercsv (~> 1.5.0) + htmlentities i18n (~> 0.6.0) jquery-rails (~> 2.0.2) + kaminari mocha (~> 0.13.3) mysql2 (= 0.3.11) net-ldap (~> 0.3.1) nokogiri (< 1.6.0) + paperclip (~> 3.5.4) rack-mini-profiler! rack-openid rails (= 3.2.13) + rich (= 1.4.6) rmagick (>= 2.0.0) ruby-openid (~> 2.1.4) sass-rails (~> 3.2.3) diff --git a/ReadMe.txt b/ReadMe.txt index 0fcba47c0..129b99216 100644 --- a/ReadMe.txt +++ b/ReadMe.txt @@ -50,4 +50,19 @@ app\controller\welcome_controller.rb 0606:新坑 user_scores表结构有问题,需要运行 bundle exec rake db:migrate:down VERSION=20140410021724 -bundle exec rake db:migrate:up VERSION=20140410021724 \ No newline at end of file +bundle exec rake db:migrate:up VERSION=20140410021724 +=============================================================================== +0708:CKEditor插件加载方法 +1.把插件文件夹拷入plugins文件夹,确保文件夹名为redmine_ckeditor +2.运行 bundle install --without development test +3.运行 rake redmine:plugins:migrate RAILS_ENV=production +4.启动服务器 +5.把文本格式 (Administration > Settings > General > Text formatting)改为CKEditor +6.配置CKEditor插件(Administration > Plugins > Configure) + +某些情况数据库未插入插件配置值解决方案: +1 复制plugins +2 启动rails +3 运行migrate +3 打开admin配置插件(http://127.0.0.1:3000/settings/plugin/redmine_ckeditor) +4 点击“查询”(就是确定的功能) \ No newline at end of file diff --git a/config/settings.yml b/config/settings.yml index 8c9f55ae0..cffbaa5fa 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -251,3 +251,15 @@ course_domain: default: course.trustie.net repository_domain: default: repository.trustie.net +plugin_redmine_ckeditor: + serialized: true + default: --- !ruby/hash:ActiveSupport::HashWithIndifferentAccess + skin: moono + ui_color: ! '#f4f4f4' + width: '' + height: '400' + enter_mode: '1' + show_blocks: '1' + toolbar_can_collapse: '0' + toolbar_location: top + toolbar: Source,ShowBlocks,--,Undo,Redo,-,Find,Replace,--,Bold,Italic,Underline,Strike,-,Subscript,Superscript,-,NumberedList,BulletedList,-,Outdent,Indent,Blockquote,-,JustifyLeft,JustifyCenter,JustifyRight,JustifyBlock,-,Link,Unlink,-,richImage,Table,HorizontalRule,/,Styles,Format,Font,FontSize,-,TextColor,BGColor diff --git a/db/schema.rb b/db/schema.rb index 6e750aa9f..72d49adf4 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20140708023356) do +ActiveRecord::Schema.define(:version => 20140704034832) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -794,7 +794,7 @@ ActiveRecord::Schema.define(:version => 20140708023356) do end create_table "relative_memos", :force => true do |t| - t.integer "osp_id" + t.integer "osp_id", :null => false t.integer "parent_id" t.string "subject", :null => false t.text "content", :null => false @@ -831,6 +831,19 @@ ActiveRecord::Schema.define(:version => 20140708023356) do add_index "repositories", ["project_id"], :name => "index_repositories_on_project_id" + create_table "rich_rich_files", :force => true do |t| + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + t.string "rich_file_file_name" + t.string "rich_file_content_type" + t.integer "rich_file_file_size" + t.datetime "rich_file_updated_at" + t.string "owner_type" + t.integer "owner_id" + t.text "uri_cache" + t.string "simplified_type", :default => "file" + end + create_table "roles", :force => true do |t| t.string "name", :limit => 30, :default => "", :null => false t.integer "position", :default => 1 diff --git a/plugins/redmine_ckeditor/.gitmodules b/plugins/redmine_ckeditor/.gitmodules new file mode 100644 index 000000000..de30e7590 --- /dev/null +++ b/plugins/redmine_ckeditor/.gitmodules @@ -0,0 +1,3 @@ +[submodule "app/assets/javascripts/ckeditor-releases"] + path = app/assets/javascripts/ckeditor-releases + url = git://github.com/ckeditor/ckeditor-releases.git diff --git a/plugins/redmine_ckeditor/Gemfile b/plugins/redmine_ckeditor/Gemfile new file mode 100644 index 000000000..5071abd08 --- /dev/null +++ b/plugins/redmine_ckeditor/Gemfile @@ -0,0 +1,6 @@ +source 'https://rubygems.org' + +gem 'rich', '1.4.6' +gem 'kaminari' +gem 'htmlentities' +gem 'paperclip', '~> 3.5.4' diff --git a/plugins/redmine_ckeditor/README.rdoc b/plugins/redmine_ckeditor/README.rdoc new file mode 100644 index 000000000..9a05ed31f --- /dev/null +++ b/plugins/redmine_ckeditor/README.rdoc @@ -0,0 +1,69 @@ += Redmine CKEditor plugin + +This plugin adds the text formatting for using CKEditor to Redmine. + +Since version 1.0.0, it includes {Rich}[https://github.com/bastiaanterhorst/rich] and supports image uploads. + +== What is CKEditor? + +CKEditor is a WYSIWYG text editor. +See {the official site}[http://ckeditor.com/] for more details. + +== Requirements + +* Redmine 2.3.x, Ruby 1.9.2 or higher, {ImageMagick}[http://www.imagemagick.org/] (version {1.0.16}[https://github.com/a-ono/redmine_ckeditor]) + # Ubuntu + apt-get install imagemagick + # Mac OS X + brew install imagemagick + +* Redmine 2.3.x (version {0.4.0}[https://github.com/a-ono/redmine_ckeditor/tree/0.4.0]) + +* Redmine 2.2.x (version {0.3.0}[https://github.com/a-ono/redmine_ckeditor/tree/0.3.0]) + +* Redmine 2.1.x (version {0.2.1}[https://github.com/a-ono/redmine_ckeditor/tree/0.2.1]) + +* Redmine 2.0.x (version {0.1.1}[https://github.com/a-ono/redmine_ckeditor/tree/0.1.1]) + +* Redmine 1.1.0 - 1.4.2 (version {0.0.6}[https://github.com/a-ono/redmine_ckeditor/tree/0.0.6]) + +== Plugin installation and setup + +1. Copy the plugin directory into the plugins directory (make sure the name is redmine_ckeditor) +2. Install the required gems (in the Redmine root directory) + bundle install --without development test +3. Execute migration + rake redmine:plugins:migrate RAILS_ENV=production +4. Start Redmine +5. Change text formatting (Administration > Settings > General > Text formatting) to CKEditor +6. Configure the plugin (Administration > Plugins > Configure) + +=== Upgrade + +1. Replace the plugin directory (plugins/redmine_ckeditor) +2. Install the required gems + bundle install --without development test +3. Execute migration + rake redmine:plugins:migrate RAILS_ENV=production +4. Delete old assets + rm -r /public/plugin_assets/redmine_ckeditor +5. Restart Redmine + +== CKEditor customization + +=== Plugins + +You can download plugins from {Add-ons Repository}[http://ckeditor.com/addons/plugins/all]. +To activate the plugin you have to copy the plugin directory into assets/ckeditor-contrib/plugins and restart Redmine, then configure toolbar settings. + +=== Skins + +You can select third-party skins placed in assets/ckeditor-contrib/skins directory. + +== Migration notes + +This plugin stores contents in HTML format and renders as is. +If you have old contents, these look weird. + +You can use {redmine_per_project_formatting}[https://github.com/a-ono/redmine_per_project_formatting] plugin for backward compatibility or execute redmine_ckeditor:migrate task for migrating old text to HTML. + rake redmine_ckeditor:migrate RAILS_ENV=production [PROJECT=project_identifier1,project_identifier2] [FORMAT=textile] diff --git a/plugins/redmine_ckeditor/app/assets/javascripts/application.js b/plugins/redmine_ckeditor/app/assets/javascripts/application.js new file mode 100644 index 000000000..8a7148b3c --- /dev/null +++ b/plugins/redmine_ckeditor/app/assets/javascripts/application.js @@ -0,0 +1,5 @@ +// +//= require rich/editor/ckeditor_path +//= require ckeditor-releases/ckeditor +//= require rich/editor/rich_editor +//= require rich/editor/rich_picker diff --git a/plugins/redmine_ckeditor/app/assets/javascripts/browser.js b/plugins/redmine_ckeditor/app/assets/javascripts/browser.js new file mode 100644 index 000000000..29fa85da8 --- /dev/null +++ b/plugins/redmine_ckeditor/app/assets/javascripts/browser.js @@ -0,0 +1,4 @@ +//= require fileuploader +//= require rich/browser/extensions +//= require rich/browser/uploader +//= require rich/browser/filebrowser diff --git a/plugins/redmine_ckeditor/app/models/redmine_ckeditor_setting.rb b/plugins/redmine_ckeditor/app/models/redmine_ckeditor_setting.rb new file mode 100644 index 000000000..1472a874a --- /dev/null +++ b/plugins/redmine_ckeditor/app/models/redmine_ckeditor_setting.rb @@ -0,0 +1,69 @@ +class RedmineCkeditorSetting + def self.setting + Setting[:plugin_redmine_ckeditor] || {} + end + + def self.default + ["1", true].include?(setting[:default]) + end + + def self.toolbar_string + setting[:toolbar] || RedmineCkeditor.default_toolbar + end + + def self.toolbar + bars = [] + bar = [] + toolbar_string.split(",").each {|item| + case item + when '/' + bars.push(bar, item) + bar = [] + when '--' + bars.push(bar) + bar = [] + else + bar.push(item) + end + } + + bars.push(bar) unless bar.empty? + bars + end + + def self.skin + setting[:skin] || "moono" + end + + def self.ui_color + setting[:ui_color] || "#f4f4f4" + end + + def self.enter_mode + (setting[:enter_mode] || 1).to_i + end + + def self.shift_enter_mode + enter_mode == 2 ? 1 : 2 + end + + def self.show_blocks + (setting[:show_blocks] || 1).to_i == 1 + end + + def self.toolbar_can_collapse + setting[:toolbar_can_collapse].to_i == 1 + end + + def self.toolbar_location + setting[:toolbar_location] || "top" + end + + def self.width + setting[:width] + end + + def self.height + setting[:height] || 400 + end +end diff --git a/plugins/redmine_ckeditor/app/views/issues/update_form.js.erb b/plugins/redmine_ckeditor/app/views/issues/update_form.js.erb new file mode 100644 index 000000000..e7d3e2ad2 --- /dev/null +++ b/plugins/redmine_ckeditor/app/views/issues/update_form.js.erb @@ -0,0 +1,11 @@ +<% if RedmineCkeditor.enabled? %> + destroyEditor("issue_description"); +<% end %> + +$('#all_attributes').html('<%= escape_javascript(render :partial => 'form') %>'); + +<% if User.current.allowed_to?(:log_time, @issue.project) %> + $('#log_time').show(); +<% else %> + $('#log_time').hide(); +<% end %> diff --git a/plugins/redmine_ckeditor/app/views/journals/new_with_ckeditor.js.erb b/plugins/redmine_ckeditor/app/views/journals/new_with_ckeditor.js.erb new file mode 100644 index 000000000..592f9d1d7 --- /dev/null +++ b/plugins/redmine_ckeditor/app/views/journals/new_with_ckeditor.js.erb @@ -0,0 +1,9 @@ +<% + # when quoting a private journal, check the private checkbox + if @journal && @journal.private_notes? +%> +$('#issue_private_notes').attr('checked', true); +<% end %> + +CKEDITOR.instances['issue_notes'].setData(<%= @content.inspect.html_safe %>); +showAndScrollTo("update", "issue_notes"); diff --git a/plugins/redmine_ckeditor/app/views/layouts/rich/application.html.erb b/plugins/redmine_ckeditor/app/views/layouts/rich/application.html.erb new file mode 100644 index 000000000..16401252c --- /dev/null +++ b/plugins/redmine_ckeditor/app/views/layouts/rich/application.html.erb @@ -0,0 +1,16 @@ + + + + Rich Browser + <%= javascript_heads %> + <%= stylesheet_link_tag "application", :plugin => "redmine_ckeditor" %> + <%= ckeditor_javascripts %> + <%= javascript_include_tag "browser", :plugin => "redmine_ckeditor" %> + <%= csrf_meta_tags %> + + + +<%= yield %> + + + diff --git a/plugins/redmine_ckeditor/app/views/messages/quote_with_ckeditor.js.erb b/plugins/redmine_ckeditor/app/views/messages/quote_with_ckeditor.js.erb new file mode 100644 index 000000000..78c9a64e9 --- /dev/null +++ b/plugins/redmine_ckeditor/app/views/messages/quote_with_ckeditor.js.erb @@ -0,0 +1,2 @@ +<%= render :file => "messages/quote" %> +CKEDITOR.instances['message_content'].setData($('#message_content').val()); diff --git a/plugins/redmine_ckeditor/app/views/rich/files/_file.html.erb b/plugins/redmine_ckeditor/app/views/rich/files/_file.html.erb new file mode 100644 index 000000000..0bdd7372c --- /dev/null +++ b/plugins/redmine_ckeditor/app/views/rich/files/_file.html.erb @@ -0,0 +1,12 @@ +
  • + +

    <%= file.rich_file_file_name %>

    + <%= link_to "delete", file.id.to_s, :method => :delete, :remote => true, :confirm => t(:delete_confirm), :class => "delete", :title => t(:delete) %> +
  • diff --git a/plugins/redmine_ckeditor/app/views/settings/_ckeditor.html.erb b/plugins/redmine_ckeditor/app/views/settings/_ckeditor.html.erb new file mode 100644 index 000000000..fefe8212c --- /dev/null +++ b/plugins/redmine_ckeditor/app/views/settings/_ckeditor.html.erb @@ -0,0 +1,142 @@ +<%= ckeditor_javascripts %> +<%= stylesheet_link_tag 'editor', :plugin => 'redmine_ckeditor'%> +<%= stylesheet_link_tag 'selector', :plugin => 'redmine_ckeditor'%> +

    + <%= content_tag :label, l(:ckeditor_skin) %> + <%= select_tag "settings[skin]", RedmineCkeditor.skin_options %> +

    +

    + <%= content_tag :label, l(:ckeditor_ui_color) %> + <%= text_field_tag "settings[ui_color]", RedmineCkeditorSetting.ui_color %> +

    +

    + <%= content_tag :label, l(:ckeditor_width) %> + <%= text_field_tag "settings[width]", RedmineCkeditorSetting.width %> +

    +

    + <%= content_tag :label, l(:ckeditor_height) %> + <%= text_field_tag "settings[height]", RedmineCkeditorSetting.height %> +

    +

    + <%= content_tag :label, l(:ckeditor_enter_mode) %> + <%= select_tag "settings[enter_mode]", RedmineCkeditor.enter_mode_options %> +

    +

    + <%= content_tag :label, l(:ckeditor_startup_show_blocks) %> + <%= hidden_field_tag "settings[show_blocks]", 0 %> + <%= check_box_tag "settings[show_blocks]", 1, RedmineCkeditorSetting.show_blocks %> +

    +

    + <%= content_tag :label, l(:ckeditor_toolbar_can_collapse) %> + <%= hidden_field_tag "settings[toolbar_can_collapse]", 0 %> + <%= check_box_tag "settings[toolbar_can_collapse]", 1, RedmineCkeditorSetting.toolbar_can_collapse %> +

    +

    + <%= content_tag :label, l(:ckeditor_toolbar_location) %> + <%= select_tag "settings[toolbar_location]", RedmineCkeditor.toolbar_location_options %> +

    +

    + <%= content_tag :label, l(:ckeditor_toolbar_buttons) %> +

    + +
    + <%= hidden_field_tag "settings[toolbar]", RedmineCkeditorSetting.toolbar_string %> + + + +
    +
    +

    +
    +
    + +
    + + + +
    +
    +
    + +<%= javascript_tag do %> + function moveItem(from, to) { + from = $("#" + from); + to = $("#" + to); + var selected = to.find("option:selected").first(); + from.find("option:selected").remove().each(function() { + if (this.value == '-' || this.value == '--' || this.value == '/') return; + selected.size() ? selected.before(this) : to.append(this); + }); + to.prop("selectedIndex", -1); + changeHandler(); + } + + function addItem(item) { + var option = $("