Skip to content

Commit

Permalink
Move blank logic to http endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
ZitaNemeckova committed Nov 1, 2019
1 parent 9ab3bde commit cb08338
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 31 deletions.
18 changes: 13 additions & 5 deletions app/controllers/dashboard_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,9 @@ def start_url

def widget_chart_data
widget = find_record_with_rbac(MiqWidget, params[:id])
datum = widget.contents_for_user(current_user).contents
content = nil
blank = widget.contents_for_user(current_user).blank?
datum = blank ? nil : widget.contents_for_user(current_user).contents
content = ""
if datum.blank?
state = 'no_data'
elsif Charting.data_ok?(datum)
Expand All @@ -150,8 +151,10 @@ def widget_chart_data
else
state = 'invalid'
end
binding.pry
render :json => {:content => content,
:minimized => widget_minimized?(params[:id]),
:blank => blank.to_s,
:state => state}
end

Expand All @@ -161,9 +164,10 @@ def widget_menu_data
role_allows?(:feature => shortcut.miq_shortcut.rbac_feature_name, :any => true)
end.map do |shortcut|
{:description => shortcut.description, :href => shortcut.miq_shortcut.url}
end
end
render :json => {:shortcuts => shortcuts,
:minimized => widget_minimized?(params[:id])}
:minimized => widget_minimized?(params[:id]),
:blank => "false"}
end

def widget_minimized?(id)
Expand All @@ -173,8 +177,12 @@ def widget_minimized?(id)

def widget_report_data
widget = find_record_with_rbac(MiqWidget, params[:id])
blank = widget.contents_for_user(current_user).blank?
content = blank ? '' : widget.contents_for_user(current_user).contents
binding.pry
render :json => {
:content => widget.contents_for_user(current_user).contents,
:blank => blank.to_s,
:content => content,
:minimized => widget_minimized?(params[:id])
}
end
Expand Down
45 changes: 21 additions & 24 deletions app/javascript/angular/dashboard/widget-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ ManageIQ.angular.app.component('widgetWrapper', {
widgetId: '@',
widgetType: '@',
widgetButtons: '@',
widgetBlank: '@',
widgetTitle: '@',
widgetLastRun: '@',
widgetNextRun: '@',
Expand All @@ -26,20 +25,21 @@ ManageIQ.angular.app.component('widgetWrapper', {
vm.$onInit = function() {
vm.divId = `w_${vm.widgetId}`;
vm.innerDivId = `dd_w${vm.widgetId}_box`;
if (vm.widgetBlank === 'false') {
vm.refreshWidgetHTML();
};
vm.refreshWidgetHTML(false);
};

vm.refreshWidgetHTML = function() {
vm.refreshWidgetHTML = function(refreshed) {
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);
}
miqSparkleOff();
if (refreshed) {
miqSparkleOff();
add_flash(sprintf(__('Dashboard "%s" was refreshed', vm.widgetTitle)), 'success');
}
deferred.resolve();
})
.catch((e) => {
Expand All @@ -49,21 +49,18 @@ ManageIQ.angular.app.component('widgetWrapper', {
});
};

vm.refresh = function() {
if (vm.widgetBlank === 'false') {
$http.post(`/dashboard/widget_refresh/?widget=${vm.widgetId}`)
.then((response) => {
debugger;
miqSparkleOn();
API.wait_for_task(response.data.task)
.then(vm.refreshWidgetHTML())
})
.catch((e) => {
vm.error = true;
miqService.handleFailure(e);
deferred.reject();
});
}
vm.refresh = function() {
$http.post(`/dashboard/widget_refresh/?widget=${vm.widgetId}`)
.then((response) => {
miqSparkleOn();
API.wait_for_task(response.data.task)
.then(vm.refreshWidgetHTML(true));
})
.catch((e) => {
vm.error = true;
miqService.handleFailure(e);
deferred.reject();
});
};

vm.widgetUrl = function() {
Expand All @@ -90,11 +87,11 @@ ManageIQ.angular.app.component('widgetWrapper', {
</div>
<widget-error ng-if="vm.error === true"></widget-error>
<widget-spinner ng-if="!vm.widgetModel && vm.widgetBlank == 'false' && !vm.error"></widget-spinner>
<div ng-if="vm.widgetBlank === 'true' || vm.widgetModel"
<div ng-if="vm.widgetModel.blank === 'true' || vm.widgetModel"
ng-attr-id="{{vm.innerDivId}}"
ng-class="{ hidden: vm.widgetModel.minimized, mc:true }">
<widget-empty ng-if="vm.widgetBlank === 'true'"></widget-empty>
<div ng-if="vm.widgetBlank === 'false'"
<widget-empty ng-if="vm.widgetModel.blank === 'true'"></widget-empty>
<div ng-if="vm.widgetModel.blank === 'false'"
ng-switch on="vm.widgetType">
<widget-menu ng-switch-when="menu"
widget-id="{{vm.widgetId}}"
Expand Down
2 changes: 0 additions & 2 deletions app/views/dashboard/_widget.html.haml
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
%div{:id => "ww_#{presenter.widget.id}"}
- last_run, next_run = last_next_run(presenter.widget)
- widget_blank = presenter.widget.content_type == 'menu' ? false : presenter.widget.contents_for_user(current_user).blank?
%widget-wrapper{"widget-id" => presenter.widget.id,
"widget-type" => presenter.widget.content_type,
"widget-buttons" => presenter.widget_buttons,
"widget-blank" => widget_blank,
"widget-last-run" => last_run,
"widget-next-run" => next_run,
"widget-title" => presenter.widget.title}
Expand Down

0 comments on commit cb08338

Please sign in to comment.