Skip to content

Commit

Permalink
Merge pull request #26 from h-kataria/ae_domains_crud_ui
Browse files Browse the repository at this point in the history
Added CRUD support for Automate Domains.
  • Loading branch information
Dan Clarizio committed Jun 18, 2014
2 parents c3b8bff + d003bb3 commit 013e7f3
Show file tree
Hide file tree
Showing 18 changed files with 682 additions and 293 deletions.
4 changes: 2 additions & 2 deletions vmdb/app/assets/javascripts/cfme_application.js
Original file line number Diff line number Diff line change
Expand Up @@ -1150,11 +1150,11 @@ function miq_jquery_disable_inactive_tabs(tabs_div){
//getting length of tabs on screen
tab_len = $j('#' + tabs_div).tabs('length');
//getting index of currently active tabs
curTab = $j('.ui-tabs-panel:not(.ui-tabs-hide)')
curTab = $j('#' + tabs_div).tabs().tabs('option', 'selected').valueOf();
//building array of tab indexes to be disabled, excluding active tab index
var arr=new Array
for(var i=1,j=0;i<=tab_len;i++){
if(i != curTab.index()){
if(i != curTab+1){
arr[j++] = i-1;
}
}
Expand Down
630 changes: 402 additions & 228 deletions vmdb/app/controllers/miq_ae_class_controller.rb

Large diffs are not rendered by default.

38 changes: 23 additions & 15 deletions vmdb/app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,15 @@ def build_toolbar_hide_button(id)
when "action_delete"
return true if !role_allows(:feature=>"action_delete")
end
when "MiqAeClass", "MiqAeField", "MiqAeInstance", "MiqAeMethod", "MiqAeNamespace"
case id
when "miq_ae_domain_lock"
return true unless @record.editable?
when "miq_ae_domain_unlock"
return true if @record.editable? || @record.priority.to_i == 0
else
return true unless @record.editable?
end
when "MiqAlert"
case id
when "alert_copy"
Expand Down Expand Up @@ -1165,6 +1174,17 @@ def build_toolbar_disable_button(id)
return "Default actions can not be deleted." if @record.action_type == "default"
return "Actions assigned to Policies can not be deleted" if @record.miq_policies.length > 0
end
when "MiqAeNamespace"
case id
when "miq_ae_domain_delete"
return "Read Only Domain cannot be deleted." unless @record.editable?
when "miq_ae_domain_edit"
return "Read Only Domain cannot be edited" unless @record.editable?
when "miq_ae_domain_lock"
return "Domain is Locked." unless @record.editable?
when "miq_ae_domain_unlock"
return "Domain is Unlocked." if @record.editable?
end
when "MiqAlert"
case id
when "alert_delete"
Expand Down Expand Up @@ -1895,9 +1915,8 @@ def center_toolbar_filename_explorer

def center_toolbar_filename_automate
nodes = x_node.split('-')
return "blank_view_tb" unless ae_object_editable?(nodes)
return case nodes.first
when "root" then "blank_view_tb"
when "root" then "miq_ae_domains_center_tb"
when "aen" then domain_or_namespace_toolbar(nodes.last)
when "aec" then case @sb[:active_tab]
when "methods" then "miq_ae_methods_center_tb"
Expand All @@ -1910,21 +1929,10 @@ def center_toolbar_filename_automate
end
end

def ae_object_editable?(nodes)
kls = case nodes.first
when "aen" then MiqAeNamespace
when "aec" then MiqAeClass
when "aei" then MiqAeInstance
when "aem" then MiqAeMethod
else nil
end
kls.find_by_id(from_cid(nodes.last)).editable? unless kls.nil?
end

def domain_or_namespace_toolbar(node_id)
ns = MiqAeNamespace.find(from_cid(node_id))
if ns.domain? && ns.editable?
"miq_ae_namespaces_center_tb"
if ns.domain?
"miq_ae_domain_center_tb"
elsif !ns.domain?
"miq_ae_namespace_center_tb"
else
Expand Down
4 changes: 4 additions & 0 deletions vmdb/app/models/miq_ae_domain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ class MiqAeDomain < MiqAeNamespace
def self.enabled
where(:enabled => true)
end

def self.highest_priority
MiqAeDomain.order('priority DESC').first.priority
end
end
5 changes: 4 additions & 1 deletion vmdb/app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,10 @@ def ldap_group

def role_allows?(options={})
return false if self.miq_user_role.nil?
self.miq_user_role.allows?(options)
feature = MiqProductFeature.find_by_identifier(options[:identifier])
feature.try(:hidden) ?
miq_user_role.allows_any?(:identifiers => [options[:identifier]]) :
miq_user_role.allows?(options)
end

def role_allows_any?(options={})
Expand Down
2 changes: 1 addition & 1 deletion vmdb/app/views/layouts/_page_header_navbar.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@
%a{:href=>'/dashboard/maintab/?tab=aut'}= h(MAIN_TABS[:aut])
%ul(class="#{primary_nav_class(:aut)}")

-if role_allows(:feature => 'miq_ae_class_explorer')
-if role_allows(:feature => 'miq_ae_domain_view')
%li(class="#{secondary_nav_class('miq_ae_class')}")
%a{:href=>'/miq_ae_class/explorer'}Explorer

Expand Down
10 changes: 5 additions & 5 deletions vmdb/app/views/miq_ae_class/_class_fields.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
:title => "Click to delete this field from schema")
%>
</td>
<% ["name", "aetype", "datatype", "default_value", "display_name", "description", "substitution", "collect", "message", "on_entry", "on_exit", "on_error", "max_retries", "max_time"].each do |fname| %>
<% ["name", "aetype", "datatype", "default_value", "display_name", "description", "substitute", "collect", "message", "on_entry", "on_exit", "on_error", "max_retries", "max_time"].each do |fname| %>
<td>
<% if ["aetype", "datatype"].include?(fname) %>
<% combo_id = "fields_#{fname}_id#{i}" %>
Expand All @@ -81,7 +81,7 @@
<% combo_url = "/miq_ae_class/fields_form_field_changed/#{@ae_class.id || 'new'}" %>
<div id="<%=combo_id%>"></div>
<%= render :partial => 'layouts/dhtmlxcombo', :locals => { :combo_id => combo_id, :combo_name => combo_name, :xml_combo => xml_combo, :combo_url => combo_url } %>
<% elsif fname == 'substitution' %>
<% elsif fname == 'substitute' %>
<%= check_box_tag("fields_#{fname}_#{i}", value="1",
checked=field.substitute,
"data-miq_observe_checkbox"=>{:url=>url}.to_json) %>
Expand Down Expand Up @@ -133,7 +133,7 @@
:title => "Add this entry")
%>
</td>
<% ["name", "aetype", "datatype", "default_value", "display_name", "description", "substitution", "collect", "message", "on_entry", "on_exit", "on_error", "max_retries", "max_time"].each do |fname| %>
<% ["name", "aetype", "datatype", "default_value", "display_name", "description", "substitute", "collect", "message", "on_entry", "on_exit", "on_error", "max_retries", "max_time"].each do |fname| %>
<td>
<% if ["aetype", "datatype"].include?(fname) %>
<% combo_id = "field_#{fname}_id" %>
Expand All @@ -142,8 +142,8 @@
<% combo_url = "/miq_ae_class/fields_form_field_changed/#{@ae_class.id || 'new'}" %>
<div id="<%=combo_id%>"></div>
<%= render :partial => 'layouts/dhtmlxcombo', :locals => { :combo_id => combo_id, :combo_name => combo_name, :xml_combo => xml_combo, :combo_url => combo_url } %>
<% elsif fname == 'substitution' %>
<% checked = !session[:field_data].blank? && session[:field_data][:substitution] %>
<% elsif fname == 'substitute' %>
<% checked = !session[:field_data].blank? && session[:field_data][:substitute] %>
<%= check_box_tag("field_#{fname}", value="1",
checked=checked,
"data-miq_observe_checkbox"=>{:url=>url}.to_json) %>
Expand Down
48 changes: 48 additions & 0 deletions vmdb/app/views/miq_ae_class/_domains_priority_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<%= render :partial => "layouts/flash_msg", :locals=>{:div_num=>"_domains_priority"} %>
<div id="domains_list">
<table class="admintable">
<tbody>
<tr>
<td >
<table width="50%" class="form" id="formtest">
<tr>
<td align="left" class="widthed">Domains:</td>
<td></td>
</tr>
<tr>
<td align="left" valign="top">
<%= select_tag('seq_fields[]', options_for_select(@edit[:new][:domain_order], @selected), { :multiple=> true, :style=>"width: 450px", :size=>20, :id=>"seq_fields" } ) %>
</td>
<td width="30" align="left" valign="middle">
<% if @edit[:new][:domain_order].length < 2 %>
<%= image_tag("/images/toolbars/up.png", :class=>"dimmed small") %>
<% else %>
<%= link_to(image_tag("/images/toolbars/up.png",
:class=>"rollover small", :alt=>"Move selected fields up"),
{:action=>'priority_form_field_changed', :button=>'up', :id=>"priority__edit"},
"data-submit" =>"domains_list",
:remote=>true,
:title=>'Move selected fields up')
%>
<% end %>

