Skip to content

Commit

Permalink
Update comments column to webui2
Browse files Browse the repository at this point in the history
Inside comments column some partials are rendered, now it renders webui2
ones.

Instead of adding the comment's form after the comment itself, it
replaces it.

After changing the form we realized that we needed to update/save the
attribute value in ProjectController#edit_comment.

Co-authored-by: Björn Geuken <bgeuken@suse.de>
  • Loading branch information
saraycp and bgeuken committed Dec 6, 2018
1 parent 738debb commit 081533c
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/api/app/controllers/webui/project_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -580,10 +580,10 @@ def edit_comment

attr = @package.attribs.where(attrib_type: at).first_or_initialize
v = attr.values.first_or_initialize
v.value = params[:text]
v.position = 1
v.update!(value: params[:text], position: 1)
attr.save!
@comment = params[:text]
switch_to_webui2
end

def status
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
%div

- if @error
%i.fa.fa-exclamation-triangle.text-warning
= @error

= render partial: 'status_comment', locals: { package_name: @package.name, editable: true, comment: @comment, project: @project }

16 changes: 16 additions & 0 deletions src/api/app/views/webui2/webui/project/_status_comment.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
- if comment
= h(comment)
- if User.current.can_modify?(project.api_obj)
- if editable
= link_to(edit_comment_form_path(project: project, package: package_name, comment: comment), remote: true) do
%i.fas.fa-edit.text-secondary
- else
= link_to(clear_failed_comment_path(project: project, package: package_name), remote: true) do
%i.fas.fa-times-circle.text-danger

- elsif editable
%span.unknown_failure
Unknown build failure
- if User.current.can_modify?(project.api_obj)
= link_to(edit_comment_form_path(project: project, package: package_name, comment: ''), remote: true) do
%i.fas.fa-edit.text-secondary
2 changes: 2 additions & 0 deletions src/api/app/views/webui2/webui/project/edit_comment.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
$('td[data-package-name="<%= @package.name %>"]').
html('<%= escape_javascript(render(partial: 'edit_comment')) %>');
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
$('#<%= params[:update] %>').replaceWith('<%= escape_javascript(render(:partial => 'edit_comment_form')) %>');

$('td[data-package-name="<%= params[:package] %>"]').
html('<%= escape_javascript(render(partial: 'edit_comment_form')) %>');
8 changes: 5 additions & 3 deletions src/api/app/views/webui2/webui/project/status.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@
" since #{distance_of_time_in_words_to_now(package['firstfail'].to_i)}")
icon = "error"
sortkey = '1-fails-%010d-%s' % [ Time.now.to_i - package['firstfail'], package['name'] ]
elsif package['failedcomment'] && User.current.can_modify?(@project.api_obj)
comments_to_clear << package['failedcomment']
end
unless sortkey
sortkey = "9-ok-" + package['name']
Expand All @@ -142,9 +144,9 @@
- outs.each do |out|
= out
%br
%td
%span{ id: valid_xml_id('comment_' + package['name']) }
= show_status_comment(package['failedcomment'], package['name'], package['firstfail'], comments_to_clear)
%td{ data: { package_name: package['name'] } }
= render partial: 'status_comment', locals: { package_name: package['name'], editable: package['firstfail'].present?,
comment: package['failedcomment'], project: @project }

- content_for :ready_function do
$('#status-table').dataTable({ 'iDisplayLength': 50, responsive: true, 'columnDefs': [ { 'width': '20%', 'targets': 0 } ] });
Expand Down
4 changes: 2 additions & 2 deletions src/api/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,9 @@ def self.public_or_about_path?(request)
get 'project/toggle_watch/:project' => :toggle_watch, constraints: cons, as: 'project_toggle_watch'
get 'project/prjconf/:project' => :prjconf, constraints: cons, as: :project_config
post 'project/save_prjconf/:project' => :save_prjconf, constraints: cons, as: :save_project_config
get 'project/clear_failed_comment/:project' => :clear_failed_comment, constraints: cons
get 'project/clear_failed_comment/:project' => :clear_failed_comment, constraints: cons, as: :clear_failed_comment
get 'project/edit/:project' => :edit, constraints: cons
get 'project/edit_comment_form/:project' => :edit_comment_form, constraints: cons
get 'project/edit_comment_form/:project' => :edit_comment_form, constraints: cons, as: :edit_comment_form
post 'project/edit_comment/:project' => :edit_comment, constraints: cons
get 'project/status/(:project)' => :status, constraints: cons, as: 'project_status'
get 'project/maintained_projects/:project' => :maintained_projects, constraints: cons, as: :project_maintained_projects
Expand Down

0 comments on commit 081533c

Please sign in to comment.