form

package
v0.4.8 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2016 License: Apache-2.0 Imports: 11 Imported by: 0

README

form

import "github.com/coralproject/shelf/internal/ask/form"

Overview

Index

Package files

aggregation.go form.go

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

Documentation

Index

Constants

View Source
const Collection = "forms"

Collection is the mongo collection where Form documents are saved.

Variables

View Source
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

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 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.

func Upsert

func Upsert(context interface{}, db *db.DB, form *Form) error

Upsert upserts the provided form into the MongoDB database collection.

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"`
	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 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 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 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.

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 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

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].

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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