diff options
author | Egil Moeller <egil.moller@freecode.no> | 2010-03-25 20:07:44 +0100 |
---|---|---|
committer | Egil Moeller <egil.moller@freecode.no> | 2010-03-25 20:07:44 +0100 |
commit | 433c3f5f2a74511d454debf7c4c129508eacd3df (patch) | |
tree | 06f80d9f6826f9026e25908e000b2e49b4082d75 | |
parent | 4a7368c13998a225f6c0b32484aa9cbf8d5334ce (diff) | |
download | etherpad-433c3f5f2a74511d454debf7c4c129508eacd3df.tar.gz etherpad-433c3f5f2a74511d454debf7c4c129508eacd3df.tar.xz etherpad-433c3f5f2a74511d454debf7c4c129508eacd3df.zip |
Got the server side of the twitter style tags to work
-rw-r--r-- | etherpad/src/plugins/twitterStyleTags/hooks.js | 47 | ||||
-rw-r--r-- | etherpad/src/plugins/twitterStyleTags/main.js | 3 |
2 files changed, 43 insertions, 7 deletions
diff --git a/etherpad/src/plugins/twitterStyleTags/hooks.js b/etherpad/src/plugins/twitterStyleTags/hooks.js index 65aef83..e3a3e0b 100644 --- a/etherpad/src/plugins/twitterStyleTags/hooks.js +++ b/etherpad/src/plugins/twitterStyleTags/hooks.js @@ -1,12 +1,47 @@ import("etherpad.log"); import("dispatch.{Dispatcher,PrefixMatcher,forward}"); import("plugins.twitterStyleTags.controllers.tagBrowser"); - -function aceGetFilterStack() { - log.info("aceGetFilterStack"); - return []; -} +import("sqlbase.sqlobj"); function handlePath() { - return [[PrefixMatcher('/ep/tags/'), forward(tagBrowser)]]; + return [[PrefixMatcher('/ep/tags/'), forward(tagBrowser)]]; } + +function padModelWriteToDB(args) { + /* Update tags for the pad */ + + var new_tags = args.pad.text().match(new RegExp("#[^,#!\\s][^,#!\\s]*", "g")); + if (new_tags == null) new_tags = new Array(); + for (i = 0; i < new_tags.length; i++) + new_tags[i] = new_tags[i].substring(1); + var new_tags_str = new_tags.join('#') + + var old_tags_row = sqlobj.selectSingle("PAD_TAG_CACHE", { id: args.padId }); + var old_tags_str; + if (old_tags_row !== null) + old_tags_str = old_tags_row['TAGS']; + else + old_tags_str = ''; + + var old_tags = old_tags_str != '' ? old_tags_str.split('#') : new Array(); + + if (new_tags_str != old_tags_str) { + log.info({message: 'Updating tags', new_tags:new_tags, old_tags:old_tags}); + + if (old_tags_row) + sqlobj.update("PAD_TAG_CACHE", { id: args.padId }, {tags: new_tags.join('#')}); + else + sqlobj.insert("PAD_TAG_CACHE", {id: args.padId, tags: new_tags.join('#')}); + + sqlobj.deleteRows("PAD_TAG", {pad_id: args.padId}); + + for (i = 0; i < new_tags.length; i++) { + var tag_row = sqlobj.selectSingle("TAG", { name: new_tags[i] }); + if (tag_row === null) { + sqlobj.insert("TAG", {name: new_tags[i]}); + tag_row = sqlobj.selectSingle("TAG", { name: new_tags[i] }); + } + sqlobj.insert("PAD_TAG", {pad_id: args.padId, tag_id: tag_row['ID']}); + } + } +}
\ No newline at end of file diff --git a/etherpad/src/plugins/twitterStyleTags/main.js b/etherpad/src/plugins/twitterStyleTags/main.js index f6dd3bf..0154121 100644 --- a/etherpad/src/plugins/twitterStyleTags/main.js +++ b/etherpad/src/plugins/twitterStyleTags/main.js @@ -3,12 +3,13 @@ import("plugins.twitterStyleTags.hooks"); import("plugins.twitterStyleTags.static.js.main"); function init() { - this.hooks = ['handlePath', 'aceGetFilterStack', 'aceCreateDomLine']; + this.hooks = ['handlePath', 'aceGetFilterStack', 'aceCreateDomLine', 'padModelWriteToDB']; this.client = new main.init(); this.description = 'Twitter-style tags'; this.handlePath = hooks.handlePath; this.aceGetFilterStack = main.aceGetFilterStack; this.aceCreateDomLine = main.aceCreateDomLine; + this.padModelWriteToDB = hooks.padModelWriteToDB; this.install = install; this.uninstall = uninstall; |