Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add total hours to reports #804

Merged
merged 1 commit into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 54 additions & 42 deletions web/js/include/ExportableGridPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,33 @@
* @param columnModel with column data.
* @return string in CSV format.
*/
function fromStoreToCSV(store, columnModel) {
var csv = "";
function fromStoreToCSV(store, columnModel, totalRow = null) {
var csv = '';

var columns = columnModel.getColumnsBy(function (c) {
return !c.hidden;
});
var columns = columnModel.getColumnsBy(function (c) {
return !c.hidden;
});

// header with column names
Ext.each(columns, function(column) {
csv += column.header + ",";
});
csv += "\n";
// header with column names
Ext.each(columns, function (column) {
csv += column.header + ',';
});
csv += '\n';

// data
store.each(function (record) {
Ext.each(columns, function(column) {
var item = store.fields.get(column.dataIndex);
csv += record.data[item.name] + ",";
});
csv += "\n";
// data
store.each(function (record) {
Ext.each(columns, function (column) {
var item = store.fields.get(column.dataIndex);
csv += record.data[item.name] + ',';
});
csv += '\n';
});

if (totalRow) {
csv += `\n\n ${totalRow}`;
}

return csv;
return csv;
}

/**
Expand All @@ -56,29 +60,37 @@ function fromStoreToCSV(store, columnModel) {
* @extends Ext.GridPanel
*/
Ext.ux.ExportableGridPanel = Ext.extend(Ext.grid.GridPanel, {
initComponent: function () {
Ext.apply(this, {
bbar: [
{
xtype: 'button',
text: 'Download as CSV',
handler: function () {
//FIXME there must be a better way to get the grid
var gridComponent = this.ownerCt.ownerCt;
const linkSource = `data:text/csv;charset=UTF-8,${encodeURIComponent(
fromStoreToCSV(
gridComponent.getStore(),
gridComponent.getColumnModel(),
gridComponent.footer.dom.innerHTML
)
)}`;
const downloadLink = document.createElement('a');
downloadLink.href = linkSource;
downloadLink.download = `${this.ownerCt.ownerCt.title.replace(/ /g, '')}.csv`;
downloadLink.click();
}
}
],
footerCfg: {
tag: 'span',
cls: 'exportable-footer x-toolbar x-small-editor x-toolbar-layout-ct',
html: ''
}
});

initComponent: function () {
Ext.apply(this, {
bbar: [
{
xtype: 'button',
text: 'Download as CSV',
handler: function () {
//FIXME there must be a better way to get the grid
var gridComponent = this.ownerCt.ownerCt;
const linkSource = `data:text/csv;charset=UTF-8,${encodeURIComponent(
fromStoreToCSV(gridComponent.getStore(), gridComponent.getColumnModel()))}`;
const downloadLink = document.createElement("a");
downloadLink.href = linkSource;
downloadLink.download = `${this.ownerCt.ownerCt.title.replace(/ /g, '')}.csv`;
downloadLink.click();
}
},
],
});

/* call the superclass to preserve base class functionality */
Ext.ux.ExportableGridPanel.superclass.initComponent.apply(this, arguments);
},

/* call the superclass to preserve base class functionality */
Ext.ux.ExportableGridPanel.superclass.initComponent.apply(this, arguments);
}
});
Loading
Loading