예제 #1
0
파일: tag.go 프로젝트: oschmid/tessernote
// Children returns all Tags this Note is parent to.
func (tag Tag) Children(c appengine.Context) ([]Tag, error) {
	children := make([]Tag, len(tag.ChildKeys))
	err := cachestore.GetMulti(c, tag.ChildKeys, children)
	if err != nil {
		c.Errorf("getting tag children: %s", err)
	}
	return children, err
}
예제 #2
0
파일: tag.go 프로젝트: oschmid/tessernote
// Notebooks returns all Notebooks that share this Tag.
func (tag Tag) Notebooks(c appengine.Context) ([]Notebook, error) {
	notebooks := make([]Notebook, len(tag.NotebookKeys))
	err := cachestore.GetMulti(c, tag.NotebookKeys, notebooks)
	if err != nil {
		c.Errorf("getting tag notebooks: %s", err)
	}
	return notebooks, err
}
예제 #3
0
// Tags returns all tags used to sort this Notebook's notes
func (notebook *Notebook) Tags(c appengine.Context) ([]Tag, error) {
	if len(notebook.tags) == 0 && len(notebook.NoteKeys) > 0 {
		notebook.tags = make([]Tag, len(notebook.TagKeys))
		err := cachestore.GetMulti(c, notebook.TagKeys, notebook.tags)
		if err != nil {
			c.Errorf("getting notebook tags: %s", err)
			return notebook.tags, err
		}
	}
	return notebook.tags, nil
}
예제 #4
0
파일: tag.go 프로젝트: oschmid/tessernote
// Notes returns all Notes that share this Tag.
func (tag Tag) Notes(c appengine.Context) ([]Note, error) {
	notes := make([]Note, len(tag.NoteKeys))
	err := cachestore.GetMulti(c, tag.NoteKeys, notes)
	if err != nil {
		c.Errorf("getting tag notes: %s", err)
		return notes, err
	}
	for i, note := range notes {
		note.ID = tag.NoteKeys[i].Encode()
	}
	return notes, nil
}
예제 #5
0
// UntaggedNotes returns all untagged notes in this Notebook
func (notebook *Notebook) UntaggedNotes(c appengine.Context) ([]Note, error) {
	if len(notebook.untaggedNotes) == 0 && len(notebook.UntaggedNoteKeys) > 0 {
		notebook.untaggedNotes = make([]Note, len(notebook.UntaggedNoteKeys))
		err := cachestore.GetMulti(c, notebook.UntaggedNoteKeys, notebook.untaggedNotes)
		if err != nil {
			c.Errorf("getting notebook untagged notes: %s", err)
			return notebook.untaggedNotes, err
		}
		for i := 0; i < len(notebook.untaggedNotes); i++ {
			note := &notebook.untaggedNotes[i]
			note.ID = notebook.UntaggedNoteKeys[i].Encode()
		}
	}
	return notebook.untaggedNotes, nil
}
예제 #6
0
파일: tag.go 프로젝트: oschmid/tessernote
// RelatedNotes returns the union of all Notes referred to by a set of Tags.
func RelatedNotes(tags []Tag, c appengine.Context) ([]Note, error) {
	if len(tags) == 0 {
		return *new([]Note), nil
	}

	noteKeys := tags[0].NoteKeys
	for i := 1; i < len(tags); i++ {
		noteKeys = unionKeys(noteKeys, tags[i].NoteKeys)
	}

	notes, err := make([]Note, len(noteKeys)), *new(error)
	if len(noteKeys) > 0 {
		err = cachestore.GetMulti(c, noteKeys, notes)
		if err != nil {
			c.Errorf("getting related notes: %s", err)
		}
	}
	return notes, err
}