Skip to content

Commit

Permalink
Remove all-trackers entry in template filters and clean-up code
Browse files Browse the repository at this point in the history
  • Loading branch information
nanego committed Sep 13, 2023
1 parent 38785d1 commit fa509cf
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 69 deletions.
14 changes: 0 additions & 14 deletions app/views/issue_templates/_filters.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@
<% unless @trackers.blank? %>
<fieldset class="box tabular" id="filters_trackers">
<legend><%= toggle_checkboxes_link('#filters_trackers input[type=checkbox]') %><%= l(:label_tracker_plural) %></legend>
<label class="floating">
<%= check_box_tag 'tracker_ids[]', 0, 1, :id => nil %>
<%= l(:label_tracker_all) %>
<div style="display: inline-block;color: grey;font-size: smaller;" class="counters">
<span class="count-enabled">0</span>/<span class="count-total">0</span>
</div>
</label>
<% @trackers.each do |tracker| %>
<label class="floating">
<%= check_box_tag 'tracker_ids[]', tracker.id, 1, :id => nil %>
Expand Down Expand Up @@ -53,13 +46,6 @@

// Filter by Trackers
var trackers_values = $('#filters_trackers input[type=checkbox]:checked');
var trackers_values_all = $('#filters_trackers input[type=checkbox]');
var trackers_ids = trackers_values.map(function() { return this.value; }).get().join();
// if option (all trackers) is selected
if ($.inArray( "0", trackers_ids) != -1){
trackers_values = trackers_values_all;
}

for(const v of trackers_values){
$('#templates_list .issue_template[data-tracker-id='+v.value+']').each(function(){
templates_to_show_by_trackers.push(this.getAttribute('data-template-id'));
Expand Down
2 changes: 1 addition & 1 deletion lib/redmine_templates/issue_category_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ class IssueCategory

has_many :issue_templates, :class_name => 'IssueTemplate', :foreign_key => 'category_id', :dependent => :nullify

end
end
8 changes: 4 additions & 4 deletions lib/redmine_templates/issue_priority_patch.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
require_dependency 'issue_priority'

class IssuePriority < Enumeration
has_many :issue_templates, :foreign_key => 'priority_id'
has_many :issue_templates, :foreign_key => 'priority_id'
end

module PluginRedmineTemplates
module IssuePriorityPatch
def objects_count
count = super
count = super
count + issue_templates.count
end

def transfer_relations(to)
super
issue_templates.update_all(:priority_id => to.id)
issue_templates.update_all(priority_id: to.id)
end

end
end

IssuePriority.prepend PluginRedmineTemplates::IssuePriorityPatch
IssuePriority.prepend PluginRedmineTemplates::IssuePriorityPatch
4 changes: 2 additions & 2 deletions lib/redmine_templates/issue_status_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class IssueStatus
before_destroy :set_default_status_id_in_issue_templates

def set_default_status_id_in_issue_templates
IssueTemplate.where('status_id = ?', id).update_all('status_id = 0')
IssueTemplate.where('status_id = ?', id).update_all('status_id = 0')
end

end
end
6 changes: 4 additions & 2 deletions lib/redmine_templates/tracker_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
class Tracker

has_many :issue_templates

before_destroy :set_default_tracker_id_in_issue_templates

def set_default_tracker_id_in_issue_templates
IssueTemplate.where('tracker_id = ?', id).update_all('tracker_id = 0')
IssueTemplate.where(tracker_id: id).update_all(tracker_id: 0)
end
end

end
8 changes: 5 additions & 3 deletions lib/redmine_templates/typology_patch.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
require_dependency "enumeration"

class Typology < Enumeration
has_many :issue_templates, :dependent => :nullify
end
class Typology < Enumeration

has_many :issue_templates, :dependent => :nullify

end
6 changes: 3 additions & 3 deletions lib/redmine_templates/user_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ module UserPatch
def remove_references_before_destroy
super
substitute = User.anonymous
IssueTemplate.where(['assigned_to_id = ?', id]).update_all('assigned_to_id = NULL')
IssueTemplate.where(['author_id = ?', id]).update_all(['author_id = ?', substitute.id])
IssueTemplate.where(assigned_to_id: id).update_all(assigned_to_id: nil)
IssueTemplate.where(author_id: id).update_all(author_id: substitute.id)
end
end
end

User.prepend PluginRedmineTemplates::UserPatch
User.prepend PluginRedmineTemplates::UserPatch
2 changes: 1 addition & 1 deletion spec/controllers/projects_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
}
end
new_project = Project.find('copy-with-templates')
assert_equal source_project.issue_templates, new_project.issue_templates, "All issue_templates were not copied"
expect(source_project.issue_templates.sort).to eq new_project.issue_templates.sort

expect(IssueTemplateProject.where(issue_template_id: 1, project_id: new_project.id).first.visibility).to eq('1|3')
expect(IssueTemplateProject.where(issue_template_id: 4, project_id: new_project.id).first.visibility).to eq('1')
Expand Down
77 changes: 38 additions & 39 deletions spec/models/issue_template_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

describe "IssueTemplate" do
fixtures :projects, :users, :members, :member_roles, :roles,
:trackers, :issue_statuses, :projects_trackers
:trackers, :issue_statuses, :projects_trackers

include Redmine::I18n

Expand Down Expand Up @@ -105,24 +105,24 @@

it "shouldn't save section with no title" do
template = IssueTemplate.new(:project_id => 1,
:tracker_id => 1,
:status_id => 1,
:author_id => 2,
:subject => 'test_create',
:template_title => 'New title template',
:template_enabled => true,
:template_project_ids => [1],
:section_groups_attributes => [{
:title => "Section group title",
:position => 1,
sections_attributes: [
{
:title => nil,
:description => "Section description",
:type => "IssueTemplateSectionTextArea",
:position => 1 }
]
}]
:tracker_id => 1,
:status_id => 1,
:author_id => 2,
:subject => 'test_create',
:template_title => 'New title template',
:template_enabled => true,
:template_project_ids => [1],
:section_groups_attributes => [{
:title => "Section group title",
:position => 1,
sections_attributes: [
{
:title => nil,
:description => "Section description",
:type => "IssueTemplateSectionTextArea",
:position => 1 }
]
}]
)
expect(template.valid?).to eq false
expect(template.save).to eq false
Expand Down Expand Up @@ -252,20 +252,19 @@
context "Update relationship tables on cascading delete" do
let(:template_test) {
template_test = IssueTemplate.create(:project_id => 1,
:tracker_id => 1,
:status_id => 1,
:author_id => 2 ,
:subject => 'test_create',
:description => 'IssueTest#test_create',
:template_title => 'New title template',
:template_enabled => true,
:template_project_ids => [1]
)}
:tracker_id => 1,
:status_id => 1,
:author_id => 2,
:subject => 'test_create',
:description => 'IssueTest#test_create',
:template_title => 'New title template',
:template_enabled => true,
:template_project_ids => [1]
) }

