Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add widget-report component and method to get data #1805

Merged
merged 6 commits into from
Aug 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions app/assets/javascripts/components/widget-report.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
ManageIQ.angular.app.component('widgetReport', {
bindings: {
id: '<',
},
controllerAs: 'vm',
controller: ['$http', 'miqService', '$sce', function($http, miqService, $sce) {
var vm = this;
vm.widgetReportModel = {};

this.$onInit = function() {
$http.get('/dashboard/widget_report_data/' + vm.id)
.then(function(response) { vm.widgetReportModel.content = $sce.getTrustedHtml(response.data.content);})
Copy link
Contributor

@himdel himdel Aug 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  .then(function(response) {
    vm.widgetReportModel.content = $sce.getTrustedHtml(response.data.content);
  })

But.. you're sure about getTrustedHtml, right? (vs trustAsHtml)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So far it wasn't problem. I like getTrustedHtml safety but trustAsHtml will work for "anything". What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, getTrustedHtml is definitely safer, it doesn't seem to remove colors from reports.. let's keep it until someone complains :)

.catch(miqService.handleFailure);
vm.div_id = "dd_w" + vm.id + "_box";
};

vm.contentPresent = function() {
return vm.widgetReportModel.content !== undefined;
};
}],
template: [
'<div class="mc" id="{{vm.div_id}}" ng-class="{ hidden: vm.widgetReportModel.minimized }">',
' <div class="blank-slate-pf " style="padding: 10px" ng-if="!vm.contentPresent()">',
' <div class="blank-slate-pf-icon">',
' <i class="fa fa-cog">',
' </i>',
' <h1>',
__('No report data found.'),
' </h1>',
' </div>',
' </div>',
' <div ng-if="vm.contentPresent()">',
' <div ng-bind-html="vm.widgetReportModel.content">',
' </div>',
' </div>',
'</div>',

].join("\n"),
});
6 changes: 6 additions & 0 deletions app/controllers/dashboard_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ def widget_menu_data
:minimized => @sb[:dashboards][@sb[:active_db]][:minimized].include?(params[:id])}
end

def widget_report_data
widget = find_record_with_rbac(MiqWidget, params[:id])
render :json => {:content => widget.contents_for_user(current_user).contents,
:minimized => @sb[:dashboards][@sb[:active_db]][:minimized].include?(params[:id])}
end

def show
@layout = "dashboard"
@dashboard = true
Expand Down
5 changes: 4 additions & 1 deletion app/views/dashboard/_widget.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@
%widget-menu{:id => presenter.widget.id}
- elsif presenter.widget.contents_for_user(current_user).blank?
= render :partial => 'widget_blank', :locals => {:widget => presenter.widget}
- elsif %w(report chart rss).include?(presenter.widget.content_type)
- elsif presenter.widget.content_type == "report"
%widget-report{:id => presenter.widget.id}
- elsif %w(chart rss).include?(presenter.widget.content_type)
= render :partial => "widget_#{presenter.widget.content_type}", :locals => {:widget => presenter.widget}
- unless presenter.widget.content_type == "menu"
= render :partial => 'widget_footer', :locals => {:widget => presenter.widget}

:javascript
miq_bootstrap("#w_#{presenter.widget.id}");
12 changes: 0 additions & 12 deletions app/views/dashboard/_widget_report.html.haml

This file was deleted.

1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,7 @@
timeline
timeline_data
widget_to_pdf
widget_report_data
start_url
widget_menu_data
),
Expand Down