-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into 'master'
Develop Closes #5 See merge request !1
- Loading branch information
Showing
28 changed files
with
553 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
gem 'immutable-struct' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
class TextBlocksController < ApplicationController | ||
layout ->{ @project ? 'base' : 'admin' } | ||
|
||
self.main_menu = false | ||
|
||
before_action :find_project_by_project_id | ||
|
||
before_action :require_admin, if: ->{ @project.nil? } | ||
before_action :authorize, if: ->{ @project.present? } | ||
|
||
menu_item :settings, only: [:new, :create, :edit, :update, :destroy] | ||
helper_method :index_path | ||
|
||
def index | ||
@text_blocks = text_block_scope | ||
end | ||
|
||
def edit | ||
@text_block = find_text_block | ||
end | ||
|
||
def new | ||
@text_block = TextBlock.new | ||
end | ||
|
||
def create | ||
r = RedmineTextBlocks::SaveTextBlock.(text_block_params, | ||
project: @project) | ||
if r.text_block_saved? | ||
redirect_to params[:continue] ? new_path : index_path | ||
else | ||
@text_block = r.text_block | ||
render 'new' | ||
end | ||
end | ||
|
||
def update | ||
@text_block = find_text_block | ||
r = RedmineTextBlocks::SaveTextBlock.(text_block_params, | ||
text_block: @text_block) | ||
if r.text_block_saved? | ||
redirect_to index_path | ||
else | ||
render 'edit' | ||
end | ||
end | ||
|
||
def destroy | ||
find_text_block.destroy | ||
redirect_to index_path | ||
end | ||
|
||
|
||
private | ||
|
||
def new_path | ||
@project ? new_project_text_block_path(@project) : new_text_block_path | ||
end | ||
|
||
def index_path | ||
@project ? settings_project_path(@project, tab: 'text_blocks') : text_blocks_path | ||
end | ||
|
||
def text_block_params | ||
params[:text_block].permit :name, :text | ||
end | ||
|
||
def find_text_block | ||
text_block_scope.find params[:id] | ||
end | ||
|
||
def find_project_by_project_id | ||
if id = params[:project_id] | ||
@project = Project.find id | ||
end | ||
end | ||
|
||
def text_block_scope | ||
TextBlock.order(name: :asc).where(project_id: @project&.id) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module TextBlocksHelper | ||
def text_block_options | ||
tags = [] | ||
tags << content_tag(:option, value: '') do | ||
t('label_select_text_block') | ||
end | ||
tags += TextBlock.where(project_id: [nil, @project.id]).to_a.map{|tb| | ||
content_tag :option, value: tb.text do | ||
tb.name | ||
end | ||
} | ||
safe_join tags | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
class TextBlock < ActiveRecord::Base | ||
belongs_to :project | ||
|
||
validates :name, presence: true | ||
validate :name_uniqueness | ||
|
||
|
||
private | ||
|
||
def name_uniqueness | ||
scope = TextBlock.where.not(id: id).where(name: name) | ||
|
||
if project_id.present? | ||
scope = scope.where project_id: [ nil, project_id ] | ||
end | ||
|
||
if scope.any? | ||
errors.add :name, I18n.t('model.text_block.name_uniqueness') | ||
end | ||
end | ||
|
||
end |
4 changes: 4 additions & 0 deletions
4
app/views/hooks/text_blocks/_view_issues_edit_notes_bottom.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<% if User.current.allowed_to?(:view_text_blocks, @project) %> | ||
<%= 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;' %> | ||
<%= javascript_include_tag 'text_blocks', plugin: 'redmine_text_blocks' %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<p> | ||
<%= link_to l(:label_text_block_new), new_project_text_block_path(@project), class: 'icon icon-add' %> | ||
</p> | ||
|
||
<%= render partial: 'text_blocks/list', locals: { text_blocks: TextBlock.where(project_id: @project.id) } %> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<%= error_messages_for 'text_block' %> | ||
|
||
<div class="box tabular"> | ||
<p><%= f.text_field :name, required: true, size: 25 %></p> | ||
<p><%= f.text_area :text, label: l(:field_text_block_text) %></p> | ||
</div> | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<% if text_blocks.any? %> | ||
<table class="list"> | ||
<thead> | ||
<tr> | ||
<th><%= l :label_text_block_name %></th> | ||
<th><%= l :label_text_block_text %></th> | ||
<th></th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<%= render collection: text_blocks, partial: 'text_blocks/text_block' %> | ||
</tbody> | ||
</table> | ||
<% else %> | ||
<p class="nodata"><%= l :label_no_data %></p> | ||
<% end %> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<tr> | ||
<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> | ||
<td><%= text_block.text %></td> | ||
<td><%= delete_link(text_block.project ? project_text_block_path(text_block.project, text_block) : text_block_path(text_block)) %> | ||
</tr> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<%= title [l(:label_text_block_plural), index_path], @text_block.name %> | ||
|
||
<%= labelled_form_for @text_block, url: (@project ? project_text_block_path(@project, @text_block) : text_block_path(@text_block)), method: :patch do |f| %> | ||
<%= render partial: 'form', locals: { f: f } %> | ||
<p> | ||
<%= submit_tag l :button_save %> | ||
</p> | ||
<% end %> | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<div class="contextual"> | ||
<%= link_to l(:label_text_block_new), new_text_block_path, class: 'icon icon-add' %> | ||
</div> | ||
|
||
<h2><%= l :label_text_block_plural %></h2> | ||
|
||
<%= render partial: 'list', locals: { text_blocks: @text_blocks } %> | ||
|
||
<% html_title l :label_text_block_plural -%> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<%= title [l(:label_text_block_plural), index_path], l(:label_text_block_new) %> | ||
|
||
<%= labelled_form_for @text_block, url: @project ? project_text_blocks_path(@project) : text_blocks_path do |f| %> | ||
<%= render partial: 'form', locals: { f: f } %> | ||
<p> | ||
<%= submit_tag l :button_create %> | ||
<%= submit_tag l(:button_create_and_continue), name: 'continue' %> | ||
</p> | ||
<% end %> | ||
|
||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
var TextBlocks = { | ||
init: function(){ | ||
var select = $('#textblock-select'); | ||
var toolbar_buttons = select.parent().find('.jstElements'); | ||
if(select.parent() != toolbar_buttons) { | ||
toolbar_buttons.find('button:last').after(select); | ||
} | ||
select.show(); | ||
}, | ||
|
||
insert: function(e){ | ||
var value = $(this).val(); | ||
if(value == '') return; | ||
|
||
console.log(value); | ||
var fieldId = $('#textblock-select').parent().next('div.jstEditor').find('textarea').attr('id'); | ||
|
||
var field = document.getElementById(fieldId); | ||
var field_ = $(field); | ||
|
||
var caretPos = field.selectionStart; | ||
var caretEnd = field.selectionEnd; | ||
var textAreaTxt = field_.val(); | ||
field_.val( | ||
textAreaTxt.substring(0, caretPos) + | ||
value + | ||
textAreaTxt.substring(caretEnd) | ||
); | ||
|
||
field_.focus(); | ||
field.selectionStart = caretPos + value.length | ||
field.selectionEnd = caretPos + value.length | ||
|
||
$(this).val(''); | ||
} | ||
|
||
} | ||
|
||
$(document).ready(TextBlocks.init); | ||
$(document).on("change", "#textblock-select", TextBlocks.insert); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/**************************************************************/ | ||
/* ICONS | ||
/**************************************************************/ | ||
|
||
#admin-menu a.text-blocks { background-image: url(../images/text_signature.png);} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
en: | ||
|
||
field_text_block_text: Text | ||
|
||
label_select_text_block: "Select text block..." | ||
label_text_block_name: Name | ||
label_text_block_text: Text | ||
label_text_block_plural: Text blocks | ||
label_text_block_new: New text block | ||
|
||
model: | ||
text_block: | ||
name_uniqueness: A text block with that name already exists. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
en: | ||
|
||
field_text_block_text: テンプレート | ||
|
||
label_select_text_block: "テンプレートを選択..." | ||
label_text_block_name: タイトル | ||
label_text_block_text: テンプレート | ||
label_text_block_plural: テンプレート | ||
label_text_block_new: 新しいテンプレート | ||
|
||
model: | ||
text_block: | ||
name_uniqueness: その名前のテンプレートはすでに存在します。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
resources :text_blocks, only: %i(index new create edit update destroy) | ||
|
||
scope 'projects/:project_id' do | ||
resources :text_blocks, only: %i(new create edit update destroy), | ||
as: :project_text_blocks | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class CreateTextBlocks < ActiveRecord::Migration | ||
def change | ||
create_table :text_blocks do |t| | ||
t.string :name | ||
t.text :text | ||
t.references :project, index: true, foreign_key: true | ||
|
||
t.timestamps null: false | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
require 'redmine' | ||
|
||
Rails.configuration.to_prepare do | ||
RedmineTextBlocks.setup | ||
end | ||
|
||
Redmine::Plugin.register :redmine_text_blocks do | ||
name 'Redmine Text Blocks Plugin' | ||
author 'Jens Krämer, Georepublic' | ||
author_url 'https://hub.georepublic.net/gtt/redmine_text_blocks' | ||
description 'Adds configurable text blocks for replying to issues' | ||
version '0.1.0' | ||
|
||
requires_redmine version_or_higher: '3.4.0' | ||
|
||
#settings default: { | ||
#}, partial: 'redmine_text_blocks/settings' | ||
|
||
project_module :text_blocks do | ||
|
||
permission :view_text_blocks, {}, require: :member, read: :true | ||
permission :manage_text_blocks, { | ||
text_blocks: %i( new edit update create destroy ), | ||
projects: %i( manage_text_blocks ) | ||
}, require: :member | ||
end | ||
|
||
menu :admin_menu, :text_blocks, | ||
{ controller: 'text_blocks', action: 'index' }, | ||
caption: :label_text_block_plural, :html => {:class => 'icon'} | ||
|
||
end | ||
|
||
class TextBlocksListener < Redmine::Hook::ViewListener | ||
render_on :view_layouts_base_html_head, inline: <<-END | ||
<%= stylesheet_link_tag 'text_blocks', :plugin => 'redmine_text_blocks' %> | ||
END | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
require 'redmine_text_blocks/view_hooks' | ||
|
||
module RedmineTextBlocks | ||
def self.setup | ||
ProjectsController.send :helper, RedmineTextBlocks::ProjectSettingsTabs | ||
IssuesController.send :helper, TextBlocksHelper | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module RedmineTextBlocks | ||
|
||
# hooks into the helper method that renders the project settings tabs | ||
module ProjectSettingsTabs | ||
|
||
def project_settings_tabs | ||
super.tap do |tabs| | ||
if User.current.allowed_to?(:manage_text_blocks, @project) | ||
tabs << { | ||
name: 'text_blocks', | ||
action: :manage_text_blocks, | ||
partial: 'projects/settings/text_blocks', | ||
label: :label_text_block_plural | ||
} | ||
end | ||
end | ||
end | ||
|
||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module RedmineTextBlocks | ||
class SaveTextBlock | ||
|
||
Result = ImmutableStruct.new :text_block_saved?, :text_block | ||
|
||
def self.call(*_) | ||
new(*_).call | ||
end | ||
|
||
def initialize(params, text_block: TextBlock.new, | ||
project: text_block.project) | ||
@params = params | ||
@text_block = text_block | ||
@project = project | ||
end | ||
|
||
|
||
def call | ||
@text_block.project = @project | ||
@text_block.attributes = @params | ||
|
||
return Result.new text_block_saved: @text_block.save, | ||
text_block: @text_block | ||
end | ||
end | ||
end |
Oops, something went wrong.