From: Jan Provaznik jprovazn@redhat.com
https://www.aeolusproject.org/redmine/issues/2382 https://bugzilla.redhat.com/show_bug.cgi?id=734503
Links are now generated in views (when jquery template is defined), and only object id is then passed in JSON data. It's not possible to pass '${id}' string as id to *_path helper methods because URI.escape is called on id, so after generating path, id is substituted with ('${id}').
Not saying this is cleanest way how to do it, but it's simplest ATM and buys us some time to figure out better solution. --- src/app/helpers/application_helper.rb | 2 +- src/app/models/deployment.rb | 5 ++--- src/app/models/instance.rb | 7 +------ src/app/models/pool.rb | 3 +-- src/app/views/deployments/_list.haml | 6 +++--- src/app/views/deployments/_pretty_view.haml | 2 +- src/app/views/deployments/_pretty_view_show.haml | 8 ++++---- src/app/views/instances/_list.haml | 2 +- src/app/views/pools/_list.haml | 4 ++-- 9 files changed, 16 insertions(+), 23 deletions(-)
diff --git a/src/app/helpers/application_helper.rb b/src/app/helpers/application_helper.rb index b22d1cf..9441d76 100644 --- a/src/app/helpers/application_helper.rb +++ b/src/app/helpers/application_helper.rb @@ -120,7 +120,7 @@ module ApplicationHelper time = (time - hours) / 24 days = time % 7
- result_string<< pluralize(days.to_i, 'day') if days != 0 + result_string<< "#{days.to_i} #{(days.to_i > 1 ? 'days' : 'day')}" if days != 0 result_string<<"#{"%02d"%hours.to_i}:#{"%02d"%minutes.to_i}:#{"%02d"%seconds.to_i}" result_string.join(", ") else diff --git a/src/app/models/deployment.rb b/src/app/models/deployment.rb index 5365af2..74b3900 100644 --- a/src/app/models/deployment.rb +++ b/src/app/models/deployment.rb @@ -288,17 +288,16 @@ class Deployment < ActiveRecord::Base :deployable_xml_name => deployable_xml.name, :instances_count => instances.count, :uptime => ApplicationHelper.count_uptime(uptime_1st_instance), - :href => Rails.application.routes.url_helpers.deployment_path(id), :pool => { :name => pool.name, - :href => Rails.application.routes.url_helpers.pool_path(pool.id), + :id => pool.id, }, })
if provider json[:provider] = { :name => provider.provider_type.name, - :href => Rails.application.routes.url_helpers.provider_path(provider.id), + :id => provider.id, } end
diff --git a/src/app/models/instance.rb b/src/app/models/instance.rb index 9274533..cb15b16 100644 --- a/src/app/models/instance.rb +++ b/src/app/models/instance.rb @@ -370,16 +370,11 @@ class Instance < ActiveRecord::Base {:include => :hardware_profile} }
- def instance_key_path - Rails.application.routes.url_helpers.key_instance_path(self) if instance_key - end - def as_json(options={}) super(options).merge({ :owner => owner.name, :provider => provider_account ? provider_account.provider.name : '', - :href => Rails.application.routes.url_helpers.instance_path(id), - :instance_key_path => instance_key_path, + :has_key => !!instance_key }) end
diff --git a/src/app/models/pool.rb b/src/app/models/pool.rb index eca5f71..b963e3a 100644 --- a/src/app/models/pool.rb +++ b/src/app/models/pool.rb @@ -110,10 +110,9 @@ class Pool < ActiveRecord::Base result = super(options).merge({ :statistics => statistics, :deployments_count => deployments.count, - :href => Rails.application.routes.url_helpers.pool_path(id), :pool_family => { :name => pool_family.name, - :href => Rails.application.routes.url_helpers.pool_family_path(pool_family.id), + :id => pool_family.id, },
}) diff --git a/src/app/views/deployments/_list.haml b/src/app/views/deployments/_list.haml index c474218..5e9d5cd 100644 --- a/src/app/views/deployments/_list.haml +++ b/src/app/views/deployments/_list.haml @@ -39,13 +39,13 @@ <td><input type="checkbox" id="deployment_checkbox_${id}" name="deployments_selected[]" value="${id}"></td> <td /> - <td><a href="${href}">${name}</a></td> + <td><a href="#{deployment_path('replace_id').sub('replace_id', '${id}')}">${name}</a></td> <td>${created_at}</td> <td>${deployable_xml_name}</td> <td>${instances_count}</td> - <td><a href="${pool.href}">${pool.name}</a></td> + <td><a href="#{pool_path('replace_id').sub('replace_id', '${pool.id}')}">${pool.name}</a></td> <td>${owner}</td> {{if provider}} - <td><a href="${provider.href}">${provider.name}</a></td> + <td><a href="#{provider_path('replace_id').sub('replace_id', '${provider.id}')}">${provider.name}</a></td> {{/if}} </tr> diff --git a/src/app/views/deployments/_pretty_view.haml b/src/app/views/deployments/_pretty_view.haml index f57b770..ccaad6c 100644 --- a/src/app/views/deployments/_pretty_view.haml +++ b/src/app/views/deployments/_pretty_view.haml @@ -30,7 +30,7 @@ :plain <li class="deployment"> <h3 class="name"> - <a href="${href}">${name}</a> + <a href="#{deployment_path('replace_id').sub('replace_id', '${id}')}">${name}</a> </h3> <dl class="statistics"> <ul> diff --git a/src/app/views/deployments/_pretty_view_show.haml b/src/app/views/deployments/_pretty_view_show.haml index 4f7fe6a..86b1bad 100644 --- a/src/app/views/deployments/_pretty_view_show.haml +++ b/src/app/views/deployments/_pretty_view_show.haml @@ -11,9 +11,9 @@ %li State: = instance.state - - if instance.instance_key_path + - if instance.instance_key %li - = link_to("Download key", instance.instance_key_path) + = link_to("Download key", key_instance_path(instance))
:javascript Conductor.setupPrettyFilterURL( @@ -26,8 +26,8 @@ <ul> <li>IP Address: ${public_addresses}</li> <li>State: ${state}</li> - {{if instance_key_path}} - <li><a href="${instance_key_path}">Download key</a></li> + {{if has_key}} + <li><a href="#{key_instance_path('replace_id').sub('replace_id', '${id}')}">Download key</a></li> {{/if}} </ul> </li> diff --git a/src/app/views/instances/_list.haml b/src/app/views/instances/_list.haml index 316ad14..70de8e6 100644 --- a/src/app/views/instances/_list.haml +++ b/src/app/views/instances/_list.haml @@ -34,7 +34,7 @@ <td><input type="checkbox" id="instance_checkbox_${id}" name="instance_selected[]" value="${id}"></td> <td /> - <td><a href="${href}">${name}</a></td> + <td><a href="#{instance_path('replace_id').sub('replace_id', '${id}')}">${name}</a></td> <td>${public_addresses}</td> <td>${state}</td> <td>${provider}</td> diff --git a/src/app/views/pools/_list.haml b/src/app/views/pools/_list.haml index f691c87..d7bf205 100644 --- a/src/app/views/pools/_list.haml +++ b/src/app/views/pools/_list.haml @@ -31,11 +31,11 @@ <td><input type="checkbox" id="pool_checkbox_${id}" name="pools_selected[]" value="${id}"></td> <td /> - <td><a href="${href}">${name}</a></td> + <td><a href="#{pool_path('replace_id').sub('replace_id', '${id}')}">${name}</a></td> <td>${deployments_count}</td> <td>${statistics.total_instances}</td> <td>${statistics.instances_pending}</td> <td>${statistics.instances_failed}</td> <td>${statistics.quota_percent}</td> - <td><a href="${pool_family.href}">${pool_family.name}</a></td> + <td><a href="#{pool_family_path('replace_id').sub('replace_id', '${pool_family.id}')}">${pool_family.name}</a></td> </tr>
On Friday 23 September 2011 11:36:25 jprovazn@redhat.com wrote:
From: Jan Provaznik jprovazn@redhat.com
https://www.aeolusproject.org/redmine/issues/2382 https://bugzilla.redhat.com/show_bug.cgi?id=734503
Links are now generated in views (when jquery template is defined), and only object id is then passed in JSON data. It's not possible to pass '${id}' string as id to *_path helper methods because URI.escape is called on id, so after generating path, id is substituted with ('${id}').
Not saying this is cleanest way how to do it, but it's simplest ATM and buys us some time to figure out better solution.
src/app/helpers/application_helper.rb | 2 +- src/app/models/deployment.rb | 5 ++--- src/app/models/instance.rb | 7 +------ src/app/models/pool.rb | 3 +-- src/app/views/deployments/_list.haml | 6 +++--- src/app/views/deployments/_pretty_view.haml | 2 +- src/app/views/deployments/_pretty_view_show.haml | 8 ++++---- src/app/views/instances/_list.haml | 2 +- src/app/views/pools/_list.haml | 4 ++-- 9 files changed, 16 insertions(+), 23 deletions(-)
diff --git a/src/app/helpers/application_helper.rb b/src/app/helpers/application_helper.rb index b22d1cf..9441d76 100644 --- a/src/app/helpers/application_helper.rb +++ b/src/app/helpers/application_helper.rb @@ -120,7 +120,7 @@ module ApplicationHelper time = (time - hours) / 24 days = time % 7
result_string<< pluralize(days.to_i, 'day') if days != 0
result_string<< "#{days.to_i} #{(days.to_i > 1 ? 'days' : 'day')}"
if days != 0 result_string<<"#{"%02d"%hours.to_i}:#{"%02d"%minutes.to_i}:#{"%02d"%secon ds.to_i}" result_string.join(", ") else diff --git a/src/app/models/deployment.rb b/src/app/models/deployment.rb index 5365af2..74b3900 100644 --- a/src/app/models/deployment.rb +++ b/src/app/models/deployment.rb @@ -288,17 +288,16 @@ class Deployment < ActiveRecord::Base
:deployable_xml_name => deployable_xml.name, :instances_count => instances.count, :uptime => ApplicationHelper.count_uptime(uptime_1st_instance),
:href => Rails.application.routes.url_helpers.deployment_path(id), :pool => { : :name => pool.name,
:href => Rails.application.routes.url_helpers.pool_path(pool.id),
:id => pool.id, },
})
if provider json[:provider] = {
:name => provider.provider_type.name,
:href =>
Rails.application.routes.url_helpers.provider_path(provider.id), + :id => provider.id, } end
diff --git a/src/app/models/instance.rb b/src/app/models/instance.rb index 9274533..cb15b16 100644 --- a/src/app/models/instance.rb +++ b/src/app/models/instance.rb @@ -370,16 +370,11 @@ class Instance < ActiveRecord::Base {:include => :hardware_profile} }
- def instance_key_path
- Rails.application.routes.url_helpers.key_instance_path(self) if
instance_key - end
def as_json(options={}) super(options).merge({
:owner => owner.name, :provider => provider_account ? provider_account.provider.name : '',
:href => Rails.application.routes.url_helpers.instance_path(id),
:instance_key_path => instance_key_path,
}) end:has_key => !!instance_key
diff --git a/src/app/models/pool.rb b/src/app/models/pool.rb index eca5f71..b963e3a 100644 --- a/src/app/models/pool.rb +++ b/src/app/models/pool.rb @@ -110,10 +110,9 @@ class Pool < ActiveRecord::Base result = super(options).merge({
:statistics => statistics, :deployments_count => deployments.count,
:href => Rails.application.routes.url_helpers.pool_path(id), :pool_family => { : :name => pool_family.name,
:href =>
Rails.application.routes.url_helpers.pool_family_path(pool_family.id), + :id => pool_family.id, },
})
diff --git a/src/app/views/deployments/_list.haml b/src/app/views/deployments/_list.haml index c474218..5e9d5cd 100644 --- a/src/app/views/deployments/_list.haml +++ b/src/app/views/deployments/_list.haml @@ -39,13 +39,13 @@ <td><input type="checkbox" id="deployment_checkbox_${id}" name="deployments_selected[]" value="${id}"></td> <td />
<td><a href="${href}">${name}</a></td>
<td><a href="#{deployment_path('replace_id').sub('replace_id',
'${id}')}">${name}</a></td> <td>${created_at}</td> <td>${deployable_xml_name}</td> <td>${instances_count}</td>
<td><a href="${pool.href}">${pool.name}</a></td>
<td><a href="#{pool_path('replace_id').sub('replace_id',
'${pool.id}')}">${pool.name}</a></td> <td>${owner}</td> {{if provider}}
<td><a href="${provider.href}">${provider.name}</a></td>
<td><a href="#{provider_path('replace_id').sub('replace_id',
'${provider.id}')}">${provider.name}</a></td> {{/if}} </tr> diff --git a/src/app/views/deployments/_pretty_view.haml b/src/app/views/deployments/_pretty_view.haml index f57b770..ccaad6c 100644 --- a/src/app/views/deployments/_pretty_view.haml +++ b/src/app/views/deployments/_pretty_view.haml @@ -30,7 +30,7 @@
:plain
<li class="deployment"> <h3 class="name">
<a href="${href}">${name}</a>
<a href="#{deployment_path('replace_id').sub('replace_id',
'${id}')}">${name}</a> </h3> <dl class="statistics"> <ul> diff --git a/src/app/views/deployments/_pretty_view_show.haml b/src/app/views/deployments/_pretty_view_show.haml index 4f7fe6a..86b1bad 100644 --- a/src/app/views/deployments/_pretty_view_show.haml +++ b/src/app/views/deployments/_pretty_view_show.haml @@ -11,9 +11,9 @@ %li State: = instance.state
- if instance.instance_key_path
- if instance.instance_key %li
= link_to("Download key", instance.instance_key_path)
= link_to("Download key", key_instance_path(instance))
:javascript
Conductor.setupPrettyFilterURL( @@ -26,8 +26,8 @@ <ul> <li>IP Address: ${public_addresses}</li> <li>State: ${state}</li>
{{if instance_key_path}}
<li><a href="${instance_key_path}">Download key</a></li>
{{if has_key}}
<li><a href="#{key_instance_path('replace_id').sub('replace_id',
'${id}')}">Download key</a></li> {{/if}} </ul> </li> diff --git a/src/app/views/instances/_list.haml b/src/app/views/instances/_list.haml index 316ad14..70de8e6 100644 --- a/src/app/views/instances/_list.haml +++ b/src/app/views/instances/_list.haml @@ -34,7 +34,7 @@ <td><input type="checkbox" id="instance_checkbox_${id}" name="instance_selected[]" value="${id}"></td> <td />
<td><a href="${href}">${name}</a></td>
<td><a href="#{instance_path('replace_id').sub('replace_id',
'${id}')}">${name}</a></td> <td>${public_addresses}</td> <td>${state}</td> <td>${provider}</td> diff --git a/src/app/views/pools/_list.haml b/src/app/views/pools/_list.haml index f691c87..d7bf205 100644 --- a/src/app/views/pools/_list.haml +++ b/src/app/views/pools/_list.haml @@ -31,11 +31,11 @@ <td><input type="checkbox" id="pool_checkbox_${id}" name="pools_selected[]" value="${id}"></td> <td />
<td><a href="${href}">${name}</a></td>
<td><a href="#{pool_path('replace_id').sub('replace_id',
'${id}')}">${name}</a></td> <td>${deployments_count}</td> <td>${statistics.total_instances}</td> <td>${statistics.instances_pending}</td> <td>${statistics.instances_failed}</td> <td>${statistics.quota_percent}</td>
<td><a href="${pool_family.href}">${pool_family.name}</a></td>
<td><a href="#{pool_family_path('replace_id').sub('replace_id',
'${pool_family.id}')}">${pool_family.name}</a></td> </tr>
ACK & pushed.
aeolus-devel@lists.fedorahosted.org