forked from ManageIQ/manageiq-ui-classic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsaved_reports.rb
150 lines (138 loc) · 6.15 KB
/
saved_reports.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
module ReportController::SavedReports
extend ActiveSupport::Concern
def show_saved
@sb[:last_saved_id] = params[:id] if params[:id] && params[:id] != "report"
fetch_saved_report(@sb[:last_saved_id])
if @report.blank? # if report was nil. reset active tree back to report tree, and keep active node report to be same
self.x_active_tree = :reports_tree
end
end
def show_saved_report
@sb[:last_savedreports_id] = params[:id].split('-').last if params[:id] && params[:id] != "savedreports"
fetch_saved_report(@sb[:last_savedreports_id])
end
def fetch_saved_report(id)
rr = MiqReportResult.for_user(current_user).find_by_id(from_cid(id.split('-').last))
if rr.nil? # Saved report no longer exists
@report = nil
return
end
@right_cell_text ||= _("Saved Report \"%{name}\"") %
{:name => "#{rr.name} - #{format_timezone(rr.created_on, Time.zone, "gt")}"}
if admin_user? || current_user.miq_group_ids.include?(rr.miq_group_id)
@report_result_id = session[:report_result_id] = rr.id
session[:report_result_runtime] = rr.last_run_on
if rr.status.downcase == "complete"
session[:rpt_task_id] = nil
unless rr.valid_report_column?
add_flash(_("Saved Report \"%{time}\" not found, Schedule may have failed") %
{:time => format_timezone(rr.created_on, Time.zone, "gtl")},
:error)
get_all_reps(rr.miq_report_id.to_s)
if x_active_tree == :savedreports_tree
self.x_node = "xx-#{to_cid(rr.miq_report_id)}"
else
@sb[:rpt_menu].each_with_index do |lvl1, i|
if lvl1[0] == @sb[:grp_title]
lvl1[1].each_with_index do |lvl2, k|
if lvl2[0].downcase == "custom"
x_node_set("xx-#{i}_xx-#{i}-#{k}_rep-#{to_cid(rr.miq_report_id)}", :reports_tree)
end
end
end
end
end
return
else
if rr.contains_records?
@html = report_first_page(rr) # Get the first page of the results
if params[:type]
@zgraph = nil
@html = nil
if ["tabular", "hybrid"].include?(params[:type])
@html = report_build_html_table(@report,
rr.html_rows(:page => @sb[:pages][:current],
:per_page => @sb[:pages][:perpage]).join)
end
if ["graph", "hybrid"].include?(params[:type])
@zgraph = true # Show the zgraph in the report
end
@ght_type = params[:type]
else
unless @report.graph.blank?
@zgraph = true
@ght_type = "hybrid"
else
@ght_type = "tabular"
end
end
@report.extras ||= {} # Create extras hash
@report.extras[:to_html] ||= @html # Save the html report
else
add_flash(_("No records found for this report"), :warning)
end
end
else
@report_result = rr
end
else
add_flash(_("Report is not authorized for the logged in user"), :error)
get_all_reps(@sb[:miq_report_id].to_s)
return
end
end
# Delete all selected or single displayed host(s)
def saved_report_delete
assert_privileges("saved_report_delete")
savedreports = find_checked_items
unless savedreports.present?
report_result = x_node.split('_').last
savedreport = report_result.split('-').last
savedreports = Array.wrap(from_cid(savedreport))
end
if savedreports.empty? && params[:id].present? && !MiqReportResult.for_user(current_user).exists?(params[:id].to_i)
# saved report is being viewed in report accordion
add_flash(_("Saved Report no longer exists"), :error)
else
savedreports.push(params[:id]) if savedreports.blank?
@report = nil
r = MiqReportResult.for_user(current_user).find(savedreports[0])
@sb[:miq_report_id] = r.miq_report_id
process_saved_reports(savedreports, "destroy") unless savedreports.empty?
add_flash(_("The selected Saved Report was deleted")) if @flash_array.nil?
@report_deleted = true
end
self.x_node = "xx-#{to_cid(@sb[:miq_report_id])}" if x_active_tree == :savedreports_tree &&
x_node.split('-').first == "rr"
replace_right_cell(:replace_trees => [:reports, :savedreports])
end
# get all saved reports for list view
def get_all_saved_reports
@force_no_grid_xml = true
@gtl_type = "list"
@ajax_paging_buttons = true
# @embedded = true
if params[:ppsetting] # User selected new per page value
@items_per_page = params[:ppsetting].to_i # Set the new per page value
@settings.store_path(:perpage, @gtl_type.to_sym, @items_per_page) # Set the per page setting for this gtl type
end
@sortcol = session["#{x_active_tree}_sortcol".to_sym].nil? ? 0 : session["#{x_active_tree}_sortcol".to_sym].to_i
@sortdir = session["#{x_active_tree}_sortdir".to_sym].nil? ? "DESC" : session["#{x_active_tree}_sortdir".to_sym]
@no_checkboxes = !role_allows?(:feature => "miq_report_saved_reports_admin", :any => true)
# show all saved reports
@view, @pages = get_view(MiqReportResult, :association => "all",
:named_scope => :with_current_user_groups_and_report)
# build_savedreports_tree
@sb[:saved_reports] = nil
@right_cell_div = "savedreports_list"
@right_cell_text = _("All Saved Reports")
@current_page = @pages[:current] unless @pages.nil? # save the current page number
session["#{x_active_tree}_sortcol".to_sym] = @sortcol
session["#{x_active_tree}_sortdir".to_sym] = @sortdir
end
private
# Build the main Saved Reports tree
def build_savedreports_tree
TreeBuilderReportSavedReports.new('savedreports_tree', 'savedreports', @sb)
end
end