Files
leanote/app/controllers/NotebookController.go

68 lines
1.9 KiB
Go
Raw Normal View History

2014-05-07 13:06:24 +08:00
package controllers
import (
"github.com/revel/revel"
2014-09-10 22:44:43 +08:00
"encoding/json"
2014-05-07 13:06:24 +08:00
"github.com/leanote/leanote/app/info"
"gopkg.in/mgo.v2/bson"
2014-09-10 22:44:43 +08:00
. "github.com/leanote/leanote/app/lea"
2014-05-07 13:06:24 +08:00
// "io/ioutil"
)
type Notebook struct {
BaseController
}
func (c Notebook) Index(notebook info.Notebook, i int, name string) revel.Result {
return c.RenderJson(notebook)
}
// 得到用户的所有笔记本
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)
}
func (c Notebook) DeleteNotebook(notebookId string) revel.Result {
re, msg := notebookService.DeleteNotebook(c.GetUserId(), notebookId)
return c.RenderJson(info.Re{Ok: re, Msg: msg})
}
// 添加notebook
func (c Notebook) AddNotebook(notebookId, title string) revel.Result {
notebook := info.Notebook{NotebookId: bson.ObjectIdHex(notebookId),
Title: title,
Seq: -1,
UserId: c.GetObjectUserId()}
re := notebookService.AddNotebook(notebook)
if(re) {
return c.RenderJson(notebook)
} else {
return c.RenderJson(false)
}
}
// 修改标题
func (c Notebook) UpdateNotebookTitle(notebookId, title string) revel.Result {
return c.RenderJson(notebookService.UpdateNotebookTitle(notebookId, c.GetUserId(), title))
}
2014-09-10 22:44:43 +08:00
2014-05-07 13:06:24 +08:00
// 排序
2014-09-10 22:44:43 +08:00
// 无用
2014-05-07 13:06:24 +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 {
CurNotebookId string
ParentNotebookId string
Siblings []string
}
// 传过来的data是JSON.stringfy数据
func (c Notebook) DragNotebooks(data string) revel.Result {
info := DragNotebooksInfo{}
json.Unmarshal([]byte(data), &info)
return c.RenderJson(notebookService.DragNotebooks(c.GetUserId(), info.CurNotebookId, info.ParentNotebookId, info.Siblings))
2014-05-07 13:06:24 +08:00
}