func (h *MailHandler) Handle(request shared.IPathRequest) (shared.IResponse, error) { reportName := "" var id uint64 recipientRaw := "" notes := "" err := request.ScanPath(&reportName, &id, &recipientRaw, ¬es) if err != nil { return nil, err } if notes == "-" { notes = "" } report, err := h.Reporter.GetReportHTMLWriter(reportName, id, request.Session()) if err != nil { return nil, err } err = h.Mailer.SendMailFromResponse(report, recipientRaw, notes) if err != nil { return nil, err } return shared.QuickStringResponse("Email sent to " + recipientRaw), nil }
func (r *Reporter) HandleReportRequest(request shared.IPathRequest) (shared.IResponse, error) { var name string var pk uint64 //var fname string err := request.ScanPath(&name, &pk) //, &fname) if err != nil { return nil, err } return r.GetReportHTMLWriter(name, pk, request.Session()) }
func (h *PDFHandler) Handle(request shared.IPathRequest) (shared.IResponse, error) { reportName := "" var id uint64 var fname string err := request.ScanPath(&reportName, &id, &fname) if err != nil { return nil, err } report, err := h.Reporter.GetReportHTMLWriter(reportName, id, request.Session()) if err != nil { return nil, err } pdfResponse := h.PDFer.ResponseAsPDF(report) return pdfResponse, nil }
func (h *CSVHandler) Handle(request shared.IPathRequest) (shared.IResponse, error) { var queryStringQuery string err := request.ScanPath(&queryStringQuery) if err != nil { return nil, err } rawQuery := databath.RawQueryConditions{} jsonQuery, err := url.QueryUnescape(queryStringQuery) if err != nil { return nil, err } log.Printf("Decode CSV Query: %s\n", jsonQuery) err = json.Unmarshal([]byte(jsonQuery), &rawQuery) if err != nil { return nil, err } var neg1 int64 = -1 rawQuery.Limit = &neg1 rawQuery.Offset = nil qc, err := rawQuery.TranslateToQuery() if err != nil { return nil, err } query, err := databath.GetQuery(request.GetContext(), h.Model, qc, false) if err != nil { return nil, err } sqlString, _, parameters, err := query.BuildSelect() if err != nil { return nil, err } db, err := request.DB() if err != nil { return nil, err } rows, err := query.RunQueryWithResults(db, sqlString, parameters) if err != nil { return nil, err } filename := *rawQuery.Collection + "-" + time.Now().Format("2006-01-02") + ".csv" /* fieldset := h.Model.Collections[*rawQuery.Collection].FieldSets[*rawQuery.Fieldset] csvFields := make([]CSVField, len(fieldset), len(fieldset)) for i, fieldDef := range fieldset { csvFields[i] = CSVField{ Title: fieldDef.GetTitle(), SQLCol: fieldDef.GetSQLColName(), } }*/ mappedFields, err := query.GetFields() if err != nil { log.Print(err) request.DoError(err) } allColNames, err := query.GetColNames() if err != nil { log.Print(err) request.DoError(err) } colNames := make([]string, 0, 0) for _, colName := range allColNames { if strings.HasPrefix(colName, "-") { continue } if strings.HasPrefix(colName, "#") { continue } colNames = append(colNames, colName) } resp := &csvResponse{ rows: rows, filename: filename, //fields: csvFields, colNames: colNames, mappedFields: mappedFields, } return resp, nil }