diff --git a/app/controllers/NoteController.go b/app/controllers/NoteController.go
index 6e6acab..bc428ac 100644
--- a/app/controllers/NoteController.go
+++ b/app/controllers/NoteController.go
@@ -259,28 +259,59 @@ func (c Note) UpdateNoteOrContent(noteOrContent NoteOrContent) revel.Result {
// 删除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()));
+func (c Note) DeleteNote(noteIds []string, isShared bool) revel.Result {
+ if !isShared {
+ for _, noteId := range noteIds {
+ trashService.DeleteNote(noteId, c.GetUserId())
+ }
+ return c.RenderJson(true)
}
-
- return c.RenderJson(trashService.DeleteSharedNote(noteId, userId, c.GetUserId()));
+
+ for _, noteId := range noteIds {
+ trashService.DeleteSharedNote(noteId, c.GetUserId())
+ }
+
+ return c.RenderJson(true)
}
-// 删除trash
+
+// 删除trash, 已弃用, 用DeleteNote
func (c Note) DeleteTrash(noteId string) revel.Result {
- return c.RenderJson(trashService.DeleteTrash(noteId, c.GetUserId()));
+ 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()));
+func (c Note) MoveNote(noteIds []string, notebookId string) revel.Result {
+ userId := c.GetUserId()
+ for _, noteId := range noteIds {
+ noteService.MoveNote(noteId, notebookId, userId)
+ }
+ return c.RenderJson(true)
}
+
// 复制note
-func (c Note) CopyNote(noteId, notebookId string) revel.Result {
- return c.RenderJson(noteService.CopyNote(noteId, notebookId, c.GetUserId()));
+func (c Note) CopyNote(noteIds []string, notebookId string) revel.Result {
+ copyNotes := make([]info.Note, len(noteIds))
+ userId := c.GetUserId()
+ for i, noteId := range noteIds {
+ copyNotes[i] = noteService.CopyNote(noteId, notebookId, userId)
+ }
+ re := info.NewRe()
+ re.Ok = true
+ re.Item = copyNotes
+ return c.RenderJson(re)
}
+
// 复制别人共享的笔记给我
-func (c Note) CopySharedNote(noteId, notebookId, fromUserId string) revel.Result {
- return c.RenderJson(noteService.CopySharedNote(noteId, notebookId, fromUserId, c.GetUserId()));
+func (c Note) CopySharedNote(noteIds []string, notebookId, fromUserId string) revel.Result {
+ copyNotes := make([]info.Note, len(noteIds))
+ userId := c.GetUserId()
+ for i, noteId := range noteIds {
+ copyNotes[i] = noteService.CopySharedNote(noteId, notebookId, fromUserId, userId)
+ }
+ re := info.NewRe()
+ re.Ok = true
+ re.Item = copyNotes
+ return c.RenderJson(re)
}
//------------
@@ -290,6 +321,7 @@ 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)
@@ -456,7 +488,9 @@ func (c Note) ExportPdf(noteId string) revel.Result {
}
// 设置/取消Blog; 置顶
-func (c Note) SetNote2Blog(noteId string, isBlog, isTop bool) revel.Result {
- re := noteService.ToBlog(c.GetUserId(), noteId, isBlog, isTop)
- return c.RenderJson(re)
+func (c Note) SetNote2Blog(noteIds []string, isBlog, isTop bool) revel.Result {
+ for _, noteId := range noteIds {
+ noteService.ToBlog(c.GetUserId(), noteId, isBlog, isTop)
+ }
+ return c.RenderJson(true)
}
diff --git a/app/service/NoteImageService.go b/app/service/NoteImageService.go
index fde855d..cbf538b 100644
--- a/app/service/NoteImageService.go
+++ b/app/service/NoteImageService.go
@@ -73,17 +73,13 @@ func (this *NoteImageService) UpdateNoteImages(userId, noteId, imgSrc, content s
// 复制图片, 把note的图片都copy给我, 且修改noteContent图片路径
func (this *NoteImageService) CopyNoteImages(fromNoteId, fromUserId, newNoteId, content, toUserId string) string {
+ /* 弃用之
// 得到fromNoteId的noteImages, 如果为空, 则直接返回content
noteImages := []info.NoteImage{}
db.ListByQWithFields(db.NoteImages, bson.M{"NoteId": bson.ObjectIdHex(fromNoteId)}, []string{"ImageId"}, ¬eImages)
-
if len(noteImages) == 0 {
return content;
}
-
- //
- // 把fileId=1232替换成新的
- replaceMap := map[string]string{}
for _, noteImage := range noteImages {
imageId := noteImage.ImageId.Hex()
ok, newImageId := fileService.CopyImage(fromUserId, imageId, toUserId)
@@ -91,20 +87,44 @@ func (this *NoteImageService) CopyNoteImages(fromNoteId, fromUserId, newNoteId,
replaceMap[imageId] = newImageId
}
}
-
- if len(replaceMap) > 0 {
- // 替换之
- reg, _ := regexp.Compile("outputImage\\?fileId=([a-z0-9A-Z]{24})")
- content = reg.ReplaceAllStringFunc(content, func(each string) string {
- // each=outputImage?fileId=541bd2f599c37b4f3r000003
- fileId := each[len(each)-24:] // 得到后24位, 也即id
- if replaceFileId, ok := replaceMap[fileId]; ok {
+ */
+
+ // 因为很多图片上传就会删除, 所以直接从内容中查看图片id进行复制
+
+ //
+ // 把fileId=1232替换成新的
+ replaceMap := map[string]string{}
+
+ reg, _ := regexp.Compile("(outputImage|getImage)\\?fileId=([a-z0-9A-Z]{24})")
+ content = reg.ReplaceAllStringFunc(content, func(each string) string {
+ // each = outputImage?fileId=541bd2f599c37b4f3r000003
+ // each = getImage?fileId=541bd2f599c37b4f3r000003
+
+ fileId := each[len(each)-24:] // 得到后24位, 也即id
+
+ if _, ok := replaceMap[fileId]; !ok {
+ if bson.IsObjectIdHex(fileId) {
+ ok2, newImageId := fileService.CopyImage(fromUserId, fileId, toUserId)
+ if ok2 {
+ replaceMap[fileId] = newImageId
+ } else {
+ replaceMap[fileId] = ""
+ }
+ } else {
+ replaceMap[fileId] = ""
+ }
+ }
+
+ replaceFileId := replaceMap[fileId]
+ if replaceFileId != "" {
+ if each[0] == 'o' {
return "outputImage?fileId=" + replaceFileId
}
- return each
- });
- }
-
+ return "getImage?fileId=" + replaceFileId
+ }
+ return each
+ });
+
return content;
}
diff --git a/app/service/NoteService.go b/app/service/NoteService.go
index e06792a..e600923 100644
--- a/app/service/NoteService.go
+++ b/app/service/NoteService.go
@@ -664,11 +664,11 @@ func (this *NoteService) CopyNote(noteId, notebookId, userId string) info.Note {
note.NotebookId = bson.ObjectIdHex(notebookId)
noteContent.NoteId = note.NoteId
- this.AddNoteAndContent(note, noteContent, note.UserId);
-
+ note = this.AddNoteAndContent(note, noteContent, note.UserId);
+
// 更新blog状态
isBlog := this.updateToNotebookBlog(note.NoteId.Hex(), notebookId, userId)
-
+
// recount
notebookService.ReCountNotebookNumberNotes(notebookId)
@@ -683,16 +683,15 @@ func (this *NoteService) CopyNote(noteId, notebookId, userId string) info.Note {
// 复制别人的共享笔记给我
// 将别人可用的图片转为我的图片, 复制图片
func (this *NoteService) CopySharedNote(noteId, notebookId, fromUserId, myUserId string) info.Note {
- // Log(shareService.HasSharedNote(noteId, myUserId) || shareService.HasSharedNotebook(noteId, myUserId, fromUserId))
// 判断是否共享了给我
- if notebookService.IsMyNotebook(notebookId, myUserId) &&
- (shareService.HasSharedNote(noteId, myUserId) || shareService.HasSharedNotebook(noteId, myUserId, fromUserId)) {
+ // Log(notebookService.IsMyNotebook(notebookId, myUserId))
+ if notebookService.IsMyNotebook(notebookId, myUserId) && shareService.HasReadPerm(fromUserId, myUserId, noteId) {
note := this.GetNote(noteId, fromUserId)
if note.NoteId == "" {
return info.Note{}
}
noteContent := this.GetNoteContent(noteId, fromUserId)
-
+
// 重新生成noteId
note.NoteId = bson.NewObjectId();
note.NotebookId = bson.ObjectIdHex(notebookId)
diff --git a/app/service/TrashService.go b/app/service/TrashService.go
index 0cc92ed..366a30e 100644
--- a/app/service/TrashService.go
+++ b/app/service/TrashService.go
@@ -25,6 +25,12 @@ type TrashService struct {
// 应该放在回收站里
// 有trashService
func (this *TrashService) DeleteNote(noteId, userId string) bool {
+ note := noteService.GetNote(noteId, userId);
+ // 如果是垃圾, 则彻底删除
+ if (note.IsTrash) {
+ return this.DeleteTrash(noteId, userId)
+ }
+
// 首先删除其共享
if shareService.DeleteShareNoteAll(noteId, userId) {
// 更新note isTrash = true
@@ -36,13 +42,15 @@ func (this *TrashService) DeleteNote(noteId, userId string) bool {
return true
}
}
+
return false
}
// 删除别人共享给我的笔记
// 先判断我是否有权限, 笔记是否是我创建的
-func (this *TrashService) DeleteSharedNote(noteId, userId, myUserId string) bool {
- note := noteService.GetNote(noteId, userId)
+func (this *TrashService) DeleteSharedNote(noteId, myUserId string) bool {
+ note := noteService.GetNoteById(noteId)
+ userId := note.UserId.Hex()
if shareService.HasUpdatePerm(userId, myUserId, noteId) && note.CreatedUserId.Hex() == myUserId {
return db.UpdateByIdAndUserId(db.Notes, noteId, userId, bson.M{"$set": bson.M{"IsTrash": true, "Usn": userService.IncrUsn(userId)}})
}
@@ -116,4 +124,4 @@ func (this *TrashService) ListNotes(userId string,
pageNumber, pageSize int, sortField string, isAsc bool) (notes []info.Note) {
_, notes = noteService.ListNotes(userId, "", true, pageNumber, pageSize, sortField, isAsc, false)
return
-}
\ No newline at end of file
+}
diff --git a/app/views/note/note-dev.html b/app/views/note/note-dev.html
index 0caf1fd..2eaa03d 100644
--- a/app/views/note/note-dev.html
+++ b/app/views/note/note-dev.html
@@ -83,6 +83,8 @@ function log(o) {
-
+
+
+
@@ -104,12 +108,14 @@ function log(o) {
{{msg . "new"}}
|
-
+
{{msg . "newMarkdown"}}
Md
-
+
+
@@ -420,12 +427,13 @@ function log(o) {
+