backend

package
v0.0.0-...-ad11b74 Latest Latest
Warning

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

Go to latest
Published: May 1, 2022 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Overview

Package backend contains the backend code for meditations

gaphql.go - GraphQL resolvers

Index

Constants

View Source
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
)
View Source
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
)
View Source
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
)
View Source
const (
	// Date format used in database
	DateFormat = "2006-01-02"
)

DateFormat is the Time.Format format used in the database

View Source
const (
	// ProjectDays is used when calculating how many days in the past to include in project recent
	// activity information
	ProjectDays = 72
)
View Source
const (
	// SchemaVersion is the current version of the meditations DB schema
	SchemaVersion = 4
)

Variables

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

View Source
var DB *gorm.DB

DB global database handle

Functions

func App

func App() *macaron.Macaron

App configures returns a meditations web application

func DBClose

func DBClose()

DBClose close database handle

func DBCreate

func DBCreate()

DBCreate initialize a new database; will not overwrite existing settings.

func DBMigrate

func DBMigrate()

DBMigrate run database migration

func DBOpen

func DBOpen()

DBOpen open database

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

func Main

func Main()

Main is the entry point for meditations; it handles CLI options and starts

Types

type ByDate

type ByDate []Entry

ByDate allows sorting by date

func (ByDate) Len

func (s ByDate) Len() int

Len length

func (ByDate) Less

func (s ByDate) Less(i, j int) bool

Less

func (ByDate) Swap

func (s ByDate) Swap(i, j int)

Swap

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 EntrySave

type EntrySave struct {
	gorm.Model
	EntryID uint
	Body    string
}

EntrySave is an emergency append-only save table

type NameLink struct {
	Name string
	ID   string
	Href string
	Sub  []NameLink
}

NameLink is a link to a named journal entry

type ProjectListMsg

type ProjectListMsg struct {
	Pinned   []Scope
	Unpinned []Scope
	Hidden   []Scope
}

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

func (project *Scope) CalculateProjectStats(days int)

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

func MakeSyncPage(name string) *SyncPage

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

func (page *SyncPage) Send(Type string, datum interface{})

Send sends any object to all clients connected in the format {Type: Type, Datum: datum}

func (*SyncPage) SendData

func (page *SyncPage) SendData(data []byte)

SendData sends a JSON message to all clients connected to a particular SyncPage

func (*SyncPage) Server

func (page *SyncPage) Server()

Server is a goroutine that handles websocket connections

type Tag

type Tag struct {
	gorm.Model
	Name string
}

Tag represents a journal tag; many-to-many relationship with ntries

type TagLink struct {
	Name  string
	Count int
}

TagLink is a link to a tag, including how many entries are in it

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

func (task *Task) Near(tasks *[]Task)

Near finds TASKS in the same scope as TASK

func (*Task) Sync

func (task *Task) Sync(updateScope bool, recalculate bool, includeMainTask bool)

Sync sends updates to the UI as necessary after a task changes

func (*Task) SyncOnlyTask

func (task *Task) SyncOnlyTask()

SyncOnlyTask just sends a single task; used for comment updates only

func (*Task) SyncWithStats

func (task *Task) SyncWithStats(includeMainTask bool)

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

type TaskEvent

type TaskEvent struct {
	Type string
	Data interface{}
}

type TaskStats

type TaskStats struct {
	ID             uint `gorm:"primary_key"`
	CreatedAt      time.Time
	UpdatedAt      time.Time
	DeletedAt      *time.Time `sql:"column:deleted_time"`
	CompletedTasks int
	TotalTasks     int
	BestStreak     int
	Streak         int
}

TaskStats tracks statistics for monthly, yearly and project tasks.

Jump to

Keyboard shortcuts

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