diff --git a/app/index.html b/app/index.html
index 2300205..10c30c1 100644
--- a/app/index.html
+++ b/app/index.html
@@ -49,6 +49,18 @@
diff --git a/app/js/app.js b/app/js/app.js
index 05d9042..41b133b 100644
--- a/app/js/app.js
+++ b/app/js/app.js
@@ -17,279 +17,359 @@ $.fn.pressEnter = function (fn) {
var Keeper = (function () {
- var self = this;
+ var self = this;
- console.log('GO!');
- var $list = $('#listContainer');
- var displayList = function (obj) {
- var html = new EJS({url: '/partials/list.ejs'}).render(obj);
- console.log(html);
- $list.empty();
- $list.append(html);
- $('#listContainer').find('.entry').not('.emptyMessage').click(function () {
- console.log('Clicked list. ' + this.id);
- getRecipe(this.id);
- });
- },
- displayPage = function (obj) {
- var $bodyContents = $('#bodyContents');
+ console.log('GO!');
+ var $list = $('#listContainer');
+ var displayList = function (obj) {
+ var html = new EJS({url: '/partials/list.ejs'}).render(obj);
+ // console.log(html);
+ $list.empty();
+ $list.append(html);
+ $('#listContainer').find('.entry').not('.emptyMessage').click(function () {
+ getBookmark(this.id);
+ });
+ },
+ displayPage = function (obj) {
+ var $bodyContents = $('#bodyContents');
- if (obj.reduced.length > 0) {
- var vdata = {
- data: {
- _id: obj._id,
- _rev: obj._rev,
- title: obj.title,
- reduced: obj.reduced,
- tags:obj.tags,
- url:obj.url
- }
- };
+ if (obj.reduced.length > 0) {
+ var vdata = {
+ data: {
+ _id: obj._id,
+ _rev: obj._rev,
+ title: obj.title,
+ reduced: obj.reduced,
+ tags: obj.tags,
+ url: obj.url
+ }
+ };
- var redoData = {
- _id: obj._id,
- _rev: obj._rev,
- url: obj.url
- };
+ var redoData = {
+ _id: obj._id,
+ _rev: obj._rev,
+ url: obj.url
+ };
+ var html = new EJS({url: 'partials/view.ejs'}).render(vdata);
- var html = new EJS({url: 'partials/view.ejs'}).render(vdata);
+ $bodyContents.empty();
+ $bodyContents.scrollTop(0);
- $bodyContents.empty();
- $bodyContents.scrollTop(0);
+ $bodyContents.append(html);
- $bodyContents.append(html);
+ $('#redo').on('click', function () {
+ self.trigger('redo', redoData);
- $('#redo').on('click', function () {
- self.trigger('redo', redoData);
-
- });
-
- $('#tagSave').on('click', function () {
- self.trigger('tagsave',redoData);
-
- });
-
- $('#tageditmode').on('click', function() {
- self.trigger('startTags');
- })
-
- }
- }, getRecipe = function (id) {
- console.log('get recipe');
- var url = '/entry/' + id;
- var data = '';
- $.ajax({
- type: 'GET',
- url: url,
- data: data,
- dataType: 'json',
-
- timeout: 10000,
-
- //contentType: ('application/json'),
- headers: {
- 'Access-Control-Allow-Origin': '*',
- 'Access-Control-Allow-Methods': 'PUT, GET, POST, DELETE, OPTIONS',
- 'Access-Control-Allow-Headers': 'Content-Type'
-
- },
- success: function (data) {
- // console.log(data);
- displayPage(data);
- },
- error: function (xhr, type) {
- console.log('ajax error');
- console.log(xhr);
- console.log(type);
- }
- });
- },
-
- getList = function () {
-
- var url = '/list';
-
- $.ajax({
- type: 'GET',
- url: url,
- data: '',
- dataType: 'json',
-
- timeout: 10000,
-
- //contentType: ('application/json'),
- headers: {
- 'Access-Control-Allow-Origin': '*',
- 'Access-Control-Allow-Methods': 'PUT, GET, POST, DELETE, OPTIONS',
- 'Access-Control-Allow-Headers': 'Content-Type'
-
- },
- success: function (data) {
- // console.log(data);
- displayList(data);
- },
- error: function (xhr, type) {
- console.log('ajax error');
- console.log(xhr);
- console.log(type);
- }
- });
- },
- saveTags = function(d) {
- function parse (input) {
- return input
- .trim()
- .split(/\s*,\s*/)
- .map(function (col) {
- return col.trim();
- })
- .filter(function (col) {
- return col && col.length;
});
+
+ $('#tagSave').on('click', function () {
+ self.trigger('tagsave', redoData);
+
+ });
+
+ $('#tageditmode').on('click', function () {
+ self.trigger('startTags');
+ });
+
+ }
+ }, getBookmark = function (id) {
+ //console.log('getBookmark');
+ var url = '/entry/' + id;
+ var data = '';
+ $.ajax({
+ type: 'GET',
+ url: url,
+ data: data,
+ dataType: 'json',
+
+ timeout: 10000,
+
+ //contentType: ('application/json'),
+ headers: {
+ 'Access-Control-Allow-Origin': '*',
+ 'Access-Control-Allow-Methods': 'PUT, GET, POST, DELETE, OPTIONS',
+ 'Access-Control-Allow-Headers': 'Content-Type'
+
+ },
+ success: function (data) {
+ // console.log(data);
+ displayPage(data);
+ },
+ error: function (xhr, type) {
+ console.log('ajax error');
+ console.log(xhr);
+ console.log(type);
+ }
+ });
+ },
+ updateMainTagList = function (obj) {
+ var $taglist = $('#tagList');
+
+ var html = new EJS({url: '/partials/taglist.ejs'}).render(obj);
+ $taglist.empty();
+ $taglist.html(html);
+
+ },
+
+ getMainTagList = function () {
+ var url = '/tags';
+
+ $.ajax({
+ type: 'GET',
+ url: url,
+ data: '',
+ dataType: 'json',
+
+ timeout: 10000,
+
+ //contentType: ('application/json'),
+ headers: {
+ 'Access-Control-Allow-Origin': '*',
+ 'Access-Control-Allow-Methods': 'PUT, GET, POST, DELETE, OPTIONS',
+ 'Access-Control-Allow-Headers': 'Content-Type'
+
+ },
+ success: function (data) {
+ // console.log(data);
+ updateMainTagList(data);
+ },
+ error: function (xhr, type) {
+ console.log('ajax error');
+ console.log(xhr);
+ console.log(type);
+ }
+ });
+ },
+ getList = function () {
+
+ var url = '/list';
+
+ $.ajax({
+ type: 'GET',
+ url: url,
+ data: '',
+ dataType: 'json',
+
+ timeout: 10000,
+
+ //contentType: ('application/json'),
+ headers: {
+ 'Access-Control-Allow-Origin': '*',
+ 'Access-Control-Allow-Methods': 'PUT, GET, POST, DELETE, OPTIONS',
+ 'Access-Control-Allow-Headers': 'Content-Type'
+
+ },
+ success: function (data) {
+ // console.log(data);
+ displayList(data);
+ },
+ error: function (xhr, type) {
+ console.log('ajax error');
+ console.log(xhr);
+ console.log(type);
+ }
+ });
+ },
+ saveTags = function (d) {
+ function parse(input) {
+ return input
+ .trim()
+ .split(/\s*,\s*/)
+ .map(function (col) {
+ return col.trim();
+ })
+ .filter(function (col) {
+ return col && col.length;
+ });
+ }
+
+ var data = d;
+ var url = '/tags';
+ var tags = {}, tagItems = $('#edittags').val();
+ tagItems = parse(tagItems);
+ tags.list = tagItems;
+ tags.solid = tagItems.join(', ');
+
+ data.tags = tags;
+
+ $.ajax({
+ type: 'POST',
+ url: url,
+ data: d,
+ dataType: 'json',
+
+ timeout: 10000,
+
+ //contentType: ('application/json'),
+ headers: {
+ 'Access-Control-Allow-Origin': '*',
+ 'Access-Control-Allow-Methods': 'PUT, GET, POST, DELETE, OPTIONS',
+ 'Access-Control-Allow-Headers': 'Content-Type'
+
+ },
+ success: function () {
+ // console.log(data);
+ // displayList(data);
+ $('#visualTabs').toggle();
+ $('#tagForm').toggle();
+ },
+ error: function (xhr, type) {
+ console.log('ajax error');
+ console.log(xhr);
+ console.log(type);
+ }
+ });
}
+ , addNew = function (newUrl) {
+ var url = '/add';
- var data = d;
- var url='/tags';
- var tags = {}, tagItems = $('#edittags').val();
- tagItems = parse(tagItems);
- tags.list = tagItems;
- tags.solid = tagItems.join(', ');
+ var data = {url: JSON.stringify(newUrl)};
+ $.ajax({
+ type: 'POST',
+ url: url,
+ data: data,
+ dataType: 'json',
- console.log('tags:' + JSON.stringify(tags));
- data.tags = tags;
+ timeout: 10000,
- console.log(data);
+ //contentType: ('application/json'),
+ headers: {
+ 'Access-Control-Allow-Origin': '*',
+ 'Access-Control-Allow-Methods': 'PUT, GET, POST, DELETE, OPTIONS',
+ 'Access-Control-Allow-Headers': 'Content-Type'
- $.ajax({
- type: 'POST',
- url: url,
- data: d,
- dataType: 'json',
+ },
+ success: function () {
+ // console.log(data);
+ // displayList(data);
+ },
+ error: function (xhr, type) {
+ console.log('ajax error');
+ console.log(xhr);
+ console.log(type);
+ }
+ });
+ },
+ redo = function (d) {
+ console.log('redooing');
+ var url = '/redo';
- timeout: 10000,
+ $.ajax({
+ type: 'POST',
+ url: url,
+ data: d,
+ dataType: 'json',
- //contentType: ('application/json'),
- headers: {
- 'Access-Control-Allow-Origin': '*',
- 'Access-Control-Allow-Methods': 'PUT, GET, POST, DELETE, OPTIONS',
- 'Access-Control-Allow-Headers': 'Content-Type'
+ timeout: 10000,
- },
- success: function () {
- // console.log(data);
- // displayList(data);
- $('#visualTabs').toggle();
- $('#tagForm').toggle();
- },
- error: function (xhr, type) {
- console.log('ajax error');
- console.log(xhr);
- console.log(type);
- }
- });
- }
+ //contentType: ('application/json'),
+ headers: {
+ 'Access-Control-Allow-Origin': '*',
+ 'Access-Control-Allow-Methods': 'PUT, GET, POST, DELETE, OPTIONS',
+ 'Access-Control-Allow-Headers': 'Content-Type'
+ },
+ success: function () {
+ // console.log(data);
+ // displayList(data);
+ },
+ error: function (xhr, type) {
+ console.log('ajax error');
+ console.log(xhr);
+ console.log(type);
+ }
+ });
+ },
+ start = function () {
- ,addNew = function (newUrl) {
- var url = '/add';
-
- var data = {url: JSON.stringify(newUrl)};
- $.ajax({
- type: 'POST',
- url: url,
- data: data,
- dataType: 'json',
-
- timeout: 10000,
-
- //contentType: ('application/json'),
- headers: {
- 'Access-Control-Allow-Origin': '*',
- 'Access-Control-Allow-Methods': 'PUT, GET, POST, DELETE, OPTIONS',
- 'Access-Control-Allow-Headers': 'Content-Type'
-
- },
- success: function () {
- // console.log(data);
- // displayList(data);
- },
- error: function (xhr, type) {
- console.log('ajax error');
- console.log(xhr);
- console.log(type);
- }
- });
- },
- redo = function (d) {
- console.log('redooing');
- var url = '/redo';
-
- $.ajax({
- type: 'POST',
- url: url,
- data: d,
- dataType: 'json',
-
- timeout: 10000,
-
- //contentType: ('application/json'),
- headers: {
- 'Access-Control-Allow-Origin': '*',
- 'Access-Control-Allow-Methods': 'PUT, GET, POST, DELETE, OPTIONS',
- 'Access-Control-Allow-Headers': 'Content-Type'
-
- },
- success: function () {
- // console.log(data);
- // displayList(data);
- },
- error: function (xhr, type) {
- console.log('ajax error');
- console.log(xhr);
- console.log(type);
- }
- });
- },
- start = function () {
-
- getList();
- };
-
- $('#newurl').pressEnter(function () {
- var url = $(this).val();
- if (url !== null) {
- console.log('Adding: ' + url);
- addNew(url);
- $('#addstatus').fadeIn(400).delay(1500).fadeOut(400);
- $(this).val('');
- /* setTimeout(function () {
getList();
- }, 5000);*/
- }
- });
+ getMainTagList();
+ },
+ listFromTag = function (tag) {
+ console.log('get for ' + tag);
+ var url = '/tags/' + tag;
- $('#fnRefresh').on('click', function () {
- getList();
- });
+ $.ajax({
+ type: 'GET',
+ url: url,
+ data: '',
+ dataType: 'json',
+ timeout: 10000,
+ //contentType: ('application/json'),
+ headers: {
+ 'Access-Control-Allow-Origin': '*',
+ 'Access-Control-Allow-Methods': 'PUT, GET, POST, DELETE, OPTIONS',
+ 'Access-Control-Allow-Headers': 'Content-Type'
- this.bind('redo', function (data) {
- redo(data);
- });
+ },
+ success: function (data) {
+ // console.log(data);
+ displayList(data);
+ },
+ error: function (xhr, type) {
+ console.log('ajax error');
+ console.log(xhr);
+ console.log(type);
+ }
+ });
- this.bind('tagsave', function (data) {
- saveTags(data);
- });
- this.bind('startTags', function (data) {
- $('#visualTabs').toggle();
- $('#tagForm').toggle();
- });
+ };
- start();
-});
+ $('#newurl').pressEnter(function () {
+ var url = $(this).val();
+ if (url !== null) {
+ console.log('Adding: ' + url);
+ addNew(url);
+ $('#addstatus').fadeIn(400).delay(1500).fadeOut(400);
+ $(this).val('');
+ /* setTimeout(function () {
+ getList();
+ }, 5000);*/
+ }
+ });
+
+ $('#fnRefresh').on('click', function () {
+ getList();
+ });
+
+ $(window).on('hashchange', ()=> {
+
+ self.trigger('hashchange', location.hash);
+ });
+
+ this.bind('redo', function (data) {
+ redo(data);
+ });
+
+ this.bind('tagsave', function (data) {
+ saveTags(data);
+ });
+ this.bind('startTags', function (data) {
+ $('#visualTabs').toggle();
+ $('#tagForm').toggle();
+ });
+
+ this.bind('hashchange', function (data) {
+
+ var tagroute = data.replace('#?', '');
+
+ if (tagroute !== '')
+ {
+ listFromTag(tagroute);
+ }
+ else
+ {
+ getList();
+ }
+ });
+
+ start();
+ })
+ ;
MicroEvent.mixin(Keeper);
diff --git a/app/partials/taglist.ejs b/app/partials/taglist.ejs
new file mode 100644
index 0000000..f9b60ac
--- /dev/null
+++ b/app/partials/taglist.ejs
@@ -0,0 +1,4 @@
+
No tag
+<% for(var i=0; i
+<%= list[i] %>
+<% } %>
\ No newline at end of file
diff --git a/gulpfile.js b/gulpfile.js
index 604a5ff..d19a1f9 100644
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -29,7 +29,7 @@ gulp.task('scripts', function() {
/*.pipe(gulp.dest('dist/js'))*/
/*.pipe(rename({suffix: '.min'}))*/
.pipe(concat('app.js'))
- .pipe(uglify({mangle: false}))
+ /*.pipe(uglify({mangle: false}))*/
.pipe(gulp.dest('dist/js'))
.pipe(notify({ message: 'Scripts task complete' }));
});
diff --git a/server/keeper.js b/server/keeper.js
index 9297eaa..cd58432 100644
--- a/server/keeper.js
+++ b/server/keeper.js
@@ -126,10 +126,67 @@ var doGetBookmarkRes = (url, res) =>
genericGrab(url, res);
};
-var doUpdateTagsDB = () =>
-{
+var doUpdateTagsDB = () => {
logger.debug('Update the tags database...');
-}
+
+ dbCouch.view('getAllTags', 'getAllTags', function (err, body) {
+ var masterList = [];
+ if (!err) {
+
+ var outJSON = [];
+ body.rows.forEach(function (doc) {
+
+ masterList = masterList.concat(doc.value);
+ });
+
+ masterList = masterList.filter((value, index, self) => {
+ return self.indexOf(value) === index;
+ });
+
+ dbCouch.view('taglist', 'taglist', function (err, body) {
+
+ if (!err) {
+
+ var outJSON = {};
+
+ body.rows.forEach(function (doc) {
+ doSaveTagsDB(doc.value,masterList);
+ })
+
+ }
+ else {
+
+ }
+ });
+
+ }
+ else {
+
+ }
+ });
+
+
+};
+
+var doSaveTagsDB = (orig, newList) =>
+{
+ logger.debug('doSaveTagsDB');
+ // logger.info('sendSocket: ' + JSON.stringify(obj));
+
+ var _obj = orig;
+
+ _obj.taglist = newList;
+
+ dbCouch.insert(_obj, function (err, body, header) {
+ if (err) {
+ logger.error('Error updating into couch');
+ return;
+ } else {
+ logger.info('Updated the tags list...');
+
+ }
+ });
+};
// Events
busEmitter.on('saveBookmarkData', doInsertBookmark);
@@ -139,6 +196,7 @@ busEmitter.on('getBookmarkRes', doGetBookmarkRes);
busEmitter.on('getBookmarkRedo', doGetBookmarkRedo);
busEmitter.on('updateTagsDB', doUpdateTagsDB);
+busEmitter.on('saveTagsDB', doSaveTagsDB);
function processBody(body, url, _id, _rev) {
@@ -318,6 +376,67 @@ router.get('/entry/:id', function (req, res) {
}
});
+});
+router.get('/tags', function (req, res) {
+ logger.debug('entry..');
+
+ logger.debug(req.params.id);
+
+ dbCouch.view('taglist', 'taglist', function (err, body) {
+ if (!err) {
+ logger.debug(body);
+ var outJSON = [];
+ body.rows.forEach(function (doc) {
+ logger.info(doc.value.taglist);
+ if (doc.value[0]==req.params.id)
+ {
+ outJSON = doc.value.taglist;
+ }
+ });
+
+ //logger.debug(util.inspect(body));
+ res.writeHead(200, {"ContentType": "application/json"});
+ res.end(JSON.stringify({list: outJSON}));
+
+ }
+ else {
+ logger.error(err);
+ res.writeHead(500, {"ContentType": "application/json"});
+ res.end(JSON.stringify({}));
+ }
+ });
+
+});
+
+router.get('/tags/:id', function (req, res) {
+ logger.debug('entry..');
+
+ logger.debug(req.params.id);
+
+ dbCouch.view('getTagByKey', 'getTagByKey', function (err, body) {
+ if (!err) {
+ // logger.debug(body);
+ var outJSON = [];
+ body.rows.forEach(function (doc) {
+ // logger.debug(doc);
+ if (doc.value[0]==req.params.id)
+ {
+ outJSON.push({id: doc.id, title: doc.value[1]})
+ }
+ });
+
+ //logger.debug(util.inspect(body));
+ res.writeHead(200, {"ContentType": "application/json"});
+ res.end(JSON.stringify({list: outJSON}));
+
+ }
+ else {
+ logger.error(err);
+ res.writeHead(500, {"ContentType": "application/json"});
+ res.end(JSON.stringify({}));
+ }
+ });
+
});
router.post('/add', function (req, res) {
@@ -403,4 +522,7 @@ router.get('/new', function (req, res) {
});
+
+busEmitter.emit('updateTagsDB');
+
module.exports = router;
diff --git a/server/maker.js b/server/maker.js
index 183c950..df14698 100644
--- a/server/maker.js
+++ b/server/maker.js
@@ -1,42 +1,79 @@
var nano = require('nano')('http://localhost:5984');
// clean up the database we created previously
-nano.db.destroy('keeper', function() {
- // create a new database
- nano.db.create('keeper', function() {
- // specify the database we are going to use
- var keeper = nano.use('keeper');
- // and insert a document in it
-/* keeper.insert({ crazy: true }, 'rabbit', function(err, body, header) {
- if (err) {
- console.log('[alice.insert] ', err.message);
- return;
- }
- console.log('you have inserted the rabbit.')
- console.log(body);
- });*/
+nano.db.destroy('keeper', function () {
+ // create a new database
+ nano.db.create('keeper', function () {
+ // specify the database we are going to use
+ var keeper = nano.use('keeper');
+ // and insert a document in it
+ /* keeper.insert({ crazy: true }, 'rabbit', function(err, body, header) {
+ if (err) {
+ console.log('[alice.insert] ', err.message);
+ return;
+ }
+ console.log('you have inserted the rabbit.')
+ console.log(body);
+ });*/
+ keeper.insert(
+ {
+ "views": {
+ "titles": {
+ "map": function (doc) { emit(null, doc.title); }
+ }
+ }
+ }, '_design/titles', function (error, response) {
+ console.log("_design/titles added");
+ });
- keeper.insert(
- { "views":
- { "titles":
- { "map": function(doc) { emit(null, doc.title); } }
- }
- }, '_design/titles', function (error, response) {
- console.log("_design/titles added");
- });
+ keeper.insert(
+ {
+ "views": {
+ "reducedView": {
+ "map": function (doc) { emit(null, [doc.title, doc.reduced]); }
+ }
+ }
+ }, '_design/reducedView', function (error, response) {
+ console.log("_design/reducedView added");
+ });
- keeper.insert(
- { "views":
- { "reducedView":
- { "map": function(doc) { emit(null, [doc.title, doc.reduced]); } }
- }
- }, '_design/reducedView', function (error, response) {
- console.log("_design/reducedView added");
- });
+ keeper.insert(
+ {
+ "views": {
+ "taglist": {
+ "map": function (doc) { if (doc.type == 1) { emit(null, doc); } }
+ }
+ }, '_design/taglist', function (error, response) {
+ console.log("_design/taglist added");
+ });
+ keeper.insert(
+ {
+ "views": {
+ "getAllTags": {
+ "map": function (doc) { if (doc.tags.list.length > 0) { emit(null, doc.tags.list); } }
+ }
+ }, '_design/getAllTags', function (error, response) {
+ console.log("_design/getAllTags added");
+ });
- });
-});/**
+ keeper.insert(
+ {
+ "views": {
+ "getAllTags": {
+ "map": function(doc) { if (doc.tags.list.length > 0) { for (var t=0;t< doc.tags.list.length;t++) { emit(doc._id, [doc.tags.list[t], doc.title]); } } }
+ }
+ }
+ }, '_design/getTagByKey', function (error, response) {
+ console.log("_design/getTagByKey added");
+ });
+
+ });
+});
+/**
* Created by Martin on 02/03/2016.
*/
+
+
+