Revision 9042033c
Added by Tomer Brisker about 5 years ago
app/helpers/application_helper.rb | ||
---|---|---|
# Methods added to this helper will be available to all templates in the application
|
||
module ApplicationHelper
|
||
# Add autogenerated html data-id attribute if not present (prefixed with "aid_")
|
||
def link_to(*args)
|
||
return super(*args) if block_given?
|
||
|
||
options = args[1] || {}
|
||
html_options = args[2] || {}
|
||
unless html_options.has_key?(:'data-id') || (options.is_a?(String) && options.start_with?('mailto', 'javascript'))
|
||
begin
|
||
path = URI(url_for(options) || html_options['href']).path.split('/').reject(&:empty?)
|
||
id = if path.empty?
|
||
''
|
||
else
|
||
path.last([path.size, 3].max).join('_')
|
||
end
|
||
rescue => e
|
||
Foreman::Logging.exception("Failed generating link using #{args.inspect}", e)
|
||
id = ''
|
||
end
|
||
html_options[:'data-id'] = "aid_#{id}" unless id.empty?
|
||
end
|
||
if html_options[:confirm]
|
||
Foreman::Deprecation.deprecation_warning('1.24', 'passing :confirm parameter in html_options to link_to is deprecated. Please use `data: {confirm: "confirmation message?"}` instead.')
|
||
html_options[:data] ||= {}
|
app/helpers/form_helper.rb | ||
---|---|---|
end
|
||
end
|
||
|
||
def form_to_submit_id(f)
|
||
object = f.object.respond_to?(:to_model) ? f.object.to_model : f.object
|
||
key = if object.present?
|
||
object.persisted? ? :update : :create
|
||
else
|
||
:submit
|
||
end
|
||
model = if object.class.respond_to?(:humanize_class_name)
|
||
object.class.humanize_class_name.downcase
|
||
elsif object.class.respond_to?(:model_name)
|
||
object.class.model_name.human.downcase
|
||
else
|
||
f.object_name.to_s
|
||
end.gsub(/\W+/, '_')
|
||
"aid_#{key}_#{model}"
|
||
end
|
||
|
||
def submit_or_cancel(f, overwrite = false, args = { })
|
||
args[:cancel_path] ||= send("#{controller_name}_path")
|
||
content_tag(:div, :class => "clearfix") do
|
||
... | ... | |
options = {}
|
||
options[:disabled] = true if args[:disabled]
|
||
options[:class] = "btn btn-#{overwrite ? 'danger' : 'primary'} remove_form_templates"
|
||
options[:'data-id'] = form_to_submit_id(f) unless options.has_key?(:'data-id')
|
||
options[:data] = args[:data] if args.key?(:data)
|
||
options
|
||
end
|
test/controllers/architectures_controller_test.rb | ||
---|---|---|
basic_pagination_per_page_test
|
||
basic_pagination_rendered_test
|
||
|
||
def test_new_submit_button_id
|
||
get :new, session: set_session_user
|
||
assert_select "[data-id='aid_create_architecture']"
|
||
end
|
||
|
||
def test_new_cancel_button_id
|
||
get :new, session: set_session_user
|
||
assert_select "[data-id='aid_architectures']"
|
||
end
|
||
|
||
def test_create_invalid
|
||
Architecture.any_instance.stubs(:valid?).returns(false)
|
||
post :create, params: { :architecture => {:name => nil} }, session: set_session_user
|
||
... | ... | |
assert_redirected_to architectures_url
|
||
end
|
||
|
||
def test_edit_submit_button_id
|
||
get :edit, params: { :id => Architecture.first }, session: set_session_user
|
||
assert_select "[data-id='aid_update_architecture']"
|
||
end
|
||
|
||
def test_update_invalid
|
||
Architecture.any_instance.stubs(:valid?).returns(false)
|
||
put :update, params: { :id => Architecture.first.to_param, :architecture => {:name => "3243"} }, session: set_session_user
|
test/integration/org_admin_js_test.rb | ||
---|---|---|
|
||
def select_org(org)
|
||
within('li#organization-dropdown ul') do
|
||
find("a#aid_taxonomy_#{org}").trigger('click')
|
||
find("a#select_taxonomy_#{org}").trigger('click')
|
||
end
|
||
end
|
||
end
|
webpack/assets/javascripts/foreman_tools.test.js | ||
---|---|---|
<ul class="dropdown-menu pull-right">
|
||
<li class="divider"></li>
|
||
<li><a id="bookmark" data-url="/bookmarks/new?kontroller=provisioning_templates" href="#" onclick="$('#bookmarks-modal').modal();; return false;">Bookmark this search</a></li>
|
||
<li><a rel="external noopener noreferrer" target="_blank" data-id="aid_manuals_1.16_index.html" href="http://www.theforeman.org/manuals/1.16/index.html#4.1.5Searching"><span class="glyphicon glyphicon-question-sign icon-black"></span> Documentation</a></li>
|
||
<li><a rel="external noopener noreferrer" target="_blank" href="http://www.theforeman.org/manuals/1.16/index.html#4.1.5Searching"><span class="glyphicon glyphicon-question-sign icon-black"></span> Documentation</a></li>
|
||
</ul>
|
||
</span>
|
||
</div>
|
webpack/assets/javascripts/react_app/components/Layout/components/TaxonomyDropdown.js | ||
---|---|---|
<li key={i}>
|
||
<a
|
||
className={`${taxonomyType.toLowerCase()}_menuitem`}
|
||
id={`aid_taxonomy_${taxonomy.title}`}
|
||
id={`select_taxonomy_${taxonomy.title}`}
|
||
href={taxonomy.href}
|
||
onClick={() => {
|
||
changeTaxonomy({ title: taxonomy.title, id: taxonomy.id });
|
webpack/assets/javascripts/react_app/components/Layout/components/__snapshots__/TaxonomyDropdown.test.js.snap | ||
---|---|---|
<a
|
||
className="organization_menuitem"
|
||
href="/organizations/1-org1/select"
|
||
id="aid_taxonomy_org1"
|
||
id="select_taxonomy_org1"
|
||
onClick={[Function]}
|
||
>
|
||
org1
|
||
... | ... | |
<a
|
||
className="organization_menuitem"
|
||
href="/organizations/2-org2/select"
|
||
id="aid_taxonomy_org2"
|
||
id="select_taxonomy_org2"
|
||
onClick={[Function]}
|
||
>
|
||
org2
|
webpack/assets/javascripts/react_app/components/common/table/components/DeleteButton.js | ||
---|---|---|
data-method="delete"
|
||
data-confirm={`${__('Delete')} ${name}?`}
|
||
href={`${controller}/${id}-${name}`}
|
||
data-id={`aid_${controller}_${id}-${name}`}
|
||
>
|
||
{__('Delete')}
|
||
</Button>
|
webpack/assets/javascripts/react_app/components/common/table/components/NameCell.js | ||
---|---|---|
|
||
const NameCell = ({ active, id, name, controller, children }) =>
|
||
active ? (
|
||
<a
|
||
href={`/${controller}/${id}-${name}/edit`}
|
||
data-id={`aid_${controller}-${id}-${name}_edit`}
|
||
>
|
||
{children}
|
||
</a>
|
||
<a href={`/${controller}/${id}-${name}/edit`}>{children}</a>
|
||
) : (
|
||
<a href="#" className="disabled" disabled="disabled" onClick={() => {}}>
|
||
{children}
|
Also available in: Unified diff
Fixes #26325 - Remove data-id aid attributes
These were used by QE automation to identify links but are no longer
needed since https://github.com/SatelliteQE/airgun/commit/8438e7274a73e01dcb7073f47068eba877e2bed5