init
This commit is contained in:
app
controllers
AuthController.goBaseController.goBlogController.goFileController.goIndexController.goMobileController.goNoteContentHistoryController.goNoteController.goNotebookController.goOauthController.goShareController.goUserController.goinit.go
db
i18n
info
BlogInfo.goNoteInfo.goNotebookInfo.goREADME.mdRe.goShareNotebookNoteInfo.goSuggestionInfo.goTagInfo.goTokenInfo.goUserInfo.gocommon.go
init.golea
release
routes
service
AuthService.goBlogService.goNoteContentHistoryService.goNoteService.goNotebookService.goPwdService.goREADME.mdShareService.goSuggestionService.goTagService.goTokenService.goTrashService.goUserService.gocommon.goinit.go
test
tmp
views
App
Blog
Errors
File
Home
find_password.htmlfind_password2.htmlfind_password2_timeout.htmlfooter.htmlheader.htmlheader_box.htmlindex.htmllogin.htmlmodal.htmlregister.html
Mobile
Note
Notebook
Oauth
Share
User
conf
messages
public
css
blog
blog.cssblog_daqi.cssblog_daqi.lessblog_default.cssblog_default.lessblog_default2.cssblog_left_fixed.cssblog_left_fixed.less
bootstrap-theme.cssbootstrap-theme.min.cssbootstrap.cssbootstrap.min.cssbootstrap修改editor.csseditor.lessfont-awesome-4.0.3
css
fonts
FontAwesome.otffontawesome-webfont.eotfontawesome-webfont.svgfontawesome-webfont.ttffontawesome-webfont.woff
less
bordered-pulled.lesscore.lessfixed-width.lessfont-awesome.lessicons.lesslarger.lesslist.lessmixins.lesspath.lessrotated-flipped.lessspinning.lessstacked.lessvariables.less
scss
theme
fonts
open-sans2
DXI1ORHCpsQm3Vp6mXoaTXhCUOGz7vYGh680lGh-uXM.woffcJZKeOuBrn4kERxqtaUH3T8E0i7KZn-EPnyo3HZu7kw.woffk3k702ZOKiLJc3WVjuplzHhCUOGz7vYGh680lGh-uXM.woffxjAJXh38I15wypJXxuGMBobN6UDyHWBl620a-IRfuBk.woff
weibo
images
favicon.icofavicon_ever.ico
home
leanote
logo-100.giflogo-120.giflogo-20-a-6.pnglogo-32-a-5.pnglogo-32-a-7.pnglogo-32.pnglogo-60-a-6.pnglogo-60.gifold-preview.png
loading-24.gifloading-30.gifloading-32.gifloading-a-20-2.gifloading-a-20.gifloading-a-24.giflogo.pngnoise.pngoutofcode.pngslider
js
ZeroClipboard
all.jsapp
blog
note-min.jsnote.jsnotebook-min.jsnotebook.jspage-min.jspage.jsshare-min.jsshare.jstag-min.jstag.jscontextmenu
ever
i18n
jQuery-slimScroll-1.3.0
jquery-1.9.0.min.jsjquery-cookie-min.jsjquery-cookie.jsobject_id-min.jsobject_id.jsmdeditor
css
bootstrap-responsive.cssbootstrap.cssindex2.html
smoothness
images
animated-overlay.gifui-bg_flat_0_aaaaaa_40x100.pngui-bg_flat_75_ffffff_40x100.pngui-bg_glass_55_fbf9ee_1x400.pngui-bg_glass_65_ffffff_1x400.pngui-bg_glass_75_dadada_1x400.pngui-bg_glass_75_e6e6e6_1x400.pngui-bg_glass_95_fef1ec_1x400.pngui-bg_highlight-soft_75_cccccc_1x100.pngui-icons_222222_256x240.pngui-icons_2e83ff_256x240.pngui-icons_454545_256x240.pngui-icons_888888_256x240.pngui-icons_cd0a0a_256x240.png
jquery-ui-1.10.2.custom.cssjquery-ui-1.10.2.custom.min.csseditor
Markdown.Extra-min.jsMarkdown.Extra.jscss_browser_selector.jseditor-min.jseditor.csseditor.jseditor2.csseditor2.js
google-code-prettify
lang-apollo.jslang-basic.jslang-clj.jslang-css.jslang-dart.jslang-erlang.jslang-go.jslang-hs.jslang-lisp.jslang-llvm.jslang-lua.jslang-matlab.jslang-ml.jslang-mumps.jslang-n.jslang-pascal.jslang-proto.jslang-r.jslang-rd.jslang-scala.jslang-sql.jslang-tcl.jslang-tex.jslang-vb.jslang-vhdl.jslang-wiki.jslang-xq.jslang-yaml.jsmine.cssprettify.cssprettify.jsrun_prettify.js
jquery.autosize-min.jsjquery.waitforimages-min.jsjquery.waitforimages.jsmathJax-min.jsmathJax.jsmd-helppagedown
LICENSE.txtMarkdown.Converter-min.jsMarkdown.Converter.jsMarkdown.Editor-min.jsMarkdown.Editor.jsMarkdown.Sanitizer-min.jsMarkdown.Sanitizer.jsREADME.txt
scrollLink-min.jsscrollLink.jsunderscore-min.jsunderscore.jsdemo
local
node-pagedown.jspackage.jsonresources
wmd-buttons.pngfont-awesome
css
font
FontAwesome.otffontawesome-webfont.eotfontawesome-webfont.svgfontawesome-webfont.ttffontawesome-webfont.woff
scss
img
mobile
tinymce
classes
AddOnManager.jsCompat.jsEditor.jsEditorCommands.jsEditorManager.jsEnterKey.jsEnv.jsFocusManager.jsForceBlocks.jsFormatter.jsLegacyInput.jsShortcuts.jsUndoManager.jsWindowManager.js
index.htmljquery.tinymce.min.jsdom
ControlSelection.jsDOMUtils.jsDomQuery.jsEventUtils.jsRange.jsRangeUtils.jsScriptLoader.jsSelection.jsSerializer.jsSizzle.jQuery.jsSizzle.jsTreeWalker.jsTridentSelection.js
html
jquery.tinymce.jsui
AbsoluteLayout.jsButton.jsButtonGroup.jsCheckbox.jsCollection.jsColorButton.jsComboBox.jsContainer.jsControl.jsDomUtils.jsDragHelper.jsElementPath.jsFactory.jsFieldSet.jsFilePicker.jsFitLayout.jsFlexLayout.jsFloatPanel.jsFlowLayout.jsForm.jsFormItem.jsFormatControls.jsGridLayout.jsIframe.jsKeyboardNavigation.jsLabel.jsLayout.jsListBox.jsMenu.jsMenuBar.jsMenuButton.jsMenuItem.jsMessageBox.jsMovable.jsPanel.jsPanelButton.jsPath.jsRadio.jsResizable.jsResizeHandle.jsScrollable.jsSelector.jsSpacer.jsSplitButton.jsStackLayout.jsTabPanel.jsTextBox.jsThrobber.jsToolbar.jsTooltip.jsWidget.jsWindow.js
util
langs
plugins
advlist
anchor
autolink
autoresize
autosave
bbcode
charmap
code
codemirror
CodeMirror
.gitattributes.gitignore.travis.ymlAUTHORSCONTRIBUTING.mdLICENSEREADME.mdpackage.json
LICENSE.txtREADME.txtaddon
comment
dialog
display
edit
fold
hint
anyword-hint.jscss-hint.jshtml-hint.jsjavascript-hint.jspig-hint.jspython-hint.jsshow-hint.cssshow-hint.jssql-hint.jsxml-hint.js
lint
merge
mode
runmode
scroll
search
selection
tern
wrap
bin
bower.jsondemo
activeline.htmlanywordhint.htmlbidi.htmlbtree.htmlbuffers.htmlchangemode.htmlclosebrackets.htmlclosetag.htmlcomplete.htmlemacs.htmlfolding.htmlfullscreen.htmlhardwrap.htmlhtml5complete.htmlindentwrap.htmllint.htmlloadmode.htmlmarker.htmlmarkselection.htmlmatchhighlighter.htmlmatchtags.htmlmerge.htmlmultiplex.htmlmustache.htmlplaceholder.htmlpreview.htmlresize.htmlrunmode.htmlsearch.htmlspanaffectswrapping_shim.htmltern.htmltheme.htmltrailingspace.htmlvariableheight.htmlvim.htmlvisibletabs.htmlwidget.htmlxmlcomplete.html
doc
activebookmark.jscompress.htmldocs.cssinternals.htmllogo.pnglogo.svgmanual.htmlrealworld.htmlreleases.htmlreporting.htmlupgrade_v2.2.htmlupgrade_v3.html
index.htmlkeymap
lib
mode
apl
asterisk
clike
clojure
cobol
coffeescript
commonlisp
css
d
diff
dtd
ecl
eiffel
erlang
fortran
gas
gfm
gherkin
go
groovy
haml
haskell
haxe
htmlembedded
htmlmixed
http
index.htmljade
javascript
jinja2
julia
less
livescript
lua
markdown
meta.jsmirc
mllike
nginx
ntriples
octave
pascal
pegjs
perl
php
pig
properties
python
q
r
rpm
rst
ruby
rust
sass
scheme
shell
sieve
smalltalk
smarty
smartymixed
sparql
sql
stex
tcl
tiddlywiki
tiki
toml
turtle
vb
vbscript
velocity
verilog
xml
xquery
yaml
z80
test
comment_test.jsdoc_test.jsdriver.jsemacs_test.jsindex.html
lint
mode_test.cssmode_test.jsphantom_driver.jsrun.jssearch_test.jstest.jsvim_test.jstheme
3024-day.css3024-night.cssambiance-mobile.cssambiance.cssbase16-dark.cssbase16-light.cssblackboard.csscobalt.csseclipse.csselegant.csserlang-dark.csslesser-dark.cssmbo.cssmidnight.cssmonokai.cssneat.cssnight.cssparaiso-dark.cssparaiso-light.csspastel-on-dark.cssrubyblue.csssolarized.cssthe-matrix.csstomorrow-night-eighties.csstwilight.cssvibrant-ink.cssxq-dark.cssxq-light.css
img
langs
plugin.jsplugin.min.jssource.htmlcodesyntax
compat3x
contextmenu
directionality
emoticons
img
smiley-cool.gifsmiley-cry.gifsmiley-embarassed.gifsmiley-foot-in-mouth.gifsmiley-frown.gifsmiley-innocent.gifsmiley-kiss.gifsmiley-laughing.gifsmiley-money-mouth.gifsmiley-sealed.gifsmiley-smile.gifsmiley-surprised.gifsmiley-tongue-out.gifsmiley-undecided.gifsmiley-wink.gifsmiley-yell.gif
plugin.jsplugin.min.jsexample
example_dependency
fullpage
fullscreen
hr
image
importcss
insertdatetime
layer
leanote_code
leanote_image
leanote_nav
legacyoutput
link
lists
media
nonbreaking
noneditable
pagebreak
paste
preview
print
save
searchreplace
spellchecker
tabfocus
table
template
textcolor
upload_image
visualblocks
css
img
address.gifarticle.gifaside.gifblockquote.gifdiv.giffigure.gifh1.gifh2.gifh3.gifh4.gifh5.gifh6.gifhgroup.gifol.gifp.gifpre.gifsection.giful.gif
plugin.jsplugin.min.jsvisualchars
wordcount
skins
custom
content.inline.min.csscontent.min.css
fonts
icomoon-small.eoticomoon-small.svgicomoon-small.ttficomoon-small.wofficomoon.eoticomoon.svgicomoon.ttficomoon.woffreadme.md
img
skin.ie7.min.cssskin.jsonskin.min.csslightgray
AbsoluteLayout.lessAnimations.lessButton.lessButtonGroup.lessCheckbox.lessColorButton.lessComboBox.lessContainer.lessContent.Inline.lessContent.Objects.lessContent.lessFieldSet.lessFitLayout.lessFloatPanel.lessFlowLayout.lessIcons.Ie7.lessIcons.lessIframe.lessLabel.lessListBox.lessMenu.lessMenuBar.lessMenuButton.lessMenuItem.lessMixins.lessPanel.lessPath.lessRadio.lessReset.lessResizeHandle.lessScrollable.lessSpacer.lessSplitButton.lessStackLayout.lessTabPanel.lessTextBox.lessThrobber.lessTinyMCE.lessToolTip.lessVariables.lessWindow.lesscontent.inline.min.csscontent.min.css
fonts
readme.mdtinymce-small.dev.svgtinymce-small.eottinymce-small.svgtinymce-small.ttftinymce-small.wofftinymce.dev.svgtinymce.eottinymce.svgtinymce.ttftinymce.woff
img
skin.dev.lessskin.ie7.lessskin.ie7.min.cssskin.lessskin.min.cssthemes
modern
upload
52d3e8ac99c37b7f0d000001
5368c9fc99c37b095a000006
images
245
app/controllers/NoteController.go
Normal file
245
app/controllers/NoteController.go
Normal file
@ -0,0 +1,245 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"github.com/revel/revel"
|
||||
// "encoding/json"
|
||||
"labix.org/v2/mgo/bson"
|
||||
. "github.com/leanote/leanote/app/lea"
|
||||
"github.com/leanote/leanote/app/lea/html2image"
|
||||
"github.com/leanote/leanote/app/info"
|
||||
// "os"
|
||||
// "github.com/leanote/leanote/app/types"
|
||||
// "io/ioutil"
|
||||
// "fmt"
|
||||
)
|
||||
|
||||
type Note struct {
|
||||
BaseController
|
||||
}
|
||||
|
||||
// 笔记首页, 判断是否已登录
|
||||
// 已登录, 得到用户基本信息(notebook, shareNotebook), 跳转到index.html中
|
||||
// 否则, 转向登录页面
|
||||
func (c Note) Index() revel.Result {
|
||||
c.SetLocale()
|
||||
|
||||
userInfo := c.GetUserInfo()
|
||||
|
||||
userId := userInfo.UserId.Hex()
|
||||
|
||||
// 没有登录
|
||||
if userId == "" {
|
||||
return c.Redirect("/login")
|
||||
}
|
||||
|
||||
// 已登录了, 那么得到所有信息
|
||||
notebooks := notebookService.GetNotebooks(userId)
|
||||
shareNotebooks, sharedUserInfos := shareService.GetShareNotebooks(userId)
|
||||
|
||||
// 还需要按时间排序(DESC)得到notes
|
||||
notes := []info.Note{}
|
||||
noteContent := info.NoteContent{}
|
||||
if len(notebooks) > 0 {
|
||||
// _, notes = noteService.ListNotes(c.GetUserId(), "", false, c.GetPage(), pageSize, defaultSortField, false, false);
|
||||
// 变成最新
|
||||
_, notes = noteService.ListNotes(c.GetUserId(), "", false, c.GetPage(), 50, defaultSortField, false, false);
|
||||
if len(notes) > 0 {
|
||||
noteContent = noteService.GetNoteContent(notes[0].NoteId.Hex(), userId)
|
||||
}
|
||||
}
|
||||
// 当然, 还需要得到第一个notes的content
|
||||
//...
|
||||
|
||||
c.RenderArgs["userInfo"] = userInfo
|
||||
c.RenderArgs["userInfoJson"] = c.Json(userInfo)
|
||||
c.RenderArgs["notebooks"] = c.Json(notebooks)
|
||||
c.RenderArgs["shareNotebooks"] = c.Json(shareNotebooks)
|
||||
c.RenderArgs["sharedUserInfos"] = c.Json(sharedUserInfos)
|
||||
|
||||
c.RenderArgs["notes"] = c.Json(notes)
|
||||
c.RenderArgs["noteContentJson"] = c.Json(noteContent)
|
||||
c.RenderArgs["noteContent"] = noteContent.Content
|
||||
|
||||
c.RenderArgs["tagsJson"] = c.Json(tagService.GetTags(c.GetUserId()))
|
||||
|
||||
if isDev, _ := revel.Config.Bool("mode.dev"); isDev {
|
||||
return c.RenderTemplate("note/note-dev.html")
|
||||
} else {
|
||||
return c.RenderTemplate("note/note.html")
|
||||
}
|
||||
}
|
||||
|
||||
// 首页, 判断是否已登录
|
||||
// 已登录, 得到用户基本信息(notebook, shareNotebook), 跳转到index.html中
|
||||
// 否则, 转向登录页面
|
||||
func (c Note) ListNotes(notebookId string) revel.Result {
|
||||
_, notes := noteService.ListNotes(c.GetUserId(), notebookId, false, c.GetPage(), pageSize, defaultSortField, false, false);
|
||||
return c.RenderJson(notes)
|
||||
}
|
||||
|
||||
// 得到trash
|
||||
func (c Note) ListTrashNotes() revel.Result {
|
||||
_, notes := noteService.ListNotes(c.GetUserId(), "", true, c.GetPage(), pageSize, defaultSortField, false, false);
|
||||
return c.RenderJson(notes)
|
||||
}
|
||||
|
||||
// 得到内容
|
||||
func (c Note) GetNoteContent(noteId string) revel.Result {
|
||||
noteContent := noteService.GetNoteContent(noteId, c.GetUserId())
|
||||
return c.RenderJson(noteContent)
|
||||
}
|
||||
|
||||
// 更新note或content
|
||||
// 肯定会传userId(谁的), NoteId
|
||||
// 会传Title, Content, Tags, 一种或几种
|
||||
type NoteOrContent struct {
|
||||
NotebookId string
|
||||
NoteId string
|
||||
UserId string
|
||||
Title string
|
||||
Desc string
|
||||
ImgSrc string
|
||||
Tags []string
|
||||
Content string
|
||||
Abstract string
|
||||
IsNew bool
|
||||
IsMarkdown bool
|
||||
FromUserId string // 为共享而新建
|
||||
IsBlog bool // 是否是blog, 更新note不需要修改, 添加note时才有可能用到, 此时需要判断notebook是否设为Blog
|
||||
}
|
||||
// 这里不能用json, 要用post
|
||||
func (c Note) UpdateNoteOrContent(noteOrContent NoteOrContent) revel.Result {
|
||||
// 新添加note
|
||||
LogJ(noteOrContent)
|
||||
if noteOrContent.IsNew {
|
||||
userId := c.GetObjectUserId();
|
||||
myUserId := userId
|
||||
// 为共享新建?
|
||||
if noteOrContent.FromUserId != "" {
|
||||
userId = bson.ObjectIdHex(noteOrContent.FromUserId)
|
||||
}
|
||||
|
||||
note := info.Note{UserId: userId,
|
||||
NoteId: bson.ObjectIdHex(noteOrContent.NoteId),
|
||||
NotebookId: bson.ObjectIdHex(noteOrContent.NotebookId),
|
||||
Title: noteOrContent.Title,
|
||||
Tags: noteOrContent.Tags,
|
||||
Desc: noteOrContent.Desc,
|
||||
ImgSrc: noteOrContent.ImgSrc,
|
||||
IsBlog: noteOrContent.IsBlog,
|
||||
IsMarkdown: noteOrContent.IsMarkdown,
|
||||
};
|
||||
noteContent := info.NoteContent{NoteId: note.NoteId,
|
||||
UserId: userId,
|
||||
IsBlog: note.IsBlog,
|
||||
Content: noteOrContent.Content,
|
||||
Abstract: noteOrContent.Abstract};
|
||||
|
||||
note = noteService.AddNoteAndContent(note, noteContent, myUserId)
|
||||
return c.RenderJson(note)
|
||||
}
|
||||
|
||||
noteUpdate := bson.M{}
|
||||
needUpdateNote := false
|
||||
|
||||
// Desc前台传来
|
||||
if c.Has("Desc") {
|
||||
needUpdateNote = true
|
||||
noteUpdate["Desc"] = noteOrContent.Desc;
|
||||
}
|
||||
if c.Has("ImgSrc") {
|
||||
needUpdateNote = true
|
||||
noteUpdate["ImgSrc"] = noteOrContent.ImgSrc;
|
||||
}
|
||||
if c.Has("Title") {
|
||||
needUpdateNote = true
|
||||
noteUpdate["Title"] = noteOrContent.Title;
|
||||
}
|
||||
|
||||
if c.Has("Tags[]") {
|
||||
needUpdateNote = true
|
||||
noteUpdate["Tags"] = noteOrContent.Tags;
|
||||
}
|
||||
|
||||
if needUpdateNote {
|
||||
noteService.UpdateNote(noteOrContent.UserId, c.GetUserId(),
|
||||
noteOrContent.NoteId, noteUpdate)
|
||||
}
|
||||
|
||||
//-------------
|
||||
|
||||
if c.Has("Content") {
|
||||
noteService.UpdateNoteContent(noteOrContent.UserId, c.GetUserId(),
|
||||
noteOrContent.NoteId, noteOrContent.Content, noteOrContent.Abstract)
|
||||
}
|
||||
|
||||
return c.RenderJson(true)
|
||||
}
|
||||
|
||||
// 删除note/ 删除别人共享给我的笔记
|
||||
// userId 是note.UserId
|
||||
func (c Note) DeleteNote(noteId, userId string, isShared bool) revel.Result {
|
||||
if(!isShared) {
|
||||
return c.RenderJson(trashService.DeleteNote(noteId, c.GetUserId()));
|
||||
}
|
||||
|
||||
return c.RenderJson(trashService.DeleteSharedNote(noteId, userId, c.GetUserId()));
|
||||
}
|
||||
// 删除trash
|
||||
func (c Note) DeleteTrash(noteId string) revel.Result {
|
||||
return c.RenderJson(trashService.DeleteTrash(noteId, c.GetUserId()));
|
||||
}
|
||||
// 移动note
|
||||
func (c Note) MoveNote(noteId, notebookId string) revel.Result {
|
||||
return c.RenderJson(noteService.MoveNote(noteId, notebookId, c.GetUserId()));
|
||||
}
|
||||
// 复制note
|
||||
func (c Note) CopyNote(noteId, notebookId string) revel.Result {
|
||||
return c.RenderJson(noteService.CopyNote(noteId, notebookId, c.GetUserId()));
|
||||
}
|
||||
// 复制别人共享的笔记给我
|
||||
func (c Note) CopySharedNote(noteId, notebookId, fromUserId string) revel.Result {
|
||||
return c.RenderJson(noteService.CopySharedNote(noteId, notebookId, fromUserId, c.GetUserId()));
|
||||
}
|
||||
|
||||
//------------
|
||||
// search
|
||||
// 通过title搜索
|
||||
func (c Note) SearchNote(key string) revel.Result {
|
||||
_, blogs := noteService.SearchNote(key, c.GetUserId(), c.GetPage(), pageSize, "UpdatedTime", false, false)
|
||||
return c.RenderJson(blogs)
|
||||
}
|
||||
// 通过tags搜索
|
||||
func (c Note) SearchNoteByTags(tags []string) revel.Result {
|
||||
_, blogs := noteService.SearchNoteByTags(tags, c.GetUserId(), c.GetPage(), pageSize, "UpdatedTime", false)
|
||||
return c.RenderJson(blogs)
|
||||
}
|
||||
|
||||
//-----------------
|
||||
// html2image
|
||||
func (c Note) Html2Image(noteId string) revel.Result {
|
||||
re := info.NewRe()
|
||||
userId := c.GetUserId()
|
||||
note := noteService.GetNote(noteId, userId)
|
||||
if note.NoteId == "" {
|
||||
return c.RenderJson(re)
|
||||
}
|
||||
content := noteService.GetNoteContent(noteId, userId)
|
||||
|
||||
// path 判断是否需要重新生成之
|
||||
fileUrlPath := "/upload/" + userId + "/images/weibo"
|
||||
dir := revel.BasePath + "/public/" + fileUrlPath
|
||||
if !ClearDir(dir) {
|
||||
return c.RenderJson(re)
|
||||
}
|
||||
|
||||
filename := note.NoteId.Hex() + ".png";
|
||||
path := dir + "/" + filename
|
||||
|
||||
// 生成之
|
||||
html2image.ToImage(userId, c.GetUsername(), noteId, note.Title, content.Content, path)
|
||||
|
||||
re.Ok = true
|
||||
re.Id = fileUrlPath + "/" + filename
|
||||
return c.RenderJson(re)
|
||||
}
|
Reference in New Issue
Block a user