# README
form
import "github.com/coralproject/shelf/internal/ask/form"
Overview
Index
- Constants
- Variables
- func AggregateFormSubmissions(context interface{}, db *db.DB, id string) (map[string]Aggregation, error)
- func Delete(context interface{}, db *db.DB, id string) error
- func GroupSubmissions(context interface{}, db *db.DB, formID string, limit int, skip int, opts submission.SearchOpts) (map[Group][]submission.Submission, error)
- func List(context interface{}, db *db.DB, limit, skip int) ([]Form, error)
- func TextAggregate(context interface{}, db *db.DB, formID string, subs []submission.Submission) ([]TextAggregation, error)
- func Upsert(context interface{}, db *db.DB, form *Form) error
- type Aggregation
- type Form
- type Group
- type MCAggregation
- type MCAnswerAggregation
- type Stats
- type Step
- type SubmissionGroup
- type TextAggregation
- type Widget
Package files
Constants
const Collection = "forms"
Collection is the mongo collection where Form documents are saved.
Variables
var ErrInvalidID = errors.New("ID is not in it's proper form")
ErrInvalidID occurs when an ID is not in a valid form.
func AggregateFormSubmissions
func AggregateFormSubmissions(context interface{}, db *db.DB, id string) (map[string]Aggregation, error)
AggregateFormSubmissions retrieves the submissions for a form, groups them then runs aggregations and counts for each one.
func Delete
func Delete(context interface{}, db *db.DB, id string) error
Delete removes the document matching the id provided from the MongoDB database collection.
func GroupSubmissions
func GroupSubmissions(context interface{}, db *db.DB, formID string, limit int, skip int, opts submission.SearchOpts) (map[Group][]submission.Submission, error)
GroupSubmissions organizes submissions by Group. It looks for questions with the group by flag and creates Group structs.
func List
func List(context interface{}, db *db.DB, limit, skip int) ([]Form, error)
List retrieves a list of forms from the MongodB database collection.
func TextAggregate
func TextAggregate(context interface{}, db *db.DB, formID string, subs []submission.Submission) ([]TextAggregation, error)
TextAggregate returns all text answers flagged with includeInGroup.
func Upsert
func Upsert(context interface{}, db *db.DB, form *Form) error
Upsert upserts the provided form into the MongoDB database collection.
type Aggregation
type Aggregation struct {
Group Group `json:"group" bson:"group"`
Count int `json:"count" bson:"count"`
MC map[string]MCAggregation `json:"MultipleChoice" bson:"MultipleChoice"` // Capitalization matches widget type MultipleChoice
}
Aggregation holds the various aggregations and stats collected.
type Form
type Form struct {
ID bson.ObjectId `json:"id" bson:"_id" validate:"required"`
Status string `json:"status" bson:"status"`
Theme interface{} `json:"theme" bson:"theme"`
Settings map[string]interface{} `json:"settings" bson:"settings"`
Header interface{} `json:"header" bson:"header"`
Footer interface{} `json:"footer" bson:"footer"`
FinishedScreen interface{} `json:"finishedScreen" bson:"finishedScreen"`
Steps []Step `json:"steps" bson:"steps"`
Stats Stats `json:"stats" bson:"stats"`
CreatedBy interface{} `json:"created_by" bson:"created_by"`
UpdatedBy interface{} `json:"updated_by" bson:"updated_by"`
DeletedBy interface{} `json:"deleted_by" bson:"deleted_by"`
DateCreated time.Time `json:"date_created,omitempty" bson:"date_created,omitempty"`
DateUpdated time.Time `json:"date_updated,omitempty" bson:"date_updated,omitempty"`
DateDeleted time.Time `json:"date_deleted,omitempty" bson:"date_deleted,omitempty"`
}
Form contains the conatical representation of a Form, containing all the Steps, and help text relating to completing the Form.
func Retrieve
func Retrieve(context interface{}, db *db.DB, id string) (*Form, error)
Retrieve retrieves the form from the MongodB database collection.
func UpdateStatus
func UpdateStatus(context interface{}, db *db.DB, id, status string) (*Form, error)
UpdateStatus updates the forms status and returns the updated form from the MongodB database collection.
func (*Form) Validate
func (f *Form) Validate() error
Validate checks the Form value for consistency.
type Group
type Group struct {
ID string `json:"group_id" bson:"group_id"`
Question string `json:"question" bson:"question"`
Answer string `json:"answer" bson:"answer"`
}
Group defines a key for a multiple choice question / answer combo to be used to define slices of submissions to be aggregated.
type MCAggregation
type MCAggregation struct {
Question string `json:"question" bson:"question"`
MCAnswers map[string]MCAnswerAggregation `json:"answers" bson:"answers"`
}
MCAggregation holds a multiple choice question and a map aggregated counts for each answer. The Answers map is keyed off an md5 of the answer as not better keys exist
type MCAnswerAggregation
type MCAnswerAggregation struct {
Title string `json:"answer" bson:"answer"`
Count int `json:"count" bson:"count"`
}
MCAnswerAggregation holds the count for selections of a single multiple choice answer.
type Stats
type Stats struct {
Responses int `json:"responses" bson:"responses"`
}
Stats describes the statistics being recorded by a specific Form.
func UpdateStats
func UpdateStats(context interface{}, db *db.DB, id string) (*Stats, error)
UpdateStats updates the Stats on a given Form.
type Step
type Step struct {
ID string `json:"id" bson:"_id"`
Name string `json:"name" bson:"name"`
Widgets []Widget `json:"widgets" bson:"widgets"`
}
Step is a collection of Widget's.
type SubmissionGroup
type SubmissionGroup struct {
Submissions map[Group][]submission.Submission `json:"submissions" bson:"submissions"`
}
SubmissionGroup is a transport that defines the transport structure for a submission group.
type TextAggregation
type TextAggregation map[string]string
TextAggregation holds the aggregated text based answers for a single question marked with the Incude in Aggregations tag, orderd by [question_id][answer].
type Widget
type Widget struct {
ID string `json:"id" bson:"_id"`
Type string `json:"type" bson:"type"`
Identity bool `json:"identity" bson:"identity"`
Component string `json:"component" bson:"component"`
Title string `json:"title" bson:"title"`
Description string `json:"description" bson:"description"`
Wrapper interface{} `json:"wrapper" bson:"wrapper"`
Props interface{} `json:"props" bson:"props"`
}
Widget describes a specific question being asked by the Form which is contained within a Step.
Generated by godoc2md