Documentation ¶
Index ¶
- Constants
- Variables
- func AggregateFormSubmissions(context interface{}, db *db.DB, id string, opts submission.SearchOpts) (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, ...) (map[Group][]submission.Submission, 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
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.
Functions ¶
func AggregateFormSubmissions ¶ added in v0.4.4
func AggregateFormSubmissions(context interface{}, db *db.DB, id string, opts submission.SearchOpts) (map[string]Aggregation, error)
AggregateFormSubmissions retrieves the submissions for a form, groups them then runs aggregations and counts for each one.
func Delete ¶
Delete removes the document matching the id provided from the MongoDB database collection.
func GroupSubmissions ¶ added in v0.4.4
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.
Types ¶
type Aggregation ¶ added in v0.4.4
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"` 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 UpdateStatus ¶
UpdateStatus updates the forms status and returns the updated form from the MongodB database collection.
type Group ¶ added in v0.4.4
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 ¶ added in v0.4.4
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 ¶ added in v0.4.4
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.
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 ¶ added in v0.4.4
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 ¶ added in v0.4.4
TextAggregation holds the aggregated text based answers for a single question marked with the Incude in Aggregations tag, orderd by [question_id][answer].
func TextAggregate ¶ added in v0.4.4
func TextAggregate(context interface{}, db *db.DB, formID string, subs []submission.Submission) ([]TextAggregation, error)
TextAggregate returns all text answers flagged with includeInGroup.
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.