Skip to content

Commit

Permalink
Add option to start policy simulation with report data in angular
Browse files Browse the repository at this point in the history
Add correct policies in nested view

Add explorer when adding policy for simulation if explorer is in @edit
  • Loading branch information
karelhala committed Mar 6, 2017
1 parent 08e1e59 commit 79ff5d5
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 4 deletions.
25 changes: 22 additions & 3 deletions app/assets/javascripts/controllers/report_data_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
MiQEndpointsService.endpoints.listDataTable = '/' + ManageIQ.constants.reportData;
}

function isCurrentControllerOrPolicies(splitUrl) {
return splitUrl && (splitUrl[1] === ManageIQ.controller || splitUrl[2] === 'policies');
}

/**
* Method for init paging component for GTL.
* Default paging has 5, 10, 20, 50, 100, 1000
Expand Down Expand Up @@ -150,17 +154,18 @@
event.preventDefault();
var prefix = this.initObject.showUrl;
var splitUrl = this.initObject.showUrl.split('/');
if (this.initObject.isExplorer && splitUrl && splitUrl[1] === ManageIQ.controller) {
if (this.initObject.isExplorer && isCurrentControllerOrPolicies(splitUrl)) {
var itemId = item.id;
if (this.initObject.showUrl.indexOf('?id=') !== -1 ){
var itemId = this.initObject.showUrl.indexOf('xx-') !== -1 ? '_-' + item.id : '-' + item.id;
}
url = prefix + itemId;
var url = prefix + itemId;
$.post(url).always(function() {
this.setExtraClasses();
}.bind(this));
} else {
this.$window.DoNav(prefix + '/' + item.id);
prefix = prefix[prefix.length -1 ] !== '/' ? prefix + '/' : prefix;
this.$window.DoNav(prefix + item.id);
}
return false;
};
Expand Down Expand Up @@ -189,6 +194,14 @@
ReportDataController.prototype.initObjects = function(initObject) {
this.gtlData = { cols: [], rows: [] };
this.initObject = initObject;
if (this.initObject.showUrl === '') {
this.initObject.showUrl = '/' + ManageIQ.controller;
if (this.initObject.isExplorer) {
this.initObject.showUrl += '/x_show/';
} else {
this.initObject.showUrl += '/show/';
}
}
this.gtlType = initObject.gtlType || 'grid';
this.settings.isLoading = true;
ManageIQ.gridChecks = [];
Expand Down Expand Up @@ -310,6 +323,12 @@
this.gtlData = gtlData;
this.perPage.text = this.settings.perpage;
this.perPage.value = this.settings.perpage;
this.initObject.showUrl = this.settings.url || this.initObject.showUrl;
var splitUrl = this.initObject.showUrl.split('/');
if (splitUrl && splitUrl[1] === 'vm') {
splitUrl[1] = 'vm_infra';
this.initObject.showUrl = splitUrl.join('/');
}
return gtlData;
}.bind(this));
};
Expand Down
8 changes: 8 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,14 @@ def report_data
settings[:sort_dir] = @sortdir unless settings.nil?
settings[:sort_col] = @sortcol unless settings.nil?
@edit = session[:edit]
@policy_sim = @edit[:policy_sim] unless @edit.nil?
controller, _action = db_to_controller(current_view.db)
if !@policy_sim.nil? && session[:policies] && session[:policies].length > 0
settings[:url] = '/' + controller + '/policies/'
end
if session[:sandboxes] && @sb
session[:sandboxes][controller] = @sb
end
render :json => {
:settings => settings,
:data => view_to_hash(current_view),
Expand Down
1 change: 1 addition & 0 deletions app/controllers/application_controller/policy_support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def policy_sim
# Add selected policy to the simulation
def policy_sim_add
@edit = session[:edit]
@explorer = @edit[:explorer]
# Profile was selected
if params[:profile_id] != "<select>"
prof = MiqPolicySet.find(params[:profile_id]) # Go thru all the profiles
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/vm_common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ def policies
return
end
@in_a_form = true
replace_right_cell
replace_right_cell({:action => 'policy_sim'})
else
render :template => 'vm/show'
end
Expand Down
2 changes: 2 additions & 0 deletions app/views/layouts/_policy_sim.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,7 @@
- if @tagitems
- @embedded = true
- @policy_sim = true
- session[:edit] ||= {}
- session[:edit][:policy_sim] = @policy_sim
= render :partial => "layouts/gtl",
:locals => {:view => @pol_view}

0 comments on commit 79ff5d5

Please sign in to comment.