├── README.rdoc ├── README.rdoc.ja ├── app └── views │ └── redmine_wiki_unc │ └── _redmine_wiki_unc_partial.html.erb ├── assets ├── images │ └── bt_wiki_unc.png ├── javascripts │ └── redmine_wiki_unc.js └── stylesheets │ └── redmine_wiki_unc.css ├── init.rb ├── lang └── en.yml ├── lib └── redmine_wiki_unc_hooks.rb ├── test └── test_helper.rb └── toolbar.png /README.rdoc: -------------------------------------------------------------------------------- 1 | = wiki_unc 2 | 3 | == What is this? 4 | 5 | This plugin provides an ability to make a link to files on your server share. 6 | 7 | 8 | 9 | == How to Install 10 | 11 | A. If you have 'git' installed on your system: 12 | 1. Run the commands below: 13 | 14 | $ cd $(REDMINE_HOME) 15 | $ ruby script/plugin install git://github.com/bearmini/redmine_wiki_unc.git 16 | 17 | 2. Restart Redmine 18 | 19 | 20 | B. Otherwise 21 | 1. Download an archived version (.zip file) of the plugin from 22 | http://github.com/bearmini/redmine_wiki_unc/zipball/master 23 | 24 | 2. Unzip it. You are going to have redmine_wiki_unc_xxxxxxx directory. 25 | ('xxxxxxx' might be a combination of some characters) 26 | 27 | 3. Move the directory into redmine\vendor\plugins\ directory. 28 | (You'll get redmine\vendor\plugins\redmine_wiki_unc_xxxxxxx\ 29 | directory and have some files in the directory.) 30 | 31 | 4. Restart Redmine 32 | 33 | 34 | Note: Currently you don't have to do 'rake db:migrate_plugins' because this plugin does not use DBs. 35 | 36 | 37 | 38 | == How to use 39 | 40 | 1. Wherever you can use Wiki notation, you can write 'unc' macro like this: 41 | 42 | {{unc(\\server-name\dir\to\file)}} 43 | 44 | The path is the thing just copied from Windows Explorer. 45 | You need to trim double quotation marks ("...") surrounding the path if exists. 46 | The path can be containing white-space without the double quotation marks. 47 | The path cannot be containing comma(,). 48 | 49 | 2. Then you'll get the HTML tags below: 50 | 51 | \\server-name\dir\to\file 52 | 53 | You can save time to type '/' 5 times! :) 54 | 55 | 56 | == How to update the installed version 57 | 58 | A. If you have the old version installed using 'git': 59 | 1. Run the commands below: 60 | 61 | $ cd $(REDMINE_HOME)/vendor/plugins/redmien_wiki_unc 62 | $ git pull origin master 63 | 64 | 2. Restart Redmine 65 | 66 | B. Otherwise 67 | 1. Repeat the steps for the installation. 68 | (Taking a backup -- just copying the plugin directory to other place -- is recomennded) 69 | 70 | 71 | == Tips 72 | 73 | 1. You can specify a 'label' instead of displaying UNC path. 74 | 75 | {{unc(\\server-name\dir\to\file, Label of the file)}} 76 | 77 | Then you'll get the HTML tags below: 78 | 79 | Label of the file 80 | 81 | 2. If you are using Firefox, you'll be happy with LocalLink plugin. 82 | (Update: The plugin is currently not working with the latest version of Firefox.) 83 | 84 | If you are using Chrome, you'll be happy with LocalLinks plugin. 85 | https://chrome.google.com/webstore/search/LocalLinks 86 | 87 | Internet Explorer can handle file:// scheme without any add-ons. 88 | 89 | For other browsers, please let me know how to work with file:// scheme happily. 90 | 91 | 3. You can create a link from the Wiki Toolbar button. 92 | 93 | [link:toolbar.png] 94 | -------------------------------------------------------------------------------- /README.rdoc.ja: -------------------------------------------------------------------------------- 1 | = Redmine plugin : wiki_unc 2 | 3 | == これは何? 4 | 5 | このプラグインを使うと、Redmine の Wiki ページから、ネットワークのサーバ上の共有ファイルへのリンクを作ることができます。 6 | 7 | 8 | == インストール方法 9 | 10 | A. git がインストールされている環境の場合 11 | 1. 以下のコマンドを実行します。 12 | 13 | $ cd $(REDMINE_HOME) 14 | $ ruby script/plugin install git://github.com/bearmini/redmine_wiki_unc.git 15 | 16 | 2. Redmine を再起動します。 17 | 18 | B. git がインストールされていない環境の場合 19 | 1. このプラグインのファイルが zip にまとめられたバージョンを 20 | 以下の URL からダウンロードします。 21 | http://github.com/bearmini/redmine_wiki_unc/zipball/master 22 | 23 | 2. ダウンロードした zip ファイルを展開します。 24 | redmine_wiki_unc_xxxxxxx という名前のディレクトリができるはずです。 25 | (xxxxxxx の部分は、英数字の組み合わせになります) 26 | 27 | 3. そのディレクトリを、redmine/vendor/plugins/ ディレクトリに 28 | 移動します。 29 | (つまり、redmine/vendor/plugins/redmine_wiki_unc_xxxxxxx/ という 30 | 名前のディレクトリができて、その中にいくつかのファイルが 31 | 存在する状態になるはずです。) 32 | 33 | 4. Redmine を再起動します。 34 | 35 | 36 | == 使い方 37 | 38 | 1. Wiki 記法が使えるところならどこでも、以下のように書くことができます。 39 | 40 | {{unc(\\server-name\dir\to\file)}} 41 | 42 | パスの部分は、エクスプローラからコピーしてきたものです。 43 | もしパスの部分が " (ダブルクオーテーションマーク)でå¾れていたら、 44 | その " を削除してください。 45 | " がなくても、パス名には空白を含めることができます。 46 | パスにはカンマ (,) を含めることができます。 47 | 48 | 2. これで、以下のような HTML タグが生成されます。 49 | 50 | \\server-name\dir\to\file 51 | 52 | '/' を 5 回入力する時間を節約できますね!:) 53 | 54 | 55 | == アップデート方法 56 | 57 | A. git を使ってインストールした場合 58 | 1. 以下のコマンドを実行します。 59 | 60 | $ cd $(REDMINE_HOME)/vendor/plugins/redmine_wiki_unc 61 | $ git pull origin master 62 | 63 | 2. Redmine を再起動します。 64 | 65 | B. git を使わずにインストールした場合 66 | 1. インストール時の手順と同じことを再度行います。 67 | 事前にプラグインのバックアップをとることをおすすめします。 68 | (単にプラグインのディレクトリをどこか他の場所にコピーしてください) 69 | 70 | 71 | == Tips 72 | 73 | 1. UNC のパスを表示させる代わりに、ラベルを指定することができます。 74 | 75 | {{unc(\\server-name\dir\to\file, Label of the file)}} 76 | 77 | こうすると、以下のような HTML タグが生成されます。 78 | 79 | Label of the file 80 | 81 | 2. Firefox をお使いなら、LocalLink プラグインをいれると良いかもしれません。 82 | (現在、LocalLink プラグインは残念ながら最新の Firefox で動作しないようです) 83 | 84 | Chrome をお使いなら、LocalLinks プラグインを入れると良いかもしれません。 85 | https://chrome.google.com/webstore/search/LocalLinks 86 | 87 | IE は標準で file:// スキームを取り扱うことができるので、そのままでファイルへの 88 | リンクが問題なく働きます。 89 | その他のブラウザではどうすれば良いか、ご存じの方は教えてください。 90 | 91 | 3. WikiのToolbarのボタンからリンクを作成できます。 92 | 93 | [link:toolbar.png] 94 | 95 | 96 | -------------------------------------------------------------------------------- /app/views/redmine_wiki_unc/_redmine_wiki_unc_partial.html.erb: -------------------------------------------------------------------------------- 1 | <% 2 | header_tags_content = content_for(:header_tags) 3 | if header_tags_content.present? && header_tags_content.include?('/jstoolbar/') 4 | content_for :header_tags do 5 | javascript_include_tag('redmine_wiki_unc.js', plugin: 'redmine_wiki_unc', 'id' => 'js-redmine-wiki-unc-script-tag', 'data-text-formatting' => Setting.text_formatting) + 6 | stylesheet_link_tag('redmine_wiki_unc.css', plugin: 'redmine_wiki_unc') 7 | end 8 | end 9 | %> 10 | -------------------------------------------------------------------------------- /assets/images/bt_wiki_unc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bearmini/redmine_wiki_unc/72e7b0c8cf01e873d0f4b1863126f8c12860b5d3/assets/images/bt_wiki_unc.png -------------------------------------------------------------------------------- /assets/javascripts/redmine_wiki_unc.js: -------------------------------------------------------------------------------- 1 | (function () { 2 | if(typeof jsToolBar === 'undefined') return false; 3 | 4 | // Create button 5 | var modalHtml = '

