batch ok
This commit is contained in:
1 parent
29244c247e
commit
263c03291e
21 files changed
+1037
-294
No files matched your search
@@ -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)
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
// <img src="/file/outputImage?fileId=12323232" />
|
||||
// 把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进行复制
|
||||
|
||||
// <img src="/file/outputImage?fileId=12323232" />
|
||||
// 把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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -83,6 +83,8 @@ function log(o) {
|
||||
</a>
|
||||
<span class="for-split"> - </span>
|
||||
<span id="curNotebookForNewNote" notebookId=""></span>
|
||||
|
||||
<!--
|
||||
<div class="dropdown" style="display: inline-block">
|
||||
<a class="ios7-a dropdown-toggle"
|
||||
id="listNotebookDropdownMenu" data-toggle="dropdown">
|
||||
@@ -94,6 +96,8 @@ function log(o) {
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
-->
|
||||
|
||||
</div>
|
||||
|
||||
<!-- 只为新建别人的笔记 -->
|
||||
@@ -104,12 +108,14 @@ function log(o) {
|
||||
<span class="new-note-text-abbr">{{msg . "new"}}</span>
|
||||
</a>
|
||||
<span class="new-split">|</span>
|
||||
<a id="newShareNoteMarkdownBtn" class="new-note" title="{{msg . "newMarkdown"}}">
|
||||
<a id="newShareNoteMarkdownBtn" class="new-note new-markdown" title="{{msg . "newMarkdown"}}">
|
||||
<span class="new-markdown-text">{{msg . "newMarkdown"}}</span>
|
||||
<span class="new-markdown-text-abbr">Md</span>
|
||||
</a>
|
||||
<span class="for-split"> - </span>
|
||||
<span id="curNotebookForNewSharedNote" notebookId="" userId=""></span>
|
||||
|
||||
<!--
|
||||
<div class="dropdown" style="display: inline-block">
|
||||
<a id="listShareNotebookDropdownMenu" class="ios7-a dropdown-toggle" data-toggle="dropdown">
|
||||
<i class="fa fa-angle-down"></i>
|
||||
@@ -118,6 +124,7 @@ function log(o) {
|
||||
<ul id="notebookNavForNewSharedNote"></ul>
|
||||
</div>
|
||||
</div>
|
||||
-->
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -420,12 +427,13 @@ function log(o) {
|
||||
|
||||
<!-- 遮罩, 为了resize3Columns用 -->
|
||||
<div id="noteMask" class="note-mask"></div>
|
||||
<div id="noteMaskForLoading" class="note-mask">
|
||||
<div id="noteMaskForLoading" class="note-mask"> <!-- z-index: 11 -->
|
||||
<img src="/images/loading-24.gif"/>
|
||||
<br />
|
||||
loading...
|
||||
</div>
|
||||
<div id="editorMask">
|
||||
<!-- for tips -->
|
||||
<div id="editorMask"> <!-- z-index: 10 -->
|
||||
{{msg . "noNoteNewNoteTips"}}
|
||||
<br />
|
||||
<br />
|
||||
@@ -437,6 +445,16 @@ function log(o) {
|
||||
{{msg . "canntNewNoteTips"}}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="batchMask" class="note-mask"> <!-- z-index: 99 -->
|
||||
<div class="batch-ctn" id="batchCtn"></div>
|
||||
<div class="batch-info">
|
||||
{{leaMsg . "<span></span> notes selected"}}
|
||||
<p><i class="fa fa-cog"></i></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div id="noteTop">
|
||||
<!-- 左侧放tag, 右侧放按钮, 比如save, info, move, delete -->
|
||||
<div id="tool" class="clearfix">
|
||||
@@ -842,7 +860,6 @@ function log(o) {
|
||||
|
||||
<script>
|
||||
var LEA = {};
|
||||
LEA.s1 = new Date();
|
||||
LEA.locale = "{{.locale}}";
|
||||
var UrlPrefix = '{{.siteUrl}}';
|
||||
var UserInfo = {{.userInfo|jsonJs}};
|
||||
@@ -887,7 +904,6 @@ var GlobalConfigs = {{.globalConfigs|jsonJs}};
|
||||
<!-- /dev -->
|
||||
|
||||
<!-- pro_app_js -->
|
||||
|
||||
<script>
|
||||
initPage();
|
||||
// 当tinymce.dev.js时, 请注释require
|
||||
@@ -904,6 +920,5 @@ window.require = {
|
||||
<!-- /dev -->
|
||||
|
||||
<script src="/public/js/plugins/main.js"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
Reference in new issue
Block a user