Changeset 712
- Timestamp:
- 11/01/07 14:01:38 (1 year ago)
- Files:
-
- trunk/app/controllers/customer_interface_controller.rb (modified) (4 diffs)
- trunk/app/helpers/customer_interface_helper.rb (modified) (4 diffs)
- trunk/app/models/customer.rb (modified) (1 diff)
- trunk/app/models/task.rb (modified) (2 diffs)
- trunk/app/views/customer_interface/_item_list.rhtml (modified) (3 diffs)
- trunk/app/views/customer_interface/index.rhtml (modified) (1 diff)
- trunk/app/views/layouts/customer_interface.rhtml (modified) (1 diff)
- trunk/db/migrate/010_customer_interface_data.rb (modified) (1 diff)
- trunk/doc/manual/latex/tex/customer_interface.tex (modified) (2 diffs)
- trunk/public/stylesheets/customer_interface_timeline.css (modified) (1 diff)
- trunk/test/functional/customer_interface_controller_test.rb (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/app/controllers/customer_interface_controller.rb
r711 r712 53 53 # Find timeline events that: 54 54 # - Belong to an asset the user is authorized to view. 55 # - Are not only comments to tasks (customers doesn't need to see these).55 # - Are not only comments created by Users to tasks (customers doesn't need to see these). 56 56 from = 'timeline_events e' 57 57 condition_strings = [] … … 60 60 if TaskEvent.count > 0 61 61 from += ', tasks t' 62 condition_strings.push('(e.type = ? AND e.event_type != ?AND e.task_id = t.id AND t.asset_id = assets.id)')63 conditions.push('TaskEvent', TaskEvent.TYPES[:COMMENTED] )62 condition_strings.push('(e.type = ? AND (e.event_type != ? OR e.created_by = ?) AND e.task_id = t.id AND t.asset_id = assets.id)') 63 conditions.push('TaskEvent', TaskEvent.TYPES[:COMMENTED], session[:user].id) 64 64 end 65 65 … … 196 196 render(:partial => 'shared/create_or_edit', 197 197 :layout => 'customer_interface', 198 :locals => {: cancel_url_options => {:action => 'index'}})198 :locals => {:submit_text => _('Submit'), :cancel_url_options => {:action => 'index'}}) 199 199 end 200 200 … … 242 242 end 243 243 244 # Method: comment_service_request 245 # =============================== 246 # Enables a customer to comment her open service request. 247 # 248 def comment_service_request 249 @task = Task.find(params[:id], :conditions => ['state != ?', Task.CLOSED]) 250 @title = _('Comment service request %s', @task.to_s) 251 252 unless @assets.include?(@task.asset) and @task.task_type and @task.task_type.is_service_request_type 253 flash[:error] = _('Service request %s not found!', @task.to_s) 254 redirect_to(:action => 'index') 255 return 256 end 257 258 if request.post? 259 if params[:comment] and params[:comment].strip != '' 260 if TaskEvent.create(:task => @task, :event_type => TaskEvent.TYPES[:COMMENTED], :comment_text => params[:comment]) 261 flash[:notice] = _('Comment successfully received') 262 redirect_to(:action => 'index') 263 else 264 flash[:error] = msg_saving_failed 265 end 266 else 267 flash[:notice] = _("Comment can't be empty. Please provide one.") 268 end 269 end 270 end 271 244 272 protected 245 273 trunk/app/helpers/customer_interface_helper.rb
r710 r712 21 21 # include_name - Include name of the <Asset> 22 22 # max_code_width - Maximum width for the full code of the <Asset>. 23 # Non-positive value means infinite width. 23 24 # Ignored if include_name is true. 24 25 # 25 def format_asset(asset, include_name = false, max_code_width = 12)26 def format_asset(asset, include_name = false, max_code_width = nil) 26 27 return '' unless asset 27 28 … … 29 30 30 31 return span_tag(tag_class, '%s (%s)' % [asset.full_code, asset.name]) if include_name 32 return span_tag(tag_class, asset.full_code) unless max_code_width and max_code_width > 0 31 33 32 34 text = '' … … 85 87 # asset_code_width - Maximum width for the full code of the <Asset>. 86 88 # Ignored if show_asset_and_description is false. 87 # 88 def format_task(task, no_text = false, show_type = true, show_asset_and_description = false, asset_code_width = 10) 89 # show_comment_link - If true, shows a link to the 'Comment service request' 90 # function. 91 # 92 def format_task(task, no_text = false, show_type = true, show_asset_and_description = false, asset_code_width = 10, show_comment_link = false) 89 93 return '' unless task 90 94 … … 92 96 content = _('Task') + ' ' + content unless no_text 93 97 content += " (#{task.task_type.name})" if show_type 94 result = s pan_tag('task', content)98 result = show_comment_link ? link_to(content, {:action => 'comment_service_request', :id => task.id}, {:class => 'task', :title => _('Comment service request %s', task.to_s)}) : span_tag('task', content) 95 99 return result unless show_asset_and_description 96 100 result += nbsp(1) trunk/app/models/customer.rb
r710 r712 33 33 'customer_interface/submit_service_request', 34 34 'customer_interface/edit_my_information', 35 'customer_interface/change_password' 35 'customer_interface/change_password', 36 'customer_interface/comment_service_request' 36 37 ] 37 38 trunk/app/models/task.rb
r710 r712 107 107 end 108 108 109 # Arguments: 110 # +create_state_change_event+:: If +true+, a new TaskEvent (representing the 111 # change to the object's current state) is created. 112 def save(create_state_change_event = false) 113 return super() unless create_state_change_event 109 # Method: save 110 # ============ 111 # Saves the object. 112 # 113 # Parameters: 114 # ----------- 115 # create_event - If true, a new <TaskEvent> is created. The event 116 # represents the change to the object's current state 117 # (the only exception being the <COMMENTED> event) 118 # and can also contain a comment text. 119 # 120 def save(create_event = false) 121 return super() unless create_event 114 122 115 123 if new_record? 116 124 task_events << TaskEvent.new(:event_type => TaskEvent.TYPES[:CREATED], 117 :comment_text => self.short_description)125 :comment_text => self.short_description) 118 126 return super() 119 127 end 120 128 121 new_state = (self.state == @original_state) ? nil : self.state 122 123 case new_state 129 case self.state 130 when @original_state 131 # State unchanged -> comment only 132 if @comment and @comment != '' 133 @event = TaskEvent.create(:event_type => TaskEvent.TYPES[:COMMENTED], 134 :task_id => self.id, 135 :comment_text => @comment) 136 end 124 137 when @@ACCEPTED 125 138 @event = TaskEvent.create(:event_type => TaskEvent.TYPES[:ACCEPTED], 126 :task_id => self.id,127 :comment_text => @comment)139 :task_id => self.id, 140 :comment_text => @comment) 128 141 when @@CLOSED 129 142 @event = TaskEvent.create(:event_type => TaskEvent.TYPES[:CLOSED], 130 :task_id => self.id,131 :comment_text => @comment)143 :task_id => self.id, 144 :comment_text => @comment) 132 145 when @@ASSIGNED 133 146 @event = TaskEvent.create(:event_type => TaskEvent.TYPES[:ASSIGNED], 134 :task_id => self.id,135 :comment_text => @comment,136 :task_owner => self.responsible_user)147 :task_id => self.id, 148 :comment_text => @comment, 149 :task_owner => self.responsible_user) 137 150 _('Task was assigned to you') # This is to trigger the gettext 138 151 @message = Message.create(:receiver => self.responsible_user, … … 141 154 when @@NEW 142 155 @event = TaskEvent.create(:event_type => TaskEvent.TYPES[:REOPENED], 143 :task_id => self.id, 144 :comment_text => @comment) 145 when nil # State unchanged 146 if @comment and @comment != '' 147 @event = TaskEvent.create(:event_type => TaskEvent.TYPES[:COMMENTED], 148 :task_id => self.id, 149 :comment_text => @comment) 150 end 156 :task_id => self.id, 157 :comment_text => @comment) 151 158 end 152 159 trunk/app/views/customer_interface/_item_list.rhtml
r710 r712 18 18 # table_id - id attribute for the table containing the items 19 19 # asset_code_width - Width for the full code of an asset 20 # show_comment_task_link - Show 'Comment task' link for task items 20 21 # 21 22 # Optional instance variables: … … 46 47 table_id ||= 'itemlist' 47 48 asset_code_width ||= 10 49 show_comment_task_link ||= false 48 50 -%> 49 51 <!-- The item list --> … … 97 99 format_attachment_event(value) 98 100 when 'Task' 99 format_task(value, true, false, true, asset_code_width )101 format_task(value, true, false, true, asset_code_width, show_comment_task_link) 100 102 when 'User' 101 103 format_user(value, true) trunk/app/views/customer_interface/index.rhtml
r710 r712 33 33 :items_offset => @service_request_offset, 34 34 :table_id => 'service_request_list', 35 :asset_code_width => 12 }) %> 35 :asset_code_width => 12, 36 :show_comment_task_link => true }) %> 36 37 </div> 37 38 <div id="statistics" class="boxblock"> trunk/app/views/layouts/customer_interface.rhtml
r710 r712 48 48 49 49 <div id="loginstatus"> 50 <div id="logged"><%= _('Logged in as') %>: <%= @show_login_name_link ? link_to(h(session[:user].login_and_name), {:action => 'edit_my_information'}, {:id => 'login_name' }) : "<span class=\"login_name\">#{h(session[:user].login_and_name)}</span>" %></div>50 <div id="logged"><%= _('Logged in as') %>: <%= @show_login_name_link ? link_to(h(session[:user].login_and_name), {:action => 'edit_my_information'}, {:id => 'login_name', :title => _('My information')}) : "<span id=\"login_name\">#{h(session[:user].login_and_name)}</span>" %></div> 51 51 <div id="logbutton"><%= link_to( image_tag('customer_interface/logout.jpg'), {:controller => 'user', :action => 'logout'} ) %></div> 52 52 </div> trunk/db/migrate/010_customer_interface_data.rb
r710 r712 14 14 'customer_interface/submit_service_request', 15 15 'customer_interface/edit_my_information', 16 'customer_interface/change_password' 16 'customer_interface/change_password', 17 'customer_interface/comment_service_request' 17 18 ].each { |name| 18 19 TempActionKey.create!(:name => name) trunk/doc/manual/latex/tex/customer_interface.tex
r711 r712 6 6 \item Submit service requests 7 7 \item View and follow their open service request 8 %\item Comment open service requests8 \item Comment open service requests 9 9 \item View statistics: Open service requests by asset 10 10 \end{itemize} … … 20 20 \subsubsection{Submit a service request} 21 21 Customers can submit service requests with this function. The service request will show up in the service request list in the Tasks menu found from the Application section. If a customer doesn't select an asset for the a service request, the service request will be saved to the customer's first asset --- You can move it to another asset if you wish. 22 \subsubsection{Comment service request} 23 An open Service request can be commented by 22 24 \subsubsection{My information} 23 25 Customers can view and edit their contact information and language by clicking the account name link after the 'Logged in as:' text at the top of the page. Changes to the account information can be saved with the 'Save changes' button. trunk/public/stylesheets/customer_interface_timeline.css
r710 r712 8 8 } 9 9 10 span.task {10 span.task, a.task { 11 11 padding-left: 20px; 12 12 background: transparent url(../images/16x16/timeline_task.gif) 0px 0px no-repeat; trunk/test/functional/customer_interface_controller_test.rb
r710 r712 189 189 # Method: test_submit_service_request 190 190 # =================================== 191 # Check that service request submitting works when assetis given.191 # Check that service request submitting works when required input (including asset) is given. 192 192 # 193 193 def test_submit_service_request … … 280 280 end 281 281 282 # Method: test_comment_service_request 283 # =================================== 284 # Checks that the service request commenting function works with valid input. 285 # 286 def test_comment_service_request 287 service_request = create_simple_task(@asset1, @service_request_type) 288 289 login(@customer.login) 290 291 # GET form 292 get 'comment_service_request', :id => service_request.id 293 assert_response :success 294 assert_template 'customer_interface/comment_service_request' 295 assert_equal service_request, assigns(:task) 296 assert_nil flash[:error] 297 assert_nil flash[:notice] 298 299 # POST form 300 comment = 'This is the comment we want to submit to the open service request' 301 post 'comment_service_request', :id => service_request.id, :comment => comment 302 assert_redirected_to :action => 'index' 303 assert_nil flash[:error] 304 assert_not_nil flash[:notice] 305 assert_equal service_request, assigns(:task) 306 comment_event = assigns(:task).task_events.find_by_event_type(TaskEvent.TYPES[:COMMENTED]) 307 assert_equal comment, comment_event.comment_text 308 assert_equal @customer, comment_event.creator 309 end 310 311 # Method: test_comment_closed_service_request 312 # =================================== 313 # Checks that closed service requests can't be commented. 314 # 315 def test_comment_closed_service_request 316 service_request = create_simple_task(@asset1, @service_request_type) 317 service_request.close 318 service_request.save! 319 320 login(@customer.login) 321 322 # GET form 323 assert_raise(ActiveRecord::RecordNotFound) { get('comment_service_request', :id => service_request.id) } 324 end 325 326 # Method: test_comment_service_request_unautorized_asset 327 # ===================================================== 328 # Checks that customer can't comment service request in unauthorized assets. 329 # 330 def test_comment_service_request_unautorized_asset 331 service_request = create_simple_task(@asset2, @service_request_type) 332 333 login(@customer.login) 334 335 # GET form 336 get 'comment_service_request', :id => service_request.id 337 assert_redirected_to :action => 'index' 338 assert_not_nil flash[:error] 339 assert_nil flash[:notice] 340 end 341 342 # Method: test_comment_service_request_unautorized_task 343 # ===================================================== 344 # Checks that customer can't comment tasks which aren't service requests 345 # 346 def test_comment_service_request_unautorized_task 347 service_request = create_simple_task(@asset1, @task_type) 348 349 login(@customer.login) 350 351 # GET form 352 get 'comment_service_request', :id => service_request.id 353 assert_redirected_to :action => 'index' 354 assert_not_nil flash[:error] 355 assert_nil flash[:notice] 356 end 357 358 # Method: test_comment_service_request_empty_comment 359 # ================================================== 360 # Checks that empty comments can't be submitted to the service request commenting function works with valid input. 361 # 362 def test_comment_service_request_empty_comment 363 service_request = create_simple_task(@asset1, @service_request_type) 364 365 login(@customer.login) 366 367 post 'comment_service_request', :id => service_request.id, :comment => ' ' 368 assert_response :success 369 assert_template 'customer_interface/comment_service_request' 370 assert_nil flash[:error] 371 assert_not_nil flash[:notice] 372 assert_equal service_request, assigns(:task) 373 assert_nil assigns(:task).task_events.find_by_event_type(TaskEvent.TYPES[:COMMENTED]) 374 end 282 375 283 376 def test_edit_my_information_get