diff --git a/src/app/crawler.js b/src/app/crawler.js index c1e15e4..b8f9454 100644 --- a/src/app/crawler.js +++ b/src/app/crawler.js @@ -1,8 +1,6 @@ function ScholarCrawler(parser, nodes, edges) { this.stack = []; - this.edge_ids = {}; - this.node_ids = {}; this.nodes = nodes; this.edges = edges; @@ -121,9 +119,8 @@ ScholarCrawler.prototype._add_child_article = function(child_article, parent_nod edge._id = edge.id; - if(!(edge._id in this.edge_ids)) + if(this.edges.getIds().indexOf(edge._id) < 0) { - this.edge_ids[edge._id] = true; this.edges.add(edge); citations_db.insert(edge); } @@ -136,9 +133,8 @@ ScholarCrawler.prototype._add_child_article = function(child_article, parent_nod else this.push(child_node, levels-1); - if(!(child_node._id in this.node_ids)) + if(this.nodes.getIds().indexOf(child_node._id) < 0) { - this.node_ids[child_node._id] = true; this.nodes.add(child_node); } else @@ -155,14 +151,14 @@ ScholarCrawler.prototype.push = function(parent_node, levels) if(!parent_node.is_dummy) { parent_node.group = "processing"; - if(parent_node._id in this.node_ids) + if(this.nodes.getIds().indexOf(parent_node._id) >= 0) { this.nodes.update(parent_node); } } }; -ScholarCrawler.prototype.next = function() +ScholarCrawler.prototype.start = function() { if(this.stack.length > 0) { @@ -171,5 +167,5 @@ ScholarCrawler.prototype.next = function() } var crawler = this; - setTimeout(function() { crawler.next() }, 1000); + setTimeout(function() { crawler.start() }, 1000); }; diff --git a/src/app/main.js b/src/app/main.js index f80bbca..068b10e 100644 --- a/src/app/main.js +++ b/src/app/main.js @@ -4,7 +4,7 @@ var nedb = require('nedb'); var path = require('path'); var win = gui.Window.get(); -win.maximize(); +//win.maximize(); function createDB(name) { @@ -22,5 +22,6 @@ function open_external(url) var articles_db = createDB("articles"); var citations_db = createDB("citations"); +var maps_db = createDB("maps"); new MainMenuView().render(document.getElementById("main")); diff --git a/src/app/model/map.js b/src/app/model/map.js new file mode 100644 index 0000000..71d06a7 --- /dev/null +++ b/src/app/model/map.js @@ -0,0 +1,8 @@ +function ScholarMap(seed_url) +{ + this.edges = []; + this.nodes = []; + this.seed_url = seed_url; + this.is_initialized = false; +} + diff --git a/src/app/templates/main_menu.html b/src/app/templates/main_menu.html index ea2152a..6472d99 100644 --- a/src/app/templates/main_menu.html +++ b/src/app/templates/main_menu.html @@ -1,6 +1,12 @@ -
-

Scholarium

-
- -
+
+ +
+

Saved maps

+
    +
    diff --git a/src/app/views/main_menu.js b/src/app/views/main_menu.js index aa3f5c6..4288c3c 100644 --- a/src/app/views/main_menu.js +++ b/src/app/views/main_menu.js @@ -5,13 +5,34 @@ MainMenuView.prototype.render = function(container) var main_menu_div = document.createElement("div"); $(main_menu_div).addClass("main_menu"); - $(main_menu_div).load("app/templates/main_menu.html", function() { - document.forms[0].onsubmit = function() { + $(main_menu_div).load("app/templates/main_menu.html", function() + { + document.forms[0].onsubmit = function() + { var seed_url = $("input[name=url]").val(); - var view = new ShowMapView(seed_url); + var view = new ShowMapView(new ScholarMap(seed_url)); view.render(container); return false; }; + + maps_db.find({}, function(err, maps) + { + maps.forEach(function(map) + { + var ul = document.getElementById('saved_maps_container'); + var li = document.createElement("li"); + var a = document.createElement("a"); + a.onclick = function() { + new ShowMapView(map).render(container); + return false; + }; + a.href = ""; + $(a).append(map.nodes[0].title); + li.appendChild(a); + ul.appendChild(li); + }); + }); + }); $(container).empty(); diff --git a/src/app/views/show_map.js b/src/app/views/show_map.js index e79b183..2a12e4b 100644 --- a/src/app/views/show_map.js +++ b/src/app/views/show_map.js @@ -1,33 +1,58 @@ -function ShowMapView(seed_url) { - this.seed_url = seed_url; +//function ShowMapView(seed_url) { +// this.seed_url = seed_url; +//}; + +function ShowMapView(map) { + this.map = map; }; ShowMapView.prototype.render = function(container) { - var edges = new vis.DataSet(); - var nodes = new vis.DataSet(); + this.nodes = new vis.DataSet(); + this.edges = new vis.DataSet(); + + this.nodes.add(this.map.nodes); + this.edges.add(this.map.edges); var parser = new ScopusParser(); - var crawler = new ScholarCrawler(parser, nodes, edges); - crawler.push({ is_dummy: true, article: { citations_url: this.seed_url } }, 2); - crawler.next(); + var crawler = new ScholarCrawler(parser, this.nodes, this.edges); + crawler.start(); document.crawler = crawler; + if(!this.map.is_initialized) + { + crawler.push({ is_dummy: true, article: { citations_url: this.map.seed_url } }, 2); + this.map.is_initialized = true; + } + var network_div = document.createElement('div'); $(network_div).addClass("mynetwork"); $(container).empty(); container.appendChild(network_div) - var data = { nodes: nodes, edges: edges }; - var network = new vis.Network(network_div, data, visjs_options); + var data = { nodes: this.nodes, edges: this.edges }; + this.network = new vis.Network(network_div, data, visjs_options); - network.on('doubleClick', function(params) { + this.network.on('doubleClick', function(params) { if(params.nodes.length > 0) - crawler.push(nodes.get(params.nodes[0]), 1); - }); + { + crawler.push(this.nodes.get(params.nodes[0]), 1); + } + else + { + console.log("saving map"); + this.network.storePosition(); + this.map.nodes = this.nodes.get(); + this.map.edges = this.edges.get(); + if(!this.map._id) + maps_db.insert(this.map); + else + maps_db.update({_id: this.map._id}, this.map); + } + }.bind(this)); - network.on("resize", function(params) { + this.network.on("resize", function(params) { var height = $(window).height(); var width = $(window).width(); $(".mynetwork").css("width", width); diff --git a/src/css/main.css b/src/css/main.css index 5e24741..64a8522 100644 --- a/src/css/main.css +++ b/src/css/main.css @@ -1,7 +1,7 @@ @import url(http://fonts.googleapis.com/css?family=Dosis:400,700&subset=latin,latin-ext); body { - background-color: #066; + background-color: #056; } html, body { diff --git a/src/css/main_menu.css b/src/css/main_menu.css index 6d6bb46..6e5cf3b 100644 --- a/src/css/main_menu.css +++ b/src/css/main_menu.css @@ -1,36 +1,55 @@ .main_menu { - text-align: center; - font-size: 16px; - font-family: sans; - height: 100vh; + text-align: center; + font-size: 16px; + font-family: sans; + height: 100vh; + color: #fff; } .main_menu input { - color: #000; - background-color: #fff; - border: 0; - border: 2px solid #fff; + color: #000; + background-color: #fff; + border: 0; + border: 2px solid #fff; - font-size: 20px; + font-size: 20px; min-width: 600px; - padding: 8px 12px; - outline: 0; + padding: 8px 12px; + outline: 0; } +.main_menu h1, +.main_menu h2 { + font-weight: normal; +} + .main_menu h1 { - color: #fff; - font-size: 60px; + font-size: 60px; +} + +.main_menu .widget_box { + margin: 10px auto; + padding: 1px 1px 50px 1px; + background-color: rgba(255,255,255,0.03); + box-shadow: 0px 0px 30px #378; + width: 800px; + +} + +.main_menu .outer_frame { + padding: 1px; + top: 50%; + position: relative; + -webkit-transform: translateY(-50%); +} + +.main_menu ul { + text-align: left; + overflow: hidden; } -.main_menu .frame { - margin: 0 auto; - padding: 1px 1px 50px 1px; - background-color: rgba(0,0,0,0); - box-shadow: 2px 2px 100px #388; - width: 800px; - - top: 50%; - position: relative; - -webkit-transform: translateY(-50%); +.main_menu a { + color: #fff; + text-decoration: none; } diff --git a/src/index.html b/src/index.html index ec63c1f..8e24db0 100644 --- a/src/index.html +++ b/src/index.html @@ -1,25 +1,27 @@ - Scholar Explorer + Scholar Explorer - - - + + + - - - + + + - - + - - + + + + + -
    - +
    +