Documentation ¶
Overview ¶
Package backend contains the backend code for meditations
gaphql.go - GraphQL resolvers
Index ¶
- Constants
- Variables
- func App() *macaron.Macaron
- func DBClose()
- func DBCreate()
- func DBMigrate()
- func DBOpen()
- func DBRepair(repair bool)
- func GetAppPath() string
- func Main()
- type ByDate
- type ChronoLink
- type Configuration
- type Entry
- type EntrySave
- type NameLink
- type ProjectListMsg
- type Scope
- type Settings
- type Sidebar
- type SyncMessage
- type SyncPage
- type Tag
- type TagLink
- type Task
- func (task *Task) CalculateStats()
- func (task *Task) CalculateStreak()
- func (task *Task) CalculateTimeAndCompletion()
- func (task *Task) Near(tasks *[]Task)
- func (task *Task) Sync(updateScope bool, recalculate bool, includeMainTask bool)
- func (task *Task) SyncOnlyTask()
- func (task *Task) SyncWithStats(includeMainTask bool)
- func (task *Task) TaskSyncScope()
- type TaskEvent
- type TaskStats
Constants ¶
const ( // ScopeUnused was originally used to refer to a global "bucket list," but this has been superceded by project support. // No tasks should have a scope of ScopeUnused. ScopeUnused = iota // ScopeDay of daily tasks and journal entries ScopeDay = iota // ScopeMonth scope of monthly tasks ScopeMonth = iota // ScopeYear scope of yearly tasks ScopeYear = iota // ScopeProject scope of projects. Note that all scopes with this or higher are projects. ScopeProject = iota )
const ( // TaskUnset when a task's status has not been set TaskUnset = iota // TaskComplete when a task is completed successfully TaskComplete = iota // TaskIncomplete when a task is not completed successfully TaskIncomplete = iota )
const ( // VisibilityHidden means a project will not be shown unless a checkbox to that effect is ticked VisibilityHidden = 0 // VisibilityUnpinned means projects will be displayed with statistics for all-time, and no // activity flame VisibilityUnpinned = 1 // VisibilityPinned means projects will be displayed with statistics and a flame indicator // based on recent activity VisibilityPinned = 2 )
const (
// Date format used in database
DateFormat = "2006-01-02"
)
DateFormat is the Time.Format format used in the database
const ( // ProjectDays is used when calculating how many days in the past to include in project recent // activity information ProjectDays = 72 )
const (
// SchemaVersion is the current version of the meditations DB schema
SchemaVersion = 4
)
Variables ¶
var Config = Configuration{ Host: "", Port: 8080, DBType: "sqlite3", DBPath: "development.sqlite3", DBLog: false, SiteTitle: "meditations", Development: true, Migrate: false, Demo: false, Message: "", PackagePath: "", }
Config is the global application configuration
var DB *gorm.DB
DB global database handle
Functions ¶
func DBCreate ¶
func DBCreate()
DBCreate initialize a new database; will not overwrite existing settings.
func DBRepair ¶
func DBRepair(repair bool)
DBRepair checks for database issues (such as out-of-order tasks) that may have been caused by using a bugged version of meditations
func GetAppPath ¶
func GetAppPath() string
GetAppPath retrieves the application path. Some care is taken to make this work outside of the go path
Types ¶
type ChronoLink ¶
type ChronoLink struct { Date string Count int Sub []ChronoLink Link string }
ChronoLink represents a link to view a month, or a year expandable to month links
type Configuration ¶
type Configuration struct { // HTTP host Host string // HTTP port Port int // Database type "postgres" or "sqlite3" DBType string // Database path DBPath string // If true, all SQL queries will be logged DBLog bool // Site title SiteTitle string // True if running in development mode Development bool // If true, run a database migration before starting Migrate bool Demo bool // Message to be displayed in navbar, used in the demo instance Message string // Package path PackagePath string }
Configuration variables, initialized from command line arguments
type Entry ¶
type Entry struct { gorm.Model Date time.Time Name string Body string LastBody string Tags []Tag `gorm:"many2many:entry_tags"` Lock string }
Entry represents a journal entry
type ProjectListMsg ¶
ProjectListMsg is sent both as a result of GETting /habits/projects and syncing project list through the socket
type Scope ¶
type Scope struct { gorm.Model Name string `gorm:"not null;unique"` // Hidden projects will not be displayed unless a checkbox is checked Visibility int `gorm:"not null;default:'1'"` // Derived statistics CompletedTasks int `gorm:"-"` Minutes int `gorm:"-"` // ProgressDirection indicates whether a user has been doing more or less on a project recently; // it's used to grow or shrink the flame indicator ProgressDirection int `gorm:"-"` }
Scope represents a task's scope. Time-based scopes (daily, monthly, yearly) are built-in, but the user can add additional "projects," each of which have their own scope with an ID of ScopeProject or greater
func (*Scope) CalculateProjectStats ¶
CalculateProjectStats calculates project statistics
type Settings ¶
type Settings struct { gorm.Model Name string `gorm:"unique"` // Schema version; for certain manually-handled migrations Schema int }
Settings represents app settings saved in the database
type Sidebar ¶
type Sidebar struct { ChronoLinks []ChronoLink TagLinks []TagLink NameLinks []NameLink }
Sidebar represents all link information
type SyncMessage ¶
type SyncMessage struct { Type string Datum interface{} }
SyncMessage is a typed message to the client
type SyncPage ¶
type SyncPage struct {
// contains filtered or unexported fields
}
SyncPage contains clients connected to a particular page
func MakeSyncPage ¶
MakeSyncPage returns a struct that represents a websocket and its connected clients
func (*SyncPage) Handler ¶
func (page *SyncPage) Handler() func(w http.ResponseWriter, r *http.Request)
Handler returns a function that can be mounted to handle HTTP requests
func (*SyncPage) Send ¶
Send sends any object to all clients connected in the format {Type: Type, Datum: datum}
type Task ¶
type Task struct { ID uint CreatedAt time.Time UpdatedAt time.Time DeletedAt *time.Time Name string // The actual date of the task, regardless of when it was created Date time.Time // The status of the task: complete, incomplete, or unset Status int // The scope of the task (monthly, yearly, daily) Scope int // The task's position within that scope Position int // Time stats (in day-scoped tasks, these are set directly by the user; in monthly/yearly scopes, // they are calculated from daily tasks) Minutes int // Comment Comment string // These statistics are derived at runtime, and not represented in SQL CompletionRate float64 `sql:"-"` CompletedTasks int `sql:"-"` TotalTasks int `sql:"-"` TotalTasksWithTime int `sql:"-"` BestStreak int `sql:"-"` Streak int `sql:"-"` }
Task represents a task in the database
func (*Task) CalculateStats ¶
func (task *Task) CalculateStats()
CalculateStats calculates all statistics for monthly and yearly tasks
func (*Task) CalculateStreak ¶
func (task *Task) CalculateStreak()
CalculateStreak Given a yearly task, calculate a streak of days
func (*Task) CalculateTimeAndCompletion ¶
func (task *Task) CalculateTimeAndCompletion()
CalculateTimeAndCompletion Given a yearly or monthly task, calculate the completion rate of all tasks in daily scopes with the same name, and calculate the amount of time spent on a task
func (*Task) SyncOnlyTask ¶
func (task *Task) SyncOnlyTask()
SyncOnlyTask just sends a single task; used for comment updates only
func (*Task) SyncWithStats ¶
SyncWithStats syncs a specific task, and recalculates tasks on higher-scoped tasks if necessary
func (*Task) TaskSyncScope ¶
func (task *Task) TaskSyncScope()
TaskSyncScope re-sends a task's entire scope. Necessary when order is changed or a task is deleted