Insert link

' 6 | + '

' 7 | + 'Address
' 8 | + '
' 9 | + 'Try link' 10 | + '

' 11 | + '

Text to display

' 12 | + '

' 13 | + ' ' 14 | + '' 15 | + '

'; 16 | 17 | var getCleanedAddress = function(inputAddress) { 18 | return inputAddress.val().replace(/"/g, '').trim(); 19 | }; 20 | var getEncodedAddress = function(inputAddress) { 21 | return getCleanedAddress(inputAddress).replace(/ /g, '%20') 22 | .replace(/\(/g, '%28') 23 | .replace(/\)/g, '%29'); 24 | }; 25 | var isInputValid = function(inputAddress) { 26 | return getCleanedAddress(inputAddress) != ''; 27 | }; 28 | 29 | var button = { 30 | title: 'Insert link', 31 | type: 'button', 32 | name: 'wiki_unc', 33 | class: 'jstb_wiki_unc', 34 | fn: { 35 | wiki: function() { 36 | $('#ajax-modal').html(modalHtml); 37 | var that = this; 38 | var inputAddress = $('#js-redmine-wiki-unc-input-address'); 39 | var inputText = $('#js-redmine-wiki-unc-input-text'); 40 | var tryLink = $('#js-redmine-wiki-unc-a-try-link'); 41 | var buttonOk = $('#js-redmine-wiki-unc-button-ok'); 42 | var buttonCancel = $('#js-redmine-wiki-unc-button-cancel'); 43 | 44 | inputAddress.keyup(function(){ 45 | if (isInputValid(inputAddress)) { 46 | buttonOk.prop('disabled', false); 47 | tryLink.attr('href', getCleanedAddress(inputAddress)); 48 | tryLink.attr('target', '_blank'); 49 | } else { 50 | buttonOk.prop('disabled', true); 51 | tryLink.attr('href', 'javascript:void(0)'); 52 | tryLink.removeAttr('target'); 53 | } 54 | }); 55 | inputAddress.keypress(function(e){ 56 | if (e.keyCode === 13) { // 13 is enter 57 | if (isInputValid(inputAddress)) { 58 | buttonOk.trigger('click'); 59 | return false; // Return false to prevent to insert new line 60 | } 61 | } 62 | }); 63 | inputText.keypress(function(e){ 64 | if (e.keyCode === 13) { // 13 is enter 65 | if (isInputValid(inputAddress)) { 66 | buttonOk.trigger('click'); 67 | return false; // Return false to prevent to insert new line 68 | } 69 | } 70 | }); 71 | buttonOk.click(function(){ 72 | if (!isInputValid(inputAddress)) { 73 | return; 74 | } 75 | hideModal(this); 76 | 77 | var address = getCleanedAddress(inputAddress); 78 | var text = inputText.val().trim(); 79 | if (text == '') { 80 | text = address; 81 | } 82 | 83 | var link; 84 | if (/^\\\\/.test(address)) { 85 | if (address == text) { 86 | link = '{{unc(' + address + ')}}'; 87 | } else { 88 | link = '{{unc(' + address + ', ' + text + ')}}'; 89 | } 90 | } else { 91 | var encoded = getEncodedAddress(inputAddress); 92 | if (encoded == text) { 93 | link = ' ' + encoded + ' '; 94 | } else { 95 | var textFormatting = $('#js-redmine-wiki-unc-script-tag').data('text-formatting'); 96 | if (textFormatting == 'markdown') { 97 | link = ' [' + text + '](' + encoded + ') '; 98 | } else { 99 | link = ' "' + text + '":' + encoded + ' '; 100 | } 101 | } 102 | } 103 | 104 | var pos = that.textarea.selectionStart; 105 | var scroll = that.textarea.scrollTop; 106 | var left = that.textarea.value.substring(0, pos); 107 | var right = that.textarea.value.substring(pos); 108 | that.textarea.value = left + link + right; 109 | that.textarea.scrollTop = scroll; 110 | that.textarea.selectionStart = that.textarea.selectionEnd = (left + link).length; 111 | }); 112 | buttonCancel.click(function(){ 113 | hideModal(this); 114 | }); 115 | 116 | $('#ajax-modal').off('dialogclose'); // If "off" is not executed, the event is added many times. 117 | showModal('ajax-modal', '60%'); 118 | $('#ajax-modal').on('dialogclose', function(event) { 119 | that.textarea.focus(); 120 | }); 121 | } 122 | } 123 | }; 124 | 125 | // Recreate toolbar 126 | var elements_new = {}; 127 | for (var i in jsToolBar.prototype.elements) { 128 | elements_new[i] = jsToolBar.prototype.elements[i]; 129 | if (i == 'img') { // Insert new button after the image button. 130 | elements_new['wiki_unc'] = button; 131 | } 132 | } 133 | jsToolBar.prototype.elements = elements_new; 134 | }()); 135 | -------------------------------------------------------------------------------- /assets/stylesheets/redmine_wiki_unc.css: -------------------------------------------------------------------------------- 1 | .jstb_wiki_unc { 2 | /* https://www.iconfinder.com/icons/3937335/chain_hyperlink_internet_link_linked_icon */ 3 | background-image: url('../images/bt_wiki_unc.png'); 4 | } 5 | -------------------------------------------------------------------------------- /init.rb: -------------------------------------------------------------------------------- 1 | require 'redmine' 2 | require_dependency 'redmine_wiki_unc_hooks' 3 | 4 | class UncHelper 5 | def initialize 6 | @head = /^\\\\/ 7 | end 8 | 9 | def is_unc?(str) 10 | (str =~ @head) != nil 11 | end 12 | 13 | def unc_to_file_proto(str) 14 | Rails.logger.info "str == #{str}, is_unc? == #{is_unc?(str)}, head=#{@head.to_s}" 15 | return "" if !is_unc?(str) 16 | str.gsub(@head, "file://///").gsub(/\\/, "/") 17 | end 18 | 19 | def trim(str) 20 | return str.strip unless str == nil 21 | return nil 22 | end 23 | 24 | def parse_args(args) 25 | unc = trim(args[0]) 26 | label = trim(args[1]) || unc 27 | 28 | return unc, label 29 | end 30 | 31 | def get_tag(args) 32 | return "(No parameters are specified. A UNC path is needed at least.)" if args.empty? 33 | unc, label = parse_args(args) 34 | 35 | return <