You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by lu...@redhat.com on 2011/08/20 03:02:04 UTC

Misc UI fixes

These patches address two of the problems that Sang-Min and Chris found,
namely that it is impossible to create firewall rules and addresses from
the HTML UI.

We still need to address the problem with attaching storage volumes to
instances. I hope it's similarly a UI-only issue.

David

[PATCH 2/4] * server.rb (firewalls/new_rule): raise a validation error if no source given

Posted by lu...@redhat.com.
From: David Lutterkort <lu...@redhat.com>


Signed-off-by: David Lutterkort <lu...@redhat.com>
---
 server/server.rb |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/server/server.rb b/server/server.rb
index 1b50476..e579eca 100644
--- a/server/server.rb
+++ b/server/server.rb
@@ -1148,7 +1148,11 @@ collection :firewalls do
       for i in (1..max_groups) do
         groups.merge!({params["group#{i}"]=>params["group#{i}owner"]})
       end
-      params.merge!( {'addresses' => addresses} ) ; params.merge!( {'groups' => groups} )
+      params['addresses'] = addresses
+      params['groups'] = groups
+      if addresses.empty? && groups.empty?
+        raise Deltacloud::Validation::Failure.new(nil, "No sources. Specify at least one source ip_address or group")
+      end
       driver.create_firewall_rule(credentials, params)
       @firewall = driver.firewall(credentials, {:id => params[:id]})
       status 201
-- 
1.7.6


[PATCH 1/4] * server.rb (firewalls/new_rule): the name of the firewall is in param[:id]

Posted by lu...@redhat.com.
From: David Lutterkort <lu...@redhat.com>


Signed-off-by: David Lutterkort <lu...@redhat.com>
---
 server/server.rb |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/server/server.rb b/server/server.rb
index 3427549..1b50476 100644
--- a/server/server.rb
+++ b/server/server.rb
@@ -1077,9 +1077,9 @@ collection :firewalls do
 
   operation :new_rule, :form => true, :member => true, :method => :get do
     description "A form to create a new firewall rule"
-    param :firewall,  :string,  :optional
+    param :id,  :string,  :required
     control do
-      @firewall_name = params[:firewall]
+      @firewall_name = params[:id]
       respond_to do |format|
         format.html {haml :"firewalls/new_rule" }
       end
-- 
1.7.6


[PATCH 4/4] addresses: make creation from HTML UI work

Posted by lu...@redhat.com.
From: David Lutterkort <lu...@redhat.com>


Signed-off-by: David Lutterkort <lu...@redhat.com>
---
 server/public/javascripts/application.js  |    9 +++++++++
 server/server.rb                          |    2 +-
 server/views/addresses/_address.html.haml |    6 ++++++
 server/views/addresses/index.html.haml    |   12 +++---------
 4 files changed, 19 insertions(+), 10 deletions(-)
 create mode 100644 server/views/addresses/_address.html.haml

diff --git a/server/public/javascripts/application.js b/server/public/javascripts/application.js
index 2e3e82b..e82ea76 100644
--- a/server/public/javascripts/application.js
+++ b/server/public/javascripts/application.js
@@ -132,3 +132,12 @@ function create_rule_source_field(name, label, hint)
 
   $(html).insertBefore("#new_rule_form_fields")
 }
+
+function create_address(url)
+{
+  $.post(url, function(data) {
+    var ul = $('#address_list')
+    ul.append($(data))
+    ul.listview('refresh')
+  })
+}
diff --git a/server/server.rb b/server/server.rb
index e579eca..78aaffc 100644
--- a/server/server.rb
+++ b/server/server.rb
@@ -994,7 +994,7 @@ collection :addresses do
       response['Location'] = address_url(@address.id)
       respond_to do |format|
         format.xml  { haml :"addresses/show", :ugly => true }
-        format.html { haml :"addresses/show" }
+        format.html { haml :"addresses/_address", :layout => false }
         format.json { convert_to_json(:address, @address) }
       end
     end
