Files
leanote/app/controllers/NotebookController.go

81 lines
2.2 KiB
Go
Raw Normal View History

2014-05-07 13:06:24 +08:00
package controllers
import (
2014-09-10 22:44:43 +08:00
"encoding/json"
2014-05-07 13:06:24 +08:00
"github.com/leanote/leanote/app/info"
2015-11-13 17:58:41 +08:00
"github.com/revel/revel"
"gopkg.in/mgo.v2/bson"
2015-11-13 17:58:41 +08:00
// . "github.com/leanote/leanote/app/lea"
// "io/ioutil"
2014-05-07 13:06:24 +08:00
)
type Notebook struct {
BaseController
}
func (c Notebook) Index(notebook info.Notebook, i int, name string) revel.Result {
return c.RenderJSON(notebook)
2014-05-07 13:06:24 +08:00
}
// 得到用户的所有笔记本
2014-05-14 22:23:35 +08:00
func (c Notebook) GetNotebooks() revel.Result {
2014-05-07 13:06:24 +08:00
re := notebookService.GetNotebooks(c.GetUserId())
return c.RenderJSON(re)
2014-05-07 13:06:24 +08:00
}
func (c Notebook) DeleteNotebook(notebookId string) revel.Result {
re, msg := notebookService.DeleteNotebook(c.GetUserId(), notebookId)
return c.RenderJSON(info.Re{Ok: re, Msg: msg})
2014-05-07 13:06:24 +08:00
}
// 添加notebook
func (c Notebook) AddNotebook(notebookId, title, parentNotebookId string) revel.Result {
2015-11-13 17:58:41 +08:00
notebook := info.Notebook{NotebookId: bson.ObjectIdHex(notebookId),
Title: title,
Seq: -1,
2014-05-07 13:06:24 +08:00
UserId: c.GetObjectUserId()}
2015-11-13 17:58:41 +08:00
if parentNotebookId != "" {
notebook.ParentNotebookId = bson.ObjectIdHex(parentNotebookId)
}
2015-03-31 14:27:26 +08:00
re, notebook := notebookService.AddNotebook(notebook)
2015-11-13 17:58:41 +08:00
if re {
return c.RenderJSON(notebook)
2014-05-07 13:06:24 +08:00
} else {
return c.RenderJSON(false)
2014-05-07 13:06:24 +08:00
}
}
2015-11-13 17:58:41 +08:00
2014-05-07 13:06:24 +08:00
// 修改标题
func (c Notebook) UpdateNotebookTitle(notebookId, title string) revel.Result {
return c.RenderJSON(notebookService.UpdateNotebookTitle(notebookId, c.GetUserId(), title))
2014-05-07 13:06:24 +08:00
}
2014-09-10 22:44:43 +08:00
2014-05-07 13:06:24 +08:00
// 排序
2014-09-10 22:44:43 +08:00
// 无用
// func (c Notebook) SortNotebooks(notebookId2Seqs map[string]int) revel.Result {
// return c.RenderJSON(notebookService.SortNotebooks(c.GetUserId(), notebookId2Seqs))
// }
2014-09-10 22:44:43 +08:00
// 调整notebooks, 可能是排序, 可能是移动到其它笔记本下
type DragNotebooksInfo struct {
2015-11-13 17:58:41 +08:00
CurNotebookId string
2014-09-10 22:44:43 +08:00
ParentNotebookId string
2015-11-13 17:58:41 +08:00
Siblings []string
2014-09-10 22:44:43 +08:00
}
2015-11-13 17:58:41 +08:00
2014-09-10 22:44:43 +08:00
// 传过来的data是JSON.stringfy数据
func (c Notebook) DragNotebooks(data string) revel.Result {
info := DragNotebooksInfo{}
json.Unmarshal([]byte(data), &info)
2015-11-13 17:58:41 +08:00
return c.RenderJSON(notebookService.DragNotebooks(c.GetUserId(), info.CurNotebookId, info.ParentNotebookId, info.Siblings))
2014-11-09 22:26:38 +08:00
}
// 设置notebook <-> blog
func (c Notebook) SetNotebook2Blog(notebookId string, isBlog bool) revel.Result {
2014-11-10 23:56:15 +08:00
re := notebookService.ToBlog(c.GetUserId(), notebookId, isBlog)
return c.RenderJSON(re)
2015-03-31 14:27:26 +08:00
}