deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dko...@apache.org
Subject [5/9] git commit: CIMI: don't render Create views in client UI if no Add operation returned in networks or addresses collection
Date Tue, 09 Jul 2013 06:25:11 GMT
CIMI: don't render Create views in client UI if no Add operation
returned in networks or addresses collection


Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/2e6c993d
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/2e6c993d
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/2e6c993d

Branch: refs/heads/master
Commit: 2e6c993d453ee571777380e2db96518c1950c429
Parents: df198d0
Author: Dies Koper <diesk@fast.au.fujitsu.com>
Authored: Mon Jul 1 15:25:16 2013 +1000
Committer: Dies Koper <diesk@fast.au.fujitsu.com>
Committed: Wed Jul 3 23:51:21 2013 +1000

----------------------------------------------------------------------
 clients/cimi/lib/entities/address.rb    |  6 ++-
 clients/cimi/lib/entities/network.rb    | 18 +++++++--
 clients/cimi/views/addresses/index.haml | 43 +++++++++++-----------
 clients/cimi/views/networks/index.haml  | 55 +++++++++++++++-------------
 4 files changed, 69 insertions(+), 53 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/2e6c993d/clients/cimi/lib/entities/address.rb
----------------------------------------------------------------------
diff --git a/clients/cimi/lib/entities/address.rb b/clients/cimi/lib/entities/address.rb
index 7973dbf..95c76d8 100644
--- a/clients/cimi/lib/entities/address.rb
+++ b/clients/cimi/lib/entities/address.rb
@@ -22,10 +22,12 @@ class CIMI::Frontend::Address < CIMI::Frontend::Entity
   end
 
   get '/cimi/addresses' do
-    address_template_xml = get_entity_collection('address_templates', credentials)
-    @address_templates = collection_class_for(:address_template).from_xml(address_template_xml)
     addresses_xml = get_entity_collection('addresses', credentials)
     @addresses = collection_class_for(:address).from_xml(addresses_xml)
+    if @addresses.operations.find {|o| o.rel == 'add'}
+      address_template_xml = get_entity_collection('address_templates', credentials)
+      @address_templates = collection_class_for(:address_template).from_xml(address_template_xml)
+    end
     haml :'addresses/index'
   end
 

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/2e6c993d/clients/cimi/lib/entities/network.rb
----------------------------------------------------------------------
diff --git a/clients/cimi/lib/entities/network.rb b/clients/cimi/lib/entities/network.rb
index af81726..361d4d9 100644
--- a/clients/cimi/lib/entities/network.rb
+++ b/clients/cimi/lib/entities/network.rb
@@ -22,12 +22,22 @@ class CIMI::Frontend::Network < CIMI::Frontend::Entity
   end
 
   get '/cimi/networks' do
-    forwarding_groups_xml = get_entity_collection('forwarding_groups', credentials)
-    @forwarding_groups = collection_class_for(:forwarding_group).from_xml(forwarding_groups_xml)
-    network_config_xml = get_entity_collection('network_configurations', credentials)
-    @network_configurations = collection_class_for(:network_configuration).from_xml(network_config_xml)
     networks_xml = get_entity_collection('networks', credentials)
     @networks = collection_class_for(:network).from_xml(networks_xml)
+    if @networks.operations.find {|o| o.rel == 'add'}
+      # note that even if 'add' is supported, both forwarding group and
+      # network config are optional in network template
+      begin
+        forwarding_groups_xml = get_entity_collection('forwarding_groups', credentials)
+        @forwarding_groups = collection_class_for(:forwarding_group).from_xml(forwarding_groups_xml)
+      rescue RestClient::ResourceNotFound
+      end
+      begin
+        network_config_xml = get_entity_collection('network_configurations', credentials)
+        @network_configurations = collection_class_for(:network_configuration).from_xml(network_config_xml)
+      rescue RestClient::ResourceNotFound
+      end
+    end
     haml :'networks/index'
   end
 

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/2e6c993d/clients/cimi/views/addresses/index.haml
----------------------------------------------------------------------
diff --git a/clients/cimi/views/addresses/index.haml b/clients/cimi/views/addresses/index.haml
index 6224291..34994b1 100644
--- a/clients/cimi/views/addresses/index.haml
+++ b/clients/cimi/views/addresses/index.haml
@@ -8,28 +8,29 @@
     %li.active
       AddressCollection
 
-- content_for :actions do
-  %p
-    %a{ :href => '#addressModal', :class => 'btn btn-primary', :'data-toggle' =>
:modal} New Address
+- if @addresses.operations.find {|o| o.rel == 'add'}
+  - content_for :actions do
+    %p
+      %a{ :href => '#addressModal', :class => 'btn btn-primary', :'data-toggle' =>
:modal} New Address
 
