Skip to content

Commit

Permalink
Update js API for report data based on QE requests
Browse files Browse the repository at this point in the history
  • Loading branch information
karelhala committed Jul 26, 2017
1 parent 0fdf621 commit f1acfd2
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 7 deletions.
5 changes: 4 additions & 1 deletion app/assets/javascripts/controllers/report_data_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@

if (event.controller === COTNROLLER_NAME && this.apiFunctions && this.apiFunctions[event.action]) {
var actionCallback = this.apiFunctions[event.action];
actionCallback.apply(this, event.data);
var resultData = actionCallback.apply(this, event.data);
if (event.eventCallback) {
event.eventCallback(resultData);
}
}
}.bind(this),
function(err) {
Expand Down
88 changes: 82 additions & 6 deletions app/assets/javascripts/miq_qe.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,39 @@ ManageIQ.qe.inFlight = function() {
ManageIQ.qe.gtl = {
actionsToFunction: function() {
var startEnd = function(pageNumber) {
var start = (pageNumber - 1) * this.settings.perpage;
var end = start + this.settings.perPage;
return {
start: start,
end: end,
};
var start = (pageNumber - 1) * this.settings.perpage;
var end = start + this.settings.perPage;
return {
start: start,
end: end,
};
}.bind(this);

var goToPage = function(pageNumber) {
var pageItems = startEnd(pageNumber);
this.onLoadNext(pageItems.start, pageItems.end);
}.bind(this);

var getItem = function(item) {
return {
select: function() {
this.onItemSelect(item, true);
this.$scope.$digest();
}.bind(this),
unselect: function() {
this.onItemSelect(item, false);
this.$scope.$digest();
}.bind(this),
is_selected: function() {
return item.selected;
},
click: function() {
this.onItemClicked(item, document.createEvent('Event'));
this.$scope.$digest();
}.bind(this),
item,
};
}.bind(this);
return {
'select_item': function(id, isSelected) {
var item = this.gtlData.rows.filter(function(currItem) {
Expand Down Expand Up @@ -132,6 +154,60 @@ ManageIQ.qe.gtl = {
'next_page': function() {
goToPage(this.settings.current + 1);
},
'get_current_page': function() {
ManageIQ.qe.gtl.result = this.settings.current;
return this.settings.current;
},
'get_pages_amount': function() {
ManageIQ.qe.gtl.result = this.settings.total;
return this.settings.total;
},
'get_items_per_page': function() {
ManageIQ.qe.gtl.result = this.settings.perpage;
return this.settings.perpage;
},
'set_items_per_page': function(itemsPerPage) {
this.settings.perPage = itemsPerPage;
goToPage(this.settings.current);
},
'get_sorting': function() {
var result = {
sortBy: this.settings.sort_col,
sortDir: this.settings.sort_dir,
};
ManageIQ.qe.gtl.result = result;
return result;
},
'set_sorting': function(sortBy) {
this.onSort(sortBy.columnId, sortBy.isAscending);
},
'get_all_items': function() {
var responseData = [];
this.gtlData.rows.forEach(function(oneItem) {
responseData.push(getItem(oneItem));
});
ManageIQ.qe.gtl.result = responseData;
return responseData;
},
'get_item': function(identificator) {
var foundItem;
var nameColumn = this.gtlData.cols.filter(function(data){ return data.text === 'Name'; });
if (nameColumn) {
var index = this.gtlData.cols.indexOf(nameColumn[0]);
foundItem = this.gtlData.rows.filter(function(oneRow){
return oneRow.cells[index].text === identificator;
});
}
if (foundItem.length === 0) {
foundItem = this.gtlData.rows.filter(function(oneRow){ return oneRow.id == identificator; });
}
if (foundItem.length === 1) {
var responseData = getItem(foundItem[0]);
ManageIQ.qe.gtl.result = responseData;
return responseData;
}
return {};
},
};
},
};

0 comments on commit f1acfd2

Please sign in to comment.