Fix nm printing did not properly wait for column selection or rows before trying to print

This commit is contained in:
nathan 2022-10-06 15:39:35 -06:00
parent d6bfa7d9ee
commit 8221d66ce2
4 changed files with 49 additions and 62 deletions

View File

@ -2853,67 +2853,39 @@ export class et2_nextmatch extends et2_DOMWidget implements et2_IResizeable, et2
const total = this.controller._grid.getTotalCount(); const total = this.controller._grid.getTotalCount();
// Defer the printing to ask about columns & rows // Defer the printing to ask about columns & rows
return new Promise((resolve, reject) => return new Promise(async(resolve, reject) =>
{ {
let pref = this.options.settings.columnselection_pref; let pref = this.options.settings.columnselection_pref;
if (pref.indexOf('nextmatch') == 0) if(pref.indexOf('nextmatch') == 0)
{ {
pref = 'nextmatch-' + pref; pref = 'nextmatch-' + pref;
} }
const app = this.getInstanceManager().app; const app = this.getInstanceManager().app;
const columns = {}; const columns = [];
const columnMgr = this.dataview.getColumnMgr(); const columnMgr = this.dataview.getColumnMgr();
pref += '_print'; pref += '_print';
const columns_selected = []; const columns_selected = [];
// Get column names for(var i = 0; i < columnMgr.columns.length; i++)
for (let i = 0; i < columnMgr.columns.length; i++)
{ {
const col = columnMgr.columns[i]; let col = columnMgr.columns[i];
const widget = this.columns[i].widget; const widget = this.columns[i].widget;
let colName = this._getColumnName(widget); columns.push({...col, widget: widget, name: this._getColumnName(widget)});
if (col.caption && col.visibility !== et2_dataview_column.ET2_COL_VISIBILITY_ALWAYS_NOSELECT &&
col.visibility !== et2_dataview_column.ET2_COL_VISIBILITY_DISABLED)
{
columns[colName] = col.caption;
if (col.visibility === et2_dataview_column.ET2_COL_VISIBILITY_VISIBLE) columns_selected.push(colName);
}
// Custom fields get listed separately
if (widget.instanceOf(et2_nextmatch_customfields))
{
delete (columns[colName]);
colName = widget.id;
if (col.visibility === et2_dataview_column.ET2_COL_VISIBILITY_VISIBLE && !
jQuery.isEmptyObject((<et2_nextmatch_customfields><unknown>widget).customfields)
)
{
columns[colName] = col.caption;
for (let field_name in (<et2_nextmatch_customfields><unknown>widget).customfields)
{
columns[et2_nextmatch_customfields.PREFIX + field_name] = " - " + (<et2_nextmatch_customfields><unknown>widget).customfields[field_name].label;
if (widget.options.fields[field_name] && columns_selected.indexOf(colName) >= 0)
{
columns_selected.push(et2_nextmatch_customfields.PREFIX + field_name);
}
}
}
}
} }
// Preference exists? Set it now // Preference exists? Set it now
if (this.egw().preference(pref, app)) if(this.egw().preference(pref, app))
{ {
this.set_columns(jQuery.extend([], this.egw().preference(pref, app))); this.set_columns(jQuery.extend([], this.egw().preference(pref, app)));
} }
const callback = function (button, value) const callback = function(button, value)
{ {
if (button === Et2Dialog.CANCEL_BUTTON) if(button === Et2Dialog.CANCEL_BUTTON)
{ {
// Give dialog a chance to close, or it will be in the print // Give dialog a chance to close, or it will be in the print
window.setTimeout(function () window.setTimeout(function()
{ {
reject(); reject();
}, 0); }, 0);
@ -2934,7 +2906,7 @@ export class et2_nextmatch extends et2_DOMWidget implements et2_IResizeable, et2
style.media = 'print'; style.media = 'print';
// @ts-ignore // @ts-ignore
if (style.styleSheet) if(style.styleSheet)
{ {
// @ts-ignore // @ts-ignore
style.styleSheet.cssText = css; style.styleSheet.cssText = css;
@ -2951,17 +2923,23 @@ export class et2_nextmatch extends et2_DOMWidget implements et2_IResizeable, et2
this.dynheight.outerNode.css('max-width', this.div.css('max-width')); this.dynheight.outerNode.css('max-width', this.div.css('max-width'));
// Handle columns // Handle columns
this.set_columns(value.columns); let column_names = [];
this.egw().set_preference(app, pref, value.columns); value.columns.forEach((col_id) =>
{
let name = columns.find((col) => col.id == col_id)?.name || ""
column_names.push(name || col_id);
})
this.set_columns(column_names);
this.egw().set_preference(app, pref, column_names);
let rows = parseInt(value.row_count); let rows = parseInt(value.row_count);
if (rows > total) if(rows > total)
{ {
rows = total; rows = total;
} }
// If they want the whole thing, style it as all // If they want the whole thing, style it as all
if (button === Et2Dialog.OK_BUTTON && rows == this.controller._grid.getTotalCount()) if(button === Et2Dialog.OK_BUTTON && rows == this.controller._grid.getTotalCount())
{ {
// Add the class, gives more reliable sizing // Add the class, gives more reliable sizing
this.div.addClass('print'); this.div.addClass('print');
@ -2969,7 +2947,7 @@ export class et2_nextmatch extends et2_DOMWidget implements et2_IResizeable, et2
jQuery('.egwGridView_scrollarea', this.div).css('height', 'auto'); jQuery('.egwGridView_scrollarea', this.div).css('height', 'auto');
} }
// We need more rows // We need more rows
if (button === 'dialog[all]' || rows > loaded_count) if(button === 'dialog[all]' || rows > loaded_count)
{ {
let count = 0; let count = 0;
let fetchedCount = 0; let fetchedCount = 0;
@ -2977,11 +2955,11 @@ export class et2_nextmatch extends et2_DOMWidget implements et2_IResizeable, et2
const nm = this; const nm = this;
const dialog = Et2Dialog.show_dialog( const dialog = Et2Dialog.show_dialog(
// Abort the long task if they canceled the data load // Abort the long task if they canceled the data load
function () function()
{ {
count = total; count = total;
cancel = true; cancel = true;
window.setTimeout(function () window.setTimeout(function()
{ {
reject(); reject();
}, 0); }, 0);
@ -3006,23 +2984,23 @@ export class et2_nextmatch extends et2_DOMWidget implements et2_IResizeable, et2
"count": Math.min(rows, 200), "count": Math.min(rows, 200),
"lastModification": this.controller._lastModification "lastModification": this.controller._lastModification
}; };
if (nm.controller.dataStorePrefix) if(nm.controller.dataStorePrefix)
{ {
// @ts-ignore // @ts-ignore
ctx.prefix = nm.controller.dataStorePrefix; ctx.prefix = nm.controller.dataStorePrefix;
} }
nm.controller.dataFetch({start: count, num_rows: Math.min(rows, 200)}, function (data) nm.controller.dataFetch({start: count, num_rows: Math.min(rows, 200)}, function(data)
{ {
// Keep track // Keep track
if (data && data.order) if(data && data.order)
{ {
fetchedCount += data.order.length; fetchedCount += data.order.length;
} }
nm.controller._fetchCallback.apply(this, arguments); nm.controller._fetchCallback.apply(this, arguments);
if (fetchedCount >= rows) if(fetchedCount >= rows)
{ {
if (cancel) if(cancel)
{ {
dialog.destroy(); dialog.destroy();
reject(); reject();
@ -3039,7 +3017,7 @@ export class et2_nextmatch extends et2_DOMWidget implements et2_IResizeable, et2
jQuery('.egwGridView_scrollarea', this.div).css('height', 'auto'); jQuery('.egwGridView_scrollarea', this.div).css('height', 'auto');
// Grid needs to redraw before it can be printed, so wait // Grid needs to redraw before it can be printed, so wait
window.setTimeout(function () window.setTimeout(function()
{ {
dialog.close(); dialog.close();
@ -3052,7 +3030,7 @@ export class et2_nextmatch extends et2_DOMWidget implements et2_IResizeable, et2
}, ctx); }, ctx);
count += 200; count += 200;
} }
while (count < rows); while(count < rows);
nm.controller._grid.setScrollHeight(nm.controller._grid.getAverageHeight() * (rows + 1)); nm.controller._grid.setScrollHeight(nm.controller._grid.getAverageHeight() * (rows + 1));
} }
else else
@ -3070,23 +3048,28 @@ export class et2_nextmatch extends et2_DOMWidget implements et2_IResizeable, et2
// No scrollbar in print view // No scrollbar in print view
jQuery('.egwGridView_scrollarea', this.div).css('overflow-y', 'hidden'); jQuery('.egwGridView_scrollarea', this.div).css('overflow-y', 'hidden');
// Give dialog a chance to close, or it will be in the print // Give dialog a chance to close, or it will be in the print
window.setTimeout(function () window.setTimeout(function()
{ {
resolve(); resolve();
}, 0); }, 0);
} }
}.bind(this); }.bind(this);
var value = { const value = {
content: { content: {
row_count: Math.min(100, total), row_count: Math.min(100, total),
columns: this.egw().preference(pref, app) || columns_selected, columns: this.egw().preference(pref, app) || columns_selected,
orientation: this.egw().preference(pref + '_orientation', app) orientation: this.egw().preference(pref + '_orientation', app)
}, },
sel_options: { modifications: {
columns: columns autoRefresh: {
disabled: true
},
columns: {
columns: columns,
}
} }
}; };
this._create_print_dialog.call(this, value, callback); await this._create_print_dialog.call(this, value, callback).updateComplete;
}); });
} }
@ -3121,6 +3104,8 @@ export class et2_nextmatch extends et2_DOMWidget implements et2_IResizeable, et2
value: value value: value
}); });
document.body.appendChild(dialog); document.body.appendChild(dialog);
return dialog;
} }
/** /**

View File

@ -1386,7 +1386,7 @@ export class etemplate2
} }
const result = _widget.beforePrint(); const result = _widget.beforePrint();
if(typeof result == "object" && result.done) if(typeof result == "object")
{ {
deferred.push(result); deferred.push(result);
} }

View File

@ -1307,9 +1307,11 @@ window.fw_base = (function(){ "use strict"; return Class.extend(
appWindow.onafterprint = afterPrint; appWindow.onafterprint = afterPrint;
// Wait for everything to be loaded, then send it off // Wait for everything to be loaded, then send it off
jQuery.when.apply(jQuery, deferred).done(function() { Promise.all(deferred).then(() =>
{
appWindow.setTimeout(appWindow.print, 0); appWindow.setTimeout(appWindow.print, 0);
}).fail(function() { }).catch(function ()
{
afterPrint(); afterPrint();
}); });
} }

View File

@ -5,7 +5,7 @@
<template id="nm_print_dialog" template="" lang="" group="0" version="16.1"> <template id="nm_print_dialog" template="" lang="" group="0" version="16.1">
<vbox> <vbox>
<description value="Columns to print"/> <description value="Columns to print"/>
<select id="columns" multiple="true" selected_first="false"/> <et2-nextmatch-columnselection id="columns"></et2-nextmatch-columnselection>
<integer id="row_count" label="How many rows to print"/> <integer id="row_count" label="How many rows to print"/>
<checkbox id="orientation" toggle_on="Portrait" toggle_off="Landscape" selected_value="portrait" unselected_value="landscape"/> <checkbox id="orientation" toggle_on="Portrait" toggle_off="Landscape" selected_value="portrait" unselected_value="landscape"/>
</vbox> </vbox>