<% if @edit[:new][:domain_order].length < 2 %>
<%= image_tag("/images/toolbars/down.png", :class=>"dimmed small") %>
<% else %>
<%= link_to(image_tag("/images/toolbars/down.png",
:class=>"rollover small", :alt=>"Move selected fields down"),
{:action=>'priority_form_field_changed', :button=>'down', :id=>"priority__edit"},
"data-submit" =>"domains_list",
:remote=>true,
:title=>'Move selected fields down')
%>
<% end %>
</td>
</tr>
<div class="note">* Select one or more consecutive groups to move up or down.</div>
</table>
</td>
</tr>
</tbody>
</table>
</div>
4 changes: 4 additions & 0 deletions vmdb/app/views/miq_ae_class/_fields_seq_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,7 @@
</tbody>
</table>
</div>
<script>
<%# disable any other tabs on screen when in edit %>
miq_jquery_disable_inactive_tabs('ae_tabs');
</script>
24 changes: 20 additions & 4 deletions vmdb/app/views/miq_ae_class/_ns_list.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@
<fieldset>
<p class="legend">Info</p>
<table class="style1">
<tr>
<td class="key"><%= Dictionary::gettext('fqname', :type=>:column, :notfound=>:titleize)%></td>
<td class="wide"><%= h(@sb[:namespace_path]) %></td>
</tr>
<% unless @edit[:new][:domain] %>
<tr>
<td class="key"><%= Dictionary::gettext('fqname', :type=>:column, :notfound=>:titleize)%></td>
<td class="wide"><%= h(@sb[:namespace_path]) %></td>
</tr>
<% end %>
<tr>
<td class="key">Name</td>
<td class="wide">
Expand All @@ -53,8 +55,22 @@
"data-miq_observe"=>{:interval=>'.5', :url=>url}.to_json) %>
</td>
</tr>
<% if @edit[:new][:domain] %>
<tr>
<td class="key">Enabled</td>
<td>
<%= check_box_tag("ns_enabled",
value = "1",
checked = @edit[:new][:enabled],
"data-miq_observe_checkbox"=>{:url=>url}.to_json) %>
</td>
</tr>
<% end %>
</table>
</fieldset>
</div>
<%# Need this to bind checkbox observers when under DHTMLX tabs %>
<%# TODO: Remove when DHTMLX tabs are converted to jQuery tabs %>
<script>miqObserveCheckboxes();</script>
<% end %>
</div>
5 changes: 5 additions & 0 deletions vmdb/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -373,9 +373,12 @@ en:
no_records_selected_for_task: 'No %{model} were selected for %{task}'
no_records_selected_to_be_disabled: 'No %{model} were selected to be disabled'
no_records_selected_to_be_enabled: 'No %{model} were selected to be enabled'
no_records_selected_to_be_marked: 'No %{model} were selected to be marked as %{action}'
no_utilization_data_available: "No Utilization data available"
no_vc_defined: "No Virtual Center instances have been defined, press a button to Add or Discover one"
press_back_button: "Press your browser's Back button or click a tab to continue"
priority_order_cancelled: "Edit of Priority Order was cancelled by the user"
priority_order_saved: "Priority Order was saved"
record_no_longer_exists: "%{record_name} no longer exists in the database"
record_not_authorized for user: "You are not authorized to view %{record_name}"
search_not_found: "The selected Filter record was not found"
Expand Down Expand Up @@ -418,6 +421,7 @@ en:
count_not_in_current_region: "%{label} are not in the current region and will be skipped"
error_during_delete_with_count: "Error during %{count_model} delete from the CFME Database"
error_no_longer_exists: "Error: Record no longer exists in the database"
invalid_button_action: "Invalid button action."
not_in_current_region: "The selected %{label} is not in the current region"
refresh_cu_data: "Refresh of recent C&U data has been initiated"
schedule_queued_to_run: "The selected Schedule has been queued to run"
Expand All @@ -427,6 +431,7 @@ en:
selected_records_deleted_with_count: "Successfully deleted %{count_model} from the CFME Database"
selected_records_were_disabled: 'The selected %{model} were disabled'
selected_records_were_enabled: 'The selected %{model} were enabled'
selected_records_were_marked: 'The selected %{model} were marked as %{action}'
task_cancelled: "%{task} was cancelled by the user"
unknown_error: "Unknown error has occurred"
user_not_authorized: "The user is not authorized for this task or item."
Expand Down
2 changes: 2 additions & 0 deletions vmdb/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,7 @@
create_instance
create_method
create_ns
domains_priority_edit
explorer
expand_toggle
field_accept
Expand All @@ -543,6 +544,7 @@
form_instance_field_changed
form_method_field_changed
form_ns_field_changed
priority_form_field_changed
reload
tree_select
tree_autoload_dynatree
Expand Down
45 changes: 45 additions & 0 deletions vmdb/db/fixtures/miq_product_features.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1922,6 +1922,51 @@
:feature_type: node
:identifier: miq_ae_class_explorer
:children:
- :name: Automate Domains
:description: Automate Domains
:feature_type: node
:identifier: miq_ae_domain
:children:
- :name: View
:description: View
:feature_type: view
:identifier: miq_ae_domain_view
- :name: Modify
:description: Modify Domain
:feature_type: admin
:identifier: miq_ae_domain_admin
:children:
- :name: Add
:description: Add Automate Domain
:feature_type: admin
:identifier: miq_ae_domain_new
- :name: Edit
:description: Edit Automate Domain
:feature_type: admin
:identifier: miq_ae_domain_edit
- :name: Delete
:description: Delete Automate Domain
:feature_type: admin
:identifier: miq_ae_domain_delete
- :name: Priority Order
:description: Edit Priority Order of Domains
:feature_type: admin
:identifier: miq_ae_domain_priority_edit
- :name: Lock/Unlock
:description: Lock/Unlock Domain
:feature_type: admin
:identifier: miq_ae_domain_lock_unlock
:children:
- :name: Unlock
:description: Unlock Domain
:feature_type: admin
:identifier: miq_ae_domain_unlock
:hidden: true
- :name: Lock
:description: Lock Domain
:feature_type: admin
:identifier: miq_ae_domain_lock
:hidden: true
- :name: Automate Namespace
:description: Automate Namespace
:feature_type: node
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,33 @@
# Toolbar config file
#
---
:model: MiqAeNamespace
:model: MiqAeDomain
:button_groups:
- :name: miq_ae_namespace_vmdb
- :name: miq_ae_domain_vmdb
:items:
- :buttonSelect: miq_ae_namespace_vmdb_choice
- :buttonSelect: miq_ae_domain_vmdb_choice
:image: vmdb
:title: Configuration
:text: Configuration
:items:
- :button: miq_ae_domain_edit
:image: edit
:text: 'Edit this Domain'
:title: 'Edit this Domain'
- :button: miq_ae_domain_delete
:image: delete
:text: 'Remove this Domain'
:title: 'Remove this Domain'
:confirm: 'Are you sure you want to remove this Domain?'
- :button: miq_ae_domain_unlock
:image: enable
:text: Unlock this Domain
:title: Unlock this Domain
- :button: miq_ae_domain_lock
:image: disable
:text: Lock this Domain
:title: Lock this Domain
- :separator:
- :button: miq_ae_namespace_new
:image: new_namespace
:text: 'Add a New Namespace'
Expand All @@ -29,4 +47,5 @@
:url_parms: 'main_div'
:confirm: 'Are you sure you want to remove the selected Namespaces?'
:enabled: 'false'
:onwhen: '1+'
:onwhen: '1+'

Loading

0 comments on commit 013e7f3

Please sign in to comment.