Project

General

Profile

Feature #2009 » manually_add_remove_related_changesets-new-r3764.patch

Patch created against trunk@r3764 - Mischa The Evil, 2010-06-01 02:07

View differences:

app/helpers/changeset_relations_helper.rb (revision 0)
1
module ChangesetRelationsHelper
2
end
app/controllers/changeset_relations_controller.rb (revision 0)
1
class ChangesetRelationsController < ApplicationController
2
  
3
  
4
  before_filter  :find_project, :authorize
5
  
6
  def new
7
    @changeset = Changeset.find(:first, :conditions => {:revision => params[:changeset][:revision], :repository_id => @project.repository})
8
    if @changeset.nil?
9
      @changeset = Changeset.new(:revision => params[:changeset][:revision])
10
      @changeset.errors.add('revision_not_found_error', '')
11
    else
12
      @changeset.issues << @issue
13
      @changeset.save if request.post?
14
    end
15
    @issue.reload
16
    respond_to do |format|
17
      format.html { redirect_to :controller => 'issues', :action => 'show', :id => @issue }
18
      format.js do
19
        render :update do |page|
20
          page.replace_html "issue-changesets-list", :partial => 'issues/changesets', :locals => { :changesets => @issue.changesets }
21
          if @changeset.errors.empty?
22
            page << "$('changeset_revision').value = ''"
23
          end
24
        end
25
      end
26
    end
27
  end
28
  
29
  def destroy
30
    changeset = Changeset.find(params[:id])
31
    if request.post? && ! changeset.nil? && changeset.issues.include?(@issue)
32
      changeset.issues.delete(@issue)
33
      @issue.reload
34
    end
35
    respond_to do |format|
36
      format.html { redirect_to :controller => 'issues', :action => 'show', :id => @issue }
37
      format.js do
38
        render(:update) do |page|
39
          page.replace_html "issue-changesets-list", :partial => 'issues/changesets', :locals => { :changesets => @issue.changesets }
40
        end
41
      end
42
    end
43
  end
44
  
45
  
46
  private
47
  
48
  def find_project
49
    @issue = Issue.find(params[:issue_id])
50
    @project = @issue.project
51
  rescue ActiveRecord::RecordNotFound
52
    render_404
53
  end
54
  
55
end
app/views/changeset_relations/_form.html.erb (revision 0)
1
<%= error_messages_for 'changeset' %>
2

  
3
<p><%= l(:label_revision) %> <%= f.text_field :revision, :size => 6 %>
4
  <%= submit_tag l(:button_add) %>
5
  <%= toggle_link l(:button_cancel), 'new-changeset-form'%>
6
</p>
7

  
8
<%= javascript_tag "setPredecessorFieldsVisibility();" %>
app/views/issues/show.rhtml (working copy)
79 79

  
80 80
</div>
81 81

  
82
<% if @changesets.present? %>
83
<div id="issue-changesets">
84
<h3><%=l(:label_associated_revisions)%></h3>
85
<%= render :partial => 'changesets', :locals => { :changesets => @changesets} %>
86
</div>
82
<% if !@project.repository.nil? && (@changesets.present? || authorize_for('changeset_relations', 'new')) %>
83
  <div id="issue-changesets">
84
    <div class="contextual">
85
      <% if authorize_for('changeset_relations', 'new') %>
86
        <%= toggle_link l(:button_add), 'new-changeset-form'%>
87
      <% end %>
88
    </div>
89
    <h3><%=l(:label_associated_revisions)%></h3>
90
    <div id="issue-changesets-list">
91
      <%= render :partial => 'changesets', :locals => { :changesets => @changesets } %>
92
    </div>
93
  </div>
87 94
<% end %>
88 95

  
89 96
<% if @journals.present? %>
app/views/issues/_changesets.rhtml (working copy)
1
<% changesets.each do |changeset| %>
1
<% remote_form_for(:changeset, @changeset,
2
                 :url => {:controller => 'changeset_relations', :action => 'new', :issue_id => @issue},
3
                 :method => :post,
4
                 :html => {:id => 'new-changeset-form', :style => (@changeset ? '' : 'display: none;')}) do |f| %>
