-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
318 lines (260 loc) · 8.43 KB
/
index.html
File metadata and controls
318 lines (260 loc) · 8.43 KB
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
<!--
*
* ========================================================================
* Dashboard Example using Jaspersoft's new Visualize.JS API
*
* ========================================================================
* Copyright 2014
* Author: Gene Arnold
*
* https://github.com/GeneArnold/
*
* Unless you have purchased a commercial license agreement from Jaspersoft Inc., the following license terms apply:
*
* This program is free software: you can redistribute it and/or modify it under the terms of the
* GNU Affero General Public License as published by the Free Software Foundation, either version 3
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
* ========================================================================
*
*
-->
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="themes/icon.css">
<link rel="stylesheet" type="text/css" href="css/portal.css">
<style type="text/css">
body{
overflow: hidden;
}
.title{
font-size:16px;
font-weight:bold;
padding:20px 10px;
background:#eee;
overflow:hidden;
border-bottom:1px solid #ccc;
}
.t-list{
padding:5px;
}
button{
width: 130px;
}
.panel-title{
font-family: sans-serif;
}
</style>
<script type="text/javascript" src="scripts/jquery.min.js"></script>
<script type="text/javascript" src="scripts/jquery.easyui.min.js"></script>
<script type="text/javascript" src="scripts/jquery.portal.js"></script>
<script type='text/javascript' src="http://localhost:8080/jasperserver-pro/client/visualize.js"></script>
<script type="text/javascript">
//Wrapping and creating the portal. Setting a few parameters around how it will look
$(function(){
$('#pp').portal({
border:false,
fit:false
});
});
//Here is the JRSClient object that will be used to access repo information and to render reports
var JRSClient;
//Log into JRS via visualize.js and create a session object that will be used though out the application
visualize({
auth: {
name: "jasperadmin",
password: "jasperadmin",
organization:"organization_1"
}
}, function (v) {
JRSClient = v;
init();
}, function () {
alert("Unexpected error!");
});
//Getting a list of all the reports the logged in user can access then run a function to display them
function init(){
JRSClient.resourcesSearch({
// server: serverUrl,
folderUri:"/public/Samples/Reports/Dashboard_Reports",
recursive:false,
success:listRepository,
error:function (err) {
alert(err);
}
});
}
//Using this function we are adding buttons to the screen to add and remove reports to the dashboard
//Custom attributes are used to hold information about the status of the report's display and URI inside of JRS
function listRepository(results) {
$.each(results, function(index) {
$("#cp").append("<button status='off' reportURI='"+this.uri+"' onclick=addReport(btnId='btn_"+index+"') title='"+this.label+"' id='btn_"+index+"'>"+reportNameTrim(this.label)+"</button>");
});
}
//Report name trim helper
function reportNameTrim(name) {
if (name.length > 20) {
var x = name.substring(0, 17) + '...';
return x;
}else{
return name;
}
}
//Adding report to the dashboard
var colIndex = 0;
function addReport(btnId){
var panelCnt = $('#pp').portal('getPanels');
var reportStatus = $("#"+btnId).attr('status');
var reportURI = $("#"+btnId).attr('reportURI');
var reportName = $("#"+btnId).attr('title');
if (reportStatus == 'off'){
if (panelCnt.length == 0){colIndex=0};
if (colIndex > 2){colIndex=0};
var p = $('<div />').appendTo('body');
p.attr('id', 'pannel_'+btnId);
p.panel({
title:reportName,
content:'<div id="report_'+btnId+'" style="padding:5px;">Loading your report...</div>',
height:450,
closable:false,
collapsible:true,
noheader:false,
tools:[{
iconCls:'icon-pdf',
handler:function(){exportReport(btnId);}
},{
iconCls:'icon-reload',
handler:function(){refreshReport(btnId);}
},{
iconCls:'icon-filter',
handler:function(){
$('#inputControls').html('');
$('#sendButtonBox').hide();
$('#dlg').attr('reportId',btnId);
$('#dlg').dialog('open');
var ic = JRSClient.inputControls({
resource: reportURI,
success: function(controls) {
controls.forEach(buildControl);
}
});
}
}]
});
$('#pp').portal('add', {
panel:p,
columnIndex:colIndex
});
colIndex = colIndex + 1;
renderReport(reportURI,'#report_'+btnId,JRSClient);
$("#"+btnId).attr('status','on');
$("#"+btnId).css( "background-color", "darkgrey" );
}else{
removeReport(btnId);
}
}
function buildControl(control) {
switch(control.type) {
case "singleSelect":
$("<input value='' />")
.attr("id", control.id)
.attr("name", "")
.appendTo("#inputControls");
$('#'+control.id).combobox({
data:control.state.options,
valueField:'value',
textField:'label',
onLoadSuccess:function(){
$('#sendButtonBox').show();
},
});
break;
case n:
//code block
break;
default:
}
}
function filterReport(id){
alert('Filters Coming Soon!');
//Get list of all input controls
//iterate through control list and build param object
//find report based on id and rerun passing param object
}
function refreshReport(id){
$.each(reportsList,
function(index,value){
if(value.container() == ("#report_"+id)){
value.refresh();
}
}
);
}
function exportReport(id){
$.each(reportsList,
function(index,value){
if(value.container() == ("#report_"+id)){
value
.export({
outputFormat: "pdf"
})
.done(function (link) {
window.open(link.href); // open new window to download report
})
.fail(function (err) {
alert(err.message);
});
}
}
);
}
//Used to remove report panels from the dashboard
function removeReport(id){
reportsList = jQuery.grep(reportsList, function( report, i ) {
return ( report.container() !== ("#report_"+id) );
});
$('#pp').portal('remove',$('#pannel_'+id));
$("#"+btnId).attr('status','off');
$("#"+btnId).css( "background-color", "buttonface" );
colIndex = 0;
}
var reportsList = new Array();
//When a pannel is added to the dashboard this function is called to use visualize.js to create the report within that pannel
function renderReport(uri,container,v) {
var report = new v.report({
resource: uri,
container: container,
error: function(err) {
alert(err.message);
}
});
reportsList.push(report);
}
</script>
</head>
<body class="easyui-layout">
<div id="cp" data-options="region:'west',title:'Report Options',split:true,minWidth:150" style="width:150px;padding-left: 5px;padding-top: 5px;"></div>
<div data-options="region:'center',title:'Dashboard'" style="padding:5px;background:#eee;">
<div id="pp" style="width:1500px;height:auto;">
<div style="width:33%"></div>
<div style="width:33%"></div>
<div style="width:33%"></div>
</div>
</div>
<div id="dlg" reportId="" class="easyui-dialog" title="Report Input Controls" data-options="closed:true" style="width:400px;height:200px;padding:10px">
<div id="inputControls"></div>
<div id="sendButtonBox">
<a id="btnFilter" href="javascript:void(0)" class="easyui-linkbutton" onclick="filterReport($('#dlg').attr('reportId'));" >SetValue</a>
</div>
</div>
</body>
</html>