mirror of
https://github.com/dolphin-emu/redmine_issue_templates.git
synced 2024-11-27 03:20:23 +00:00
Add feature for inherit issue templates. (IssueID: #985)
This commit is contained in:
parent
773e0fedcb
commit
148cbcd050
@ -24,7 +24,18 @@ class IssueTemplatesController < ApplicationController
|
||||
@issue_templates = IssueTemplate.where('project_id = ?',
|
||||
@project.id).order('position')
|
||||
|
||||
render :template => 'issue_templates/index.html.erb', :layout => !request.xhr?
|
||||
@setting = IssueTemplateSetting.find_or_create(@project.id)
|
||||
inherit_template = @setting.enabled_inherit_templates?
|
||||
@inherit_templates = nil
|
||||
|
||||
project_ids = inherit_template ? @project.ancestors.collect(&:id) : [@project.id]
|
||||
if inherit_template
|
||||
@inherit_templates = IssueTemplate.where('project_id in (?) AND enabled = ?
|
||||
AND enabled_sharing = ?',
|
||||
project_ids, true, true).order('position')
|
||||
end
|
||||
|
||||
render :template => 'issue_templates/index.html.erb', :layout => !request.xhr?
|
||||
end
|
||||
|
||||
def show
|
||||
@ -73,15 +84,29 @@ class IssueTemplatesController < ApplicationController
|
||||
|
||||
# update pulldown
|
||||
def set_pulldown
|
||||
@setting = IssueTemplateSetting.find_or_create(@project.id)
|
||||
inherit_template = @setting.enabled_inherit_templates?
|
||||
|
||||
project_ids = inherit_template ? @project.ancestors.collect(&:id) : [@project.id]
|
||||
issue_templates = IssueTemplate.where('project_id = ? AND tracker_id = ? AND enabled = ?',
|
||||
@project.id, @tracker.id, true).order('position')
|
||||
|
||||
@grouped_options = []
|
||||
group = []
|
||||
|
||||
@default_template = IssueTemplate.where('project_id = ? AND tracker_id = ? AND enabled = ? AND is_default = ?',
|
||||
@default_template = IssueTemplate.where('project_id = ? AND tracker_id = ? AND enabled = ?
|
||||
AND is_default = ?',
|
||||
@project.id, @tracker.id, true, true).first
|
||||
if issue_templates.size > 0
|
||||
issue_templates.each { |x| group.push([x.title, x.id]) }
|
||||
|
||||
if inherit_template
|
||||
inherit_templates = IssueTemplate.where('project_id in (?) AND tracker_id = ? AND enabled = ?
|
||||
AND enabled_sharing = ?',
|
||||
project_ids, @tracker.id, true, true).order('position')
|
||||
inherit_templates.each { |x| group.push([x.title, x.id]) }
|
||||
end
|
||||
|
||||
@grouped_options.push([@tracker.name, group])
|
||||
end
|
||||
render :action => "_template_pulldown", :layout => false
|
||||
|
@ -7,7 +7,9 @@ class IssueTemplatesSettingsController < ApplicationController
|
||||
if params[:settings] != nil
|
||||
@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])
|
||||
@issue_templates_setting.update_attributes(:enabled => attribute[:enabled],
|
||||
:help_message => attribute[:help_message],
|
||||
:inherit_templates => attribute[:inherit_templates])
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
redirect_to :controller => 'projects',
|
||||
:action => "settings", :id => @project, :tab => 'issue_templates'
|
||||
|
@ -12,7 +12,8 @@ class IssueTemplate < ActiveRecord::Base
|
||||
acts_as_list :scope => :tracker
|
||||
|
||||
# author and project should be stable.
|
||||
safe_attributes 'title', 'description', 'tracker_id', 'note', 'enabled', 'issue_title','is_default'
|
||||
safe_attributes 'title', 'description', 'tracker_id', 'note', 'enabled', 'issue_title','is_default',
|
||||
'enabled_sharing','visible_children'
|
||||
def enabled?
|
||||
self.enabled == true
|
||||
end
|
||||
|
@ -6,7 +6,7 @@ class IssueTemplateSetting < ActiveRecord::Base
|
||||
validates_uniqueness_of :project_id
|
||||
validates_presence_of :project_id
|
||||
|
||||
safe_attributes 'help_message', 'enabled'
|
||||
safe_attributes 'help_message', 'enabled', 'inherit_templates'
|
||||
|
||||
def self.find_or_create(project_id)
|
||||
setting = IssueTemplateSetting.find(:first, :conditions => ['project_id = ?', project_id])
|
||||
@ -24,4 +24,11 @@ class IssueTemplateSetting < ActiveRecord::Base
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
def enabled_inherit_templates?
|
||||
if self.inherit_templates == true
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
@ -69,5 +69,38 @@
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<% unless @inherit_templates.blank? %>
|
||||
<h3 class="template"><%=h "#{l(:label_inherited_templates)}" %></h3>
|
||||
|
||||
<table class="list issues">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>#</th>
|
||||
<th><%= l(:issue_template_name) %></th>
|
||||
<th><%= l(:field_tracker) %></th>
|
||||
<th><%= l(:field_author) %></th>
|
||||
<th><%= l(:field_updated_on) %></th>
|
||||
<th><%= l(:field_is_default) %></th>
|
||||
<th><%= l(:label_enabled) %></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @inherit_templates.each do |issue_template| %>
|
||||
<tr class="<%= cycle("odd", "even") %> issue_template issue">
|
||||
<td><%= link_to h(issue_template.id), {:controller => 'issue_templates',
|
||||
:action => 'show', :id => issue_template.id,
|
||||
:project_id => issue_template.project_id }, {:title => issue_template.note } %></td>
|
||||
|
||||
<td><%= issue_template.title %></td>
|
||||
<td><%=h issue_template.tracker.name %></td>
|
||||
<td><%=h issue_template.author %></td>
|
||||
<td><%= format_time(issue_template.updated_on)%> </td>
|
||||
<td class="center"><%= checked_image issue_template.is_default? %></td>
|
||||
<td class="center"><%= checked_image issue_template.enabled? %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
<% end %>
|
@ -65,6 +65,9 @@
|
||||
<p><label><%= l(:label_enabled) %></label>
|
||||
<%= checked_image @issue_template.enabled? %>
|
||||
</p>
|
||||
<p><label><%= l(:label_enabled_sharing) %></label>
|
||||
<%= checked_image @issue_template.enabled_sharing? %>
|
||||
</p>
|
||||
|
||||
<p><label><%= l(:field_author) %></label>
|
||||
<%= authoring @issue_template.created_on, @issue_template.author %>
|
||||
|
@ -15,11 +15,18 @@
|
||||
:html => {:id => 'issue_templates_settings' } do |f| %>
|
||||
<%= error_messages_for 'issue_templates_setting' %>
|
||||
<div class="box tabular">
|
||||
|
||||
<p><%= f.check_box :inherit_templates, :label => l(:label_inherit_templates) %>
|
||||
<a class="icon icon-help" href="#" title="<%= l(:help_for_this_field) %>"
|
||||
onclick="checkExpand('inherit_templates_help_content'); return false;"><%= l(:help_for_this_field) %>
|
||||
</a><br/>
|
||||
<span id="inherit_templates_help_content" class="help_content" style="display: none;"><%= l(:label_inherit_templates_help_message) %></span>
|
||||
</p>
|
||||
<p><%= f.check_box :enabled, :label => l(:label_show_help_message) %></p>
|
||||
<p><label><%=l(:label_help_message)%></label>
|
||||
<%=content_tag(:label, l(:label_help_message)) %>
|
||||
<%=text_area_tag 'settings[help_message]', @issue_templates_setting['help_message'], :size =>"50x5",
|
||||
:class => 'wiki-edit' ,:required => true %><br/>
|
||||
:class => 'wiki-edit' %><br/>
|
||||
<%= wikitoolbar_for "settings_help_message" %>
|
||||
<%= preview_link url_for(:controller => 'issue_templates_settings', :action => 'preview',
|
||||
:project_id => @project),
|
||||
@ -30,4 +37,12 @@
|
||||
<%= submit_tag l(:button_save) %>
|
||||
<% end %>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
//<![CDATA[
|
||||
function checkExpand(ch) {
|
||||
var obj=document.all && document.all(ch) || document.getElementById && document.getElementById(ch);
|
||||
if(obj && obj.style) obj.style.display=
|
||||
"none" == obj.style.display ?"" : "none"
|
||||
}
|
||||
</script>
|
||||
|
||||
|
@ -26,4 +26,7 @@ en:
|
||||
label_isdefault_help_message: "Check and you can use this as a default template of target tracker."
|
||||
defaulf_template_loaded: "Loaded default template into description textarea. (Tracker: %{tracker})"
|
||||
text_no_tracker_enabled: "Any trackers for this project have not been configured yet.\nPlease set them first because templates are assigned to project trackers. "
|
||||
label_enabled_sharing: "Enabled sharing with project tree."
|
||||
label_enabled_sharing: "Enabled sharing with project tree."
|
||||
label_inherit_templates: "Inherit templates"
|
||||
label_inherit_templates_help_message: "Inherit templates from parent project. (Only parent's templates are listed which marked as enabled sharing with project tree.)"
|
||||
label_inherited_templates: "Inherited Templates"
|
@ -26,4 +26,7 @@ ja:
|
||||
label_isdefault_help_message: "デフォルト値にチェックすると、チケットの新規登録時に、該当するトラッカーのテンプレートとして読み込まれます。"
|
||||
defaulf_template_loaded: "デフォルトテンプレートが「詳細」テキストエリアにロードされました。(トラッカー: %{tracker})"
|
||||
text_no_tracker_enabled: "テンプレートはトラッカー毎に設定します。\nプロジェクトが利用するトラッカーの設定が必要です。"
|
||||
label_enabled_sharing: "プロジェクトツリーでの共有を許可"
|
||||
label_enabled_sharing: "プロジェクトツリーでの共有を許可"
|
||||
label_inherit_templates: "親プロジェクトのテンプレートを継承"
|
||||
label_inherit_templates_help_message: "親プロジェクトのテンプレートを継承します。ただし、親プロジェクトのテンプレートで、プロジェクトツリーでの利用を許可しているものに限られます。"
|
||||
label_inherited_templates: "継承されたテンプレート"
|
@ -0,0 +1,9 @@
|
||||
class AddEnabledSharingToIssueTemplates < ActiveRecord::Migration
|
||||
def self.up
|
||||
add_column :issue_templates, :enabled_sharing, :boolean, :default => false
|
||||
end
|
||||
|
||||
def self.down
|
||||
remove_column :issue_templates, :enabled_sharing
|
||||
end
|
||||
end
|
@ -0,0 +1,9 @@
|
||||
class AddInheritTemplatesToIssueTemplateSettings < ActiveRecord::Migration
|
||||
def self.up
|
||||
add_column :issue_template_settings, :inherit_templates, :boolean, :default => false, :null => false
|
||||
end
|
||||
|
||||
def self.down
|
||||
remove_column :issue_template_settings, :inherit_templates
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user