Skip to content

Commit ea9c73e

Browse files
authored
Merge pull request #23 from onozaty/develop
release v1.2.0
2 parents ac7d272 + 87cd1d3 commit ea9c73e

34 files changed

+516
-125
lines changed

README.ja.md

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
# Redmine view customize plugin
2+
3+
[Redmine](http://www.redmine.org)の画面をカスタマイズするためのプラグインです。
4+
5+
## 機能
6+
7+
条件に一致した画面に対して、JavaScript、CSSを埋め込むことで、画面をカスタマイズします。
8+
9+
## インストール方法
10+
11+
Redmineのプラグインディレクトリに、このリポジトリを`view_customize`としてクローンします。
12+
13+
cd {RAILS_ROOT}/plugins
14+
git clone https://github.com/onozaty/redmine-view-customize.git view_customize
15+
cd ../
16+
bundle exec rake redmine:plugins:migrate RAILS_ENV=production
17+
18+
**注意: ディレクトリ名は`view_customize`とする必要があります。ディレクトリ名が異なると、プラグインの実行に失敗します。**
19+
20+
## 使用方法
21+
22+
### 追加
23+
24+
プラグインをインストールすると、管理者メニューに「View customize」が追加されます。
25+
26+
![Screenshot of admin menu](screenshots/admin.en.png)
27+
28+
「View customize」を押下すると、一覧画面に遷移します。
29+
30+
![Screenshot of list new](screenshots/list_new.en.png)
31+
32+
「New view customize」を押下し、各種項目を入力します。
33+
34+
![Screenshot of new](screenshots/new.en.png)
35+
36+
「Path pattern」は正規表現で指定します。ページのパスと一致すると、コードを挿入して実行します。
37+
以下は設定例です。
38+
* `.*` : 全てのページ
39+
* `/issues$` : チケット一覧
40+
* `/issues/[0-9]+` : 個々のチケットの内容表示画面
41+
42+
「Insertion position」は、コードの挿入位置です。v1.2.0にて追加された項目になります。
43+
* 「Head of all pages」 : 全てのページのヘッダ部分。(v1.2.0より前のバージョンと同じ位置)
44+
* 「Bottom of issue form」 : チケットの入力欄の下部。<br>
45+
チケットの入力欄は、トラッカーやステータスを変えると再構成されますが、「Bottom of issue form」を指定しておくと再構成された際に再度実行されるので、入力欄に対する処理はこれを指定すると便利です。
46+
* 「Bottom of issue detail」 : チケットの詳細表示の下部。
47+
48+
該当ページにコードの挿入位置に該当する箇所が無かった場合、コードは埋め込まれません。たとえば、「Path pattern」で`.*`で全ページを指定しても、「Insertion position」に「Bottom of issue detail」を指定していると、チケットの詳細表示画面でしか実行されないことになります。
49+
50+
「Type」にてコードの種類(「JavaScript」または「CSS」)を選択し、「Code」に実際のコードを入力します。
51+
52+
「Comment」にはカスタマイズに対する概要を記載できます。ここで入力した内容は、一覧表示で表示されます。(Commentが入力されていればComment、Commentが入力されていない場合はCodeが一覧に表示)
53+
54+
「Create」ボタン押下で新規カスタマイズの追加が完了です。
55+
56+
「Path pattern」に一致したページで指定のコードが実行され、画面がカスタマイズされるようになります。
57+
58+
![Screenshot of example](screenshots/example.en.png)
59+
60+
### 編集/削除
61+
62+
![Screenshot of list edit](screenshots/list_edit.en.png)
63+
64+
カスタマイズ一覧の番号を押下すると、カスタマイズ詳細画面へ遷移します。
65+
66+
![Screenshot of detail](screenshots/detail.en.png)
67+
68+
「Delete」を押下すると削除できます。「Edit」を押下すると、編集画面へ遷移します。
69+
70+
入力項目は新規カスタマイズ作成時と同じです。
71+
72+
### 無効化 / プライベート
73+
74+
「Enabled」のチェックを外すと、無効化することができます。「Private」をチェックすると、作成者のみに有効となります。
75+
76+
![Screenshot of enabled and private](screenshots/enable_private.en.png)
77+
78+
まずは「Private」で動作確認したうえで、動作に問題なければ全体に公開するといった使い方ができます。
79+
80+
### ViewCustomize.context (JavaScript)
81+
82+
JavaScriptのコードでは、`ViewCustomize.context`としてユーザやプロジェクトの情報にアクセスすることができます。
83+
84+
`ViewCustomize.context`の情報は下記のようなイメージです。
85+
86+
```javascript
87+
ViewCustomize = {
88+
"context": {
89+
"user": {
90+
"id": 1,
91+
"login": "admin",
92+
"admin": true,
93+
"firstname": "Redmine",
94+
"lastname": "Admin",
95+
"groups": [
96+
{"id": 5, "name": "Group1"}
97+
],
98+
"roles": [ // ユーザに紐づく全てのロール(全プロジェクト)
99+
{"id": 4, "name": "Developer"},
100+
{"id": 6, "name": "RoleX"}
101+
],
102+
"apiKey": "3dd35b5ad8456d90d21ef882f7aea651d367a9d8",
103+
"customFields": [
104+
{"id": 1, "name": "[Custom field] Text", "value": "text"},
105+
{"id": 2, "name": "[Custom field] List", "value": ["B", "A"]},
106+
{"id": 3, "name": "[Custom field] Boolean", "value": "1"}
107+
]
108+
},
109+
"project": {
110+
"identifier": "project-a",
111+
"name": "Project A",
112+
"roles": [ // プロジェクト内でのロール
113+
{"id": 6, "name": "RoleX"}
114+
]
115+
},
116+
"issue": {
117+
"id": 1
118+
}
119+
}
120+
}
121+
```
122+
123+
例えばユーザのAPIキーにアクセスするには`ViewCustomize.context.user.apiKey`となります。
124+
125+
## 設定例
126+
127+
* [onozaty/redmine\-view\-customize\-scripts: Script list for "Redmine View Customize Plugin"](https://github.com/onozaty/redmine-view-customize-scripts)
128+
129+
## サポートバージョン
130+
131+
* Redmine 2.0.x 以降
132+
133+
## ライセンス
134+
135+
このプラグインは [GNU General Public License](http://www.gnu.org/licenses/gpl-2.0.html) バージョン2またはそれ以降の条件で利用できます。

README.md

Lines changed: 127 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,143 @@
1-
Redmine view customize plugin
2-
===========================
1+
# Redmine view customize plugin
32

43
This a plugin allows you to customize the view for the [Redmine](http://www.redmine.org).
54

6-
Features
7-
------------
5+
## Features
86

9-
By adding JavaScript or CSS to the matched path, a screen is made customizable.
7+
Customize the page by inserting JavaScript or CSS on the page that matched the condition.
108

11-
12-
Installation
13-
------------
9+
## Installation
1410

1511
Install the plugin in your Redmine plugins directory, clone this repository as `view_customize`:
1612

17-
cd {RAILS_ROOT}/plugins
18-
git clone https://github.com/onozaty/redmine-view-customize.git view_customize
19-
cd ../
20-
bundle exec rake redmine:plugins:migrate RAILS_ENV=production
13+
```
14+
cd {RAILS_ROOT}/plugins
15+
git clone https://github.com/onozaty/redmine-view-customize.git view_customize
16+
cd ../
17+
bundle exec rake redmine:plugins:migrate RAILS_ENV=production
18+
```
2119

2220
**note: The directory name must be a `view_customize`. Directory name is different, it will fail to run the Plugin.**
2321

24-
Usage
25-
------------
26-
27-
### Setting
28-
29-
1. After you install the Plugin, "View customize" the administrator menu is added.
30-
![Screenshot of admin menu](screenshots/admin.png)
31-
![Screenshot of list](screenshots/list_new.png)
32-
2. Add a new setting.
33-
![Screenshot of new](screenshots/new.png)
34-
3. Path pattern is specified with a regular expression. (ex. /issues/[0-9]+)
35-
If there is a match with the path of the page, the code(JavaScript/StyleSheet) is executed.
36-
![Screenshot of new path pattern](screenshots/new_pathpattern.png)
37-
4. Input code.
38-
![Screenshot of new JavaScript](screenshots/new_javascript.png)
39-
![Screenshot of new StyleSheet](screenshots/new_stylesheet.png)
40-
5. Matches the path, StyleSheet or JavaScrpt is embedded, the screen display is changed.
41-
![Screenshot of view JavaScript](screenshots/view_javascript.png)
42-
![Screenshot of view StyleSheet](screenshots/view_stylesheet.png)
43-
44-
Supported versions
45-
------------------
22+
## Usage
23+
24+
### Add
25+
26+
When installing the plugin, "View customize" is added to the administrator menu.
27+
28+
![Screenshot of admin menu](screenshots/admin.en.png)
29+
30+
Click "View customize" go to the list screen.
31+
32+
![Screenshot of list new](screenshots/list_new.en.png)
33+
34+
Click "New view customize" and enter items.
35+
36+
![Screenshot of new](screenshots/new.en.png)
37+
38+
"Path pattern" is specified by regular expression. If it matches the path of the page, insert the code and execute it.
39+
40+
The following is an example.
41+
* `.*` : All pages
42+
* `/issues$` : Issue list
43+
* `/issues/[0-9]+` : Issue detail page
44+
45+
"Insertion position" is the code insertion position. It becomes item added in v1.2.0.
46+
47+
* "Head of all pages" (The same position as the version before v1.2.0)
48+
* "Bottom of issue form"<br>
49+
Issue input fields are reconstructed when trackers or statuses are changed. If "Bottom of issue form" is specified, it will be executed again when reconstructed.
50+
* "Bottom of issue detail"
51+
52+
If there is no part corresponding to the insertion position of the code on the page, the code is not insert.
53+
For example, even if you specify `.*` in "Path pattern", if "Bottom of issue detail" is specified for "Insertion position", it will be executed only on the issue detail page.
54+
55+
In "Type", select the type of code ("JavaScript" or "CSS") and enter the actual code in "Code".
56+
57+
For "Comment" you can put an overview on customization. The contents entered here are displayed in the list display.
58+
When "Comment" is entered, "Comment" is displayed on the list.
59+
If "Comment" is not entered, "Code" is displayed in the list.
60+
61+
Addition is completed by clicking "Create" button.
62+
63+
The specified code is executed on the page that matches "Path pattern", and the page will be customized.
64+
65+
![Screenshot of example](screenshots/example.en.png)
66+
67+
### Edit / Delete
68+
69+
![Screenshot of list edit](screenshots/list_edit.en.png)
70+
71+
When you click the number of the customize list, go to the detail page.
72+
73+
![Screenshot of detail](screenshots/detail.en.png)
74+
75+
You can delete it by clicking "Delete".
76+
77+
Click "Edit" to switch to the edit page.
78+
The input item is the same as when creating a new one.
79+
80+
### Disable / Private
81+
82+
You can disable it by unchecking "Enabled". If you check "Private", it will be enable only for the author.
83+
84+
![Screenshot of enabled and private](screenshots/enable_private.en.png)
85+
86+
If you check the operation with "Private" and there is no problem in operation, it will be good to release it to the all.
87+
88+
### ViewCustomize.context (JavaScript)
89+
90+
You can access information on users and projects using `ViewCustomize.context`.
91+
92+
`ViewCustomize.context` is as follows.
93+
94+
```javascript
95+
ViewCustomize = {
96+
"context": {
97+
"user": {
98+
"id": 1,
99+
"login": "admin",
100+
"admin": true,
101+
"firstname": "Redmine",
102+
"lastname": "Admin",
103+
"groups": [
104+
{"id": 5, "name": "Group1"}
105+
],
106+
"roles": [ // All roles associated with users (all projects)
107+
{"id": 4, "name": "Developer"},
108+
{"id": 6, "name": "RoleX"}
109+
],
110+
"apiKey": "3dd35b5ad8456d90d21ef882f7aea651d367a9d8",
111+
"customFields": [
112+
{"id": 1, "name": "[Custom field] Text", "value": "text"},
113+
{"id": 2, "name": "[Custom field] List", "value": ["B", "A"]},
114+
{"id": 3, "name": "[Custom field] Boolean", "value": "1"}
115+
]
116+
},
117+
"project": {
118+
"identifier": "project-a",
119+
"name": "Project A",
120+
"roles": [ // Roles in the project
121+
{"id": 6, "name": "RoleX"}
122+
]
123+
},
124+
"issue": {
125+
"id": 1
126+
}
127+
}
128+
}
129+
```
130+
131+
For example, to access the user's API key is `ViewCustomize.context.user.apiKey`.
132+
133+
## Examples
134+
135+
* [onozaty/redmine\-view\-customize\-scripts: Script list for "Redmine View Customize Plugin"](https://github.com/onozaty/redmine-view-customize-scripts)
136+
137+
## Redmine 2.0.x or later
46138

47139
* Redmine 2.0.x or later
48140

49-
License
50-
-------
141+
## License
51142

52143
The plugin is available under the terms of the [GNU General Public License](http://www.gnu.org/licenses/gpl-2.0.html), version 2 or later.

app/controllers/view_customizes_controller.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@ class ViewCustomizesController < ApplicationController
66
before_filter :require_admin
77
before_filter :find_view_customize, :except => [:index, :new, :create]
88

9+
helper :sort
10+
include SortHelper
11+
912
def index
10-
@view_customizes = ViewCustomize.all
13+
sort_init 'id', 'desc'
14+
sort_update %w(id path_pattern insertion_position customize_type code comments is_enabled is_private)
15+
@view_customizes = ViewCustomize.all.order(sort_clause)
1116
end
1217

1318
def new

app/models/view_customize.rb

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
class ViewCustomize < ActiveRecord::Base
42
unloadable
53

@@ -14,28 +12,46 @@ class ViewCustomize < ActiveRecord::Base
1412

1513
attr_protected :id
1614

17-
TYPE_JAVASCRIPT = 1
18-
TYPE_STYLESHEET = 2
15+
TYPE_JAVASCRIPT = "javascript"
16+
TYPE_CSS = "css"
1917

2018
@@customize_types = {
21-
"JavaScript" => TYPE_JAVASCRIPT,
22-
"StyleSheet" => TYPE_STYLESHEET
19+
:label_javascript => TYPE_JAVASCRIPT,
20+
:label_css => TYPE_CSS
21+
}
22+
23+
INSERTION_POSITION_HTML_HEAD = "html_head"
24+
INSERTION_POSITION_ISSUE_FORM = "issue_form"
25+
INSERTION_POSITION_ISSUE_SHOW = "issue_show"
26+
27+
@@insertion_positions = {
28+
:label_insertion_position_html_head => INSERTION_POSITION_HTML_HEAD,
29+
:label_insertion_position_issue_form => INSERTION_POSITION_ISSUE_FORM,
30+
:label_insertion_position_issue_show => INSERTION_POSITION_ISSUE_SHOW
2331
}
2432

2533
def customize_types
2634
@@customize_types
2735
end
2836

29-
def customize_type_name
37+
def customize_type_label
3038
@@customize_types.key(customize_type)
3139
end
3240

41+
def insertion_positions
42+
@@insertion_positions
43+
end
44+
45+
def insertion_position_label
46+
@@insertion_positions.key(insertion_position)
47+
end
48+
3349
def is_javascript?
3450
customize_type == TYPE_JAVASCRIPT
3551
end
3652

37-
def is_stylesheet?
38-
customize_type == TYPE_STYLESHEET
53+
def is_css?
54+
customize_type == TYPE_CSS
3955
end
4056

4157
def available?(user=User.current)

0 commit comments

Comments
 (0)