Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[webui] Show if request is a new package submission #3960

Merged
merged 1 commit into from
Oct 9, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -609,6 +609,7 @@ Rails/OutputSafety:
- 'src/api/app/helpers/webui/package_helper.rb'
- 'src/api/app/helpers/webui/project_helper.rb'
- 'src/api/app/helpers/webui/webui_helper.rb'
- 'src/api/app/helpers/webui/request_helper.rb'

# Offense count: 136
# Cop supports --auto-correct.
9 changes: 9 additions & 0 deletions src/api/app/helpers/webui/request_helper.rb
Original file line number Diff line number Diff line change
@@ -9,6 +9,14 @@ def request_state_color(state)
STATE_COLORS[state.to_s] || ''
end

def new_or_update_request(row)
if row.target_package_id
row.request_type
else
"#{row.request_type} <small>(new package)</small>".html_safe
end
end

def merge_opt(res, opt, value)
res[opt] ||= value
res[opt] = :multiple if value != res[opt]
@@ -29,6 +37,7 @@ def common_parts(req)
merge_opt(res, :target_package, ae.target_package)
merge_opt(res, :target_project, ae.target_project)
merge_opt(res, :request_type, ae.action_type)
res[:target_package_id] ||= ae.target_package_id
end

res[:request_type] = map_request_type(res[:request_type])
4 changes: 4 additions & 0 deletions src/api/app/models/bs_request/data_table/row.rb
Original file line number Diff line number Diff line change
@@ -20,6 +20,10 @@ def request_type
cache[:request_type]
end

def target_package_id
cache[:target_package_id]
end

def target_project
cache[:target_project]
end
2 changes: 1 addition & 1 deletion src/api/app/views/webui/shared/bs_requests/index.json.erb
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@
"<%= escape_javascript(project_or_package_link(project: row.source_project, package: row.source_package, creator: row.creator, trim_to: 40, short: true)) %>",
"<%= escape_javascript(target_project_link(row)) %>",
"<%= escape_javascript(user_with_realname_and_icon(row.creator, short: true)) %>",
"<%= escape_javascript(row.request_type) %>",
"<%= escape_javascript(new_or_update_request(row)) %>",
"<%= escape_javascript(row.priority) %>",
"<%= escape_javascript(link_to(sprite_tag('req-showdiff', title: "Show request ##{row.number}"), request_show_path(row.number), { class: :request_link })) %>"
<% end %>
32 changes: 32 additions & 0 deletions src/api/spec/helpers/webui/request_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require 'rails_helper'

RSpec.describe Webui::RequestHelper do

describe '#new_or_update' do
context 'for a new package' do
let(:request) { create(:bs_request) }
let(:row) { BsRequest::DataTable::Row .new(request) }

it { expect(new_or_update_request(row)).to eq("BsRequestAction <small>(new package)</small>") }
it { expect(new_or_update_request(row)).to be_a(ActiveSupport::SafeBuffer) }
end

context 'for an existing package' do
let(:target_package) { create(:package) }
let(:target_project) { target_package.project }
let(:source_package) { create(:package) }
let(:source_project) { source_package.project }
let(:bs_request_with_submit_action) do
create(:bs_request_with_submit_action,
target_project: target_project,
target_package: target_package,
source_project: source_project,
source_package: source_package
)
end
let(:row) { BsRequest::DataTable::Row .new(bs_request_with_submit_action) }

it { expect(new_or_update_request(row)).to eq("submit") }
end
end
end