NAME
CallBackery::GuiPlugin::AbstractTable - Base Class for a table plugin
SYNOPSIS
use Mojo::Base 'CallBackery::GuiPlugin::AbstractTable';
DESCRIPTION
The base class for table plugins, derived from CallBackery::GuiPlugin::AbstractForm
ATTRIBUTES
The attributes of the CallBackery::GuiPlugin::AbstractForm class and these:
tableCfg
a table configuration
return [
{
label => trm('Id'),
type => 'number',
flex => 1,
key => 'id',
sortable => true,
},
{
label => trm('Date'),
type => 'str',
flex => 2
key => 'date'
},
{
label => trm('Content'),
type => 'str',
flex => 8,
key => 'date'
},
]
METHODS
All the methods of CallBackery::GuiPlugin::AbstractForm plus:
getData ('tableData|tableRowCount',tableDataRequest);
Return the requested table data and pass other types of request on to the upper levels.
getTableData({formData=>{},firstRow=>{},lastRow=>{},sortColumn=>'key',sortDesc=>true})
return data appropriate for the remote table widget
getTableRowCount({formData=>{}})
return the number of rows matching the given formData
_exportColumnPlan($tableCfg,$extraCols)
Merge the extra export columns into the table configuration and return the resulting list of output columns. Each element is either
{ col => $tableCfgEntry }
for a normal data column, or
{ extra => $extraColSpec }
for a generated one. The insertAfter indices of all extra columns refer to the original $tableCfg, so several extra columns cannot shift each other around.
_qrEncoder()
Return a shared Text::QRCode instance, loading the module on first use.
_qrPng($matrix,$moduleSize,$quietZone)
Render a Text::QRCode matrix (rows of * and space) into a 1 bit greyscale PNG and return it as a byte string. $moduleSize is the edge length of one QR module in pixels (default 4) and $quietZone the width of the mandatory light border in modules (default 4).
Writing the PNG by hand keeps this free of any image library.
makeExportAction(type => 'XLSX', filename => 'export-"now"', label => 'Export')
Create export button. The default type is XLSX, also available is CSV.
An XLSX export can carry extra generated columns next to the table data:
$self->makeExportAction(
type => 'XLSX',
extraCols => [
{ type => 'qrCode',
content => 'serial',
insertAfter => 1,
label => trm('QR'),
size => 100,
},
],
);
Every entry adds one column and takes these keys:
- type
-
The kind of column to generate. Only
qrCodeexists so far. It embeds the content as a QR code image. - content
-
Where the content comes from: either the key of a field in the table data, or a code reference which is called with the record hash reference and returns the string to encode. A record whose content is undefined or empty gets no image.
- insertAfter
-
Optional. The zero based index in "tableCfg" the new column is placed after. The indices of all extra columns refer to the original "tableCfg", so several extra columns cannot shift each other around. Without it the column follows the column named by
content, which is therefore mandatory for a code reference content. - label
-
Optional column heading, translated like any other label. It defaults to the heading of the column named by
content. - size
-
Optional edge length of the image in pixels, 100 by default. The row height and the column width are adjusted to fit.
extraCols is ignored for a CSV export, which has nowhere to put an image.
A qrCode column needs Text::QRCode, which is loaded on first use so that installations without QR code exports do not have to carry it.
LICENSE
This program is free software; you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
COPYRIGHT
Copyright (c) 2013 by OETIKER+PARTNER AG. All rights reserved.
AUTHOR
Tobias Oetiker <tobi@oetiker.ch>
HISTORY
2013-12-16 to 1.0 first version