model

package
v1.10.4 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package model provides describes the internal types and their behaviors

Index

Constants

View Source
const EnableCalendar bool = true

Variables

View Source
var (
	ErrorConflictFile              = errors.New("Created _CONFLICT file")
	ErrorMutexLockOn               = errors.New("Mutex Lock is ON; there is already a session running!")
	ErrorInteractiveProcessSkipped = errors.New("Skipped running the interactive process. Try again!")
)

Functions

func MakeSureFileExists

func MakeSureFileExists(dataFilePath string, askUserInput bool) error

MakeSureFileExists function makes sure that the dataFilePath exists.

Types

type BaseStruct

type BaseStruct struct {
	CreatedAt int64 `json:"created_at,omitempty"`
	UpdatedAt int64 `json:"updated_at,omitempty"`
}

A BaseStruct provides set of common fields.

type Comment

type Comment struct {
	Text string `json:"text"`
	BaseStruct
}

A Comment is an update to a note.

Consider it a statement representing an action to be taken/done or just an update about the Note.

A comment belongs to a particular note, whereas a note can have multiple comments

func (*Comment) String

func (comment *Comment) String() string

String provides basic string representation of a commment.

type Comments

type Comments []*Comment

A Comments is a slice of Comment objects.

By default it is sorted by its CreatedAt field

func (Comments) Len

func (c Comments) Len() int

func (Comments) Less

func (c Comments) Less(i, j int) bool

func (Comments) Strings

func (comments Comments) Strings() []string

Strings provides representation of Commments in terms of slice of strings.

func (Comments) Swap

func (c Comments) Swap(i, j int)

type Note

type Note struct {
	Text     string   `json:"text"`
	Comments Comments `json:"comments"`
	Summary  string   `json:"summary"`
	// Status can be "pending", "done", or "suspended".
	// The "pending" status is special, and notes marked with it show up everywhere, whereas
	// the nodes marked with other status show up only under "Search" or their dedicated menu.
	Status     NoteStatus `json:"status"`
	TagIds     []int      `json:"tag_ids"`
	IsMain     bool       `json:"is_main"`
	CompleteBy int64      `json:"complete_by"`

	BaseStruct
	// contains filtered or unexported fields
}

A Note represents a task.

A note can be main or incidental. A note can be multiple tags, and a tag can be assocaited with mutiple notes.

func NewNote

func NewNote(tagIDs []int, useText string) (*Note, error)

NewNote function provides prompt to register a new Note, and returns its answer.

func (*Note) AddComment

func (note *Note) AddComment(text string) error

AddComment adds a new comment to note.

func (*Note) ExternalText

func (note *Note) ExternalText(reminderData *ReminderData) (string, error)

ExternalText prints a note with its tags slugs. This is used as final external reprensentation for display of a single note.

func (*Note) GoogleCalendarEvent added in v1.9.16

func (note *Note) GoogleCalendarEvent(repeatAnnuallyTagId int, repeatMonthlyTagId int, timezoneIANA string, tagger Tagger) (*gc.Event, error)

GoogleCalendarEvent converts a note to Google Calendar Event.

func (*Note) RepeatType

func (note *Note) RepeatType(repeatAnnuallyTagId int, repeatMonthlyTagId int) string

RepeatType return - (Not-repeat), A (Annual-Repeat), or M (Monthly-Repeat) string representing repeat-type of the note

func (*Note) SafeExtText added in v1.9.22

func (note *Note) SafeExtText(tagger Tagger) (string, error)

SafeExtText prints a note with its tags slugs, but only the safe components. This is used as final external reprensentation for display of a single note to external services like Google Calendar.

func (*Note) SearchableText

func (note *Note) SearchableText() (string, error)

SearchableText provides string representation of the object. It is used while performing full text search on Text and Comments of a note.

func (*Note) Strings

func (note *Note) Strings() ([]string, error)

Strings provides basic string representation (as a slice of strings) of a note with each element of slice representing certain field of the note.

func (*Note) ToggleMainFlag

func (note *Note) ToggleMainFlag() error

ToggleMainFlag toggles note's main flag.

func (*Note) Type

func (note *Note) Type() string

Type returns type of the note: main or incidental.

func (*Note) UpdateCompleteBy

func (note *Note) UpdateCompleteBy(text string) error

UpdateCompleteBy updates note's due date. The input is of the form DD-MM-YYYY or just DD-MM (with implicity value for year; either current or next). If input is "nil", the existing due date is cleared.

func (*Note) UpdateStatus