-  %div{ :id => :addressModal, :class => 'modal hide fade' }
-    .modal-header
-      %h3 Create new Address entity
-    .modal-body
-      %form{ :action => "/cimi/addresses", :method => :post }
-        %fieldset
-          .control-group
-            %label.control-label{ :for => 'address[name]' } Address Name
-            .controls
-              %input{ :type => :text, :name => 'address[name]' }
-            %label.control-label{ :for => 'address[address_template]' } Address Image
-            .controls
-              %select{ :name => 'address[address_template]' }
-                - @address_templates.address_templates.each do |template|
-                  %option{ :value => template.id }=href_to_id(template.id)
-    .modal-footer
-      %a{ :href => '#', :class => 'btn btn-primary', :'data-loading-text' => 'Creating
Address...', :onclick => "postModalForm(this, 'addressModal')"} Continue
-      %a{ :href => '#', :class => 'btn', :'data-dismiss' => 'modal'} Cancel
+    %div{ :id => :addressModal, :class => 'modal hide fade' }
+      .modal-header
+        %h3 Create new Address entity
+      .modal-body
+        %form{ :action => "/cimi/addresses", :method => :post }
+          %fieldset
+            .control-group
+              %label.control-label{ :for => 'address[name]' } Address Name
+              .controls
+                %input{ :type => :text, :name => 'address[name]' }
+              %label.control-label{ :for => 'address[address_template]' } Address Image
+              .controls
+                %select{ :name => 'address[address_template]' }
+                  - @address_templates.address_templates.each do |template|
+                    %option{ :value => template.id }=href_to_id(template.id)
+      .modal-footer
+        %a{ :href => '#', :class => 'btn btn-primary', :'data-loading-text' => 'Creating
Address...', :onclick => "postModalForm(this, 'addressModal')"} Continue
+        %a{ :href => '#', :class => 'btn', :'data-dismiss' => 'modal'} Cancel
   %p
     %a{ :href => "#{@addresses.id}?format=xml", :class => 'label warning' } XML
     %a{ :href => "#{@addresses.id}?format=json", :class => 'label warning' } JSON

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/2e6c993d/clients/cimi/views/networks/index.haml
----------------------------------------------------------------------
diff --git a/clients/cimi/views/networks/index.haml b/clients/cimi/views/networks/index.haml
index 405cd11..7a2720c 100644
--- a/clients/cimi/views/networks/index.haml
+++ b/clients/cimi/views/networks/index.haml
@@ -9,34 +9,37 @@
 
       NetworkCollection
 
-- content_for :actions do
+- if @networks.operations.find {|o| o.rel == 'add'}
+  - content_for :actions do
 
-  %p
-    %a{ :href => '#networkModal', :class => 'btn btn-primary', :'data-toggle' =>
:modal} New Network
+    %p
+      %a{ :href => '#networkModal', :class => 'btn btn-primary', :'data-toggle' =>
:modal} New Network
 
-  %div{ :id => :networkModal, :class => 'modal hide fade' }
-    .modal-header
-      %h3 Create new Network entity
-    .modal-body
-      %form{ :action => "/cimi/networks", :method => :post }
-        %fieldset
-          .control-group
-            %label.control-label{ :for => 'network[name]' } Network Name
-            .controls
-              %input{ :type => :text, :name => 'network[name]' }
-            %label.control-label{ :for => 'network[forwarding_group]' } Forwarding Group
-            .controls
-              %select{ :name => 'network[forwarding_group]' }
-                - @forwarding_groups.forwarding_groups.each do |group|
-                  %option{ :value => group.id }=href_to_id(group.id)
-            %label.control-label{ :for => 'network[network_configuration]' } Network Configuration
-            .controls
-              %select{ :name => 'network[network_configuration]' }
-                - @network_configurations.network_configurations.each do |configuration|
-                  %option{ :value => configuration.id }=href_to_id(configuration.id)
-    .modal-footer
-      %a{ :href => '#', :class => 'btn btn-primary', :'data-loading-text' => 'Creating
Network...', :onclick => "postModalForm(this, 'networkModal')"} Continue
-      %a{ :href => '#', :class => 'btn', :'data-dismiss' => 'modal'} Cancel
+    %div{ :id => :networkModal, :class => 'modal hide fade' }
+      .modal-header
+        %h3 Create new Network entity
+      .modal-body
+        %form{ :action => "/cimi/networks", :method => :post }
+          %fieldset
+            .control-group
+              %label.control-label{ :for => 'network[name]' } Network Name
+              .controls
+                %input{ :type => :text, :name => 'network[name]' }
+              - if @forwarding_groups
+                %label.control-label{ :for => 'network[forwarding_group]' } Forwarding
Group
+                .controls
+                  %select{ :name => 'network[forwarding_group]' }
+                    - @forwarding_groups.forwarding_groups.each do |group|
+                      %option{ :value => group.id }=href_to_id(group.id)
+              - if @network_configurations
+                %label.control-label{ :for => 'network[network_configuration]' } Network
Configuration
+                .controls
+                  %select{ :name => 'network[network_configuration]' }
+                    - @network_configurations.network_configurations.each do |configuration|
+                      %option{ :value => configuration.id }=href_to_id(configuration.id)
+      .modal-footer
+        %a{ :href => '#', :class => 'btn btn-primary', :'data-loading-text' => 'Creating
Network...', :onclick => "postModalForm(this, 'networkModal')"} Continue
+        %a{ :href => '#', :class => 'btn', :'data-dismiss' => 'modal'} Cancel
   %p
     %a{ :href => "#{@networks.id}?format=xml", :class => 'label warning' } XML
     %a{ :href => "#{@networks.id}?format=json", :class => 'label warning' } JSON


Mime
View raw message