Project

General

Profile

Feature #5893 » HOW_TO.txt

HOW TO - Simon RES, 2011-03-30 14:54

 
1
--------------------------------------------------------------------------------
2
--    HOW TO add a private/public field for journals in Redmine with Linux    --
3
--------------------------------------------------------------------------------
4

    
5
This how-to will show you now to add a private/public field in the journals database to hide or show some journals.
6

    
7
STEP 1 : Add a new column in the MySQL DB
8
-----------------------------------------
9

    
10
First we have to add a column in the journals' table in the database.
11
First go to Redmine installation directory (e.g. cd /opt/redmine-1.1.2-1/) as root. When run this command to enter the MySQL monitor :
12
# mysql -h localhost -p[password] -u[user] bitnami_redmine
13
Then enter this command to add a column in the journals' table :
14
mysql> ALTER TABLE journals ADD is_public tinyint(1) DEFAULT 1;
15
The result should be stg like that :
16
Query OK, 121 rows affected (0.03 sec)
17
Records: 121  Duplicates: 0  Warnings: 0
18

    
19
You can press ^C to exit.
20

    
21

    
22
STEP 2 : Add checkboxes in some forms
23
-------------------------------------
24

    
25
Now we can add another field in the forms.
26

    
27
Step 2.1 : Add a checkbox in the form witch creates journals
28
............................................................
29

    
30
Open the file app/views/issues/_edit.rhtml. You can add this code where you want, e.g. line 42 :
31
<label style="float:right;"><%= check_box_tag 'is_public' %> Is public</label>
32

    
33
Step 2.2 : Add a checkbox in the form witch updates journals
34
............................................................
35

    
36
Open the file app/views/journals/_notes_form.rhtml. You can add this code where you want, e.g. line 5 :
37
<label style="float:right;"><%= check_box_tag 'is_public', '1', @journal.is_public %> Is public</label>
38

    
39

    
40
STEP 3 : Add an icon next to the journals
41
-----------------------------------------
42

    
43
Now we will add an icon next to the journals' title. Open app/views/issues/_history.rhtml and replace the content by the code bellow :
44
<% reply_links = authorize_for('issues', 'edit') -%>
45
<% for journal in journals %>
46
  <div id="change-<%= journal.id %>" class="<%= journal.css_classes %>">
47
    <h4>
48
    <div class="journal-link">
49
	<% if (journal.is_public) %>
50
		<img src="/redmine/images/public.png" alt="" title="Public" id="journal-<%= journal.id %>-is_public"/>
51
	<% else %>
52
		<img src="/redmine/images/private.png" alt="" title="Private" id="journal-<%= journal.id %>-is_public"/>
53
	<% end %>
54
	<%= link_to "##{journal.indice}", :anchor => "note-#{journal.indice}" %>
55
    </div>
56
    <%= avatar(journal.user, :size => "24") %>
57
    <%= content_tag('a', '', :name => "note-#{journal.indice}")%>
58
		<%= authoring journal.created_on, journal.user, :label => :label_updated_time_by %></h4>
59
    
60
    <% if journal.details.any? %>
61
    <ul class="details">
62
      <% for detail in journal.details %>
63
       <li><%= show_detail(detail) %></li>
64
      <% end %>
65
    </ul>
66
    <% end %>
67
    <%= render_notes(issue, journal, :reply_links => reply_links) unless journal.notes.blank? %>
68
  </div>
69
  <%= call_hook(:view_issues_history_journal_bottom, { :journal => journal }) %>
70
<% end %>
71

    
72
You should add some icons named public.png and private.png in the directory public/images/.
73

    
74

    
75
STEP 4 : Edit the issues' controller
76
------------------------------------
77

    
78
Now open app/views/controllers/issues_controller.rb and add after the line 270 : 
79
    @is_public = !(params[:is_public].nil?)
80
    @issue.init_journal(User.current, @notes, @is_public)
81

    
82

    
83
STEP 4 : Edit the issues' model
84
-------------------------------
85

    
86
Open app/views/models/issue.rb and :
87
- Replace the code form line 350 to 359 by :
88
  def init_journal(user, notes = "", is_public = 1)
89
    @current_journal ||= Journal.new(:journalized => self, :user => user, :notes => notes, :is_public => is_public)
90
    @issue_before_change = self.clone
91
    @issue_before_change.status = self.status
92
    @custom_values_before_change = {}
93
    self.custom_values.each {|c| @custom_values_before_change.store c.custom_field_id, c.value }
94
    # Make sure updated_on is updated when adding a note.
95
    updated_on_will_change!
96
    @current_journal
97
  end
98

    
99
- Replace the line 821 by : duplicate.init_journal(@current_journal.user, @current_journal.notes, @current_journal.is_public)
100
- Replace the line 850 by : init_journal @current_journal.user, @current_journal.notes, @current_journal.is_public
101

    
102

    
103
STEP 5 : Edit the JS action after submitting the form to update a journal
104
-------------------------------------------------------------------------
105

    
106
Edit app/views/journals/update.rjs and replace the content by :
107
if @journal.frozen?
108
  # journal was destroyed
109
  page.remove "change-#{@journal.id}"
110
else
111
  page.replace "journal-#{@journal.id}-notes", render_notes(@journal.issue, @journal, :reply_links => authorize_for('issues', 'edit'))
112
  page.remove "journal-#{@journal.id}-is_public"
113
  page.show "journal-#{@journal.id}-notes"
114
  page.remove "journal-#{@journal.id}-form"
115
  page.reload
116
end
117

    
118
call_hook(:view_journals_update_rjs_bottom, { :page => page, :journal => @journal })
119

    
120

    
121
STEP 7 : Restart Redmine
122
------------------------
123

    
124
Now restart Redmine by entering this command :
125
# ./ctlscript.sh restart redmine
126

    
127
Enjoy !
(1-1/7)