reports

package
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 3, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BootStrap

func BootStrap()

BootStrap check and initialize the reports

func GetAction

func GetAction(reportID string, id int64, additionalData Data) *actions.Action

GetAction returns an action for the report with the given reportID for the record with the given id and optional additionalData.

func Register

func Register(r Report)

Register add the given report to the registry

Types

type Collection

type Collection struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

A Collection is a collection of reports

var Registry *Collection

Registry is the report collection of the application

func NewCollection

func NewCollection() *Collection

NewCollection returns a pointer to a new Collection instance

func (*Collection) Add

func (rr *Collection) Add(r Report)

Add adds the given report to our Collection

func (*Collection) Get

func (rr *Collection) Get(id string) (Report, bool)

Get returns the Report with the given id

func (*Collection) MustGet

func (rr *Collection) MustGet(id string) Report

MustGet returns the Report with the given id. It panics if the record doesn't exist.

func (*Collection) Replace

func (rr *Collection) Replace(r Report)

Replace the given report in our Collection

type Data

type Data map[string]interface{}

Data holds the item specific data used to render a report.

type Document

type Document struct {
	// Content is the binary content of the rendered report
	Content []byte
	// MimeType of the content
	MimeType string
	// Filename for the document
	Filename string
}

A Document is the result of rendering a report

type Report

type Report interface {
	fmt.Stringer
	// ID returns the unique identifying code of this report
	ID() string
	// Model that this report is bound to.
	Model() models.Modeler
	// Render this report.
	Render(id int64, additionalData Data) (*Document, error)
	// Init initializes the report. Init is called at bootstrap.
	Init() error
	// Type returns the type of the record
	Type() string
}

A Report is bound to a model and can render a report given an ID of the model.

A report typically contains: - A template - A rendering mechanism to inject data into the template and provide the output to the user.

type TextReport

type TextReport struct {
	Id       string
	Name     string
	Modeler  models.Modeler
	MimeType string
	Filename string
	Template string
	DataFunc func(int64, Data) Data
}

A TextReport is a simple text or html report.

It uses the html/template package if the report"s mime type is text/html and text/template if the mimetype is text/plain.

func (*TextReport) ID

func (r *TextReport) ID() string

ID returns the unique identifying code of this report

func (*TextReport) Init

func (r *TextReport) Init() error

Init initializes the report. Init is called at bootstrap.

func (*TextReport) Model

func (r *TextReport) Model() models.Modeler

Model returns the name of the model that this report is bound to.

func (*TextReport) Render

func (r *TextReport) Render(id int64, additionalData Data) (*Document, error)

Render this report. Returns the rendered report, the report mimetype,the report filename and an error.

func (*TextReport) String

func (r *TextReport) String() string

func (*TextReport) Type

func (r *TextReport) Type() string

Type of the report: TextReport

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL