Skip to content

Commit

Permalink
Merge pull request #23 from onozaty/develop
Browse files Browse the repository at this point in the history
release v1.2.0
  • Loading branch information
onozaty authored Sep 30, 2018
2 parents ac7d272 + 87cd1d3 commit ea9c73e
Show file tree
Hide file tree
Showing 34 changed files with 516 additions and 125 deletions.
135 changes: 135 additions & 0 deletions README.ja.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
# Redmine view customize plugin

[Redmine](http://www.redmine.org)の画面をカスタマイズするためのプラグインです。

## 機能

条件に一致した画面に対して、JavaScript、CSSを埋め込むことで、画面をカスタマイズします。

## インストール方法

Redmineのプラグインディレクトリに、このリポジトリを`view_customize`としてクローンします。

cd {RAILS_ROOT}/plugins
git clone https://github.com/onozaty/redmine-view-customize.git view_customize
cd ../
bundle exec rake redmine:plugins:migrate RAILS_ENV=production

**注意: ディレクトリ名は`view_customize`とする必要があります。ディレクトリ名が異なると、プラグインの実行に失敗します。**

## 使用方法

### 追加

プラグインをインストールすると、管理者メニューに「View customize」が追加されます。

![Screenshot of admin menu](screenshots/admin.en.png)

「View customize」を押下すると、一覧画面に遷移します。

![Screenshot of list new](screenshots/list_new.en.png)

「New view customize」を押下し、各種項目を入力します。

![Screenshot of new](screenshots/new.en.png)

「Path pattern」は正規表現で指定します。ページのパスと一致すると、コードを挿入して実行します。
以下は設定例です。
* `.*` : 全てのページ
* `/issues$` : チケット一覧
* `/issues/[0-9]+` : 個々のチケットの内容表示画面

「Insertion position」は、コードの挿入位置です。v1.2.0にて追加された項目になります。
* 「Head of all pages」 : 全てのページのヘッダ部分。(v1.2.0より前のバージョンと同じ位置)
* 「Bottom of issue form」 : チケットの入力欄の下部。<br>
チケットの入力欄は、トラッカーやステータスを変えると再構成されますが、「Bottom of issue form」を指定しておくと再構成された際に再度実行されるので、入力欄に対する処理はこれを指定すると便利です。
* 「Bottom of issue detail」 : チケットの詳細表示の下部。

該当ページにコードの挿入位置に該当する箇所が無かった場合、コードは埋め込まれません。たとえば、「Path pattern」で`.*`で全ページを指定しても、「Insertion position」に「Bottom of issue detail」を指定していると、チケットの詳細表示画面でしか実行されないことになります。

「Type」にてコードの種類(「JavaScript」または「CSS」)を選択し、「Code」に実際のコードを入力します。

「Comment」にはカスタマイズに対する概要を記載できます。ここで入力した内容は、一覧表示で表示されます。(Commentが入力されていればComment、Commentが入力されていない場合はCodeが一覧に表示)

「Create」ボタン押下で新規カスタマイズの追加が完了です。

「Path pattern」に一致したページで指定のコードが実行され、画面がカスタマイズされるようになります。

![Screenshot of example](screenshots/example.en.png)

### 編集/削除

![Screenshot of list edit](screenshots/list_edit.en.png)

カスタマイズ一覧の番号を押下すると、カスタマイズ詳細画面へ遷移します。

![Screenshot of detail](screenshots/detail.en.png)

「Delete」を押下すると削除できます。「Edit」を押下すると、編集画面へ遷移します。

入力項目は新規カスタマイズ作成時と同じです。

### 無効化 / プライベート

「Enabled」のチェックを外すと、無効化することができます。「Private」をチェックすると、作成者のみに有効となります。

![Screenshot of enabled and private](screenshots/enable_private.en.png)

まずは「Private」で動作確認したうえで、動作に問題なければ全体に公開するといった使い方ができます。

### ViewCustomize.context (JavaScript)

JavaScriptのコードでは、`ViewCustomize.context`としてユーザやプロジェクトの情報にアクセスすることができます。

`ViewCustomize.context`の情報は下記のようなイメージです。

```javascript
ViewCustomize = {
"context": {
"user": {
"id": 1,
"login": "admin",
"admin": true,
"firstname": "Redmine",
"lastname": "Admin",
"groups": [
{"id": 5, "name": "Group1"}
],
"roles": [ // ユーザに紐づく全てのロール(全プロジェクト)
{"id": 4, "name": "Developer"},
{"id": 6, "name": "RoleX"}
],
"apiKey": "3dd35b5ad8456d90d21ef882f7aea651d367a9d8",
"customFields": [
{"id": 1, "name": "[Custom field] Text", "value": "text"},
{"id": 2, "name": "[Custom field] List", "value": ["B", "A"]},
{"id": 3, "name": "[Custom field] Boolean", "value": "1"}
]
},
"project": {
"identifier": "project-a",
"name": "Project A",
"roles": [ // プロジェクト内でのロール
{"id": 6, "name": "RoleX"}
]
},
"issue": {
"id": 1
}
}
}
```

例えばユーザのAPIキーにアクセスするには`ViewCustomize.context.user.apiKey`となります。

## 設定例

* [onozaty/redmine\-view\-customize\-scripts: Script list for "Redmine View Customize Plugin"](https://github.com/onozaty/redmine-view-customize-scripts)

## サポートバージョン

* Redmine 2.0.x 以降

## ライセンス

このプラグインは [GNU General Public License](http://www.gnu.org/licenses/gpl-2.0.html) バージョン2またはそれ以降の条件で利用できます。
163 changes: 127 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,52 +1,143 @@
Redmine view customize plugin
===========================
# Redmine view customize plugin

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

Features
------------
## Features

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


Installation
------------
## Installation

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

cd {RAILS_ROOT}/plugins
git clone https://github.com/onozaty/redmine-view-customize.git view_customize
cd ../
bundle exec rake redmine:plugins:migrate RAILS_ENV=production
```
cd {RAILS_ROOT}/plugins
git clone https://github.com/onozaty/redmine-view-customize.git view_customize
cd ../
bundle exec rake redmine:plugins:migrate RAILS_ENV=production
```

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

Usage
------------

### Setting

1. After you install the Plugin, "View customize" the administrator menu is added.
![Screenshot of admin menu](screenshots/admin.png)
![Screenshot of list](screenshots/list_new.png)
2. Add a new setting.
![Screenshot of new](screenshots/new.png)
3. Path pattern is specified with a regular expression. (ex. /issues/[0-9]+)
If there is a match with the path of the page, the code(JavaScript/StyleSheet) is executed.
![Screenshot of new path pattern](screenshots/new_pathpattern.png)
4. Input code.
![Screenshot of new JavaScript](screenshots/new_javascript.png)
![Screenshot of new StyleSheet](screenshots/new_stylesheet.png)
5. Matches the path, StyleSheet or JavaScrpt is embedded, the screen display is changed.
![Screenshot of view JavaScript](screenshots/view_javascript.png)
![Screenshot of view StyleSheet](screenshots/view_stylesheet.png)

Supported versions
------------------
## Usage

### Add

When installing the plugin, "View customize" is added to the administrator menu.

![Screenshot of admin menu](screenshots/admin.en.png)

Click "View customize" go to the list screen.

![Screenshot of list new](screenshots/list_new.en.png)

Click "New view customize" and enter items.

![Screenshot of new](screenshots/new.en.png)

"Path pattern" is specified by regular expression. If it matches the path of the page, insert the code and execute it.

The following is an example.
* `.*` : All pages
* `/issues$` : Issue list
* `/issues/[0-9]+` : Issue detail page

"Insertion position" is the code insertion position. It becomes item added in v1.2.0.

* "Head of all pages" (The same position as the version before v1.2.0)
* "Bottom of issue form"<br>
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.
* "Bottom of issue detail"

If there is no part corresponding to the insertion position of the code on the page, the code is not insert.
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.

In "Type", select the type of code ("JavaScript" or "CSS") and enter the actual code in "Code".

For "Comment" you can put an overview on customization. The contents entered here are displayed in the list display.
When "Comment" is entered, "Comment" is displayed on the list.
If "Comment" is not entered, "Code" is displayed in the list.

Addition is completed by clicking "Create" button.

The specified code is executed on the page that matches "Path pattern", and the page will be customized.

![Screenshot of example](screenshots/example.en.png)

### Edit / Delete

![Screenshot of list edit](screenshots/list_edit.en.png)

When you click the number of the customize list, go to the detail page.

![Screenshot of detail](screenshots/detail.en.png)

You can delete it by clicking "Delete".

Click "Edit" to switch to the edit page.
The input item is the same as when creating a new one.

### Disable / Private

You can disable it by unchecking "Enabled". If you check "Private", it will be enable only for the author.

![Screenshot of enabled and private](screenshots/enable_private.en.png)

If you check the operation with "Private" and there is no problem in operation, it will be good to release it to the all.

### ViewCustomize.context (JavaScript)

You can access information on users and projects using `ViewCustomize.context`.

`ViewCustomize.context` is as follows.

```javascript
ViewCustomize = {
"context": {
"user": {
"id": 1,
"login": "admin",
"admin": true,
"firstname": "Redmine",
"lastname": "Admin",
"groups": [
{"id": 5, "name": "Group1"}
],
"roles": [ // All roles associated with users (all projects)
{"id": 4, "name": "Developer"},
{"id": 6, "name": "RoleX"}
],
"apiKey": "3dd35b5ad8456d90d21ef882f7aea651d367a9d8",
"customFields": [
{"id": 1, "name": "[Custom field] Text", "value": "text"},
{"id": 2, "name": "[Custom field] List", "value": ["B", "A"]},
{"id": 3, "name": "[Custom field] Boolean", "value": "1"}
]
},
"project": {
"identifier": "project-a",
"name": "Project A",
"roles": [ // Roles in the project
{"id": 6, "name": "RoleX"}
]
},
"issue": {
"id": 1
}
}
}
```

For example, to access the user's API key is `ViewCustomize.context.user.apiKey`.

## Examples

* [onozaty/redmine\-view\-customize\-scripts: Script list for "Redmine View Customize Plugin"](https://github.com/onozaty/redmine-view-customize-scripts)

## Redmine 2.0.x or later

* Redmine 2.0.x or later

License
-------
## License

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.
7 changes: 6 additions & 1 deletion app/controllers/view_customizes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ class ViewCustomizesController < ApplicationController
before_filter :require_admin
before_filter :find_view_customize, :except => [:index, :new, :create]

helper :sort
include SortHelper

def index
@view_customizes = ViewCustomize.all
sort_init 'id', 'desc'
sort_update %w(id path_pattern insertion_position customize_type code comments is_enabled is_private)
@view_customizes = ViewCustomize.all.order(sort_clause)
end

def new
Expand Down
34 changes: 25 additions & 9 deletions app/models/view_customize.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


class ViewCustomize < ActiveRecord::Base
unloadable

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

attr_protected :id

TYPE_JAVASCRIPT = 1
TYPE_STYLESHEET = 2
TYPE_JAVASCRIPT = "javascript"
TYPE_CSS = "css"

@@customize_types = {
"JavaScript" => TYPE_JAVASCRIPT,
"StyleSheet" => TYPE_STYLESHEET
:label_javascript => TYPE_JAVASCRIPT,
:label_css => TYPE_CSS
}

INSERTION_POSITION_HTML_HEAD = "html_head"
INSERTION_POSITION_ISSUE_FORM = "issue_form"
INSERTION_POSITION_ISSUE_SHOW = "issue_show"

@@insertion_positions = {
:label_insertion_position_html_head => INSERTION_POSITION_HTML_HEAD,
:label_insertion_position_issue_form => INSERTION_POSITION_ISSUE_FORM,
:label_insertion_position_issue_show => INSERTION_POSITION_ISSUE_SHOW
}

def customize_types
@@customize_types
end

def customize_type_name
def customize_type_label
@@customize_types.key(customize_type)
end

def insertion_positions
@@insertion_positions
end

def insertion_position_label
@@insertion_positions.key(insertion_position)
end

def is_javascript?
customize_type == TYPE_JAVASCRIPT
end

def is_stylesheet?
customize_type == TYPE_STYLESHEET
def is_css?
customize_type == TYPE_CSS
end

def available?(user=User.current)
Expand Down
Loading

0 comments on commit ea9c73e

Please sign in to comment.