Skip to content

Commit 61c10ce

Browse files
authored
Merge pull request #6 from gtt-project/develop
Develop into master
2 parents b36391f + 4ea1258 commit 61c10ce

File tree

16 files changed

+126
-17
lines changed

16 files changed

+126
-17
lines changed

.github/workflows/redmine.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Test with Redmine
2+
3+
on:
4+
push:
5+
branches:
6+
- develop
7+
- main
8+
- master
9+
pull_request:
10+
branches:
11+
- develop
12+
- main
13+
- master
14+
15+
jobs:
16+
test:
17+
runs-on: ubuntu-latest
18+
strategy:
19+
matrix:
20+
redmine: [v4.0,v4.1]
21+
ruby: [v2.6]
22+
database: [postgresql]
23+
steps:
24+
- name: Checkout repository
25+
uses: actions/checkout@v2
26+
27+
- name: Redmine plugin test
28+
uses: two-pack/redmine-plugin-test-action@v2
29+
with:
30+
plugin_name: redmine_text_blocks
31+
redmine_version: ${{ matrix.redmine }}
32+
ruby_version: ${{ matrix.ruby }}
33+
database: ${{ matrix.database }}

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@
22

33
This plugin adds configurable text blocks for replying to issues.
44

5+
## Project health
6+
7+
![CI #develop](https://github.com/gtt-project/redmine_text_blocks/workflows/Test%20with%20Redmine/badge.svg)
58

69
## Requirements
710

8-
- Redmine >= 3.4.0
11+
- Redmine >= 3.4.0
912

1013
## Installation
1114

12-
To install Redmine text blocks plugin, download or clone this repository in your Redmine installation plugins directory!
15+
To install Redmine text blocks plugin, download or clone this repository in your Redmine installation plugins directory!
1316

1417
`git clone https://hub.georepublic.net/gtt/redmine_text_blocks.git`
1518

@@ -31,7 +34,7 @@ More information on installing Redmine plugins can be found here: http://www.red
3134

3235
- 1.0.2 Fixes localization
3336
- 1.0.1 Bugfix
34-
37+
3538

3639
## Authors
3740

app/controllers/text_blocks_controller.rb

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ class TextBlocksController < ApplicationController
44
self.main_menu = false
55

66
before_action :find_project_by_project_id
7+
before_action :get_issue_statuses, except: [:index, :destroy]
78

8-
before_action :require_admin, if: ->{ @project.nil? }
9-
before_action :authorize, if: ->{ @project.present? }
9+
before_action :require_admin, if: ->{ @project.nil? } , except: :blocks_by_status
10+
before_action :authorize, if: ->{ @project.present? }, except: :blocks_by_status
1011

1112
menu_item :settings, only: [:new, :create, :edit, :update, :destroy]
1213
helper_method :index_path
@@ -50,6 +51,12 @@ def destroy
5051
redirect_to index_path
5152
end
5253

54+
def blocks_by_status
55+
@txtblocks = get_blocks_by_status(params[:status_id])
56+
respond_to do |format|
57+
format.json { render json: @txtblocks.to_json }
58+
end
59+
end
5360

5461
private
5562

@@ -62,7 +69,7 @@ def index_path
6269
end
6370

6471
def text_block_params
65-
params[:text_block].permit :name, :text
72+
params[:text_block].permit :name, :text, :issue_status_ids => []
6673
end
6774

6875
def find_text_block
@@ -79,4 +86,11 @@ def text_block_scope
7986
TextBlock.order(name: :asc).where(project_id: @project&.id)
8087
end
8188

89+
def get_issue_statuses
90+
@issue_statuses = IssueStatus.all.sorted
91+
end
92+
93+
def get_blocks_by_status(status_id)
94+
IssueStatus.find(status_id).text_blocks.blank? ? text_block_scope : IssueStatus.find(status_id).text_blocks.where(project_id: [nil, @project&.id])
95+
end
8296
end

app/helpers/text_blocks_helper.rb

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
11
module TextBlocksHelper
2-
def text_block_options
2+
def text_block_options(issue=nil)
33
tags = []
44
tags << content_tag(:option, value: '') do
55
t('label_select_text_block')
66
end
7-
tags += TextBlock.where(project_id: [nil, @project.id]).to_a.map{|tb|
8-
content_tag :option, value: tb.text do
9-
tb.name
10-
end
11-
}
7+
status_textblocks = IssueStatus.find(issue.status_id).text_blocks if issue
8+
if !status_textblocks.blank?
9+
tags += status_textblocks.where(project_id: [nil, @project.id]).map{|tb|
10+
content_tag :option, value: tb.text do
11+
tb.name
12+
end
13+
}
14+
else
15+
tags += TextBlock.where(project_id: [nil, @project.id]).to_a.map{|tb|
16+
content_tag :option, value: tb.text do
17+
tb.name
18+
end
19+
}
20+
end
1221
safe_join tags
1322
end
1423
end

app/models/text_block.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
class TextBlock < ActiveRecord::Base
22
belongs_to :project
3+
has_and_belongs_to_many :issue_statuses
34

45
validates :name, presence: true
56
validate :name_uniqueness
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<% if User.current.allowed_to?(:view_text_blocks, @project) %>
2-
<%= select_tag :text_block, text_block_options, id: 'textblock-select', style: 'display:none; border: 1px solid #e0e2e3; background: #f6f6f6; height: 24px; color: #3d454c; vertical-align: bottom; margin-left: 6px; margin-botton: 0;' %>
2+
<%= select_tag :text_block, text_block_options(@issue), id: 'textblock-select', style: 'display:none; border: 1px solid #e0e2e3; background: #f6f6f6; height: 24px; color: #3d454c; vertical-align: bottom; margin-left: 6px; margin-botton: 0;' %>
33
<%= javascript_include_tag 'text_blocks', plugin: 'redmine_text_blocks' %>
44
<% end %>

app/views/text_blocks/_form.html.erb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@
33
<div class="box tabular">
44
<p><%= f.text_field :name, required: true, size: 25 %></p>
55
<p><%= f.text_area :text, label: l(:field_text_block_text), rows: 10 %></p>
6+
<p>
7+
<%= content_tag :label, l(:label_issue_status_plural) %>
8+
<%= f.collection_select :issue_status_ids,
9+
@issue_statuses,
10+
:id,
11+
:name,
12+
{ prompt: "" },
13+
{ multiple: true } %>
14+
</p>
615
</div>
716

817
<%= wikitoolbar_for 'text_block_text' %>

app/views/text_blocks/_list.html.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<tr>
55
<th><%= l :label_text_block_name %></th>
66
<th><%= l :label_text_block_text %></th>
7+
<th><%= l :label_issue_status_plural %></th>
78
<th></th>
89
</tr>
910
</thead>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
<tr>
22
<td><%= link_to text_block.name, (text_block.project ? edit_project_text_block_path(text_block.project, text_block) : edit_text_block_path(text_block)) %></td>
33
<td class="text"><div><%= textilizable text_block.text %></div></td>
4+
<td class="text"><div>
5+
<% text_block.issue_statuses.pluck(:name).map do |s| %>
6+
<%= textilizable s %>
7+
<% end %>
8+
</div></td>
49
<td><%= delete_link(text_block.project ? project_text_block_path(text_block.project, text_block) : text_block_path(text_block)) %>
510
</tr>

assets/javascripts/text_blocks.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ var TextBlocks = {
1313
if(value == '') return;
1414

1515
console.log(value);
16-
var fieldId = $('#textblock-select').parent().next('div.jstEditor').find('textarea').attr('id');
16+
var fieldId = $('#textblock-select').parents().next('div.jstEditor').find('textarea').attr('id');
1717

1818
var field = document.getElementById(fieldId);
1919
var field_ = $(field);
@@ -32,9 +32,24 @@ var TextBlocks = {
3232
field.selectionEnd = caretPos + value.length
3333

3434
$(this).val('');
35-
}
35+
},
3636

37+
reload: function(e){
38+
$("#textblock-select option:gt(0)").remove();
39+
$.ajax({
40+
url: "/text_blocks_by_status/"+$("#issue_status_id").val()+"/"+$("#issue_project_id").val(),
41+
method: "GET",
42+
success: function(data){
43+
data.forEach(function(tb){
44+
$("#textblock-select").append($("<option></option>")
45+
.attr("value", tb.text).text(tb.name));
46+
});
47+
}
48+
});
49+
}
3750
}
3851

3952
$(document).ready(TextBlocks.init);
4053
$(document).on("change", "#textblock-select", TextBlocks.insert);
54+
$(document).on("change", "#issue_status_id", TextBlocks.reload);
55+
$(document).on("change", "#issue_project_id", TextBlocks.reload);

0 commit comments

Comments
 (0)