redmine2.4.1でjQuery VisualizeをPluginとして動かしてみた | Ujsag.Takashi.Lap

Ujsag.Takashi.Lap

身の回りのことやらメモをつれずれと。

jQuery VisualizerというのがTableを作っておくだけでいい感じに描画してくれる、
ということを聞いて、Redmineのチケットをテーブルにするだけでいい感じにグラフ
になるのかも?と思って調べてみた。

Redmineのプラグインといして、jQuery Visualizeを組み込んでいろいろすることは可能っぽい。

jQuery-Visualize on Redmine


確認した手順メモ

1. 任意のRedmineのプラグインを作成する。

2. jQuery-Visualize関連ファイルをプラグインの管理下にコピーする。

2-1. jQuery-Visualize関連のjs以下のファイルを作成したプラグインのassets/javascripts/にコピーする。
2-2. jQuery-Visualize関連のcss以下のファイルを作成したプラグインのassets/stylesheet/にコピーする。
2-3. jQuery-Visualizeはenhances.jsがないと動かないのでダウンロードして、作成したプラグインのassets/javascripts/にコピーする。

3. javascriptに実行権がついているか確認する。
 ※ついていないと動作しない・・・と悩むことに。

4. 作成したRedmineプラグインにサンプルコードの追加。
 app/views/の下にあるxxx.erbという表示にかかわるソースに、
 サンプルコードを追加して動作を確認する。


<%= stylesheet_link_tag "basic.css", :plugin => "(plugin名)s" %>
<%= javascript_include_tag "enhance.js", :plugin => "(plugin名)" %>
<%= javascript_tag do %>
enhance({
loadScripts: [
{src: '/plugin_assets/(plugin名)/javascripts/excanvas.js', iecondition: 'all'},
'/plugin_assets/(plugin名)/javascripts/jquery.js',
'/plugin_assets/(plugin名)/javascripts/visualize.jQuery.js',
'/plugin_assets/(plugin名)/javascripts/example.js'
],
loadStyles: [
'/plugin_assets/(plugin名)/stylesheets/visualize.css',
'/plugin_assets/(plugin名)/stylesheets/visualize-dark.css'
]
});
<table>
<caption>2009 Employee Sales by Department</caption>
<thead>
<tr>
<td></td>
<th scope="col">food</th>
<th scope="col">auto</th>
<th scope="col">household</th>
<th scope="col">furniture</th>
<th scope="col">kitchen</th>
<th scope="col">bath</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Mary</th>
<td>190</td>
<td>160</td>
<td>40</td>
<td>120</td>
<td>30</td>
<td>70</td>
</tr>
<tr>
<th scope="row">Tom</th>
<td>3</td>
<td>40</td>
<td>30</td>
<td>45</td>
<td>35</td>
<td>49</td>
</tr>
</tbody>
</table>



プラグインを有効化してみるとちゃんとjQuery-Visualizeのサンプルの
index.htmlみたいなものが中で動作して、テーブルの下にグラフが表示される。

Redmineの動作の仕組みが少し見えたかも。
Issueの一覧とってきてテーブルで確認しつつグラフを見る、ってことも夢ではなさそう。


参考
- jQuery-Visualize GitHub
- Rails を知らない人のための Redmine プラグイン開発ガイド (r-labs)