model

package
v0.0.0-...-7a09d4d Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2018 License: MIT Imports: 32 Imported by: 16

Documentation

Index

Constants

View Source
const (
	// NewBuryTime sets the time to bury related new cards.
	NewBuryTime = 7 * fb.Day

	// MinBuryTime is the minimal burial time.
	MinBuryTime = 1 * fb.Day

	// MaxBuryTime is the maximal burial time.
	MaxBuryTime = 10 * fb.Day

	// MaxBuryRatio is the maximum burial-time / interval ratio.
	MaxBuryRatio = 0.20
)
View Source
const (
	// Question is a card's first face
	Question = iota
	// Answer is a card's second face
	Answer
)
View Source
const (
	UserDDocID      = "_design/index"
	UserDDocVersion = 1
)

copied from github.com/flimzy/flashback-server2

Variables

View Source
var ErrNotLoggedIn = kerrors.Status(kivik.StatusUnauthorized, "not logged in")

ErrNotLoggedIn is returned by CurrentUser if no user is logged in.

Functions

func RegisterModelController

func RegisterModelController(c ModelController)

RegisterModelController registers a model controller for use in the app. The passed controller's Type() must return a unique value.

func RegisteredModelControllers

func RegisteredModelControllers() []string

RegisteredModelControllers returns a list of registered controller type

func Schedule

func Schedule(card *Card, answerDelay time.Duration, quality flashback.AnswerQuality) error

Schedule implements the default scheduler.

Types

type Card

type Card struct {
	*fb.Card
	// contains filtered or unexported fields
}

Card wraps an *fb.Card and its dependencies.

func (*Card) Action

func (c *Card) Action(ctx context.Context, face *int, startTime time.Time, query interface{}) (done bool, err error)

Action handles a card action produced by the user.

func (*Card) Body

func (c *Card) Body(ctx context.Context, face int) (body string, err error)

Body produces the HTML body of the card to be displayed.

func (*Card) Buttons

func (c *Card) Buttons(face int) (studyview.ButtonMap, error)

Buttons returns the list of buttons to be made visible for the card face.

func (*Card) FieldValue

func (c *Card) FieldValue(fieldName string) *fb.FieldValue

FieldValue returns the card's value for the requested field.

func (*Card) Fields

func (c *Card) Fields() []string

Fields returns a list of field names for the card.

func (*Card) MarshalJSON

func (c *Card) MarshalJSON() ([]byte, error)

MarshalJSON marshals a Card for the benefit of javascript context in HTML templates.

type Deck

type Deck struct {
	Name           string
	ID             string
	TotalCards     int
	DueCards       int
	LearningCards  int
	MatureCards    int
	NewCards       int
	SuspendedCards int
}

Deck represents a single deck.

type FlashbackDoc

type FlashbackDoc interface {
	DocID() string
	SetRev(string)
	ImportedTime() time.Time
	ModifiedTime() time.Time
	MergeImport(interface{}) (bool, error)
	json.Marshaler
	json.Unmarshaler
}

FlashbackDoc is a generic interface for all types of FB docs

type FuncMapper

type FuncMapper interface {
	// FuncMap is given the card and face, and is expected to return a
	// template.FuncMap which can be used when parsing the HTML templates for
	// this note type. If card is nil, the function is fine to return only
	// non-functional, placeholder methods.
	FuncMap(card *Card, face int) template.FuncMap
}

FuncMapper is an optional interface that a ModelController may fulfill.

type ModelController

type ModelController interface {
	// Type returns the Model Type identifier string.
	Type() string
	// IframeScript returns a blob of JavaScript, which is loaded inside the
	// iframe of each card associated with this model type.
	IframeScript() []byte
	// Buttons returns the attributes for the three available answer buttons'
	// initial state. Index 0 = left button, 1 = center, 2 = right
	Buttons(card *Card, face int) (studyview.ButtonMap, error)
	// Action is called when the card submits the 'mainform' form. `query` is the
	// deserialized content of the form submission, which should include at minimum
	// `submit` key. If done is returned as true, the next card is selected. If
	// done is false, the same card will be displayed, with the current value
	// of face (possibly changed by the function)
	Action(card *Card, face *int, startTime time.Time, query interface{}) (done bool, err error)
}

ModelController is an interface for the per-type model controllers.

func GetModelController

func GetModelController(mType string) (ModelController, error)

GetModelController returns the ModelController for the registered model type, 'mType'.

type Repo

type Repo struct {
	// contains filtered or unexported fields
}

Repo represents an instance of the Couch/Pouch model.

func New

func New(ctx context.Context, remoteURL, appURL string) (*Repo, error)

New returns a new Repo instance, pointing to the specified remote server.

func (*Repo) Auth

func (r *Repo) Auth(ctx context.Context, provider, token string) error

Auth attempts to authenticate with the provided OAuth2 provider/token pair.

func (*Repo) BuryRelatedCards

func (r *Repo) BuryRelatedCards(ctx context.Context, card *fb.Card) error

BuryRelatedCards buries related cards.

The burial strategy involves the following:

  1. New cards (reviewCount = 0) are buried for NewBuryTime. This should help start of new card review to get off on the right foot.
  2. All related cards are buried for a minimum of 1 day (this is all Anki does)
  3. The target burial time is the current card's interval, divided by the number of related cards. NewBuryTime is used as the minimum target burial time.
  4. The maximum burial is MaxBuryRatio of the card's interval.

func (*Repo) CurrentUser

func (r *Repo) CurrentUser() (string, error)

CurrentUser returns the currently registered user.

func (*Repo) DeckList

func (r *Repo) DeckList(ctx context.Context) ([]*Deck, error)

DeckList returns a complete list of decks available for study.

func (*Repo) FetchAttachment

func (r *Repo) FetchAttachment(ctx context.Context, cardID, filename string) (*fb.Attachment, error)

FetchAttachment fetches the requested attachment associated with the specified card.

func (*Repo) GetCardToStudy

func (r *Repo) GetCardToStudy(ctx context.Context, deck string) (flashback.CardView, error)

GetCardToStudy returns a CardView to display to the user to study, and buries related cards.

func (*Repo) Import

func (r *Repo) Import(ctx context.Context, f io.Reader, reporter progress.ReportFunc) error

Import imports a .fbb file and stores the content

func (*Repo) ImportFile

func (r *Repo) ImportFile(ctx context.Context, f inputFile, reporter progress.ReportFunc) error

ImportFile imports a *.fbb file, as from an HTML form submission.

func (*Repo) Logout

func (r *Repo) Logout(ctx context.Context) error

Logout clears the auth session.

func (*Repo) SaveBundle

func (r *Repo) SaveBundle(ctx context.Context, bundle *fb.Bundle) error

SaveBundle saves the bundle.

func (*Repo) Sync

func (r *Repo) Sync(ctx context.Context) error

Sync performs a bi-directional sync.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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