From 5bf1d1b5ecce673de10bff654337df56bf361a3f Mon Sep 17 00:00:00 2001 From: life Date: Mon, 19 Jan 2015 00:03:46 +0800 Subject: [PATCH] notebook,note, tag OK --- index.html | 858 ++++++++++++++++++ main copy.js | 26 - node_modules/common.js | 4 + node_modules/note.js | 9 + node_modules/objectid.js | 109 +++ node_modules/tag.js | 66 +- npm-debug.log | 25 - public/js/app/page.js | 5 +- public/js/app/service.js | 3 +- public/js/app/tag.js | 4 +- .../plugins/leanote_code/plugin.min.js | 1 + 11 files changed, 1054 insertions(+), 56 deletions(-) create mode 100755 index.html delete mode 100755 main copy.js create mode 100644 node_modules/objectid.js delete mode 100644 npm-debug.log create mode 100644 public/tinymce/plugins/leanote_code/plugin.min.js diff --git a/index.html b/index.html new file mode 100755 index 00000000..994b2084 --- /dev/null +++ b/index.html @@ -0,0 +1,858 @@ + + + + + + + + + + +Leanote, Not Just A Notebook + + + + + + + + + + + + + + + + + + +
+
+ + + + + +
+
+ +
+
+ loading... +
+
+
+
+
+ + + Notebook + +
+ +
+
+ +
+ +
    +
      +
      +
      + +
      +
      + + + Tag + +
      + + +
      + +
      +
      + + + Recent Notes + +
      + +
        +
      +
      + + + +
      + + +
      + +
      + + +
      +
      + + +
      +
      +
      + +
      +
      +
      + + +
      + +
      + +
      +
      + +
      + loading... +
      +
      +
      +
      + + + + + + +
      + +
      +
      +
      + +
      +
      + + + +
      +
        +
      +
      +
      + +
      + +
      + +
      +
      +
      +

      +
      + + + + + Update + + + + Create + +
      +
      + +
      +
      +
      +
      + +
      +
      + +
      + loading... +
      +
      + The notebook is empty, why not... +
      +
      + +
      + Sorry, cannot new note in here, please choose a notebook at first. +
      +
      +
      + +
      + + + + +
      +
      +
      + + +
      + + +
      + +
      + +
      +
      + +
      + +
      +
      + + +
      +
      +
      +

      + + Note nav +

      +
      +
      +
      + + +
      +
      + Drop images to here + +
      +
        +
      +
      + + +
      + {{.noteContent}} +
      +
      + +
      + + +
      +
      + +
      +
      +
      +
      +
      +
      +
      +
      +
      +
      +
      +
      +
      +
      +
      +
      +
      +
      +

      + + Note nav +

      +
      +
      +
      +
      +
      +
      +
      + + +
      +
      +
      + + + + + + + + + + + + + + + + + + + + + + + + + +
      +
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/main copy.js b/main copy.js deleted file mode 100755 index aeb46b3b..00000000 --- a/main copy.js +++ /dev/null @@ -1,26 +0,0 @@ -global.$ = $; - -var abar = require('address_bar'); -var folder_view = require('folder_view'); -var path = require('path'); -var shell = require('nw.gui').Shell; - -$(document).ready(function() { - var folder = new folder_view.Folder($('#files')); - var addressbar = new abar.AddressBar($('#addressbar')); - - folder.open(process.cwd()); - addressbar.set(process.cwd()); - - folder.on('navigate', function(dir, mime) { - if (mime.type == 'folder') { - addressbar.enter(mime); - } else { - shell.openItem(mime.path); - } - }); - - addressbar.on('navigate', function(dir) { - folder.open(dir); - }); -}); diff --git a/node_modules/common.js b/node_modules/common.js index e0f58fa2..20335d8d 100644 --- a/node_modules/common.js +++ b/node_modules/common.js @@ -2,6 +2,7 @@ var fs = require('fs'); var User = require('user'); var Image = require('image'); var Evt = require('evt'); +var ObjectId = require('objectid'); // var gui = require('nw.gui'); // console.log(gui.App); @@ -9,6 +10,9 @@ var Evt = require('evt'); function log(o) {console.log(o)} var Common = { + objectId: function() { + return ObjectId() + }, _uuid: 1, uuid: function() { this._uuid++; diff --git a/node_modules/note.js b/node_modules/note.js index e6391f4e..70e5f85f 100644 --- a/node_modules/note.js +++ b/node_modules/note.js @@ -1,6 +1,7 @@ var db = require('db'); var User = require('user'); var Notebook = require('notebook'); +var Tag = require('tag'); var Notes = db.notes; function log(o) { @@ -50,6 +51,10 @@ var Note = { // 重新统计笔记本的笔记数量 Notebook.reCountNotebookNumberNotes(noteOrContent.NotebookId); + // 标签 + if(noteOrContent.Tags && noteOrContent.Tags.length > 0) { + Tag.addTags(noteOrContent.Tags); + } } }); // 更新笔记 @@ -73,6 +78,10 @@ var Note = { callback && callback(false); } else { callback && callback(noteOrContent); + // 标签 + if(noteOrContent.Tags && noteOrContent.Tags.length > 0) { + Tag.addTags(noteOrContent.Tags); + } } }); } diff --git a/node_modules/objectid.js b/node_modules/objectid.js new file mode 100644 index 00000000..72fd6192 --- /dev/null +++ b/node_modules/objectid.js @@ -0,0 +1,109 @@ +/* +* +* Copyright (c) 2011 Justin Dearing (zippy1981@gmail.com) +* Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) +* and GPL (http://www.opensource.org/licenses/gpl-license.php) version 2 licenses. +* This software is not distributed under version 3 or later of the GPL. +* +* Version 1.0.1-dev +* +*/ + +/** + * Javascript class that mimics how WCF serializes a object of type MongoDB.Bson.ObjectId + * and converts between that format and the standard 24 character representation. +*/ +var ObjectId = (function () { + var increment = 0; + var pid = Math.floor(Math.random() * (32767)); + var machine = Math.floor(Math.random() * (16777216)); + + /* + if (typeof (localStorage) != 'undefined') { + var mongoMachineId = parseInt(localStorage['mongoMachineId']); + if (mongoMachineId >= 0 && mongoMachineId <= 16777215) { + machine = Math.floor(localStorage['mongoMachineId']); + } + // Just always stick the value in. + localStorage['mongoMachineId'] = machine; + document.cookie = 'mongoMachineId=' + machine + ';expires=Tue, 19 Jan 2038 05:00:00 GMT' + } + else { + var cookieList = document.cookie.split('; '); + for (var i in cookieList) { + var cookie = cookieList[i].split('='); + if (cookie[0] == 'mongoMachineId' && cookie[1] >= 0 && cookie[1] <= 16777215) { + machine = cookie[1]; + break; + } + } + document.cookie = 'mongoMachineId=' + machine + ';expires=Tue, 19 Jan 2038 05:00:00 GMT'; + + } + */ + + function ObjId() { + if (!(this instanceof ObjectId)) { + return new ObjectId(arguments[0], arguments[1], arguments[2], arguments[3]).toString(); + } + + if (typeof (arguments[0]) == 'object') { + this.timestamp = arguments[0].timestamp; + this.machine = arguments[0].machine; + this.pid = arguments[0].pid; + this.increment = arguments[0].increment; + } + else if (typeof (arguments[0]) == 'string' && arguments[0].length == 24) { + this.timestamp = Number('0x' + arguments[0].substr(0, 8)), + this.machine = Number('0x' + arguments[0].substr(8, 6)), + this.pid = Number('0x' + arguments[0].substr(14, 4)), + this.increment = Number('0x' + arguments[0].substr(18, 6)) + } + else if (arguments.length == 4 && arguments[0] != null) { + this.timestamp = arguments[0]; + this.machine = arguments[1]; + this.pid = arguments[2]; + this.increment = arguments[3]; + } + else { + this.timestamp = Math.floor(new Date().valueOf() / 1000); + this.machine = machine; + this.pid = pid; + this.increment = increment++; + if (increment > 0xffffff) { + increment = 0; + } + } + }; + return ObjId; +})(); + +ObjectId.prototype.getDate = function () { + return new Date(this.timestamp * 1000); +}; + +ObjectId.prototype.toArray = function () { + var strOid = this.toString(); + var array = []; + var i; + for(i = 0; i < 12; i++) { + array[i] = parseInt(strOid.slice(i*2, i*2+2), 16); + } + return array; +}; + +/** +* Turns a WCF representation of a BSON ObjectId into a 24 character string representation. +*/ +ObjectId.prototype.toString = function () { + var timestamp = this.timestamp.toString(16); + var machine = this.machine.toString(16); + var pid = this.pid.toString(16); + var increment = this.increment.toString(16); + return '00000000'.substr(0, 8 - timestamp.length) + timestamp + + '000000'.substr(0, 6 - machine.length) + machine + + '0000'.substr(0, 4 - pid.length) + pid + + '000000'.substr(0, 6 - increment.length) + increment; +}; + +module.exports = ObjectId; \ No newline at end of file diff --git a/node_modules/tag.js b/node_modules/tag.js index ab64dc5d..4a3eabcc 100644 --- a/node_modules/tag.js +++ b/node_modules/tag.js @@ -1,6 +1,70 @@ var db = require('db'); +var Common = require('common'); +var User = require('user'); +var Tags = db.tags; +/* +TagId +UserId +Title +NumberNotes +CreatedTime +UpdatedTime +Usn +*/ // 笔记本服务 var Tag = { - + // 添加多个标签 + addTags: function(titles) { + for(var i in titles) { + var title = titles[i]; + this.addTag(title); + } + }, + // 添加标签, 先查询是否存在 + addTag: function(title, callback) { + userId = User.getCurActiveUserId(); + Tags.count({UserId: userId, Title: title}, function(err, count) { + if(count) { + callback && callback({Ok: false, IsExists: true}); + } else { + var date = new Date(); + Tags.insert({ + TagId: Common.objectId(), + UserId: userId, + Title: title, + CreatedTime: date, + UpdatedTime: date + }, function(err, doc) { + if(!err) { + callback && callback({Ok: false, Inserted: false}); + } else { + callback && callback(doc); + } + }); + } + }); + }, + // 更新标签标题 + updateTagTitle: function(tagId, Title, callback) { + userId = User.getCurActiveUserId(); + // Tags.update({TagId: tagId, userId: userId}, {$set: {NumberNotes: count}}, {}) + Tags.update({TagId: tagId, userId: userId}, {$set: {Title: title}}, {}, function(err) { + if(err) { + callback && callback(false); + } else { + callback && callback(true); + } + }); + }, + // 得到标签 + getTags: function(callback) { + Tags.find({UserId: User.getCurActiveUserId()}, function(err, tags) { + if(err) { + callback && callback(false); + } else { + callback && callback(tags); + } + }); + } }; module.exports = Tag; \ No newline at end of file diff --git a/npm-debug.log b/npm-debug.log deleted file mode 100644 index 414a4810..00000000 --- a/npm-debug.log +++ /dev/null @@ -1,25 +0,0 @@ -0 info it worked if it ends with ok -1 verbose cli [ 'node', '/usr/bin/npm', 'install', 'life' ] -2 info using npm@2.1.11 -3 info using node@v0.10.33 -4 verbose node symlink /usr/bin/node -5 verbose stack Error: Invalid version: "0.1" -5 verbose stack at Object.module.exports.fixVersionField (/usr/lib/node_modules/npm/node_modules/normalize-package-data/lib/fixer.js:190:13) -5 verbose stack at /usr/lib/node_modules/npm/node_modules/normalize-package-data/lib/normalize.js:30:38 -5 verbose stack at Array.forEach (native) -5 verbose stack at normalize (/usr/lib/node_modules/npm/node_modules/normalize-package-data/lib/normalize.js:29:15) -5 verbose stack at final (/usr/lib/node_modules/npm/node_modules/read-package-json/read-json.js:342:33) -5 verbose stack at then (/usr/lib/node_modules/npm/node_modules/read-package-json/read-json.js:126:33) -5 verbose stack at /usr/lib/node_modules/npm/node_modules/read-package-json/read-json.js:331:40 -5 verbose stack at evalmachine.:271:14 -5 verbose stack at /usr/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:102:5 -5 verbose stack at Object.oncomplete (evalmachine.:107:15) -6 verbose cwd /Users/life/Documents/kuaipan/leanote/desktop-app -7 error Darwin 13.4.0 -8 error argv "node" "/usr/bin/npm" "install" "life" -9 error node v0.10.33 -10 error npm v2.1.11 -11 error Invalid version: "0.1" -12 error If you need help, you may report this error at: -12 error -13 verbose exit [ 1, true ] diff --git a/public/js/app/page.js b/public/js/app/page.js index e0f426fb..4d505372 100644 --- a/public/js/app/page.js +++ b/public/js/app/page.js @@ -1318,7 +1318,10 @@ function initPage() { } } - Tag.renderTagNav(tagsJson); + // 标签 + Service.tagService.getTags(function(tags) { + Tag.renderTagNav(tags); + }); // init notebook后才调用 // initSlimScroll(); diff --git a/public/js/app/service.js b/public/js/app/service.js index 9e2282c5..6ec8efce 100644 --- a/public/js/app/service.js +++ b/public/js/app/service.js @@ -5,7 +5,8 @@ var Service = { notebookService: require('notebook'), noteService: require('note'), tagService: require('tag'), - userService: require('user') + userService: require('user'), + tagService: require('tag') }; // 分发服务 // route = /note/notebook diff --git a/public/js/app/tag.js b/public/js/app/tag.js index 2c5d2b83..695bd7bb 100644 --- a/public/js/app/tag.js +++ b/public/js/app/tag.js @@ -191,13 +191,13 @@ function reRenderTags() { Tag.renderTagNav = function(tags) { tags = tags || []; for(var i in tags) { - var tag = tags[i]; + var tag = tags[i].Title; if(tag == "red" || tag == "blue" || tag == "yellow" || tag == "green") { continue; } var text = Tag.mapEn2Cn[tag] || tag; var classes = Tag.classes[tag] || "label label-default"; - $("#tagNav").append(tt('
    • ?
    • ', text, classes, text)); + $("#tagNav").append(tt('
    • ?
    • ', text, classes, text)); } } diff --git a/public/tinymce/plugins/leanote_code/plugin.min.js b/public/tinymce/plugins/leanote_code/plugin.min.js new file mode 100644 index 00000000..b36b0036 --- /dev/null +++ b/public/tinymce/plugins/leanote_code/plugin.min.js @@ -0,0 +1 @@ +tinymce.PluginManager.requireLangPack("leanote_code"),tinymce.PluginManager.add("leanote_code",function(e,t){function n(e){return e?("object"==typeof e&&(e=$(e).html()),e.replace(/\
      /gi,"\n").replace(/<\/(p|li|div|ul|ol|hr)>/,"\n").replace(/(<([^>]+)>)/gi,"").replace(/\n\n/g,"\n")):e}function o(e){return e?("object"==typeof e&&(e=$(e).html()),e.replace(/\n/g,"
      ")):e}function a(e){r=tinymce.activeEditor;var t,a=r.selection.getNode(),c=r.selection.getContent(),i=LeaAce.isInAce(a),l=!1,d=!1;if(i&&(l=i[0],d=i[1]),$("#editorContent .toggle-raw").remove(),log("curNode:"),log(a),e&&"convert"!=e){if(l&&l.session.setMode("ace/mode/"+e),d||"PRE"!=a.nodeName||(d=$(a)),d){var s=LeaAce.getPreBrush(d);return void d.removeClass(s).addClass("brush:"+e)}}else if(e&&("BODY"==a.nodeName||"editorContent"==$(a).attr("id")))return;if(LeaAce.canAce()){var p=LeaAce.getAceId();if(LeaAce.disableAddHistory(),l){var g=l.getValue();g=g.replace(//g,">"),g=g.replace(/\n/g,"
      "),d.replaceWith("

      "+g+"

      "),l.destroy()}else{if("PRE"==a.nodeName){var d=$(a),g=d.html();return g&&(g=g.replace(/\n/g,"
      ")),void d.replaceWith("

      "+g+"

      ")}var t=c;if(!t&&("BODY"==a.nodeName||"editorContent"==$(a).attr("id")))return;t?(t=n(t),r.insertContent('
      '+t+"
      ")):(t=n(a),$(a).replaceWith("
      "+t+"
      "));var u=LeaAce.initAce(p);u&&(u.focus(),e&&u.session.setMode("ace/mode/"+e))}LeaAce.resetAddHistory()}else if("PRE"!=a.nodeName&&(a=$(a).closest("pre").get(0)),a&&"PRE"==a.nodeName){var d=$(a),g=d.html();g&&(g=g.replace(/\n/g,"
      ")),d.replaceWith("

      "+g+"

      ")}else{try{t=$.trim($(c).text())}catch(v){}t||(t=$.trim(c));var h=null,p=LeaAce.getAceId();t?(t=o(t),h='
      '+t+"
      ",r.insertContent(h)):a?(t=o(a),h='
      '+t+"
      ",$(a).replaceWith(h)):(h='
      '+t+"
      ",r.insertContent(h))}}function c(){return function(){var t=this;e.on("nodeChange",function(){var n=null;try{var o=e.selection.getNode();if("PRE"!=o.nodeName&&(o=$(o).closest("pre").get(0)),o){var a=LeaAce.isInAce(o),c=!1,r=!1;if(a||"PRE"==o.nodeName){a?(c=a[0],r=a[1]):r=$(o);var i=LeaAce.getPreBrush(r);n=$.trim(i.split(":")[1]),t.diableValue("convert",!1)}else t.diableValue("convert",!0)}}catch(l){log(l)}"convert"!=n&&t.value(n)})}}var r=e;e.addButton("leanote_code",function(){var e=["Convert Code:convert","CSS:css","C/C++:c_cpp","C#:csharp","HTML:html","Javascript:javascript","Java:java","PHP:php","Python:python","Shell:shell","Delphi:delphi","Golang:golang","Erlang:erlang","Groovy:groovy","ActionScript:actionScript"],t=[];for(var n in e){var o=e[n].split(":");t.push({text:o[0],value:o[1]})}return{type:"listbox",text:"codeLang",tooltip:"toggleCode",values:t,fixedWidth:!0,onselect:function(e){e.control.settings.value&&a(e.control.settings.value)},onPostRender:c(t)}}),e.addButton("leanote_inline_code",{icon:"code",tooltip:"Inline Code",stateSelector:"code",onclick:function(){e.execCommand("mceToggleFormat",!1,"code")}}),LeaAce.canAce()&&e.addButton("leanote_ace_pre",{icon:"code",image:t+"/img/ace-pre2.png",tooltip:"Toggle ace with raw html",active:LeaAce.isAce===!1,onclick:function(){LeaAce.isAce===!1?(this.active(!1),LeaAce.isAce=!0,LeaAce.initAceFromContent(e)):(this.active(!0),LeaAce.allToPre(e),LeaAce.isAce=!1)}}),r.addCommand("toggleCode",a),r.addShortcut("ctrl+shift+c","","toggleCode"),r.addShortcut("command+shift+c","","toggleCode"),LeaAce.canAce()&&e.on("keydown",function(){var e=LeaAce.nowIsInAce();return e?(setTimeout(function(){e[0].focus()}),!0):void 0}),r.on("keydown",function(e){var t=e.which?e.which:e.keyCode;return 9==t?(e.shiftKey||r.insertContent("    "),e.preventDefault(),e.stopPropagation(),!1):void 0})}); \ No newline at end of file