Skip to content

Commit

Permalink
Add refresh of the Dashbord widget's content
Browse files Browse the repository at this point in the history
  • Loading branch information
ZitaNemeckova committed Oct 25, 2019
1 parent 7e8431f commit affc588
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
7 changes: 7 additions & 0 deletions app/controllers/dashboard_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,13 @@ def widget_zoom
end
end

def widget_refresh
assert_privileges("widget_generate_content")
w = MiqWidget.find(params[:widget])
w.queue_generate_content
render :json => {}, :status => 200
end

# A widget has been dropped
def widget_dd_done
if params[:col1] || params[:col2] || params[:col3]
Expand Down
30 changes: 20 additions & 10 deletions app/javascript/angular/dashboard/widget-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,30 @@ ManageIQ.angular.app.component('widgetWrapper', {
vm.divId = `w_${vm.widgetId}`;
vm.innerDivId = `dd_w${vm.widgetId}_box`;

vm.refresh();
vm.refreshWidgetHTML();
};

vm.refreshWidgetHTML = function() {
return $http.get(vm.widgetUrl())
.then((response) => {
vm.widgetModel = response.data;
// if there's html make it passable
if (vm.widgetModel.content) {
vm.widgetModel.content = $sce.trustAsHtml(vm.widgetModel.content);
}
deferred.resolve();
})
.catch((e) => {
vm.error = true;
miqService.handleFailure(e);
deferred.reject();
});
};

vm.refresh = function() {
if (vm.widgetBlank === 'false') {
$http.get(vm.widgetUrl())
.then((response) => {
vm.widgetModel = response.data;
// if there's html make it passable
if (vm.widgetModel.content) {
vm.widgetModel.content = $sce.trustAsHtml(vm.widgetModel.content);
}
deferred.resolve();
})
$http.post(`/dashboard/widget_refresh/?widget=${vm.widgetId}`)
.then(vm.refreshWidgetHTML())
.catch((e) => {
vm.error = true;
miqService.handleFailure(e);
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1196,6 +1196,7 @@
widget_add
widget_close
widget_dd_done
widget_refresh
widget_toggle_minmax
widget_zoom
)
Expand Down

0 comments on commit affc588

Please sign in to comment.