diff --git a/server/views/addresses/_address.html.haml b/server/views/addresses/_address.html.haml
new file mode 100644
index 0000000..28420a1
--- /dev/null
+++ b/server/views/addresses/_address.html.haml
@@ -0,0 +1,6 @@
+%li
+  %a{ :href => address_url(@address.id), :'data-ajax' => 'false'}
+    %img{ :class => 'ui-link-thumb', :src => '/images/address.png'}
+    %h3= @address.id
+    %span{ :class => 'ui-li-count'}
+      = @address.instance_id ? @address.instance_id : 'Free'
diff --git a/server/views/addresses/index.html.haml b/server/views/addresses/index.html.haml
index fd48540..9cac99f 100644
--- a/server/views/addresses/index.html.haml
+++ b/server/views/addresses/index.html.haml
@@ -1,15 +1,9 @@
 =header "Addresses" do
-  %a{ :href => create_address_url, :'data-icon' => :plus, :'data-role' => :button, :class => 'ui-btn-right', :'data-ajax' => "false", :'method' => :post} Create new address
+  %a{ :href => "#", :onclick => "create_address('#{create_address_url}')", :'data-icon' => :plus, :'data-role' => :button, :class => 'ui-btn-right', :'data-ajax' => "false", :method => :post} Create new address
 =subheader "#{Thread::current[:provider] || ENV['API_PROVIDER'] || 'default'}"
 
 %div{ :'data-role' => :content, :'data-theme' => 'c'}
-  %ul{ :'data-role' => :listview , :'data-inset' => :true, :'data-divider-theme' => 'a'}
+  %ul#address_list{ :'data-role' => :listview , :'data-inset' => :true, :'data-divider-theme' => 'a'}
     %li{ :'data-role' => 'list-divider'}=driver_symbol
     - @elements.each do |address|
-      %li
-        %a{ :href => address_url(address.id), :'data-ajax' => 'false'}
-          %img{ :class => 'ui-link-thumb', :src => '/images/address.png'}
-          %h3=address.id
-          %span{ :class => 'ui-li-count'}=address.instance_id ? address.instance_id : 'Free'
-
-
+      = haml :"addresses/_address", :locals => { :@address => address, :partial => true }
-- 
1.7.6


[PATCH 3/4] views (firewalls/new_rule): fix the new_rule form

Posted by lu...@redhat.com.
From: David Lutterkort <lu...@redhat.com>

The form had two problems:

  * the source fields (address/group) were generated outside the <form> tag
    and hence the fields were never submitted
  * the names for the port_from and port_to fields were incorrect

Signed-off-by: David Lutterkort <lu...@redhat.com>
---
 server/public/javascripts/application.js  |   32 +++++++++++-----------------
 server/views/firewalls/new_rule.html.haml |    7 +++--
 2 files changed, 17 insertions(+), 22 deletions(-)

diff --git a/server/public/javascripts/application.js b/server/public/javascripts/application.js
index aa755d3..2e3e82b 100644
--- a/server/public/javascripts/application.js
+++ b/server/public/javascripts/application.js
@@ -108,33 +108,27 @@ var addresses = 0;
 var groups = 0;
 function make_fields(type)
 {
-  form = document.getElementById("new_rule_form")
-  button = document.getElementById("submit_button")
-  if(type == "address")
+  if (type == "address")
   {
     name = "ip_address" + eval(++addresses)
-    create_rule_source_field(name, "Address " + eval(addresses) + " [use CIDR notation 0.0.0.0/0]", form, button)
+    create_rule_source_field(name, "Address " + eval(addresses),
+                             "[use CIDR notation 0.0.0.0/0]")
   }
-  else if(type == "group")
+  else if (type == "group")
   {
     name = "group" + eval(++groups)
-    create_rule_source_field(name, "Name of group " + eval(groups), form, button)
+    create_rule_source_field(name, "Name of group " + eval(groups), "")
     name = "group" + eval(groups) + "owner"
-    create_rule_source_field(name, "Group " + eval(groups) + " owner (required)", form, button)
+    create_rule_source_field(name, "Group " + eval(groups) + " owner", "(required)")
   }
 }
 