5
<%= render :partial => 'changeset_relations/form', :locals => {:f => f}%>
6
<% end %>
7

  
8
<% if !changesets.empty? %>
9
  <% changesets.each do |changeset| %>
2 10
    <div class="changeset <%= cycle('odd', 'even') %>">
3 11
    <p><%= link_to("#{l(:label_revision)} #{changeset.revision}",
4
                :controller => 'repositories', :action => 'revision', :id => changeset.project, :rev => changeset.revision) %><br />
5
        <span class="author"><%= authoring(changeset.committed_on, changeset.author) %></span></p>
12
                :controller => 'repositories', :action => 'revision', :id => changeset.project, :rev => changeset.revision) %>
13
       <span class="contextual">
14
       <%= link_to_remote(image_tag('delete.png'), { :url => {:controller => 'changeset_relations', :action => 'destroy', :issue_id => @issue, :id => changeset},
15
                                                     :method => :post
16
                                                   }, :title => l(:label_changeset_delete)) if authorize_for('changeset_relations', 'destroy') %>
17
       </span>
18
       <br />
19
       <span class="author"><%= authoring(changeset.committed_on, changeset.author) %></span></p>
6 20
    <%= textilizable(changeset, :comments) %>
7 21
    </div>
22
  <% end %>
8 23
<% end %>
db/migrate/20100531224709_add_manage_changeset_relations_permission.rb (revision 0)
1
class AddManageChangesetRelationsPermission < ActiveRecord::Migration
2
  def self.up
3
    Role.find(:all).each do |r|
4
      r.add_permission!(:manage_changeset_relations) if r.has_permission?(:manage_issue_relations)
5
    end
6
  end
7

  
8
  def self.down
9
    Role.find(:all).each do |r|
10
      r.remove_permission!(:manage_changeset_relations)
11
    end
12
  end
13
end
config/locales/en.yml (working copy)
900 900
  enumeration_doc_categories: Document categories
901 901
  enumeration_activities: Activities (time tracking)
902 902
  enumeration_system_activity: System Activity
903

  
903
  
904
  label_changeset_delete: Delete associated revision
905
  field_revision_not_found_error: Revision not found in project repository
lib/redmine.rb (working copy)
65 65
    map.permission :add_issues, {:issues => [:new, :create, :update_form]}
66 66
    map.permission :edit_issues, {:issues => [:edit, :update, :reply, :bulk_edit, :update_form]}
67 67
    map.permission :manage_issue_relations, {:issue_relations => [:new, :destroy]}
68
    map.permission :manage_changeset_relations, {:changeset_relations => [:new, :destroy]}
68 69
    map.permission :manage_subtasks, {}
69 70
    map.permission :add_issue_notes, {:issues => [:edit, :update, :reply]}
70 71
    map.permission :edit_issue_notes, {:journals => :edit}, :require => :loggedin
public/stylesheets/application.css (working copy)
285 285
fieldset#filters td.add-filter { text-align: right; vertical-align: top; }
286 286
.buttons { font-size: 0.9em; margin-bottom: 1.4em; margin-top: 1em; }
287 287

  
288
div#issue-changesets {float:right; width:45%; margin-left: 1em; margin-bottom: 1em; background: #fff; padding-left: 1em; font-size: 90%;}
288
div#issue-changesets {float:right; width:45%; margin-left: 1em; margin-bottom: 0em; background: #fff; padding-left: 1em; font-size: 90%;}
289 289
div#issue-changesets .changeset { padding: 4px;}
290 290
div#issue-changesets .changeset { border-bottom: 1px solid #ddd; }
291 291
div#issue-changesets p { margin-top: 0; margin-bottom: 1em;}
(13-13/14)