birt 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/Gemfile.lock +3 -0
- data/app/assets/javascripts/application.js +1 -1
- data/app/assets/stylesheets/application.css +1 -0
- data/app/controllers/birt/api_controller.rb +16 -0
- data/app/controllers/birt_test_controller.rb +4 -0
- data/app/helpers/birt/api_helper.rb +30 -0
- data/app/views/birt/api/index.json.jbuilder +8 -0
- data/app/views/birt_test/index.html.erb +3 -0
- data/app/views/layouts/application.html.erb +9 -4
- data/birt.gemspec +1 -1
- data/lib/assets/javascripts/birt/birt.js +90 -0
- data/lib/assets/javascripts/birt/components/loading.js +28 -0
- data/lib/assets/javascripts/birt/utils/string.js +22 -0
- data/lib/assets/javascripts/birt.js +8 -0
- data/lib/assets/stylesheets/birt/base/constant.scss +48 -0
- data/lib/assets/stylesheets/birt/base/mixins.scss +30 -0
- data/lib/assets/stylesheets/birt/components/loading.scss +158 -0
- data/lib/assets/stylesheets/birt/components/table.scss +20 -0
- data/lib/assets/stylesheets/birt.scss +9 -0
- data/lib/birt/api.rb +4 -0
- data/lib/birt/{data_set.rb → core/data_set.rb} +11 -7
- data/lib/birt/core/data_set_result.rb +20 -0
- data/lib/birt/{data_source.rb → core/data_source.rb} +1 -1
- data/lib/birt/{mysql.rb → core/mysql.rb} +1 -1
- data/lib/birt/core/report/base_report.rb +12 -0
- data/lib/birt/core/report/property.rb +15 -0
- data/lib/birt/core/report/table_cell_data.rb +16 -0
- data/lib/birt/core/report/table_cell_label.rb +15 -0
- data/lib/birt/core/report/table_detail.rb +13 -0
- data/lib/birt/core/report/table_footer.rb +13 -0
- data/lib/birt/core/report/table_header.rb +15 -0
- data/lib/birt/core/report/table_report.rb +17 -0
- data/lib/birt/core/report/table_row.rb +15 -0
- data/lib/birt/core/report/table_row_cell.rb +16 -0
- data/lib/birt/core/report/text_property.rb +15 -0
- data/lib/birt/core/rpt_design.rb +61 -0
- data/lib/birt/core.rb +4 -0
- data/lib/birt/version.rb +8 -2
- data/lib/birt.rb +3 -4
- metadata +36 -15
- data/app/controllers/concerns/.keep +0 -0
- data/app/helpers/application_helper.rb +0 -2
- data/app/mailers/.keep +0 -0
- data/app/models/.keep +0 -0
- data/app/models/concerns/.keep +0 -0
- data/lib/birt/report/table_report.rb +0 -2
- data/lib/birt/rpt_design.rb +0 -36
- data/lib/tasks/.keep +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2dbe60a6cb1ae6007827db8ec686023e7fc75089
|
4
|
+
data.tar.gz: 7c0f4a629690cc1f7c3e9849a90f8b2c1e089242
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d944213a3a0fb69c351c7673509bc610930d9d3863b5df53ad295587c2fad995a1f60cf983283e85e35e0f2e2b8148b549a60a952f51e61182eec7253a67388
|
7
|
+
data.tar.gz: a9b61a25159ae319540d91047a63bf16c742a1c3e4f24c12520375d00c98b670c058b83e7928850636efd4793a30504f6fbf3209fd9730221ed5d5858b61540b
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -56,6 +56,8 @@ GEM
|
|
56
56
|
execjs (2.5.2)
|
57
57
|
globalid (0.3.5)
|
58
58
|
activesupport (>= 4.1.0)
|
59
|
+
highcharts-rails (4.1.5)
|
60
|
+
railties (>= 3.1)
|
59
61
|
i18n (0.7.0)
|
60
62
|
jbuilder (2.3.1)
|
61
63
|
activesupport (>= 3.0.0, < 5)
|
@@ -146,6 +148,7 @@ PLATFORMS
|
|
146
148
|
DEPENDENCIES
|
147
149
|
byebug
|
148
150
|
coffee-rails (~> 4.1.0)
|
151
|
+
highcharts-rails (~> 4.1)
|
149
152
|
jbuilder (~> 2.0)
|
150
153
|
jquery-rails
|
151
154
|
mysql2
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'birt'
|
2
|
+
module Birt
|
3
|
+
class ApiController < ActionController::Base
|
4
|
+
protect_from_forgery with: :exception
|
5
|
+
|
6
|
+
def index
|
7
|
+
|
8
|
+
rpt_design_path = params[:_report] || '003.rptdesign'
|
9
|
+
@rpt_design = Birt::Core::RptDesign.new("./birt/reports/#{rpt_design_path}")
|
10
|
+
|
11
|
+
#数据解析
|
12
|
+
@rpt_design.parse_rpt
|
13
|
+
@rpt_design.data_sets.values.each { |data_set| data_set.data_set_result }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Birt
|
2
|
+
module ApiHelper
|
3
|
+
|
4
|
+
def parse_table_header(table_header, table=nil)
|
5
|
+
header = []
|
6
|
+
table_header.rows.each_with_index { |row, index|
|
7
|
+
header << []
|
8
|
+
row.row_cells.each { |row_cell|
|
9
|
+
header[index] << row_cell.cell_labels[0].text_properties[0].text
|
10
|
+
}
|
11
|
+
}
|
12
|
+
header
|
13
|
+
end
|
14
|
+
|
15
|
+
def parse_table_detail(table_detail, table)
|
16
|
+
detail = []
|
17
|
+
table_detail.rows.each_with_index { |row|
|
18
|
+
row.row_cells.each { |row_cell|
|
19
|
+
data = row_cell.cell_datas[0].properties[0]
|
20
|
+
data_set_result = table.data_set.data_set_result
|
21
|
+
data_set_result.columns[data_set_result.column_headers.index(data.text)].each_with_index { |d, row_i|
|
22
|
+
detail << [] unless detail[row_i]
|
23
|
+
detail[row_i] << d
|
24
|
+
}
|
25
|
+
}
|
26
|
+
}
|
27
|
+
detail
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -1,14 +1,19 @@
|
|
1
1
|
<!DOCTYPE html>
|
2
2
|
<html>
|
3
3
|
<head>
|
4
|
-
<
|
5
|
-
|
6
|
-
|
4
|
+
<meta charset="utf-8">
|
5
|
+
<title>BirtView</title>
|
6
|
+
|
7
|
+
<%= stylesheet_link_tag 'application' %>
|
7
8
|
<%= csrf_meta_tags %>
|
9
|
+
|
10
|
+
<meta id="viewport" name="viewport" content="width=device-width,minimum-scale=1,maximum-scale=1,initial-scale=1,user-scalable=no">
|
11
|
+
<meta name="apple-mobile-web-app-capable" content="yes">
|
8
12
|
</head>
|
9
13
|
<body>
|
10
14
|
|
11
15
|
<%= yield %>
|
12
16
|
|
17
|
+
<%= javascript_include_tag 'application' %>
|
13
18
|
</body>
|
14
|
-
</html>
|
19
|
+
</html>
|
data/birt.gemspec
CHANGED
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
|
|
22
22
|
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
23
|
end
|
24
24
|
|
25
|
-
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|pkg|public|config|birt)/}) }
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(tmp|log|test|spec|features|pkg|public|config|birt)/}) }
|
26
26
|
spec.bindir = "exe"
|
27
27
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
28
|
spec.require_paths = ["app","lib"]
|
@@ -0,0 +1,90 @@
|
|
1
|
+
var Birt = (function () {
|
2
|
+
var _this;
|
3
|
+
|
4
|
+
var rptDesignJsonData;
|
5
|
+
|
6
|
+
var $birt;
|
7
|
+
|
8
|
+
function Birt(designJsonData) {
|
9
|
+
_this = this;
|
10
|
+
rptDesignJsonData = designJsonData;
|
11
|
+
$birt = $('.birt');
|
12
|
+
}
|
13
|
+
|
14
|
+
/**
|
15
|
+
* 获取报表数据
|
16
|
+
* @param rptDesignName
|
17
|
+
*/
|
18
|
+
Birt.prototype.getRetDesign = function (rptDesignName) {
|
19
|
+
$.birtLoading();
|
20
|
+
$.ajax(
|
21
|
+
{
|
22
|
+
url: '/birt/api.json?_report={0}'.format(rptDesignName),
|
23
|
+
type: 'GET',
|
24
|
+
success: function (data) {
|
25
|
+
$.birtLoading('hide');
|
26
|
+
rptDesignJsonData = data.rpt_design;
|
27
|
+
_this.showDisplayName();
|
28
|
+
console.log(data.rpt_design.tables);
|
29
|
+
var tables = data.rpt_design.tables;
|
30
|
+
for (var i = 0; i < tables.length; i++) {
|
31
|
+
var table = tables[i];
|
32
|
+
_this.showTable(table);
|
33
|
+
}
|
34
|
+
},
|
35
|
+
error: function (data) {
|
36
|
+
$.birtLoading('hide');
|
37
|
+
}
|
38
|
+
}
|
39
|
+
);
|
40
|
+
};
|
41
|
+
|
42
|
+
Birt.prototype.showDisplayName = function () {
|
43
|
+
$birt.append('<h2>{0}</h2>'.format(rptDesignJsonData.display_name));
|
44
|
+
};
|
45
|
+
|
46
|
+
/**
|
47
|
+
* 显示行
|
48
|
+
* @param rowData
|
49
|
+
* @param cellName
|
50
|
+
* @returns {string}
|
51
|
+
*/
|
52
|
+
Birt.prototype.showTableRow = function (rowData, cellName) {
|
53
|
+
|
54
|
+
var row_html = '<tr>';
|
55
|
+
for (var i = 0; i < rowData.length; i++) {
|
56
|
+
if (cellName == 'th') {
|
57
|
+
row_html += "<th>{0}</th>".format(rowData[i]);
|
58
|
+
} else {
|
59
|
+
row_html += "<td>{0}</td>".format(rowData[i]);
|
60
|
+
}
|
61
|
+
}
|
62
|
+
row_html += '</tr>';
|
63
|
+
return row_html;
|
64
|
+
};
|
65
|
+
|
66
|
+
/**
|
67
|
+
* 显示表格
|
68
|
+
* @param table
|
69
|
+
* @returns {string}
|
70
|
+
*/
|
71
|
+
Birt.prototype.showTable = function (table) {
|
72
|
+
var table_html = '<table class="birt-table">';
|
73
|
+
|
74
|
+
for (var i = 0; i < table.header.length; i++) {
|
75
|
+
table_html += _this.showTableRow(table.header[i], 'th');
|
76
|
+
}
|
77
|
+
|
78
|
+
|
79
|
+
for (var i = 0; i < table.detail.length; i++) {
|
80
|
+
table_html += _this.showTableRow(table.detail[i], 'td');
|
81
|
+
}
|
82
|
+
|
83
|
+
table_html += "</table>";
|
84
|
+
|
85
|
+
$(".birt").append(table_html);
|
86
|
+
console.log(table);
|
87
|
+
return table_html;
|
88
|
+
};
|
89
|
+
return Birt;
|
90
|
+
})();
|
@@ -0,0 +1,28 @@
|
|
1
|
+
;
|
2
|
+
(function ($) {
|
3
|
+
$.extend({
|
4
|
+
birtLoading: function (action) {
|
5
|
+
var loadingHtml = '<div class="birt-loading">' +
|
6
|
+
'<div class="icon">' +
|
7
|
+
'<img src="http://img.tanliani.com/public/assets/vd/icon_loading.png">' +
|
8
|
+
'</div>' +
|
9
|
+
'<p class="label">' +
|
10
|
+
'Birt报表' +
|
11
|
+
'</p>' +
|
12
|
+
|
13
|
+
' <div class="points">' +
|
14
|
+
' <i class="one"></i>' +
|
15
|
+
' <i class="two"></i>' +
|
16
|
+
' <i class="three"></i>' +
|
17
|
+
' </div>' +
|
18
|
+
'</div>';
|
19
|
+
$('.birt-loading').remove();
|
20
|
+
$('body').append(loadingHtml);
|
21
|
+
if (action == undefined || action == 'show') {
|
22
|
+
$(".birt-loading").show();
|
23
|
+
} else {
|
24
|
+
$(".birt-loading").hide();
|
25
|
+
}
|
26
|
+
}
|
27
|
+
});
|
28
|
+
})(jQuery);
|
@@ -0,0 +1,22 @@
|
|
1
|
+
String.prototype.format = function (args) {
|
2
|
+
var result = this;
|
3
|
+
if (arguments.length > 0) {
|
4
|
+
if (arguments.length == 1 && typeof (args) == "object") {
|
5
|
+
for (var key in args) {
|
6
|
+
if (args[key] != undefined) {
|
7
|
+
var reg = new RegExp("({" + key + "})", "g");
|
8
|
+
result = result.replace(reg, args[key]);
|
9
|
+
}
|
10
|
+
}
|
11
|
+
}
|
12
|
+
else {
|
13
|
+
for (var i = 0; i < arguments.length; i++) {
|
14
|
+
if (arguments[i] != undefined) {
|
15
|
+
var reg = new RegExp("({[" + i + "]})", "g");
|
16
|
+
result = result.replace(reg, arguments[i]);
|
17
|
+
}
|
18
|
+
}
|
19
|
+
}
|
20
|
+
}
|
21
|
+
return result;
|
22
|
+
}
|
@@ -0,0 +1,48 @@
|
|
1
|
+
/*z-index*/
|
2
|
+
$z-index-content: 999;
|
3
|
+
$z-index-header: 1000;
|
4
|
+
$z-index-footer: 1000;
|
5
|
+
$z-index-top-menu: 1001;
|
6
|
+
$z-index-option-menu: 1002;
|
7
|
+
$z-index-select: 1001;
|
8
|
+
$z-index-modal-view: 1001;
|
9
|
+
|
10
|
+
$z-index-input-dialog: 1102;
|
11
|
+
$z-index-confirm: 1102;
|
12
|
+
$z-index-loading: 1103;
|
13
|
+
$z-index-toast: 1104;
|
14
|
+
|
15
|
+
/*color*/
|
16
|
+
$color-line: #EBEBEB;
|
17
|
+
$color-text-orange: #FC7203;
|
18
|
+
$color-text-green: #44AD1C;
|
19
|
+
$color-text-gray: #ABABAB;
|
20
|
+
$color-text-danger: red;
|
21
|
+
$color-text-danger-press: #b30000;
|
22
|
+
$color-text-danger-disabled: #ff8080;
|
23
|
+
$color-white-press: #cccccc;
|
24
|
+
$color-btn-success: #44AD1C;
|
25
|
+
$color-btn-success-press: #338014;
|
26
|
+
$color-btn-success-disabled: #99cc99;
|
27
|
+
|
28
|
+
$color-loading-point-white: #fff;
|
29
|
+
$color-loading-point-gray: #A9A5AD;
|
30
|
+
$color-loading-point-grayer: #8C8990;
|
31
|
+
|
32
|
+
$color-switch-off: #ddd;
|
33
|
+
$color-switch-on: #4cd964;
|
34
|
+
|
35
|
+
/*num*/
|
36
|
+
$num-header-height: 45px;
|
37
|
+
$num-footer-tabs-height: 50px;
|
38
|
+
$num-button-height: 38px;
|
39
|
+
$num-button-normal-height: 35px;
|
40
|
+
$num-button-small-height: 28px;
|
41
|
+
|
42
|
+
/*other*/
|
43
|
+
$border-color: #ddd;
|
44
|
+
$border-blue-color: #145fd7;
|
45
|
+
|
46
|
+
$blue: #4a87ee;
|
47
|
+
$hover: #f5f5f5;
|
48
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
@mixin float-middle-center {
|
2
|
+
top: 50%;
|
3
|
+
left: 50%;
|
4
|
+
transform: translate(-50%, -50%);
|
5
|
+
-webkit-transform: translate(-50%, -50%);
|
6
|
+
}
|
7
|
+
|
8
|
+
@mixin mix_loading_point {
|
9
|
+
animation-duration: 1000ms;
|
10
|
+
-webkit-animation-duration: 1000ms;
|
11
|
+
animation-iteration-count: infinite;
|
12
|
+
-webkit-animation-iteration-count: infinite;
|
13
|
+
animation-timing-function: linear;
|
14
|
+
-webkit-animation-timing-function: linear;
|
15
|
+
}
|
16
|
+
|
17
|
+
@mixin mix_button {
|
18
|
+
-webkit-appearance: none;
|
19
|
+
height: $num-button-height;
|
20
|
+
border-radius: 4px;
|
21
|
+
min-width: 120px;
|
22
|
+
outline: none;
|
23
|
+
box-shadow: none;
|
24
|
+
}
|
25
|
+
|
26
|
+
@mixin birt_base {
|
27
|
+
-webkit-box-sizing: border-box;
|
28
|
+
-moz-box-sizing: border-box;
|
29
|
+
box-sizing: border-box;
|
30
|
+
}
|
@@ -0,0 +1,158 @@
|
|
1
|
+
@keyframes loading_point {
|
2
|
+
0% {
|
3
|
+
background-color: $color-loading-point-white;
|
4
|
+
}
|
5
|
+
|
6
|
+
33.3% {
|
7
|
+
background-color: $color-loading-point-gray;
|
8
|
+
}
|
9
|
+
|
10
|
+
66.6% {
|
11
|
+
background-color: $color-loading-point-grayer;
|
12
|
+
}
|
13
|
+
|
14
|
+
100% {
|
15
|
+
background-color: $color-loading-point-white;
|
16
|
+
}
|
17
|
+
}
|
18
|
+
|
19
|
+
@-webkit-keyframes loading_point {
|
20
|
+
0% {
|
21
|
+
background-color: $color-loading-point-white;
|
22
|
+
}
|
23
|
+
|
24
|
+
33.3% {
|
25
|
+
background-color: $color-loading-point-gray;
|
26
|
+
}
|
27
|
+
|
28
|
+
66.6% {
|
29
|
+
background-color: $color-loading-point-grayer;
|
30
|
+
}
|
31
|
+
|
32
|
+
100% {
|
33
|
+
background-color: $color-loading-point-white;
|
34
|
+
}
|
35
|
+
}
|
36
|
+
|
37
|
+
@keyframes loading_point_two {
|
38
|
+
0% {
|
39
|
+
background-color: $color-loading-point-grayer;
|
40
|
+
}
|
41
|
+
|
42
|
+
33.3% {
|
43
|
+
background-color: $color-loading-point-white;
|
44
|
+
}
|
45
|
+
|
46
|
+
66.6% {
|
47
|
+
background-color: $color-loading-point-gray;
|
48
|
+
}
|
49
|
+
|
50
|
+
100% {
|
51
|
+
background-color: $color-loading-point-grayer;
|
52
|
+
}
|
53
|
+
}
|
54
|
+
|
55
|
+
@-webkit-keyframes loading_point_two {
|
56
|
+
0% {
|
57
|
+
background-color: $color-loading-point-grayer;
|
58
|
+
}
|
59
|
+
|
60
|
+
33.3% {
|
61
|
+
background-color: $color-loading-point-white;
|
62
|
+
}
|
63
|
+
|
64
|
+
66.6% {
|
65
|
+
background-color: $color-loading-point-gray;
|
66
|
+
}
|
67
|
+
|
68
|
+
100% {
|
69
|
+
background-color: $color-loading-point-grayer;
|
70
|
+
}
|
71
|
+
}
|
72
|
+
|
73
|
+
@keyframes loading_point_three {
|
74
|
+
0% {
|
75
|
+
background-color: $color-loading-point-gray;
|
76
|
+
}
|
77
|
+
|
78
|
+
33.3% {
|
79
|
+
background-color: $color-loading-point-grayer;
|
80
|
+
}
|
81
|
+
|
82
|
+
66.6% {
|
83
|
+
background-color: $color-loading-point-white;
|
84
|
+
}
|
85
|
+
|
86
|
+
100% {
|
87
|
+
background-color: $color-loading-point-gray;
|
88
|
+
}
|
89
|
+
}
|
90
|
+
|
91
|
+
@-webkit-keyframes loading_point_three {
|
92
|
+
0% {
|
93
|
+
background-color: $color-loading-point-gray;
|
94
|
+
}
|
95
|
+
|
96
|
+
33.3% {
|
97
|
+
background-color: $color-loading-point-grayer;
|
98
|
+
}
|
99
|
+
|
100
|
+
66.6% {
|
101
|
+
background-color: $color-loading-point-white;
|
102
|
+
}
|
103
|
+
|
104
|
+
100% {
|
105
|
+
background-color: $color-loading-point-gray;
|
106
|
+
}
|
107
|
+
}
|
108
|
+
|
109
|
+
|
110
|
+
.birt-loading {
|
111
|
+
@include birt_base;
|
112
|
+
width: 120px;
|
113
|
+
height: 120px;
|
114
|
+
background: rgba(0, 0, 0, 0.6);
|
115
|
+
display: none;
|
116
|
+
position: fixed;
|
117
|
+
z-index: $z-index-loading;
|
118
|
+
color: white;
|
119
|
+
text-align: center;
|
120
|
+
vertical-align: middle;
|
121
|
+
border-radius: 5px;
|
122
|
+
padding: 12px;
|
123
|
+
@include float-middle-center;
|
124
|
+
.icon > img {
|
125
|
+
width: 35px;
|
126
|
+
margin: 8px;
|
127
|
+
}
|
128
|
+
p.label {
|
129
|
+
font-size: 12pt;
|
130
|
+
font-weight: normal;
|
131
|
+
margin: 0;
|
132
|
+
}
|
133
|
+
.points {
|
134
|
+
margin-top: 5px;
|
135
|
+
text-align: center;
|
136
|
+
> i {
|
137
|
+
display: inline-table;
|
138
|
+
width: 5px;
|
139
|
+
height: 5px;
|
140
|
+
margin: 2px;
|
141
|
+
background: white;
|
142
|
+
border-radius: 100%;
|
143
|
+
animation: loading_point;
|
144
|
+
-webkit-animation: loading_point;
|
145
|
+
@include mix_loading_point;
|
146
|
+
&.two {
|
147
|
+
animation: loading_point_two;
|
148
|
+
-webkit-animation: loading_point_two;
|
149
|
+
@include mix_loading_point;
|
150
|
+
}
|
151
|
+
&.three {
|
152
|
+
animation: loading_point_three;
|
153
|
+
-webkit-animation: loading_point_three;
|
154
|
+
@include mix_loading_point;
|
155
|
+
}
|
156
|
+
}
|
157
|
+
}
|
158
|
+
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
table.birt-table {
|
2
|
+
width: 100%;
|
3
|
+
border: 1px solid #ddd;
|
4
|
+
border-radius: 0;
|
5
|
+
border-spacing: 0;
|
6
|
+
margin-bottom: 12px;
|
7
|
+
tr {
|
8
|
+
td, th {
|
9
|
+
border-bottom: 1px solid #ddd;
|
10
|
+
border-right: 1px solid #ddd;
|
11
|
+
padding: 5px 8px;
|
12
|
+
&:last-child {
|
13
|
+
border-right: none;
|
14
|
+
}
|
15
|
+
}
|
16
|
+
&:last-child td {
|
17
|
+
border-bottom: none;
|
18
|
+
}
|
19
|
+
}
|
20
|
+
}
|
data/lib/birt/api.rb
ADDED
@@ -1,17 +1,17 @@
|
|
1
|
-
class Birt::DataSet
|
1
|
+
class Birt::Core::DataSet
|
2
2
|
|
3
3
|
attr_accessor :name
|
4
4
|
attr_accessor :columns
|
5
5
|
attr_accessor :query_text
|
6
|
-
attr_accessor :
|
6
|
+
attr_accessor :data_set_result
|
7
7
|
attr_accessor :data_source
|
8
8
|
|
9
9
|
def initialize(xml_element)
|
10
|
-
|
10
|
+
@columns = []
|
11
11
|
if xml_element
|
12
12
|
self.name = xml_element.attribute(:name).value
|
13
13
|
xml_element.get_elements("list-property[@name='resultSet']/structure/property[@name='name']").each do |column|
|
14
|
-
self.columns
|
14
|
+
self.columns << column.text
|
15
15
|
end
|
16
16
|
self.query_text = xml_element.get_elements("xml-property[@name='queryText']")[0].text.gsub("\n", ' ')
|
17
17
|
end
|
@@ -20,8 +20,12 @@ class Birt::DataSet
|
|
20
20
|
|
21
21
|
#开始查询
|
22
22
|
def query
|
23
|
-
Birt::Mysql.query(self.data_source, query_text)
|
24
|
-
|
25
|
-
|
23
|
+
Birt::Core::Mysql.query(self.data_source, query_text)
|
24
|
+
end
|
25
|
+
|
26
|
+
#查询结果
|
27
|
+
def data_set_result
|
28
|
+
@data_set_result ||= Birt::Core::DataSetResult.new(self.query)
|
26
29
|
end
|
30
|
+
|
27
31
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class Birt::Core::DataSetResult
|
2
|
+
|
3
|
+
attr_accessor :rows
|
4
|
+
attr_accessor :row_headers
|
5
|
+
attr_accessor :columns
|
6
|
+
attr_accessor :column_headers
|
7
|
+
|
8
|
+
def initialize(data_result)
|
9
|
+
@rows, @row_headers, @columns, @column_headers= [], [], [], []
|
10
|
+
|
11
|
+
data_result.each do |row|
|
12
|
+
@column_headers = row.keys.inject([]) { |acc, (k,v)| acc<<k.to_s; acc } if column_headers.empty?
|
13
|
+
@row_headers << row.values[0]
|
14
|
+
@rows << row.values
|
15
|
+
row.values.each_with_index { |v, i| @columns[i]||=[]; @columns[i]<<v; }
|
16
|
+
end if data_result
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class Birt::Core::Property < Birt::Core::BaseReport
|
2
|
+
attr_accessor :name
|
3
|
+
attr_accessor :text
|
4
|
+
|
5
|
+
def initialize(x_ele)
|
6
|
+
|
7
|
+
super(x_ele) do
|
8
|
+
self.name = x_ele.attribute(:name).value
|
9
|
+
self.text = x_ele.text
|
10
|
+
end
|
11
|
+
|
12
|
+
yield(self) if block_given?
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class Birt::Core::TableCellData < Birt::Core::BaseReport
|
2
|
+
|
3
|
+
|
4
|
+
attr_accessor :properties
|
5
|
+
|
6
|
+
def initialize(x_ele)
|
7
|
+
self.properties = Array.new
|
8
|
+
|
9
|
+
super(x_ele) do
|
10
|
+
x_ele.get_elements(xpath="property").each { |tp| self.properties.push Birt::Core::Property.new(tp) }
|
11
|
+
end
|
12
|
+
|
13
|
+
yield(self) if block_given?
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class Birt::Core::TableCellLabel < Birt::Core::BaseReport
|
2
|
+
|
3
|
+
attr_accessor :text_properties
|
4
|
+
|
5
|
+
def initialize(x_ele)
|
6
|
+
self.text_properties = Array.new
|
7
|
+
|
8
|
+
super(x_ele) do
|
9
|
+
x_ele.get_elements(xpath="text-property").each { |tp| self.text_properties.push Birt::Core::TextProperty.new(tp) }
|
10
|
+
end
|
11
|
+
|
12
|
+
yield(self) if block_given?
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class Birt::Core::TableDetail < Birt::Core::BaseReport
|
2
|
+
attr_accessor :rows
|
3
|
+
|
4
|
+
def initialize(x_ele)
|
5
|
+
self.rows = Array.new
|
6
|
+
|
7
|
+
super(x_ele) do
|
8
|
+
x_ele.get_elements(xpath="row").each { |row| self.rows.push Birt::Core::TableRow.new(row) }
|
9
|
+
end
|
10
|
+
|
11
|
+
yield(self) if block_given?
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class Birt::Core::TableFooter< Birt::Core::BaseReport
|
2
|
+
attr_accessor :rows
|
3
|
+
|
4
|
+
def initialize(x_ele)
|
5
|
+
self.rows = Array.new
|
6
|
+
|
7
|
+
super(x_ele) do
|
8
|
+
x_ele.get_elements(xpath="row").each { |row| self.rows.push Birt::Core::TableRow.new(row)}
|
9
|
+
end
|
10
|
+
|
11
|
+
yield(self) if block_given?
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class Birt::Core::TableHeader < Birt::Core::BaseReport
|
2
|
+
|
3
|
+
attr_accessor :rows
|
4
|
+
|
5
|
+
def initialize(x_ele)
|
6
|
+
self.rows = Array.new
|
7
|
+
|
8
|
+
super(x_ele) do
|
9
|
+
x_ele.get_elements(xpath="row").each { |row| self.rows.push Birt::Core::TableRow.new(row)}
|
10
|
+
end
|
11
|
+
|
12
|
+
yield(self) if block_given?
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class Birt::Core::TableReport < Birt::Core::BaseReport
|
2
|
+
attr_accessor :header
|
3
|
+
attr_accessor :detail
|
4
|
+
attr_accessor :footer
|
5
|
+
attr_accessor :data_set
|
6
|
+
|
7
|
+
def initialize(xml_element)
|
8
|
+
|
9
|
+
super(xml_element) do
|
10
|
+
self.header = Birt::Core::TableHeader.new(xml_element.get_elements(xpath="header")[0])
|
11
|
+
self.detail = Birt::Core::TableDetail.new(xml_element.get_elements(xpath="detail")[0])
|
12
|
+
self.footer = Birt::Core::TableDetail.new(xml_element.get_elements(xpath="footer")[0])
|
13
|
+
end
|
14
|
+
|
15
|
+
yield(self) if block_given?
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class Birt::Core::TableRow < Birt::Core::BaseReport
|
2
|
+
|
3
|
+
attr_accessor :row_cells
|
4
|
+
|
5
|
+
def initialize(x_ele)
|
6
|
+
self.row_cells = Array.new
|
7
|
+
|
8
|
+
super(x_ele) do
|
9
|
+
x_ele.get_elements(xpath="cell").each { |cell| self.row_cells.push Birt::Core::TableRowCell.new(cell) }
|
10
|
+
end
|
11
|
+
|
12
|
+
yield(self) if block_given?
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class Birt::Core::TableRowCell < Birt::Core::BaseReport
|
2
|
+
attr_accessor :cell_labels
|
3
|
+
attr_accessor :cell_datas
|
4
|
+
|
5
|
+
def initialize(x_ele)
|
6
|
+
self.cell_labels = Array.new
|
7
|
+
self.cell_datas = Array.new
|
8
|
+
|
9
|
+
super(x_ele) do
|
10
|
+
x_ele.get_elements(xpath="label").each { |label| self.cell_labels.push Birt::Core::TableCellLabel.new(label) }
|
11
|
+
x_ele.get_elements(xpath="data").each { |data| self.cell_datas.push Birt::Core::TableCellData.new(data) }
|
12
|
+
end
|
13
|
+
|
14
|
+
yield(self) if block_given?
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class Birt::Core::TextProperty < Birt::Core::BaseReport
|
2
|
+
attr_accessor :name
|
3
|
+
attr_accessor :text
|
4
|
+
|
5
|
+
def initialize(x_ele)
|
6
|
+
|
7
|
+
super(x_ele) do
|
8
|
+
self.name = x_ele.attribute(:name).value
|
9
|
+
self.text = x_ele.text
|
10
|
+
end
|
11
|
+
|
12
|
+
yield(self) if block_given?
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
class Birt::Core::RptDesign
|
2
|
+
|
3
|
+
#design文件路径
|
4
|
+
attr_accessor :rpt_design_path
|
5
|
+
|
6
|
+
#报表的名字
|
7
|
+
attr_accessor :display_name
|
8
|
+
|
9
|
+
#数据源
|
10
|
+
attr_accessor :data_sources
|
11
|
+
|
12
|
+
#数据集
|
13
|
+
attr_accessor :data_sets
|
14
|
+
|
15
|
+
#图表
|
16
|
+
attr_accessor :reports
|
17
|
+
|
18
|
+
|
19
|
+
def initialize(rpt_design_path)
|
20
|
+
self.rpt_design_path = rpt_design_path
|
21
|
+
@data_sources, @data_sets = {}, {}
|
22
|
+
@reports = {tables: {}}
|
23
|
+
end
|
24
|
+
|
25
|
+
def display_name(root=nil)
|
26
|
+
unless @display_name
|
27
|
+
_root = root|| REXML::Document.new(File.read(self.rpt_design_path)).root
|
28
|
+
names = _root.get_elements("/report/text-property[@name='displayName']")
|
29
|
+
@display_name = names[0].text if names && names[0]
|
30
|
+
end
|
31
|
+
@display_name
|
32
|
+
end
|
33
|
+
|
34
|
+
#解析文件
|
35
|
+
def parse_rpt
|
36
|
+
_root = REXML::Document.new(File.read(self.rpt_design_path)).root
|
37
|
+
|
38
|
+
#报表名称
|
39
|
+
@display_name = self.display_name(_root)
|
40
|
+
|
41
|
+
#数据源
|
42
|
+
_root.each_element(xpath = '/report/data-sources/oda-data-source') do |item|
|
43
|
+
p @data_sources[item.attribute(:name).value] = Birt::Core::DataSource.new(item)
|
44
|
+
end
|
45
|
+
|
46
|
+
#数据集
|
47
|
+
_root.each_element(xpath='/report/data-sets/oda-data-set') do |item|
|
48
|
+
@data_sets[item.attribute(:name).value] = Birt::Core::DataSet.new(item) do |data_set|
|
49
|
+
data_set.data_source = @data_sources[item.get_elements("property[@name='dataSource']")[0].text]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
#报表
|
54
|
+
_root.each_element(xpath='/report/body/table') do |item|
|
55
|
+
@reports[:tables]["#{item.attribute(:id).value}"] = Birt::Core::TableReport.new(item) do |report|
|
56
|
+
report.data_set = @data_sets[item.get_elements("property[@name='dataSet']")[0].text]
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
data/lib/birt/core.rb
ADDED
data/lib/birt/version.rb
CHANGED
data/lib/birt.rb
CHANGED
@@ -4,9 +4,8 @@ require 'base64'
|
|
4
4
|
require 'pry'
|
5
5
|
require 'mysql2'
|
6
6
|
|
7
|
-
Dir.glob("#{File.dirname(__FILE__)}/birt/*.rb") { |f| require f }
|
8
|
-
Dir.glob("#{File.dirname(__FILE__)}/birt/report/*.rb") { |f| require f }
|
7
|
+
Dir.glob("#{File.dirname(__FILE__)}/birt/core/*.rb") { |f| require f }
|
8
|
+
Dir.glob("#{File.dirname(__FILE__)}/birt/core/report/*.rb") { |f| require f }
|
9
9
|
|
10
10
|
module Birt
|
11
|
-
|
12
|
-
end
|
11
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: birt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- saxer
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-08-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -113,11 +113,11 @@ files:
|
|
113
113
|
- app/assets/javascripts/application.js
|
114
114
|
- app/assets/stylesheets/application.css
|
115
115
|
- app/controllers/application_controller.rb
|
116
|
-
- app/controllers/
|
117
|
-
- app/
|
118
|
-
- app/
|
119
|
-
- app/
|
120
|
-
- app/
|
116
|
+
- app/controllers/birt/api_controller.rb
|
117
|
+
- app/controllers/birt_test_controller.rb
|
118
|
+
- app/helpers/birt/api_helper.rb
|
119
|
+
- app/views/birt/api/index.json.jbuilder
|
120
|
+
- app/views/birt_test/index.html.erb
|
121
121
|
- app/views/layouts/application.html.erb
|
122
122
|
- bin/bundle
|
123
123
|
- bin/console
|
@@ -128,14 +128,35 @@ files:
|
|
128
128
|
- birt.gemspec
|
129
129
|
- config.ru
|
130
130
|
- lib/assets/.keep
|
131
|
+
- lib/assets/javascripts/birt.js
|
132
|
+
- lib/assets/javascripts/birt/birt.js
|
133
|
+
- lib/assets/javascripts/birt/components/loading.js
|
134
|
+
- lib/assets/javascripts/birt/utils/string.js
|
135
|
+
- lib/assets/stylesheets/birt.scss
|
136
|
+
- lib/assets/stylesheets/birt/base/constant.scss
|
137
|
+
- lib/assets/stylesheets/birt/base/mixins.scss
|
138
|
+
- lib/assets/stylesheets/birt/components/loading.scss
|
139
|
+
- lib/assets/stylesheets/birt/components/table.scss
|
131
140
|
- lib/birt.rb
|
132
|
-
- lib/birt/
|
133
|
-
- lib/birt/
|
134
|
-
- lib/birt/
|
135
|
-
- lib/birt/
|
136
|
-
- lib/birt/
|
141
|
+
- lib/birt/api.rb
|
142
|
+
- lib/birt/core.rb
|
143
|
+
- lib/birt/core/data_set.rb
|
144
|
+
- lib/birt/core/data_set_result.rb
|
145
|
+
- lib/birt/core/data_source.rb
|
146
|
+
- lib/birt/core/mysql.rb
|
147
|
+
- lib/birt/core/report/base_report.rb
|
148
|
+
- lib/birt/core/report/property.rb
|
149
|
+
- lib/birt/core/report/table_cell_data.rb
|
150
|
+
- lib/birt/core/report/table_cell_label.rb
|
151
|
+
- lib/birt/core/report/table_detail.rb
|
152
|
+
- lib/birt/core/report/table_footer.rb
|
153
|
+
- lib/birt/core/report/table_header.rb
|
154
|
+
- lib/birt/core/report/table_report.rb
|
155
|
+
- lib/birt/core/report/table_row.rb
|
156
|
+
- lib/birt/core/report/table_row_cell.rb
|
157
|
+
- lib/birt/core/report/text_property.rb
|
158
|
+
- lib/birt/core/rpt_design.rb
|
137
159
|
- lib/birt/version.rb
|
138
|
-
- lib/tasks/.keep
|
139
160
|
homepage: https://github.com/mumaoxi/birt
|
140
161
|
licenses:
|
141
162
|
- MIT
|
@@ -158,8 +179,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
158
179
|
version: '0'
|
159
180
|
requirements: []
|
160
181
|
rubyforge_project:
|
161
|
-
rubygems_version: 2.4.
|
182
|
+
rubygems_version: 2.4.6
|
162
183
|
signing_key:
|
163
184
|
specification_version: 4
|
164
|
-
summary:
|
185
|
+
summary: 百灵报表(birt)rails runtime
|
165
186
|
test_files: []
|
File without changes
|
data/app/mailers/.keep
DELETED
File without changes
|
data/app/models/.keep
DELETED
File without changes
|
data/app/models/concerns/.keep
DELETED
File without changes
|
data/lib/birt/rpt_design.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
class Birt::RptDesign
|
2
|
-
|
3
|
-
#design文件路径
|
4
|
-
attr_accessor :rpt_design_path
|
5
|
-
attr_accessor :data_sources
|
6
|
-
attr_accessor :data_sets
|
7
|
-
|
8
|
-
def initialize(rpt_design_path)
|
9
|
-
self.rpt_design_path = rpt_design_path
|
10
|
-
self.data_sources = Hash.new
|
11
|
-
self.data_sets = Hash.new
|
12
|
-
end
|
13
|
-
|
14
|
-
#解析文件
|
15
|
-
def parse_rpt
|
16
|
-
_root = REXML::Document.new(File.read(self.rpt_design_path)).root
|
17
|
-
|
18
|
-
#数据源
|
19
|
-
_root.each_element(xpath = '/report/data-sources/oda-data-source') do |item|
|
20
|
-
self.data_sources[item.attribute(:name).value] = Birt::DataSource.new(item)
|
21
|
-
end
|
22
|
-
|
23
|
-
#数据集
|
24
|
-
_root.each_element(xpath='/report/data-sets/oda-data-set') do |item|
|
25
|
-
self.data_sets[item.attribute(:name).value] = Birt::DataSet.new(item) do |data_set|
|
26
|
-
data_set.data_source = self.data_sources[item.get_elements("property[@name='dataSource']")[0].text]
|
27
|
-
data_set.query
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
p self.data_sources
|
32
|
-
p self.data_sets
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|
data/lib/tasks/.keep
DELETED
File without changes
|