This commit is contained in:
Martin Donnelly 2016-03-21 16:23:19 +00:00
parent 7564136a67
commit c69eef875b
6 changed files with 537 additions and 282 deletions

View File

@ -49,6 +49,18 @@
<div id="functions" class="fnBlock">
<span id="fnRefresh" class="lnr lnr-sync"></span>
<span id="fnSearch" class="lnr lnr-magnifier"></span>
<span class="mui-dropdown">
<button class="mui-btn mui-btn--primary" data-mui-toggle="dropdown">
Tags
<span class="mui-caret"></span>
</button>
<ul class="mui-dropdown__menu" id="tagList">
<li><a href="#?node">Node</a></li>
<li><a href="#?ember">Ember</a></li>
<li><a href="#">Option 3</a></li>
<li><a href="#">Option 4</a></li>
</ul>
</span>
</div>
<div id='searchbox' class="mui-textfield" style="display: none;">
<input id='newsearch' type="text" placeholder="Search for..">

View File

@ -23,12 +23,11 @@ var Keeper = (function () {
var $list = $('#listContainer');
var displayList = function (obj) {
var html = new EJS({url: '/partials/list.ejs'}).render(obj);
console.log(html);
// console.log(html);
$list.empty();
$list.append(html);
$('#listContainer').find('.entry').not('.emptyMessage').click(function () {
console.log('Clicked list. ' + this.id);
getRecipe(this.id);
getBookmark(this.id);
});
},
displayPage = function (obj) {
@ -41,8 +40,8 @@ var Keeper = (function () {
_rev: obj._rev,
title: obj.title,
reduced: obj.reduced,
tags:obj.tags,
url:obj.url
tags: obj.tags,
url: obj.url
}
};
@ -52,7 +51,6 @@ var Keeper = (function () {
url: obj.url
};
var html = new EJS({url: 'partials/view.ejs'}).render(vdata);
$bodyContents.empty();
@ -66,17 +64,17 @@ var Keeper = (function () {
});
$('#tagSave').on('click', function () {
self.trigger('tagsave',redoData);
self.trigger('tagsave', redoData);
});
$('#tageditmode').on('click', function() {
$('#tageditmode').on('click', function () {
self.trigger('startTags');
})
});
}
}, getRecipe = function (id) {
console.log('get recipe');
}, getBookmark = function (id) {
//console.log('getBookmark');
var url = '/entry/' + id;
var data = '';
$.ajax({
@ -105,7 +103,44 @@ var Keeper = (function () {
}
});
},
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';
@ -136,8 +171,8 @@ var Keeper = (function () {
}
});
},
saveTags = function(d) {
function parse (input) {
saveTags = function (d) {
function parse(input) {
return input
.trim()
.split(/\s*,\s*/)
@ -149,19 +184,15 @@ var Keeper = (function () {
});
}
var data = d;
var url='/tags';
var url = '/tags';
var tags = {}, tagItems = $('#edittags').val();
tagItems = parse(tagItems);
tags.list = tagItems;
tags.solid = tagItems.join(', ');
console.log('tags:' + JSON.stringify(tags));
data.tags = tags;
console.log(data);
$.ajax({
type: 'POST',
url: url,
@ -191,8 +222,7 @@ var Keeper = (function () {
});
}
,addNew = function (newUrl) {
, addNew = function (newUrl) {
var url = '/add';
var data = {url: JSON.stringify(newUrl)};
@ -255,6 +285,38 @@ var Keeper = (function () {
start = function () {
getList();
getMainTagList();
},
listFromTag = function (tag) {
console.log('get for ' + tag);
var url = '/tags/' + tag;
$.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);
}
});
};
$('#newurl').pressEnter(function () {
@ -274,7 +336,10 @@ var Keeper = (function () {
getList();
});
$(window).on('hashchange', ()=> {
self.trigger('hashchange', location.hash);
});
this.bind('redo', function (data) {
redo(data);
@ -288,8 +353,23 @@ var Keeper = (function () {
$('#tagForm').toggle();
});
this.bind('hashchange', function (data) {
var tagroute = data.replace('#?', '');
if (tagroute !== '')
{
listFromTag(tagroute);
}
else
{
getList();
}
});
start();
});
})
;
MicroEvent.mixin(Keeper);

4
app/partials/taglist.ejs Normal file
View File

@ -0,0 +1,4 @@
<li><a href="#?"><em>No tag</em></a></li>
<% for(var i=0; i<list.length; i++) {%>
<li><a href="#?<%= list[i] %>"><%= list[i] %></a></li>
<% } %>

View File

@ -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' }));
});

View File

@ -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;

View File

@ -1,13 +1,13 @@
var nano = require('nano')('http://localhost:5984');
// clean up the database we created previously
nano.db.destroy('keeper', function() {
nano.db.destroy('keeper', function () {
// create a new database
nano.db.create('keeper', function() {
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) {
/* keeper.insert({ crazy: true }, 'rabbit', function(err, body, header) {
if (err) {
console.log('[alice.insert] ', err.message);
return;
@ -16,27 +16,64 @@ nano.db.destroy('keeper', function() {
console.log(body);
});*/
keeper.insert(
{ "views":
{ "titles":
{ "map": function(doc) { emit(null, doc.title); } }
{
"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]); } }
{
"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.
*/