Skip to content
This repository has been archived by the owner on Jan 23, 2021. It is now read-only.

Commit

Permalink
Merge pull request #301 from akiko-pusu/develop
Browse files Browse the repository at this point in the history
Release v0.3.7
  • Loading branch information
akiko-pusu authored Dec 9, 2019
2 parents 822b980 + 5ed9855 commit 489e4ae
Show file tree
Hide file tree
Showing 18 changed files with 88 additions and 64 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,16 @@ If you have any requests, bug reports, please use GitHub issues. <https://github

## Changelog

### 0.3.7

This is bugfix release to prevent the conflict with other plugins.

* Bugfix: Tooltip for template body preview is hidden. (GitHub PR #300)
* Refactor: Change to use project menu to prevent the project setting tab's conflict. (GitHub PR #299)

Thank you for the valuable information and feedback, @ChrisUHZ!


### 0.3.6

This is bugfix release against v0.3.5.
Expand Down
11 changes: 8 additions & 3 deletions app/controllers/issue_templates_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
# noinspection ALL
class IssueTemplatesController < ApplicationController
layout 'base'
Expand Down Expand Up @@ -64,7 +65,7 @@ def update
def load
issue_template_id = params[:template_id]
template_type = params[:template_type]
issue_template = if !template_type.blank? && template_type == 'global'
issue_template = if template_type.present? && template_type == 'global'
GlobalIssueTemplate.find(issue_template_id)
else
IssueTemplate.find(issue_template_id)
Expand Down Expand Up @@ -97,8 +98,8 @@ def set_pulldown
def list_templates
(default_global, default_inherit, default_project) = default_templates

default_template = default_inherit.present? ? default_inherit : default_global
default_template = default_project.present? ? default_project : default_template
default_template = default_inherit.presence || default_global
default_template = default_project.presence || default_template

respond_to do |format|
format.html do
Expand All @@ -119,6 +120,10 @@ def list_templates
end
end

def menu_items
{ issue_templates: { default: :issue_templates, actions: {} } }
end

# preview
def preview
issue_template = params[:issue_template]
Expand Down
23 changes: 17 additions & 6 deletions app/controllers/issue_templates_settings_controller.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
# frozen_string_literal: true

# noinspection RubocopInspection
class IssueTemplatesSettingsController < ApplicationController
before_action :find_project, :find_user
before_action :authorize, except: %i[show_help preview]
before_action :authorize, except: %i[preview]

def index
@issue_templates_setting = IssueTemplateSetting.find_or_create(@project.id)
end

def edit
@issue_templates_setting = IssueTemplateSetting.find(@project.id)
return if params[:settings].blank?

update_template_setting
flash[:notice] = l(:notice_successful_update)
redirect_to controller: 'projects', action: 'settings', id: @project, tab: 'issue_templates'
redirect_to action: 'index', project_id: @project
end

def preview
@text = params[:settings][:help_message]
render partial: 'common/preview'
end

def menu_items
{ issue_templates_settings: { default: :issue_templates, actions: {} } }
end

private

def find_user
Expand All @@ -31,9 +42,9 @@ def find_project
def update_template_setting
issue_templates_setting = IssueTemplateSetting.find_or_create(@project.id)
attribute = params[:settings]
issue_templates_setting.update_attributes(enabled: attribute[:enabled],
help_message: attribute[:help_message],
inherit_templates: attribute[:inherit_templates],
should_replaced: attribute[:should_replaced])
issue_templates_setting.update(enabled: attribute[:enabled],
help_message: attribute[:help_message],
inherit_templates: attribute[:inherit_templates],
should_replaced: attribute[:should_replaced])
end
end
4 changes: 4 additions & 0 deletions app/controllers/note_templates_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ def destroy
redirect_to action: 'index', project_id: @project
end

def menu_items
{ note_templates: { default: :issue_templates, actions: {} } }
end

private

def find_object
Expand Down
9 changes: 8 additions & 1 deletion app/views/common/_template_links.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div style="display: flex; float: right; padding-top: 20px;
<div style="display: flex; float: right; padding-top: 40px;
position: relative; bottom: 6px; right: 0;">
<div class="template_link_area">
<label><%= l(:issue_template) %>: </label>
Expand All @@ -20,4 +20,11 @@
{ controller: 'note_templates', action: 'new', project_id: @project },
class: 'icon icon-add') %>
</div>