-function create_rule_source_field(name, label, form, button)
+function create_rule_source_field(name, label, hint)
 {
-    element = document.createElement("INPUT")
-    element.type = "input"
-    element.size = 35
-    element.name = name
-    text = document.createTextNode(label)
-    form.insertBefore(element, button)
-    form.insertBefore(text, element)
-    form.insertBefore(document.createElement('BR'), element)
-    form.insertBefore(document.createElement('BR'), button)
-    form.insertBefore(document.createElement('BR'), button)
-    form.insertBefore(document.createElement('BR'), button)
+  html = "<br/>" +
+    "<label>" + label + "</label>&nbsp;" +
+    "<input name='" + name + "' size=35 type='text'/>" +
+    "<span>&nbsp;" + hint + "</span>"
+
+  $(html).insertBefore("#new_rule_form_fields")
 }
diff --git a/server/views/firewalls/new_rule.html.haml b/server/views/firewalls/new_rule.html.haml
index 110ac8e..1cba509 100644
--- a/server/views/firewalls/new_rule.html.haml
+++ b/server/views/firewalls/new_rule.html.haml
@@ -7,13 +7,14 @@
       %input{ :type => :text, :id => :protocol, :name => :protocol, :value => '', :size => 10 }
     %div{ 'data-role' => :fieldcontain }
       %label{ :for => :name} From port:
-      %input{ :type => :text, :id => :from_port, :name => :from_port, :value => '', :size => 10 }
+      %input{ :type => :text, :id => :port_from, :name => :port_from, :value => '', :size => 10 }
     %div{ 'data-role' => :fieldcontain }
       %label{ :for => :name} To port:
-      %input{ :type => :text, :id => :to_port, :name => :to_port, :value => '', :size => 10 }
+      %input{ :type => :text, :id => :port_to, :name => :port_to, :value => '', :size => 10 }
     %div{ 'data-role' => :fieldcontain }
       %a{ :href => "javascript:;", :onclick => "make_fields('address');"} Add source IP address
       %br
       %a{ :href => "javascript:;", :onclick => "make_fields('group');"} Add source group
+      %br
+      #new_rule_form_fields
     %button{ :type => :submit} Create
-
-- 
1.7.6


Re: Misc UI fixes

Posted by Sang-Min Park <sa...@eucalyptus.com>.
ACK
Confirmed it works.

On Mon, Aug 22, 2011 at 1:44 AM, Michal Fojtik <mf...@redhat.com> wrote:

>
> On Aug 20, 2011, at 3:02 AM, lutter@redhat.com wrote:
>
> >
> > These patches address two of the problems that Sang-Min and Chris found,
> > namely that it is impossible to create firewall rules and addresses from
> > the HTML UI.
> >
> > We still need to address the problem with attaching storage volumes to
> > instances. I hope it's similarly a UI-only issue.
>
> ACK to whole set.
>
>  -- Michal
>
> ------------------------------------------------------
> Michal Fojtik, mfojtik@redhat.com
> Deltacloud API: http://deltacloud.org
>
>


-- 

----------------------------------------------------
Sang-Min Park
Engineer
Eucalyptus Systems

Re: Misc UI fixes

Posted by Michal Fojtik <mf...@redhat.com>.
On Aug 20, 2011, at 3:02 AM, lutter@redhat.com wrote:

> 
> These patches address two of the problems that Sang-Min and Chris found,
> namely that it is impossible to create firewall rules and addresses from
> the HTML UI.
> 
> We still need to address the problem with attaching storage volumes to
> instances. I hope it's similarly a UI-only issue.

ACK to whole set.

  -- Michal

------------------------------------------------------
Michal Fojtik, mfojtik@redhat.com
Deltacloud API: http://deltacloud.org