func (note *Note) UpdateStatus(status NoteStatus, repeatTagIDs []int) error

UpdateStatus updates note's status ("done"/"pending"). Status of a note tag with repeat tag cannot be mared as "done".

func (*Note) UpdateSummary

func (note *Note) UpdateSummary(text string) error

UpdateSummary updates note's summary. If input is "nil", the existing summary is cleared.

func (*Note) UpdateTags

func (note *Note) UpdateTags(tagIDs []int) error

UpdateTags updates note's tags.

func (*Note) UpdateText

func (note *Note) UpdateText(text string) error

UpdateText updates note's text. Once updated, the text cannot be made empty.

type NoteStatus added in v1.8.3

type NoteStatus string
const (
	NoteStatus_Undefined NoteStatus = "undefined"
	// "pending":   tasks which are yet to be done
	NoteStatus_Pending NoteStatus = "pending"
	// "suspended": tasks which are yet to be done but for now marked as suspended so as to keep them hidden at most of the places
	NoteStatus_Suspended NoteStatus = "suspended"
	// "done":      tasks which have been completed (or not to be done)
	NoteStatus_Done NoteStatus = "done"
)

type Notes

type Notes []*Note

A Notes is a slice of Note objects.

By default it is sorted by its CreatedAt field.

func (Notes) ExternalTexts

func (notes Notes) ExternalTexts(maxStrLen int, repeatAnnuallyTagId int, repeatMonthlyTagId int) []string

ExternalTexts returns display text (that is, external representation) of list of notes with width of each note is truncated to maxStrLen. It returns empty []string if there are no notes. Note: You may use repeatAnnuallyTagId and repeatMonthlyTagId as 0, if they are not required In the output: R means "repeat-type", C means "number of comments", S means "status", and D means "due date"

func (Notes) Len

func (c Notes) Len() int

func (Notes) Less

func (c Notes) Less(i, j int) bool

func (Notes) OnlyMain

func (notes Notes) OnlyMain() Notes

OnlyMain filters notes which are set as main. It returns empty Notes if no main notes is found.

func (Notes) PopulateTempDueDate added in v1.9.29

func (notes Notes) PopulateTempDueDate()

PopulateTempDueDate popultes tempDueDate field of note from its CompleteBy field.

func (Notes) Swap

func (c Notes) Swap(i, j int)

func (Notes) WithCompleteBy added in v1.9.17

func (notes Notes) WithCompleteBy() Notes

