func (m *Basic) Action(card *model.Card, face *int, startTime time.Time, payload interface{}) (bool, error) {
	query := convertQuery(payload)
	log.Debugf("Submit recieved for face %d: %v\n", *face, query)
	button := studyview.Button(query.Submit)
	log.Debugf("Button %s pressed\n", button)
	switch *face {
	case QuestionFace:
		// Any input is fine; the only options are the right button, or 'ENTER' in a text field.
	case AnswerFace:
		key := buttonsKey(card, *face)
		if _, valid := buttonMaps[key][button]; !valid {
			return false, errors.Errorf("Unexpected button press %s", button)
		}
	default:
		return false, errors.Errorf("Unexpected face %d", *face)
	}
	switch *face {
	case QuestionFace:
		*face++
		typedAnswers := query.TypedAnswers
		if len(typedAnswers) > 0 {
			results := make(map[string]answer)
			for _, fieldName := range card.Fields() {
				if typedAnswer, ok := typedAnswers[fieldName]; ok {
					fv := card.FieldValue(fieldName)
					if fv == nil {
						panic("No field value for field")
					}
					correct, d := diff.Diff(fv.Text, typedAnswer)
					results[fieldName] = answer{
						Text:    d,
						Correct: correct,
					}
				}
			}
			card.Context = map[string]interface{}{
				contextKeyTypedAnswers: results,
			}
			return false, nil
		}
		return false, nil
	case AnswerFace:
		log.Debugf("Old schedule: Due %s, Interval: %s, Ease: %f, ReviewCount: %d\n", card.Due, card.Interval, card.EaseFactor, card.ReviewCount)
		if err := model.Schedule(card, time.Now().Sub(startTime), quality(button)); err != nil {
			return false, err
		}
		log.Debugf("New schedule: Due %s, Interval: %s, Ease: %f, ReviewCount: %d\n", card.Due, card.Interval, card.EaseFactor, card.ReviewCount)
		card.Context = nil // Clear any saved answers
		return true, nil
	}
	log.Printf("Unexpected face/button combo: %d / %+v\n", *face, button)
	return false, nil
}
// Action responds to a card action, such as a button press
Action responds to a card action, such as a button press
// Action responds to a card action such as a button press
func (m *Basic) Action(card *model.Card, face *int, startTime time.Time, payload interface{}) (bool, error) {
	query := convertQuery(payload)
	log.Debugf("Submit recieved for face %d: %v\n", *face, query)
	button := studyview.Button(query.Submit)
	log.Debugf("Button %s pressed\n", button)
	switch *face {
	case QuestionFace:
	case AnswerFace:
		key := buttonsKey(card, *face)
		if _, valid := buttonMaps[key][button]; !valid {
			return false, errors.Errorf("Unexpected button press %s", button)
		}
	default:
		return false, errors.Errorf("Unexpected face %d", *face)
	}
	switch *face {
	case QuestionFace:
		*face++
		typedAnswers := query.TypedAnswers
		if len(typedAnswers) > 0 {
			results := make(map[string]answer)
			for _, fieldName := range card.Fields() {
				if typedAnswer, ok := typedAnswers[fieldName]; ok {
					fv := card.FieldValue(fieldName)
					if fv == nil {
						panic("No field value for field")
					}
					correct, d := diff.Diff(fv.Text, typedAnswer)
					results[fieldName] = answer{
						Text:    d,
						Correct: correct,
					}
				}
			}
			card.Context = map[string]interface{}{
				contextKeyTypedAnswers: results,
			}
			return false, nil
		}
		return false, nil
	case AnswerFace:
		log.Debugf("Old schedule: Due %s, Interval: %s, Ease: %f, ReviewCount: %d\n", card.Due, card.Interval, card.EaseFactor, card.ReviewCount)
		if err := model.Schedule(card, time.Now().Sub(startTime), quality(button)); err != nil {
			return false, err
		}
		log.Debugf("New schedule: Due %s, Interval: %s, Ease: %f, ReviewCount: %d\n", card.Due, card.Interval, card.EaseFactor, card.ReviewCount)
		card.Context = nil 
		return true, nil
	}
	log.Printf("Unexpected face/button combo: %d / %+v\n", *face, button)
	return false, nil
}
func ( m * Basic ) Action ( card * model . Card , face * int , startTime time . Time , payload interface { } ) ( bool , error ) { query := convertQuery ( payload ) log . Debugf ( " \n " , * face , query ) button := studyview . Button ( query . Submit ) log . Debugf ( " \n " , button ) switch * face { case QuestionFace : case AnswerFace : key := buttonsKey ( card , * face ) if _ , valid := buttonMaps [ key ] [ button ] ; ! valid { return false , errors . Errorf ( " " , button ) } default : return false , errors . Errorf ( " " , * face ) } switch * face { case QuestionFace : * face ++ typedAnswers := query . TypedAnswers if len ( typedAnswers ) > 0 { results := make ( map [ string ] answer ) for _ , fieldName := range card . Fields ( ) { if typedAnswer , ok := typedAnswers [ fieldName ] ; ok { fv := card . FieldValue ( fieldName ) if fv == nil { panic ( " " ) } correct , d := diff . Diff ( fv . Text , typedAnswer ) results [ fieldName ] = answer { Text : d , Correct : correct , } } } card . Context = map [ string ] interface { } { contextKeyTypedAnswers : results , } return false , nil } return false , nil case AnswerFace : log . Debugf ( " \n " , card . Due , card . Interval , card . EaseFactor , card . ReviewCount ) if err := model . Schedule ( card , time . Now ( ) . Sub ( startTime ) , quality ( button ) ) ; err != nil { return false , err } log . Debugf ( " \n " , card . Due , card . Interval , card . EaseFactor , card . ReviewCount ) card . Context = nil return true , nil } log . Printf ( " \n " , * face , button ) return false , nil }
Action responds to a card action, such as a button press
Action responds to a card action such as a button press
// Any input is fine; the only options are the right button, or 'ENTER' in a text field. // Clear any saved answers