<div class="template_link_area">
<label><%= l(:issue_templates_optional_settings, default: 'Templates Optional Settings') %>: </label>
<%= link_to_if_authorized(l(:label_settings, default: 'Settings'),
{ controller: 'issue_templates_settings', action: 'index', project_id: @project },
class: 'icon icon-settings') %>
</div>
</div>
1 change: 1 addition & 0 deletions app/views/issue_templates/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@
<% end %>
<% end %>

<div style="float: right;"><%= render partial: "common/template_links" %></div>
2 changes: 2 additions & 0 deletions app/views/issue_templates/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,5 @@
</p>

</div>

<%= render partial: "common/template_links" %>
Original file line number Diff line number Diff line change
@@ -1,36 +1,14 @@
<div id="issue_templates_settings">
<%= render partial: "common/nodata", locals: { trackers: @project.trackers } %>

<h2 class="issue_template_setting"><%= l(:link_to_index_edit_template) %></h2>
<div style="display: flex;">
<div class="template_link_area">
<label><%= l(:issue_template) %>: </label>
<%= link_to(l(:label_list_templates),
{ controller: 'issue_templates',
action: 'index',
project_id: @project}, class: 'icon icon-template') %> |
<%= link_to_if_authorized(l(:label_new_templates),
{ controller: 'issue_templates', action: 'new', project_id: @project },
class: 'icon icon-add') %>
</div>
<div class="template_link_area">
<label><%= l(:note_template) %>: </label>
<%= link_to(l(:label_list_templates),
{ controller: 'note_templates',
action: 'index',
project_id: @project}, class: 'icon icon-template') %> |
<%= link_to_if_authorized(l(:label_new_templates),
{ controller: 'note_templates', action: 'new', project_id: @project },
class: 'icon icon-add') %>
</div>
</div>
<h2 class="issue_template_setting"><%= l(:issue_templates_settings, default: 'Issue Templates Setting') %></h2>
<p></p>
<div class="template_box">
<h2>Optional settings</h2>
<h2><%= l(:issue_templates_optional_settings, default: 'Templates Optional Settings') %></h2>
<p><%= l(:about_help_message) %></p>
<%= labelled_form_for :settings, @issue_templates_setting,
url: { controller: 'issue_templates_settings',
action: 'edit', project_id: @project, tab: 'issue_templates',
action: 'edit', project_id: @project,
setting_id: @issue_templates_setting.id },
html: { id: 'issue_templates_settings' } do |f| %>
<%= error_messages_for 'issue_templates_setting' %>
Expand Down Expand Up @@ -82,3 +60,4 @@
<!--- help content -->
</div>

<div style="float: right;"><%= render partial: "common/template_links" %></div>
1 change: 1 addition & 0 deletions app/views/note_templates/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@
<% end %>
<% end %>

<%= render partial: "common/template_links" %>
2 changes: 2 additions & 0 deletions app/views/note_templates/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,5 @@
</p>

</div>

<%= render partial: "common/template_links" %>
7 changes: 7 additions & 0 deletions assets/stylesheets/issue_templates.css
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,16 @@ a.template_tooltip {
font-style: italic;
}

table.list {
overflow: overlay;
border: 2px solid #e4e4e4;
}

table.list.template_list {
width: 480px;
margin: 8px 0;
border: 2px solid #e4e4e4;
overflow: overlay;
}