WithCompleteBy filters-in only notes with non-nil CompleteBy filed of the notes. It returns empty Notes if no matching Note is found (even when given status doesn't exist).

func (Notes) WithStatus

func (notes Notes) WithStatus(status NoteStatus) Notes

WithStatus filters-in notes with given status (such as "pending" status). It returns empty Notes if no matching Note is found (even when given status doesn't exist).

func (Notes) WithTagIdAndStatus

func (notes Notes) WithTagIdAndStatus(tagID int, status NoteStatus) Notes

WithTagIdAndStatus returns all notes with given tagID and given status. It returns empty Notes if no matching Note is found (even when given tagID or status doesn't exist).

type NotesByDueDate

type NotesByDueDate []*Note

A NotesByDueDate is a slice of Note objects.

By default it is sorted by its CreatedAt field.

func (NotesByDueDate) Len

func (c NotesByDueDate) Len() int

func (NotesByDueDate) Less

func (c NotesByDueDate) Less(i, j int) bool

func (NotesByDueDate) Swap

func (c NotesByDueDate) Swap(i, j int)

type Prompter

type Prompter interface {
	Run() (string, error)
}

A Prompter representing Prompt which can be Run.

type ReminderData

type ReminderData struct {
	User         *User  `json:"user"`
	Notes        Notes  `json:"notes"`
	Tags         Tags   `json:"tags"`
	DataFile     string `json:"data_file"`
	LastBackupAt int64  `json:"last_backup_at"`
	MutexLock    bool   `json:"mutex_lock"`
	BaseStruct
}

A ReminderData represents the whole reminder data-structure.

func BlankReminder

func BlankReminder(askUserInput bool, dataFilePath string) (*ReminderData, error)

BlankReminder function creates blank ReminderData object.

func ReadDataFile

func ReadDataFile(dataFilePath string, silentMode bool) (*ReminderData, error)

ReadDataFile function reads data file as instance of `ReminderData`

func (*ReminderData) AddNoteComment

func (rd *ReminderData) AddNoteComment(note *Note, text string) error

AddNoteComment adds note's comment.

func (*ReminderData) AskTagIds

func (rd *ReminderData) AskTagIds(tagIDs []int) []int

AskTagIds (recursive) ask tagIDs that are to be associated with a note.. It also registers tags for you, if user asks.

func (*ReminderData) AutoBackup

func (rd *ReminderData) AutoBackup(gapSecs int64) (string, error)

AutoBackup does auto backup.

func (*ReminderData) CreateBackup

func (rd *ReminderData) CreateBackup() (string, error)

CreateBackup creates timestamped backup. It returns path of the data file. Like utils.AskOptions, it prints any encountered error, but doesn't return the error.

func (*ReminderData) CreateDataFile added in v1.9.23

func (rd *ReminderData) CreateDataFile(msg string) error

CreateDataFile creates data file with current state of `rd`. The msg is any additional message to be printed.

func (*ReminderData) DisplayDataFile

func (rd *ReminderData) DisplayDataFile() error

DisplayDataFile displays the data file. Like utils.AskOptions, it prints any encountered error, and returns that error just for information.

func (*ReminderData) FindNotesByTagId

func (rd *ReminderData) FindNotesByTagId(tagID int, status NoteStatus) Notes

FindNotesByTagId gets all notes with given tagID and given status.

func (*ReminderData) FindNotesByTagSlug

func (rd *ReminderData) FindNotesByTagSlug(tagSlug string, status NoteStatus) Notes

FindNotesByTagSlug gets all notes with given tagSlug and given status.

func (*ReminderData) GoogleCalendarEvents added in v1.9.16

func (rd *ReminderData) GoogleCalendarEvents(timezoneIANA string) ([]*gc.Event, error)

GoogleCalendarEvents returns list of Google Calendar Events.

func (*ReminderData) ListTags

func (rd *ReminderData) ListTags() error

ListTags prompts a list of all tags (and their notes underneath). Like utils.AskOptions, it prints any encountered error, and returns that error just for information.

func (*ReminderData) NewNoteRegistration

func (rd *ReminderData) NewNoteRegistration(tagIDs []int) (*Note, error)

NewNoteRegistration registers new note. The note is saved to the data file.

func (*ReminderData) NewTagRegistration

func (rd *ReminderData) NewTagRegistration() (int, error)

NewTagRegistration registers a new tag.

func (*ReminderData) NotesApprachingDueDate

func (rd *ReminderData) NotesApprachingDueDate(view string) Notes

NotesApprachingDueDate fetches all pending notes which are urgent. It accepts view as an argument with "default" or "long" as acceptable values Note: NotesApprachingDueDate is dangerous as it manipulates the due date (CompleteBy) date of repeating tags which can cause persitence of manupulated dates, if the returned data is persisted.

func (*ReminderData) PrintNoteAndAskOptions

func (rd *ReminderData) PrintNoteAndAskOptions(note *Note) string

PrintNoteAndAskOptions prints note and display options. Like utils.AskOptions, it prints any encountered error, but doesn't returns that error just for information. It return string representing workflow direction.

func (*ReminderData) PrintNotesAndAskOptions

func (rd *ReminderData) PrintNotesAndAskOptions(notes Notes, display_mode string, tagID int, sortBy string) error

PrintNotesAndAskOptions (recursively) prints notes interactively. In some cases, updated list notes will be fetched, so blank notes can be passed in those cases. Unless notes are to be fetched, the passed `status` doesn't make sense, so in such cases it can be passed as "fake". Like utils.AskOptions, it prints any encountered error, and returns that error just for information. It accepts following values for `display_mode`: - "done_notes": fetch only done notes - "suspended_notes": fetch only suspended notes - "pending_tag_notes": fetch pending notes with given tagID - "pending_only_main_notes": fetch pending notes with IsMain set as true - "pending_approaching_notes": fetch pending notes with approaching due date - "pending_long_view_notes": fetch long-view (52 weeks) of pending notes - "passed_notes": use passed notes

func (*ReminderData) RegisterBasicTags

func (rd *ReminderData) RegisterBasicTags() error

RegisterBasicTags registers basic tags.

func (*ReminderData) SearchNotes

func (rd *ReminderData) SearchNotes() error

SearchNotes searches throught all notes. Like utils.AskOptions, it prints any encountered error, and returns that error just for information.

func (*ReminderData) SortedTagSlugs

func (rd *ReminderData) SortedTagSlugs() []string

SortedTagSlugs sorts the tags in-place and return slugs. Empty Tags is returned if there are no tags.

func (*ReminderData) Stats

func (rd *ReminderData) Stats() (string, error)

Stats returns current status.

func (*ReminderData) SyncCalendar added in v1.9.16

func (rd *ReminderData) SyncCalendar(calOptions *calendar.Options) error

SyncCalendar syncs pending notes to Cloud Calendar.

func (*ReminderData) TagFromSlug

func (rd *ReminderData) TagFromSlug(slug string) *Tag

TagFromSlug returns tag with given slug.

func (*ReminderData) TagIdsForGroup

func (rd *ReminderData) TagIdsForGroup(group string) []int

TagIdsForGroup gets tag ids for given group.

func (*ReminderData) TagsFromIds

func (rd *ReminderData) TagsFromIds(tagIDs []int) []string

TagsFromIds returns tag slugs from tagIDs.

func (*ReminderData) ToggleNoteMainFlag

func (rd *ReminderData) ToggleNoteMainFlag(note *Note) error

ToggleNoteMainFlag toggles note's priority.

func (*ReminderData) UpdateDataFile

func (rd *ReminderData) UpdateDataFile(msg string) error

UpdateDataFile updates data file with current state of `rd`. The msg is any additional message to be printed.

func (*ReminderData) UpdateNoteCompleteBy

func (rd *ReminderData) UpdateNoteCompleteBy(note *Note, text string) error

UpdateNoteCompleteBy updates the note's due date (complete by).

func (*ReminderData) UpdateNoteStatus

func (rd *ReminderData) UpdateNoteStatus(note *Note, status NoteStatus) error

UpdateNoteStatus updates note's status.

func (*ReminderData) UpdateNoteSummary

func (rd *ReminderData) UpdateNoteSummary(note *Note, text string) error

UpdateNoteSummary updates the note's summary.

func (*ReminderData) UpdateNoteTags

func (rd *ReminderData) UpdateNoteTags(note *Note, tagIDs []int) error

UpdateNoteTags updates note's tags.

func (*ReminderData) UpdateNoteText

func (rd *ReminderData) UpdateNoteText(note *Note, text string) error

UpdateNoteText updates note's text.

type Tag

type Tag struct {
	Id    int    `json:"id"`    // internal int-based id of the tag
	Slug  string `json:"slug"`  // client-facing string-based id for tag
	Group string `json:"group"` // a note can be part of only one tag within a group
	BaseStruct
}

A Tag represents classification of a note.

A note can have multiple tags, and a tag can be associated with multiple notes.

func NewTag

func NewTag(tagID int, useSlug string, useGroup string) (*Tag, error)

NewTag funciton provides prompt for creating new Tag. Pass useSlug and/or useGroup to use given values instead of prompting user.

func (Tag) String

func (t Tag) String() string

String provides basic string representation of a tag.

type Tagger added in v1.9.28

type Tagger interface {
	TagsFromIds(tagIDs []int) []string
}

Tagger is interface representing ReminderData with TagsFromIds method.

type Tags

type Tags []*Tag

A Tags is a slice of Tag objects.

By default it is sorted by its Slug field.

func BasicTags

func BasicTags() Tags

BasicTags function returns an array of basic tags which can be used for initial setup of the application. Here some of the tags will have special meaning/functionality such as repeat-annually and repeat-monthly.

func (Tags) FromIds

func (tags Tags) FromIds(tagIDs []int) Tags

FromIds returns tags from tagIDs. It returns empty Tags if non of tagIDs match.

func (Tags) FromSlug

func (tags Tags) FromSlug(slug string) *Tag

FromSlug fetches tag with given slug. It return nil if given tag is not found.

func (Tags) IdsForGroup

func (tags Tags) IdsForGroup(group string) []int

IdsForGroup returns tag ids of given group. It returns empty []int if group with given group name doesn't exist.

func (Tags) Len

func (c Tags) Len() int

func (Tags) Less

func (c Tags) Less(i, j int) bool

func (Tags) Slugs

func (tags Tags) Slugs() []string

Slugs returns slugs of given tags.

func (Tags) Swap

func (c Tags) Swap(i, j int)

type User

type User struct {
	Name    string `json:"name"`
	EmailId string `json:"email_id"`
}

A User represents the user of the reminder app.

The app doesn't have multi-tenant setting, but it is supposed to be used only locally and by the user who is owner of the OS account.

func (User) String

func (u User) String() string

String provides basic string representation of a user.

Jump to

Keyboard shortcuts

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