Skip to content

Commit

Permalink
Unify endpoint data for report data.
Browse files Browse the repository at this point in the history
model_name for name of model (either current model to be displayed, or association if parent ID is set)
parent_id ID of parent so we know from where to fetch assocation.

Align tests based on renamed values
  • Loading branch information
karelhala committed Sep 27, 2017
1 parent 225874f commit b1c918e
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 28 deletions.
11 changes: 6 additions & 5 deletions app/assets/javascripts/controllers/report_data_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@
* modelName: string,
* gtlType: string,
* activeTree: string,
* currId: string,
* parentId: string,
* isExplorer: Boolean
* }
* ```
Expand All @@ -289,7 +289,7 @@
this.setExtraClasses(initObject.gtlType);
return this.getData(initObject.modelName,
initObject.activeTree,
initObject.currId,
initObject.parentId,
initObject.isExplorer,
this.settings,
initObject.records)
Expand Down Expand Up @@ -402,20 +402,21 @@
* Method for fetching data from server. gtlData, settings and pePage is selected after fetching data.
* @param {String} modelName name of current model.
* @param {Number} activeTree ID of active tree node.
* @param {Number} currId current Id, if some nested items are displayed.
* @param {Number} parentId parent Id, if some nested items are displayed.
* @param {Boolean} isExplorer true | false if we are in explorer part of application.
* @param {Object} settings settings object.
* @param {Array} records array of reccords.
* @returns {Object} promise of retriveRowsAndColumnsFromUrl of MiQDataTableService.
*/
ReportDataController.prototype.getData = function(modelName, activeTree, currId, isExplorer, settings, records) {
ReportDataController.prototype.getData = function(modelName, activeTree, parentId, isExplorer, settings, records) {
var basicSettings = {
current: 1,
perpage: 20,
sort_col: 0,
sort_dir: 'DESC',
};
return this.MiQDataTableService.retrieveRowsAndColumnsFromUrl(modelName, activeTree, currId, isExplorer, settings, records)
return this.MiQDataTableService
.retrieveRowsAndColumnsFromUrl(modelName, activeTree, parentId, isExplorer, settings, records)
.then(function(gtlData) {
this.settings = gtlData.settings || basicSettings;
if (this.settings.sort_col === -1) {
Expand Down
26 changes: 13 additions & 13 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -410,10 +410,10 @@ def init_report_data(controller_name)
{
:controller_name => controller_name,
:data => {
:modelName => @display.nil? && !self.class.model.nil? ? self.class.model.to_s.tableize : @display,
:model_name => @display.nil? && !self.class.model.nil? ? self.class.model.to_s.tableize : @display,
:activeTree => x_active_tree.to_s,
:gtlType => @gtl_type,
:currId => params[:id],
:parent_id => params[:id],
:sortColIdx => @sortcol,
:sortDir => @sortdir,
:isExplorer => @explorer,
Expand Down Expand Up @@ -444,8 +444,8 @@ def process_params_options(params)
end

# handle exceptions
if params[:model]
options = case params[:model]
if params[:model_name]
options = case params[:model_name]
when 'miq_requests'
page_params
when 'miq_tasks'
Expand All @@ -459,15 +459,15 @@ def process_params_options(params)
end
end

if params[:model_id] && !params[:active_tree]
curr_model_id = from_cid(params[:model_id])
unless curr_model_id.nil?
options[:parent] = identify_record(curr_model_id, controller_to_model) if curr_model_id && options[:parent].nil?
if params[:id] && !params[:active_tree]
parent_id = from_cid(params[:parent_id])
unless parent_id.nil?
options[:parent] = identify_record(parent_id, controller_to_model) if parent_id && options[:parent].nil?
end
end

options[:parent] = options[:parent] || @parent
options[:association] = HAS_ASSOCATION[params[:model]] if HAS_ASSOCATION.include?(params[:model])
options[:association] = HAS_ASSOCATION[params[:model_name]] if HAS_ASSOCATION.include?(params[:model_name])
options[:selected_ids] = params[:records]
options
end
Expand All @@ -483,15 +483,15 @@ def process_params_options(params)
# @option options :model [Object]
# If model was chosen somehow before calling this method use this model instead of finding it.
def process_params_model_view(params, options)
if options[:model]
model_view = options[:model].constantize
if options[:model_name]
model_view = options[:model_name].constantize
end

if model_view.nil? && params[:active_tree]
model_view = model_from_active_tree(params[:active_tree].to_sym)
end
if model_view.nil? && params[:model]
model_view = model_string_to_constant(params[:model])
if model_view.nil? && params[:model_name]
model_view = model_string_to_constant(params[:model_name])
end

if model_view.nil?
Expand Down
6 changes: 3 additions & 3 deletions app/views/layouts/angular/_gtl.html.haml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
- current_model = model_to_report_data
- model_name = model_to_report_data
- no_flash_div ||= false
- gtl_type_string = j_str(@gtl_type)
- active_tree = x_active_tree unless params[:display] || @use_action
Expand Down Expand Up @@ -40,10 +40,10 @@
sendDataWithRx({initController: {
name: 'reportDataController',
data: {
modelName: '#{h(j_str(current_model))}',
modelName: '#{h(j_str(model_name))}',
activeTree: '#{active_tree}',
gtlType: '#{h(gtl_type_string)}',
currId: '#{h(j_str(params[:id])) unless @display.nil?}',
parent_id: '#{h(j_str(params[:id])) unless @display.nil?}',
sortColIdx: '#{@sortcol}',
sortDir: '#{@sortdir}',
isExplorer: '#{@explorer}' === 'true' ? true : false,
Expand Down
6 changes: 3 additions & 3 deletions spec/controllers/provider_foreman_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@
gtl_init_data = controller.init_report_data('reportDataController')
expect(gtl_init_data[:data][:modelName]).to eq("manageiq/providers/configuration_managers")
expect(gtl_init_data[:data][:activeTree]).to eq("configuration_manager_providers_tree")
expect(gtl_init_data[:data][:currId]).to eq(ems_id)
expect(gtl_init_data[:data][:parent_id]).to eq(ems_id)
expect(gtl_init_data[:data][:isExplorer]).to eq(true)
view = controller.instance_variable_get(:@view)
expect(view.table.data[0].description).to eq("testprofile")
Expand All @@ -351,7 +351,7 @@
gtl_init_data = controller.init_report_data('reportDataController')
expect(gtl_init_data[:data][:modelName]).to eq("manageiq/providers/configuration_managers")
expect(gtl_init_data[:data][:activeTree]).to eq("configuration_manager_providers_tree")
expect(gtl_init_data[:data][:currId]).to eq(config_profile_id2)
expect(gtl_init_data[:data][:parent_id]).to eq(config_profile_id2)
expect(gtl_init_data[:data][:isExplorer]).to eq(true)
view = controller.instance_variable_get(:@view)
expect(view.table.data[0].hostname).to eq("test2a_configured_system")
Expand Down Expand Up @@ -386,7 +386,7 @@
gtl_init_data = controller.init_report_data('reportDataController')
expect(gtl_init_data[:data][:modelName]).to eq("manageiq/providers/configuration_managers")
expect(gtl_init_data[:data][:activeTree]).to eq("configuration_manager_providers_tree")
expect(gtl_init_data[:data][:currId]).to eq(ems_id)
expect(gtl_init_data[:data][:parent_id]).to eq(ems_id)
expect(gtl_init_data[:data][:isExplorer]).to eq(true)
expect(view.table.data[0].data).to include('description' => "testprofile")
expect(view.table.data[2]).to include('description' => _("Unassigned Profiles Group"),
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/storage_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
expect(response.body).to include("modelName: '#{session_storage[:active_accord].to_s.pluralize}'")
expect(response.body).to include("activeTree: '#{session_storage[:active_tree]}'")
expect(response.body).to include("gtlType: 'list'")
expect(response.body).to include("currId: ''")
expect(response.body).to include("parent_id: ''")
expect(response.body).to include("sortColIdx: '0'")
expect(response.body).to include("isExplorer: 'true' === 'true' ? true : false")
expect(response.body).to include("showUrl: '/#{session_storage[:active_accord]}/x_show/'")
Expand Down
4 changes: 2 additions & 2 deletions spec/javascripts/controllers/report_data_controller_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('reportDataController', function () {
modelName: 'manageiq/providers/infra_manager/vms',
activeTree: 'vandt_tree',
gtlType: 'grid',
currId: '',
parent_id: '',
sortColIdx: '0',
sortDir: 'DESC',
isExplorer: false,
Expand Down Expand Up @@ -44,7 +44,7 @@ describe('reportDataController', function () {
it('should get data', function(done) {
var settings = {isLoading: true};
var result = $controller
.getData(initObject.modelName, initObject.activeTree, initObject.currId, initObject.isExplorer, settings);
.getData(initObject.modelName, initObject.activeTree, initObject.parent_id, initObject.isExplorer, settings);
result.then(function(data) {
expect(angular.equals($controller.gtlData.cols, report_data.data.head)).toBeTruthy();
expect(angular.equals($controller.gtlData.rows, report_data.data.rows)).toBeTruthy();
Expand Down
2 changes: 1 addition & 1 deletion spec/support/controller_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def assert_nested_list(parent, children, relation, label, child_path: nil, gtl_t
expect(response.body).to include("modelName: '#{relation}'")
expect(response.body).to include("activeTree: ''")
expect(response.body).to include("gtlType: '#{gtl_types.first}'")
expect(response.body).to include("currId: '#{parent.id}'")
expect(response.body).to include("parent_id: '#{parent.id}'")
expect(response.body).to include("showUrl: '/#{child_route}/'")
end

Expand Down

0 comments on commit b1c918e

Please sign in to comment.