|
--------------------------------------------------------------------------------
|
|
-- HOW TO add a private/public field for journals in Redmine with Linux --
|
|
--------------------------------------------------------------------------------
|
|
|
|
This how-to will show you now to add a private/public field in the journals database to hide or show some journals.
|
|
|
|
STEP 1 : Add a new column in the MySQL DB
|
|
-----------------------------------------
|
|
|
|
First we have to add a column in the journals' table in the database.
|
|
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 :
|
|
# mysql -h localhost -p[password] -u[user] bitnami_redmine
|
|
Then enter this command to add a column in the journals' table :
|
|
mysql> ALTER TABLE journals ADD is_public tinyint(1) DEFAULT 1;
|
|
The result should be stg like that :
|
|
Query OK, 121 rows affected (0.03 sec)
|
|
Records: 121 Duplicates: 0 Warnings: 0
|
|
|
|
You can press ^C to exit.
|
|
|
|
|
|
STEP 2 : Add checkboxes in some forms
|
|
-------------------------------------
|
|
|
|
Now we can add another field in the forms.
|
|
|
|
Step 2.1 : Add a checkbox in the form witch creates journals
|
|
............................................................
|
|
|
|
Open the file app/views/issues/_edit.rhtml. You can add this code where you want, e.g. line 42 :
|
|
<label style="float:right;"><%= check_box_tag 'is_public' %> Is public</label>
|
|
|
|
Step 2.2 : Add a checkbox in the form witch updates journals
|
|
............................................................
|
|
|
|
Open the file app/views/journals/_notes_form.rhtml. You can add this code where you want, e.g. line 5 :
|
|
<label style="float:right;"><%= check_box_tag 'is_public', '1', @journal.is_public %> Is public</label>
|
|
|
|
|
|
STEP 3 : Add an icon next to the journals
|
|
-----------------------------------------
|
|
|
|
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 :
|
|
<% reply_links = authorize_for('issues', 'edit') -%>
|
|
<% for journal in journals %>
|
|
<div id="change-<%= journal.id %>" class="<%= journal.css_classes %>">
|
|
<h4>
|
|
<div class="journal-link">
|
|
<% if (journal.is_public) %>
|
|
<img src="/redmine/images/public.png" alt="" title="Public" id="journal-<%= journal.id %>-is_public"/>
|
|
<% else %>
|
|
<img src="/redmine/images/private.png" alt="" title="Private" id="journal-<%= journal.id %>-is_public"/>
|
|
<% end %>
|
|
<%= link_to "##{journal.indice}", :anchor => "note-#{journal.indice}" %>
|
|
</div>
|
|
<%= avatar(journal.user, :size => "24") %>
|
|
<%= content_tag('a', '', :name => "note-#{journal.indice}")%>
|
|
<%= authoring journal.created_on, journal.user, :label => :label_updated_time_by %></h4>
|
|
|
|
<% if journal.details.any? %>
|
|
<ul class="details">
|
|
<% for detail in journal.details %>
|
|
<li><%= show_detail(detail) %></li>
|
|
<% end %>
|
|
</ul>
|
|
<% end %>
|
|
<%= render_notes(issue, journal, :reply_links => reply_links) unless journal.notes.blank? %>
|
|
</div>
|
|
<%= call_hook(:view_issues_history_journal_bottom, { :journal => journal }) %>
|
|
<% end %>
|
|
|
|
You should add some icons named public.png and private.png in the directory public/images/.
|
|
|
|
|
|
STEP 4 : Edit the issues' controller
|
|
------------------------------------
|
|
|
|
Now open app/views/controllers/issues_controller.rb and add after the line 270 :
|
|
@is_public = !(params[:is_public].nil?)
|
|
@issue.init_journal(User.current, @notes, @is_public)
|
|
|
|
|
|
STEP 4 : Edit the issues' model
|
|
-------------------------------
|
|
|
|
Open app/views/models/issue.rb and :
|
|
- Replace the code form line 350 to 359 by :
|
|
def init_journal(user, notes = "", is_public = 1)
|
|
@current_journal ||= Journal.new(:journalized => self, :user => user, :notes => notes, :is_public => is_public)
|
|
@issue_before_change = self.clone
|
|
@issue_before_change.status = self.status
|
|
@custom_values_before_change = {}
|
|
self.custom_values.each {|c| @custom_values_before_change.store c.custom_field_id, c.value }
|
|
# Make sure updated_on is updated when adding a note.
|
|
updated_on_will_change!
|
|
@current_journal
|
|
end
|
|
|
|
- Replace the line 821 by : duplicate.init_journal(@current_journal.user, @current_journal.notes, @current_journal.is_public)
|
|
- Replace the line 850 by : init_journal @current_journal.user, @current_journal.notes, @current_journal.is_public
|
|
|
|
|
|
STEP 5 : Edit the JS action after submitting the form to update a journal
|
|
-------------------------------------------------------------------------
|
|
|
|
Edit app/views/journals/update.rjs and replace the content by :
|
|
if @journal.frozen?
|
|
# journal was destroyed
|
|
page.remove "change-#{@journal.id}"
|
|
else
|
|
page.replace "journal-#{@journal.id}-notes", render_notes(@journal.issue, @journal, :reply_links => authorize_for('issues', 'edit'))
|
|
page.remove "journal-#{@journal.id}-is_public"
|
|
page.show "journal-#{@journal.id}-notes"
|
|
page.remove "journal-#{@journal.id}-form"
|
|
page.reload
|
|
end
|
|
|
|
call_hook(:view_journals_update_rjs_bottom, { :page => page, :journal => @journal })
|
|
|
|
|
|
STEP 7 : Restart Redmine
|
|
------------------------
|
|
|
|
Now restart Redmine by entering this command :
|
|
# ./ctlscript.sh restart redmine
|
|
|
|
Enjoy !
|