it "when deleting a tracker" do

tracker_test = Tracker.create!(:name => 'Test', :default_status_id => 1)
template_test.tracker_id = Tracker.last.id
template_test.tracker_id = tracker_test.id
template_test.save
tracker_test.destroy

Expand All @@ -275,7 +274,7 @@

it "when deleting a issue status" do
status_test = IssueStatus.create!(:name => 'Test')
template_test.status_id = IssueStatus.last.id
template_test.status_id = status_test.id
template_test.save
status_test.destroy

Expand All @@ -286,7 +285,7 @@
it "when deleting a issue category" do
category_test = IssueCategory.create(project: Project.find(1), name: "To Be Removed Issue Category")
template_test.category_id = category_test.id
template_test.save
template_test.save
category_test.destroy
template_test.reload

Expand All @@ -295,7 +294,7 @@

it "when deleting a author user" do
user_test = User.create(:login => "test", :firstname => 'test', :lastname => 'test',
:mail => 'test.test@test.fr', :language => 'fr')
:mail => 'test.test@test.fr', :language => 'fr')
template_test.author_id = user_test.id
template_test.save

Expand All @@ -306,7 +305,7 @@

it "when deleting a assigne_to user" do
user_test = User.create(:login => "test", :firstname => 'test', :lastname => 'test',
:mail => 'test.test@test.fr', :language => 'fr')
:mail => 'test.test@test.fr', :language => 'fr')
template_test.assigned_to_id = user_test.id
template_test.save

Expand All @@ -315,13 +314,13 @@
expect(template_test.assigned_to_id).to be_nil
end

it "calculate issue_templates in the method objects_count" do
it "calculate issue_templates in the method objects_count" do
priority_test = IssuePriority.all[5]
expect(priority_test.objects_count).to eq(0)

template_test.priority_id = priority_test.id
template_test.save
#Since there are objects_count is greater than 0, it does not accept removing priority
# Since there are objects_count is greater than 0, it does not accept removing priority
expect(priority_test.issue_templates.count).to eq(1)
expect(priority_test.issues.count).to eq(0)
expect(priority_test.objects_count).to eq(1)
Expand All @@ -338,6 +337,6 @@
expect(template_test.typology_id).to be_nil
end
end
end

end
end

0 comments on commit fa509cf

Please sign in to comment.