You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by mf...@redhat.com on 2011/06/02 12:19:07 UTC
Cleanup in views
Hi,
just a small cleanup inside views/ directory. I unified way how
we generate index action output by using partial renders, removed
obsoleted 'accounts' views (what was that for btw? ;-) and added
'AVAILABLE' state to Mock Images.
Thanks to Chris and Marios to open this issue [1].
-- Michal
[1] https://teambox.com/projects/deltacloud/task_lists/74335/tasks/341707
[PATCH core 2/3] Unified way how we generate index output using partial render
Posted by mf...@redhat.com.
From: Michal Fojtik <mf...@redhat.com>
Signed-off-by: Michal fojtik <mf...@redhat.com>
---
server/views/buckets/index.xml.haml | 10 ++----
server/views/buckets/show.xml.haml | 8 +++--
server/views/images/index.xml.haml | 17 ++--------
server/views/images/show.xml.haml | 3 +-
server/views/instances/index.xml.haml | 38 +-----------------------
server/views/instances/show.xml.haml | 3 +-
server/views/load_balancers/index.xml.haml | 1 -
server/views/realms/index.xml.haml | 10 +-----
server/views/realms/show.xml.haml | 3 +-
server/views/storage_snapshots/index.xml.haml | 7 +---
server/views/storage_snapshots/show.xml.haml | 3 +-
11 files changed, 26 insertions(+), 77 deletions(-)
diff --git a/server/views/buckets/index.xml.haml b/server/views/buckets/index.xml.haml
index e8cbeec..9f1fd20 100644
--- a/server/views/buckets/index.xml.haml
+++ b/server/views/buckets/index.xml.haml
@@ -1,8 +1,4 @@
-!!! XML
+!!!XML
%buckets
- - @elements.each do |bucket|
- %bucket{:href => bucket_url(bucket.id), :id => bucket.id}
- - bucket.attributes.select{ |attr| attr!=:id }.each do |attribute|
- - haml_tag("#{attribute}".tr('-', '_'), :<) do
- - haml_concat bucket.send(attribute)
-
+ - @elements.each do |c|
+ = haml :'buckets/show', :locals => { :@bucket => c, :partial => true }
diff --git a/server/views/buckets/show.xml.haml b/server/views/buckets/show.xml.haml
index 9b650e2..67f6935 100644
--- a/server/views/buckets/show.xml.haml
+++ b/server/views/buckets/show.xml.haml
@@ -1,8 +1,10 @@
-!!! XML
+- unless defined?(partial)
+ !!! XML
%bucket{:href => bucket_url(@bucket.id), :id => @bucket.id}
- @bucket.attributes.select{ |attr| attr!=:id }.each do |attribute|
- unless attribute == :blob_list
-haml_tag(attribute, :<) do
- haml_concat @bucket.send(attribute)
- - @bucket.blob_list.each do |blb|
- %blob{:id => blb, :href => bucket_url(@bucket.id) +"/#{blb}"}
\ No newline at end of file
+ - if @bucket.blob_list
+ - @bucket.blob_list.each do |blb|
+ %blob{:id => blb, :href => bucket_url(@bucket.id) +"/#{blb}"}
diff --git a/server/views/images/index.xml.haml b/server/views/images/index.xml.haml
index b05bf73..52d86e6 100644
--- a/server/views/images/index.xml.haml
+++ b/server/views/images/index.xml.haml
@@ -1,14 +1,5 @@
-!!! XML
+- unless defined?(partial)
+ !!! XML
%images
- - @elements.each do |image|
- %image{:href => image_url(image.id), :id => image.id}
- - image.attributes.select{ |attr| attr!=:id }.each do |attribute|
- - haml_tag("#{attribute}".tr('-', '_'), :<) do
- - if [:name, :description].include?(attribute)
- =cdata do
- - haml_concat image.send(attribute)
- - else
- - haml_concat image.send(attribute)
- %actions
- %link{ :rel => 'create_instance', :method => :post, :href => "#{instances_url};image_id=#{image.id}"}
-
+ - @elements.each do |c|
+ = haml :'images/show', :locals => { :@image => c, :partial => true }
diff --git a/server/views/images/show.xml.haml b/server/views/images/show.xml.haml
index b35b249..c1f5348 100644
--- a/server/views/images/show.xml.haml
+++ b/server/views/images/show.xml.haml
@@ -1,4 +1,5 @@
-!!! XML
+- unless defined?(partial)
+ !!! XML
%image{:href => image_url(@image.id), :id => @image.id}
- @image.attributes.select{ |attr| attr!=:id }.each do |attribute|
- haml_tag(attribute, :<) do
diff --git a/server/views/instances/index.xml.haml b/server/views/instances/index.xml.haml
index 0f317ba..e5f39ba 100644
--- a/server/views/instances/index.xml.haml
+++ b/server/views/instances/index.xml.haml
@@ -1,38 +1,4 @@
!!! XML
%instances
- - @elements.each do |instance|
- %instance{:href => instance_url(instance.id), :id => instance.id}
- %name #{instance.name}
- %owner_id #{instance.owner_id}
- %image{:href => image_url(instance.image_id), :id => instance.image_id }
- %realm{:href => realm_url(instance.realm_id), :id => instance.realm_id }
- %state #{instance.state}
- - haml_tag :"hardware_profile", { :id => instance.instance_profile.id, :href => hardware_profile_url(instance.instance_profile.id)} do
- - instance.instance_profile.overrides.each do |p, v|
- %property{:kind => 'fixed', :name => p, :value => v, :unit => Deltacloud::HardwareProfile::unit(p)}
- %actions
- - instance.actions.compact.each do |action|
- %link{:rel => action, :href => self.send("#{action}_instance_url", instance.id), :method => instance_action_method(action)}
- - if driver.respond_to?(:run_on_instance)
- %link{:rel => 'run', :method => :post, :href => run_instance_url(instance.id)}
- - if instance.can_create_image?
- %link{:rel => 'create_image', :method => :post, :href => "#{create_image_url};instance_id=#{instance.id}"}
- %public_addresses
- - instance.public_addresses.each do |address|
- %address #{address}
- %private_addresses
- - instance.private_addresses.each do |address|
- %address #{address}
- - if driver_has_auth_features?
- %authentication{ :type => driver_auth_feature_name }
- - if instance.authn_feature_failed?
- %error #{instance.authn_error}
- - else
- - if driver_auth_feature_name == 'password'
- %login
- %username #{instance.username}
- %password #{instance.password}
- - if driver_auth_feature_name == 'key'
- %login
- %keyname #{instance.keyname}
-
+ - @elements.each do |c|
+ = haml :'instances/show', :locals => { :@instance => c, :partial => true }
diff --git a/server/views/instances/show.xml.haml b/server/views/instances/show.xml.haml
index 45cd84b..efbdac1 100644
--- a/server/views/instances/show.xml.haml
+++ b/server/views/instances/show.xml.haml
@@ -1,4 +1,5 @@
-!!! XML
+- unless defined?(partial)
+ !!! XML
%instance{:href => instance_url(@instance.id), :id => @instance.id}
- if @instance.name
%name<
diff --git a/server/views/load_balancers/index.xml.haml b/server/views/load_balancers/index.xml.haml
index 22c6911..053b628 100644
--- a/server/views/load_balancers/index.xml.haml
+++ b/server/views/load_balancers/index.xml.haml
@@ -1,4 +1,3 @@
-
!!!XML
%load_balancers
- @elements.each do |c|
diff --git a/server/views/realms/index.xml.haml b/server/views/realms/index.xml.haml
index e67f282..71d1cb1 100644
--- a/server/views/realms/index.xml.haml
+++ b/server/views/realms/index.xml.haml
@@ -1,10 +1,4 @@
!!!XML
%realms
- - @elements.each do |realm|
- %realm{:href => realm_url(realm.id), :id => realm.id }
- %name<
- =realm.name
- %state<
- =realm.state
- %limit<
- =realm.limit.eql?(:unlimited) ? '' : realm.limit
+ - @elements.each do |c|
+ = haml :'realms/show', :locals => { :@realm => c, :partial => true }
diff --git a/server/views/realms/show.xml.haml b/server/views/realms/show.xml.haml
index f53c46a..42f77c3 100644
--- a/server/views/realms/show.xml.haml
+++ b/server/views/realms/show.xml.haml
@@ -1,4 +1,5 @@
-!!!XML
+- unless defined?(partial)
+ !!! XML
%realm{:href => realm_url(@realm.id), :id => @realm.id }
%name<
=@realm.name
diff --git a/server/views/storage_snapshots/index.xml.haml b/server/views/storage_snapshots/index.xml.haml
index 8748532..9ae9675 100644
--- a/server/views/storage_snapshots/index.xml.haml
+++ b/server/views/storage_snapshots/index.xml.haml
@@ -1,7 +1,4 @@
!!!XML
%storage_snapshots
- - @elements.each do |snapshot|
- %storage_snapshot{ :href => storage_snapshot_url(snapshot.id), :id => snapshot.id }
- %created<
- =snapshot.created
- %storage_volume{ :href => storage_volume_url(snapshot.storage_volume_id), :id => snapshot.storage_volume_id }
+ - @elements.each do |c|
+ = haml :'storage_snapshots/show', :locals => { :@storage_snapshot => c, :partial => true }
diff --git a/server/views/storage_snapshots/show.xml.haml b/server/views/storage_snapshots/show.xml.haml
index 3cfa8a6..f9596a6 100644
--- a/server/views/storage_snapshots/show.xml.haml
+++ b/server/views/storage_snapshots/show.xml.haml
@@ -1,4 +1,5 @@
-!!!XML
+- unless defined?(partial)
+ !!! XML
%storage_snapshot{:href => storage_snapshot_url(@storage_snapshot.id), :id => @storage_snapshot.id }
%created<
=@storage_snapshot.created
--
1.7.4.1
[PATCH core 3/3] Added missing state to Image in Mock driver
Posted by mf...@redhat.com.
From: Michal Fojtik <mf...@redhat.com>
Signed-off-by: Michal fojtik <mf...@redhat.com>
---
server/lib/deltacloud/drivers/mock/mock_driver.rb | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/server/lib/deltacloud/drivers/mock/mock_driver.rb b/server/lib/deltacloud/drivers/mock/mock_driver.rb
index 83a7404..df2fff0 100644
--- a/server/lib/deltacloud/drivers/mock/mock_driver.rb
+++ b/server/lib/deltacloud/drivers/mock/mock_driver.rb
@@ -121,6 +121,7 @@ class MockDriver < Deltacloud::BaseDriver
image = YAML.load( File.read( image_file ) )
image[:id] = File.basename( image_file, ".yml" )
image[:name] = image[:description]
+ image[:state] = "AVAILABLE"
images << Image.new( image )
end
images = filter_on( images, :id, opts )
--
1.7.4.1
Re: Cleanup in views
Posted by "marios@redhat.com" <ma...@redhat.com>.
Hi Michal - ACK but please can you check that the rendering of
storage_snapshots is ok for you? I can't understand why, but with the
new 'partial' method I get an empty response from the server (both using
browser and curl). But when I switch git branch to the old 'full' method
I get the proper list of snapshots. I've been staring at the code for
ages but couldn't find an issue; might be some kind of buffering issue
with haml gem and rendering so many items (a *lot* of snapshots are
returned),
marios
On 02/06/11 13:19, mfojtik@redhat.com wrote:
> Hi,
>
> just a small cleanup inside views/ directory. I unified way how
> we generate index action output by using partial renders, removed
> obsoleted 'accounts' views (what was that for btw? ;-) and added
> 'AVAILABLE' state to Mock Images.
>
> Thanks to Chris and Marios to open this issue [1].
>
> -- Michal
>
> [1] https://teambox.com/projects/deltacloud/task_lists/74335/tasks/341707
>
[PATCH core 1/3] Removed obsoleted accounts views
Posted by mf...@redhat.com.
From: Michal Fojtik <mf...@redhat.com>
Signed-off-by: Michal fojtik <mf...@redhat.com>
---
server/views/accounts/index.html.haml | 11 -----------
server/views/accounts/show.html.haml | 30 ------------------------------
2 files changed, 0 insertions(+), 41 deletions(-)
delete mode 100644 server/views/accounts/index.html.haml
delete mode 100644 server/views/accounts/show.html.haml
diff --git a/server/views/accounts/index.html.haml b/server/views/accounts/index.html.haml
deleted file mode 100644
index df73d19..0000000
--- a/server/views/accounts/index.html.haml
+++ /dev/null
@@ -1,11 +0,0 @@
-%h1 Accounts
-
-%table
- %thead
- %tr
- %th ID
- %tbody
- - @accounts.each do |account|
- %tr
- %td
- = link_to account, account
diff --git a/server/views/accounts/show.html.haml b/server/views/accounts/show.html.haml
deleted file mode 100644
index 2688b3e..0000000
--- a/server/views/accounts/show.html.haml
+++ /dev/null
@@ -1,30 +0,0 @@
-%h1
- = @account[:id]
-
-%h2 Instances
-
-%table
- %thead
- %tr
- %th Instance ID
- %tbody
- - @account[:instance_ids].each do |instance_id|
- %tr
- %td
- = link_to instance_id, instance_url( instance_id )
-
-%h2 Images
-
-%table
- %thead
- %tr
- %th Image ID
- %th Description
- %tbody
- %tbody
- - @images.each do |image|
- %tr
- %td
- = link_to image[:id], image_url( image[:id] )
- %td
- = image[:description]
--
1.7.4.1