td.template_title {
Expand Down
2 changes: 2 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,5 @@ en:
roles: to these roles only
open: to any users
please_select_at_least_one_role: "Please select at least one role."
issue_templates_settings: Issue Templates Setting
issue_templates_optional_settings: Templates Optional Settings
2 changes: 2 additions & 0 deletions config/locales/ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,5 @@ ja:
roles: 次のロールのみ
open: すべてのユーザー
please_select_at_least_one_role: 1つ以上のロールを指定してください。
issue_templates_settings: チケットテンプレート設定
issue_templates_optional_settings: テンプレートオプション設定
4 changes: 3 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
get 'list_templates', on: :collection
end

resources :issue_templates_settings, only: [], concerns: [:previewable] do
resources :issue_templates_settings, only: [:edit], concerns: [:previewable] do
patch 'edit', on: :collection
end

get 'issue_templates_settings', to: 'issue_templates_settings#index'

resources :note_templates, except: [:edit]
end

Expand Down
15 changes: 12 additions & 3 deletions init.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# Redmine Issue Template Plugin
#
# This is a plugin for Redmine to generate and use issue templates
Expand All @@ -21,7 +23,6 @@
require 'redmine'
require 'issue_templates/issues_hook'
require 'issue_templates/journals_hook'
require 'issue_templates/projects_helper_patch'

# NOTE: Keep error message for a while to support Redmine3.x users.
def issue_template_version_message(original_message = nil)
Expand All @@ -37,12 +38,16 @@ def issue_template_version_message(original_message = nil)
USAGE
end

def template_menu_allowed?
proc { |p| User.current.allowed_to?({ controller: 'issue_templates', action: 'show' }, p) }
end

Redmine::Plugin.register :redmine_issue_templates do
begin
name 'Redmine Issue Templates plugin'
author 'Akiko Takano'
description 'Plugin to generate and use issue templates for each project to assist issue creation.'
version '0.3.6'
version '0.3.7'
author_url 'http://twitter.com/akiko_pusu'
requires_redmine version_or_higher: '4.0'
url 'https://github.com/akiko-pusu/redmine_issue_templates'
Expand All @@ -56,11 +61,15 @@ def issue_template_version_message(original_message = nil)
menu :admin_menu, :redmine_issue_templates, { controller: 'global_issue_templates', action: 'index' },
caption: :global_issue_templates, html: { class: 'icon icon-global_issue_templates' }

menu :project_menu, :issue_templates, { controller: 'issue_templates', action: 'index' },
caption: :issue_templates, param: :project_id,
after: :settings, if: template_menu_allowed?

project_module :issue_templates do
permission :edit_issue_templates, issue_templates: %i[new create edit update destroy move], note_templates: %i[new create edit update destroy move]
permission :show_issue_templates, issue_templates: %i[index show load set_pulldown list_templates orphaned_templates],
note_templates: %i[index show load list_templates]
permission :manage_issue_templates, { issue_templates_settings: %i[show edit] }, require: :member
permission :manage_issue_templates, { issue_templates_settings: %i[index edit] }, require: :member
end
rescue ::Redmine::PluginRequirementError => e
raise ::Redmine::PluginRequirementError.new(issue_template_version_message(e.message)) # rubocop:disable Style/RaiseArgs
Expand Down
20 changes: 0 additions & 20 deletions lib/issue_templates/projects_helper_patch.rb

This file was deleted.

4 changes: 2 additions & 2 deletions test/functional/issue_templates_settings_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ def test_update_with_permission_and_redirect
settings: { enabled: '1', help_message: 'Hoo', project_id: 2, inherit_templates: true },
setting_id: 1, tab: 'issue_templates' }
assert_response :redirect
assert_redirected_to controller: 'projects',
action: 'settings', id: @project, tab: 'issue_templates'
assert_redirected_to controller: 'issue_templates_settings',
action: 'index', project_id: @project
end

def test_preview_template_setting
Expand Down
6 changes: 3 additions & 3 deletions test/functional/projects_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ class ProjectsControllerTest < Redmine::ControllerTest
def setup
# as project admin
@request.session[:user_id] = 2
Role.find(1).add_permission! :manage_issue_templates
Role.find(1).add_permission! :show_issue_templates
# Enabled Template module
@project = Project.find(1)
@project.enabled_modules << EnabledModule.new(name: 'issue_templates')
@project.save!
end

def test_settings
get :settings, params: { id: 1 }
get :show, params: { id: 1 }
assert_response :success
assert_select 'a#tab-issue_templates'
assert_select '#main-menu > ul > li > a.issue-templates'
end
end

0 comments on commit 489e4ae

Please sign in to comment.