From bea49ae24532284ca4ef9ce72733b78f77e480d5 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sat, 2 Feb 2008 10:50:31 +0000 Subject: [PATCH] Administrators can edit issue notes. git-svn-id: http://redmine.rubyforge.org/svn/trunk@1105 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/issues_controller.rb | 1 + app/controllers/journals_controller.rb | 40 +++++++++++++++ app/helpers/journals_helper.rb | 37 ++++++++++++++ app/models/journal.rb | 4 ++ app/views/issues/_history.rhtml | 2 +- app/views/journals/_notes_form.rhtml | 7 +++ app/views/journals/edit.rjs | 3 ++ app/views/journals/update.rjs | 3 ++ public/images/delete.png | Bin 265 -> 1022 bytes public/images/edit.png | Bin 1340 -> 1343 bytes public/stylesheets/application.css | 3 +- test/fixtures/journals.yml | 8 +++ test/functional/journals_controller_test.rb | 51 ++++++++++++++++++++ 13 files changed, 156 insertions(+), 3 deletions(-) create mode 100644 app/controllers/journals_controller.rb create mode 100644 app/helpers/journals_helper.rb create mode 100644 app/views/journals/_notes_form.rhtml create mode 100644 app/views/journals/edit.rjs create mode 100644 app/views/journals/update.rjs create mode 100644 test/functional/journals_controller_test.rb diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index fdece9e1a..dfee53841 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -27,6 +27,7 @@ class IssuesController < ApplicationController cache_sweeper :issue_sweeper, :only => [ :new, :edit, :update, :destroy ] + helper :journals helper :projects include ProjectsHelper helper :custom_fields diff --git a/app/controllers/journals_controller.rb b/app/controllers/journals_controller.rb new file mode 100644 index 000000000..b867b4ae6 --- /dev/null +++ b/app/controllers/journals_controller.rb @@ -0,0 +1,40 @@ +# redMine - project management software +# Copyright (C) 2006-2008 Jean-Philippe Lang +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +class JournalsController < ApplicationController + layout 'base' + before_filter :find_journal + + def edit + if request.post? + @journal.update_attributes(:notes => params[:notes]) if params[:notes] + respond_to do |format| + format.html { redirect_to :controller => 'issues', :action => 'show', :id => @journal.journalized_id } + format.js { render :action => 'update' } + end + return + end + end + +private + def find_journal + @journal = Journal.find(params[:id]) + render_403 and return false unless @journal.editable_by?(User.current) + rescue ActiveRecord::RecordNotFound + render_404 + end +end diff --git a/app/helpers/journals_helper.rb b/app/helpers/journals_helper.rb new file mode 100644 index 000000000..c97446448 --- /dev/null +++ b/app/helpers/journals_helper.rb @@ -0,0 +1,37 @@ +# redMine - project management software +# Copyright (C) 2006-2008 Jean-Philippe Lang +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +module JournalsHelper + def render_notes(journal, options={}) + content = '' + editable = journal.editable_by?(User.current) + if editable + links = [] + links << link_to_in_place_notes_editor(image_tag('edit.png'), "journal-#{journal.id}-notes", + { :controller => 'journals', :action => 'edit', :id => journal }, + :title => l(:button_edit)) + content << content_tag('div', links.join(' '), :class => 'contextual') + end + content << textilizable(journal, :notes) + content_tag('div', content, :id => "journal-#{journal.id}-notes", :class => (editable ? 'editable' : nil)) + end + + def link_to_in_place_notes_editor(text, field_id, url, options={}) + onclick = "new Ajax.Request('#{url_for(url)}', {asynchronous:true, evalScripts:true, method:'get'}); return false;" + link_to text, '#', options.merge(:onclick => onclick) + end +end diff --git a/app/models/journal.rb b/app/models/journal.rb index d02067a9d..df7308435 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -49,4 +49,8 @@ class Journal < ActiveRecord::Base c = details.detect {|detail| detail.prop_key == prop} c ? c.value : nil end + + def editable_by?(usr) + usr && usr.admin? + end end diff --git a/app/views/issues/_history.rhtml b/app/views/issues/_history.rhtml index bab37b4fd..edfb9b94d 100644 --- a/app/views/issues/_history.rhtml +++ b/app/views/issues/_history.rhtml @@ -8,6 +8,6 @@
  • <%= show_detail(detail) %>
  • <% end %> - <%= textilizable(journal.notes) unless journal.notes.blank? %> + <%= render_notes(journal) unless journal.notes.blank? %> <% note_id += 1 %> <% end %> diff --git a/app/views/journals/_notes_form.rhtml b/app/views/journals/_notes_form.rhtml new file mode 100644 index 000000000..9baec03fa --- /dev/null +++ b/app/views/journals/_notes_form.rhtml @@ -0,0 +1,7 @@ +<% form_remote_tag(:url => {}, :html => { :id => "journal-#{@journal.id}-form" }) do %> + <%= text_area_tag :notes, @journal.notes, :class => 'wiki-edit', + :rows => (@journal.notes.blank? ? 10 : [[10, @journal.notes.length / 50].max, 100].min) %> +

    <%= submit_tag l(:button_save) %> + <%= link_to l(:button_cancel), '#', :onclick => "Element.remove('journal-#{@journal.id}-form'); " + + "Element.show('journal-#{@journal.id}-notes'); return false;" %>

    +<% end %> diff --git a/app/views/journals/edit.rjs b/app/views/journals/edit.rjs new file mode 100644 index 000000000..798cb0f04 --- /dev/null +++ b/app/views/journals/edit.rjs @@ -0,0 +1,3 @@ +page.hide "journal-#{@journal.id}-notes" +page.insert_html :after, "journal-#{@journal.id}-notes", + :partial => 'notes_form' diff --git a/app/views/journals/update.rjs b/app/views/journals/update.rjs new file mode 100644 index 000000000..9da0ebeae --- /dev/null +++ b/app/views/journals/update.rjs @@ -0,0 +1,3 @@ +page.replace "journal-#{@journal.id}-notes", render_notes(@journal) +page.show "journal-#{@journal.id}-notes" +page.remove "journal-#{@journal.id}-form" diff --git a/public/images/delete.png b/public/images/delete.png index 137baa68eac092124487651cd173a02c67f5a940..a1af31d8334a2d5ee776711876b58dd6c9f27581 100644 GIT binary patch literal 1022 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbL!PKj$oiE~kEVo7FxoQosX}gIrh<`yfw_XAft8V=m5Hf>wt=C6L7#I^08k%$iKnkC`wb>W5f!x){P`er zISV`@iy0WWK7cTz(;AZ*KtYytM_)$E)e-c?47?>FXd_r9RGcbJr{=KJX&hzKb z|NjT_M!{$ZjGz!;Z+)@@=v~H=AirP+hi5m^fE*i77srr_TfKdrd<+I0Opd?*n_pj& zG~M}eK~htvgZS>Q0Qp1n8r7~Gi7=O}VO4HlP`RWfeOttoggVD9GbXHO6g+ox>0MA5 Ndb;|#taD0e0suNuR676w delta 210 zcmeyz-pQoc8Q|y6%O%Cdz`(%k>ERLtr1^oEhl3eNcFhsLHc`>B{yHlwhnN9Jv+g#a zAZLL`WHAE+w-5+3Ub#+poSnjXK8<8-9v0*k^1GPO9WIV*mnAS3j3^P69AcK75{ wEGmq;li#!GDKF*e@v-63@C!fiPCSN*fp_gzXWmeWJO&`}boFyt=akR{0Oai+&;S4c diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index ec3ae159d..eb4e855b4 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -122,7 +122,7 @@ div.square { width: .6em; height: .6em; } -.contextual {float:right; white-space: nowrap; line-height:1.4em;margin-top:5px;font-size:0.9em;} +.contextual {float:right; white-space: nowrap; line-height:1.4em;margin-top:5px; padding-left: 10px; font-size:0.9em;} .contextual input {font-size:0.9em;} .splitcontentleft{float:left; width:49%;} @@ -227,7 +227,6 @@ text-align:center; padding:0.6em; z-index:100; filter:alpha(opacity=50); --moz-opacity:0.5; opacity: 0.5; -khtml-opacity: 0.5; } diff --git a/test/fixtures/journals.yml b/test/fixtures/journals.yml index 0de938168..169713fc5 100644 --- a/test/fixtures/journals.yml +++ b/test/fixtures/journals.yml @@ -6,3 +6,11 @@ journals_001: journalized_type: Issue user_id: 1 journalized_id: 1 +journals_002: + created_on: <%= 1.days.ago.to_date.to_s(:db) %> + notes: "Some notes" + id: 2 + journalized_type: Issue + user_id: 2 + journalized_id: 1 + \ No newline at end of file diff --git a/test/functional/journals_controller_test.rb b/test/functional/journals_controller_test.rb new file mode 100644 index 000000000..f231d10ee --- /dev/null +++ b/test/functional/journals_controller_test.rb @@ -0,0 +1,51 @@ +# redMine - project management software +# Copyright (C) 2006-2008 Jean-Philippe Lang +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +require File.dirname(__FILE__) + '/../test_helper' +require 'journals_controller' + +# Re-raise errors caught by the controller. +class JournalsController; def rescue_action(e) raise e end; end + +class JournalsControllerTest < ActionController::TestCase + fixtures :projects, :users, :members, :roles, :issues, :journals, :journal_details, :enabled_modules + + def setup + @controller = JournalsController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + User.current = nil + end + + def test_get_edit + @request.session[:user_id] = 1 + xhr :get, :edit, :id => 2 + assert_response :success + assert_select_rjs :insert, :after, 'journal-2-notes' do + assert_select 'form[id=journal-2-form]' + assert_select 'textarea' + end + end + + def test_post_edit + @request.session[:user_id] = 1 + xhr :post, :edit, :id => 2, :notes => 'Updated notes' + assert_response :success + assert_select_rjs :replace, 'journal-2-notes' + assert_equal 'Updated notes', Journal.find(2).notes + end +end -- 2.39.5