[QueryReport] Column titles in CSV Export (#5216)
This commit is contained in:
parent
5e8ff63942
commit
625083d664
2 changed files with 111 additions and 37 deletions
|
|
@ -221,8 +221,8 @@ frappe.views.QueryReport = class QueryReport extends frappe.views.BaseList {
|
|||
this.toggle_message(false);
|
||||
|
||||
if (data.result && data.result.length) {
|
||||
this.render_chart(r.message);
|
||||
this.render_report(r.message);
|
||||
this.render_chart(data);
|
||||
this.render_report(data);
|
||||
} else {
|
||||
this.toggle_nothing_to_show(true);
|
||||
}
|
||||
|
|
@ -231,21 +231,21 @@ frappe.views.QueryReport = class QueryReport extends frappe.views.BaseList {
|
|||
|
||||
render_report(data) {
|
||||
this._data = data.result;
|
||||
this._columns = data.columns;
|
||||
this.is_tree_report = data.result.some(d => 'indent' in d);
|
||||
this._columns = this.prepare_columns(data.columns);
|
||||
this.is_tree_report = this._data.some(d => 'indent' in d);
|
||||
|
||||
const columns = this.prepare_columns(this._columns);
|
||||
const columns = this.get_columns_for_datatable();
|
||||
|
||||
if (this.datatable) {
|
||||
this.datatable.refresh(data.result, columns);
|
||||
this.datatable.refresh(this._data, columns);
|
||||
return;
|
||||
}
|
||||
|
||||
this.datatable = new DataTable(this.$report[0], {
|
||||
columns: columns,
|
||||
data: data.result,
|
||||
enableInlineFilters: true,
|
||||
enableTreeView: this.is_tree_report,
|
||||
data: this._data,
|
||||
inlineFilters: true,
|
||||
treeView: this.is_tree_report,
|
||||
layout: 'fixed',
|
||||
events: {
|
||||
onRemoveColumn: () => this.save_user_settings(),
|
||||
|
|
@ -288,7 +288,7 @@ frappe.views.QueryReport = class QueryReport extends frappe.views.BaseList {
|
|||
}
|
||||
|
||||
prepare_columns(columns) {
|
||||
const docfields = columns.map(column => {
|
||||
return columns.map(column => {
|
||||
if (typeof column === 'string') {
|
||||
if (column.includes(':')) {
|
||||
let [label, fieldtype, width] = column.split(':');
|
||||
|
|
@ -300,6 +300,7 @@ frappe.views.QueryReport = class QueryReport extends frappe.views.BaseList {
|
|||
|
||||
return {
|
||||
label,
|
||||
fieldname: label,
|
||||
fieldtype,
|
||||
width,
|
||||
options
|
||||
|
|
@ -308,17 +309,20 @@ frappe.views.QueryReport = class QueryReport extends frappe.views.BaseList {
|
|||
|
||||
return {
|
||||
label: column,
|
||||
fieldname: column,
|
||||
fieldtype: 'Data'
|
||||
};
|
||||
}
|
||||
|
||||
return column;
|
||||
});
|
||||
}
|
||||
|
||||
columns = docfields.map(df => {
|
||||
get_columns_for_datatable() {
|
||||
const columns = this._columns.map(df => {
|
||||
return {
|
||||
id: df.fieldname || df.label,
|
||||
content: df.label,
|
||||
id: df.fieldname,
|
||||
name: df.label,
|
||||
width: df.width || null,
|
||||
editable: false,
|
||||
format: (value, row, column, data) =>
|
||||
|
|
@ -327,17 +331,15 @@ frappe.views.QueryReport = class QueryReport extends frappe.views.BaseList {
|
|||
};
|
||||
});
|
||||
|
||||
if (this.user_settings.column_order && this.user_settings.column_order.length > 0) {
|
||||
return this.user_settings.column_order
|
||||
.map(id => columns.find(col => col.id === id))
|
||||
.filter(Boolean);
|
||||
} else {
|
||||
return columns;
|
||||
}
|
||||
}
|
||||
|
||||
get_data() {
|
||||
return columns;
|
||||
|
||||
// if (this.user_settings.column_order && this.user_settings.column_order.length > 0) {
|
||||
// return this.user_settings.column_order
|
||||
// .map(id => columns.find(col => col.id === id))
|
||||
// .filter(Boolean);
|
||||
// } else {
|
||||
// return columns;
|
||||
// }
|
||||
}
|
||||
|
||||
get_filter_values(raise) {
|
||||
|
|
@ -453,7 +455,11 @@ frappe.views.QueryReport = class QueryReport extends frappe.views.BaseList {
|
|||
reqd: 1
|
||||
}, ({ file_format }) => {
|
||||
if (file_format === 'CSV') {
|
||||
frappe.tools.downloadify(this.get_data_for_print(), null, this.report_name);
|
||||
const column_row = this._columns.map(col => col.label);
|
||||
const data = this.get_data_for_print();
|
||||
const out = [column_row].concat(data);
|
||||
|
||||
frappe.tools.downloadify(out, null, this.report_name);
|
||||
} else {
|
||||
const filters = this.get_filter_values(true);
|
||||
|
||||
|
|
@ -472,7 +478,13 @@ frappe.views.QueryReport = class QueryReport extends frappe.views.BaseList {
|
|||
|
||||
get_data_for_print() {
|
||||
const indices = this.datatable.datamanager.getFilteredRowIndices();
|
||||
return indices.map(i => this._data[i]);
|
||||
return indices.map(i => {
|
||||
const d = this._data[i];
|
||||
if (d === null || d === undefined) {
|
||||
return '';
|
||||
}
|
||||
return d;
|
||||
});
|
||||
}
|
||||
|
||||
get_columns_for_print() {
|
||||
|
|
|
|||
86
yarn.lock
86
yarn.lock
|
|
@ -246,6 +246,12 @@ chalk@^2.3.2:
|
|||
escape-string-regexp "^1.0.5"
|
||||
supports-color "^5.3.0"
|
||||
|
||||
cli@0.4.3:
|
||||
version "0.4.3"
|
||||
resolved "https://registry.yarnpkg.com/cli/-/cli-0.4.3.tgz#e6819c8d5faa957f64f98f66a8506268c1d1f17d"
|
||||
dependencies:
|
||||
glob ">= 3.1.4"
|
||||
|
||||
cliui@^4.0.0:
|
||||
version "4.0.0"
|
||||
resolved "https://registry.yarnpkg.com/cliui/-/cliui-4.0.0.tgz#743d4650e05f36d1ed2575b59638d87322bfbbcc"
|
||||
|
|
@ -276,6 +282,10 @@ color-name@^1.1.1:
|
|||
version "1.1.3"
|
||||
resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.3.tgz#a7d0558bd89c42f795dd42328f740831ca53bc25"
|
||||
|
||||
colors@>=0.6.x:
|
||||
version "1.2.1"
|
||||
resolved "https://registry.yarnpkg.com/colors/-/colors-1.2.1.tgz#f4a3d302976aaf042356ba1ade3b1a2c62d9d794"
|
||||
|
||||
combined-stream@1.0.6, combined-stream@^1.0.5, combined-stream@~1.0.5:
|
||||
version "1.0.6"
|
||||
resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.6.tgz#723e7df6e801ac5613113a7e445a9b69cb632818"
|
||||
|
|
@ -286,6 +296,10 @@ commander@~2.14.1:
|
|||
version "2.14.1"
|
||||
resolved "https://registry.yarnpkg.com/commander/-/commander-2.14.1.tgz#2235123e37af8ca3c65df45b026dbd357b01b9aa"
|
||||
|
||||
commander@~2.15.0:
|
||||
version "2.15.0"
|
||||
resolved "https://registry.yarnpkg.com/commander/-/commander-2.15.0.tgz#ad2a23a1c3b036e392469b8012cec6b33b4c1322"
|
||||
|
||||
component-bind@1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/component-bind/-/component-bind-1.0.0.tgz#00c608ab7dcd93897c0009651b1d3a8e1e73bbd1"
|
||||
|
|
@ -626,9 +640,10 @@ forwarded@~0.1.2:
|
|||
|
||||
frappe-datatable@frappe/datatable:
|
||||
version "0.0.2"
|
||||
resolved "https://codeload.github.com/frappe/datatable/tar.gz/b3f281b2146085226ec6741ce30cb9c6cbd6b00c"
|
||||
resolved "https://codeload.github.com/frappe/datatable/tar.gz/98b0359f08fc340be7c7f39dbf622de72e27589d"
|
||||
dependencies:
|
||||
clusterize.js "^0.18.0"
|
||||
lodash "^4.17.5"
|
||||
sortablejs "^1.7.0"
|
||||
|
||||
frappe-gantt@^0.1.0:
|
||||
|
|
@ -661,6 +676,16 @@ fuse.js@^3.2.0:
|
|||
version "3.2.0"
|
||||
resolved "https://registry.yarnpkg.com/fuse.js/-/fuse.js-3.2.0.tgz#f0448e8069855bf2a3e683cdc1d320e7e2a07ef4"
|
||||
|
||||
fuse@^0.4.0:
|
||||
version "0.4.0"
|
||||
resolved "https://registry.yarnpkg.com/fuse/-/fuse-0.4.0.tgz#2c38eaf888abb0a9ba7960cfe3339d1f3f53f6e6"
|
||||
dependencies:
|
||||
colors ">=0.6.x"
|
||||
jshint "0.9.x"
|
||||
optimist ">=0.3.5"
|
||||
uglify-js ">=2.2.x"
|
||||
underscore ">=1.4.x"
|
||||
|
||||
get-caller-file@^1.0.1:
|
||||
version "1.0.2"
|
||||
resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-1.0.2.tgz#f702e63127e7e231c160a80c1554acb70d5047e5"
|
||||
|
|
@ -688,7 +713,7 @@ glob-parent@^2.0.0:
|
|||
dependencies:
|
||||
is-glob "^2.0.0"
|
||||
|
||||
glob@^7.0.5:
|
||||
"glob@>= 3.1.4", glob@^7.0.5:
|
||||
version "7.1.2"
|
||||
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.2.tgz#c19c9df9a028702d678612384a6552404c636d15"
|
||||
dependencies:
|
||||
|
|
@ -925,6 +950,13 @@ jsbn@~0.1.0:
|
|||
version "0.1.1"
|
||||
resolved "https://registry.yarnpkg.com/jsbn/-/jsbn-0.1.1.tgz#a5e654c2e5a2deb5f201d96cefbca80c0ef2f513"
|
||||
|
||||
jshint@0.9.x:
|
||||
version "0.9.1"
|
||||
resolved "https://registry.yarnpkg.com/jshint/-/jshint-0.9.1.tgz#ff32ec7f09f84001f7498eeafd63c9e4fbb2dc0e"
|
||||
dependencies:
|
||||
cli "0.4.3"
|
||||
minimatch "0.0.x"
|
||||
|
||||
json-schema@0.2.3:
|
||||
version "0.2.3"
|
||||
resolved "https://registry.yarnpkg.com/json-schema/-/json-schema-0.2.3.tgz#b480c892e59a2f05954ce727bd3f2a4e882f9e13"
|
||||
|
|
@ -1008,6 +1040,10 @@ locate-path@^2.0.0:
|
|||
p-locate "^2.0.0"
|
||||
path-exists "^3.0.0"
|
||||
|
||||
lodash@^4.17.5:
|
||||
version "4.17.5"
|
||||
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.5.tgz#99a92d65c0272debe8c96b6057bc8fbfa3bed511"
|
||||
|
||||
lru-cache@^4.0.1:
|
||||
version "4.1.1"
|
||||
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-4.1.1.tgz#622e32e82488b49279114a4f9ecf45e7cd6bba55"
|
||||
|
|
@ -1015,6 +1051,10 @@ lru-cache@^4.0.1:
|
|||
pseudomap "^1.0.2"
|
||||
yallist "^2.1.2"
|
||||
|
||||
lru-cache@~1.0.2:
|
||||
version "1.0.6"
|
||||
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-1.0.6.tgz#aa50f97047422ac72543bda177a9c9d018d98452"
|
||||
|
||||
magic-string@^0.22.4:
|
||||
version "0.22.4"
|
||||
resolved "https://registry.yarnpkg.com/magic-string/-/magic-string-0.22.4.tgz#31039b4e40366395618c1d6cf8193c53917475ff"
|
||||
|
|
@ -1103,6 +1143,12 @@ mimic-fn@^1.0.0:
|
|||
version "1.2.0"
|
||||
resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-1.2.0.tgz#820c86a39334640e99516928bd03fca88057d022"
|
||||
|
||||
minimatch@0.0.x:
|
||||
version "0.0.5"
|
||||
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-0.0.5.tgz#96bb490bbd3ba6836bbfac111adf75301b1584de"
|
||||
dependencies:
|
||||
lru-cache "~1.0.2"
|
||||
|
||||
minimatch@^3.0.2, minimatch@^3.0.4:
|
||||
version "3.0.4"
|
||||
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083"
|
||||
|
|
@ -1117,6 +1163,10 @@ minimist@^1.2.0:
|
|||
version "1.2.0"
|
||||
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.0.tgz#a35008b20f41383eec1fb914f4cd5df79a264284"
|
||||
|
||||
minimist@~0.0.1:
|
||||
version "0.0.10"
|
||||
resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.10.tgz#de3f98543dbf96082be48ad1a0c7cda836301dcf"
|
||||
|
||||
mkdirp@^0.5.0:
|
||||
version "0.5.1"
|
||||
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903"
|
||||
|
|
@ -1184,6 +1234,13 @@ once@^1.3.0:
|
|||
dependencies:
|
||||
wrappy "1"
|
||||
|
||||
optimist@>=0.3.5:
|
||||
version "0.6.1"
|
||||
resolved "https://registry.yarnpkg.com/optimist/-/optimist-0.6.1.tgz#da3ea74686fa21a19a111c326e90eb15a0196686"
|
||||
dependencies:
|
||||
minimist "~0.0.1"
|
||||
wordwrap "~0.0.2"
|
||||
|
||||
os-homedir@^1.0.1:
|
||||
version "1.0.2"
|
||||
resolved "https://registry.yarnpkg.com/os-homedir/-/os-homedir-1.0.2.tgz#ffbc4988336e0e833de0c168c7ef152121aa7fb3"
|
||||
|
|
@ -1434,12 +1491,6 @@ rimraf@^2.2.8:
|
|||
dependencies:
|
||||
glob "^7.0.5"
|
||||
|
||||
rollup-plugin-alias@^1.4.0:
|
||||
version "1.4.0"
|
||||
resolved "https://registry.yarnpkg.com/rollup-plugin-alias/-/rollup-plugin-alias-1.4.0.tgz#120cba7c46621c03138f0ca6fd5dd2ade9872db9"
|
||||
dependencies:
|
||||
slash "^1.0.0"
|
||||
|
||||
rollup-plugin-buble@^0.19.2:
|
||||
version "0.19.2"
|
||||
resolved "https://registry.yarnpkg.com/rollup-plugin-buble/-/rollup-plugin-buble-0.19.2.tgz#c0590c7d3d475b5ed59f129764ec93710cc6e8dd"
|
||||
|
|
@ -1579,10 +1630,6 @@ signal-exit@^3.0.0:
|
|||
version "3.0.2"
|
||||
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d"
|
||||
|
||||
slash@^1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/slash/-/slash-1.0.0.tgz#c41f2f6c39fc16d1cd17ad4b5d896114ae470d55"
|
||||
|
||||
sntp@1.x.x:
|
||||
version "1.0.9"
|
||||
resolved "https://registry.yarnpkg.com/sntp/-/sntp-1.0.9.tgz#6541184cc90aeea6c6e7b35e2659082443c66198"
|
||||
|
|
@ -1780,10 +1827,21 @@ uglify-es@^3.3.7:
|
|||
commander "~2.14.1"
|
||||
source-map "~0.6.1"
|
||||
|
||||
uglify-js@>=2.2.x:
|
||||
version "3.3.15"
|
||||
resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.3.15.tgz#5b8783b6856110d3a03a9b81e07324a3b925f2dd"
|
||||
dependencies:
|
||||
commander "~2.15.0"
|
||||
source-map "~0.6.1"
|
||||
|
||||
ultron@~1.1.0:
|
||||
version "1.1.1"
|
||||
resolved "https://registry.yarnpkg.com/ultron/-/ultron-1.1.1.tgz#9fe1536a10a664a65266a1e3ccf85fd36302bc9c"
|
||||
|
||||
underscore@>=1.4.x:
|
||||
version "1.8.3"
|
||||
resolved "https://registry.yarnpkg.com/underscore/-/underscore-1.8.3.tgz#4f3fb53b106e6097fcf9cb4109f2a5e9bdfa5022"
|
||||
|
||||
unpipe@1.0.0, unpipe@~1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/unpipe/-/unpipe-1.0.0.tgz#b2bf4ee8514aae6165b4817829d21b2ef49904ec"
|
||||
|
|
@ -1834,6 +1892,10 @@ which@^1.2.12, which@^1.2.9:
|
|||
dependencies:
|
||||
isexe "^2.0.0"
|
||||
|
||||
wordwrap@~0.0.2:
|
||||
version "0.0.3"
|
||||
resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-0.0.3.tgz#a3d5da6cd5c0bc0008d37234bbaf1bed63059107"
|
||||
|
||||
wrap-ansi@^2.0.0:
|
||||
version "2.1.0"
|
||||
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-2.1.0.tgz#d8fc3d284dd05794fe84973caecdd1cf824fdd85"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue