accurator/commit
Saving uri arrays for path and cluster in local storage.
author | Chris Dijkshoorn |
---|---|
Thu Mar 24 16:53:29 2016 +0100 | |
committer | Chris Dijkshoorn |
Thu Mar 24 16:53:29 2016 +0100 | |
commit | 6956cc612a2dd5a31026d793aef7a2751d0138de |
tree | ea16a5dce32ed4aa72a6bf48cb415a5615c4c0d5 |
parent | c61edb7fbeddc4177728651c5905db611dfb3e12 |
Diff style: patch stat
diff --git a/web/js/components/cluster.js b/web/js/components/cluster.js index 0a02fa2..0aa71a7 100644 --- a/web/js/components/cluster.js +++ b/web/js/components/cluster.js @@ -114,7 +114,7 @@ Cluster.prototype.addThumbnails = function(numberDisplayedItems) { $(this.node).find("#thumbnailRow" + this.id).append( thumbnail.node ); - thumbnail.setClickEvent(this.items[i].link, this); + thumbnail.setClickEvent(this.items[i].link, this.uris, this.path.path); this.thumbnails[i] = thumbnail; } } @@ -141,7 +141,7 @@ Cluster.prototype.changeThumbnails = function(currentPage, nextPage, numberDispl thumbnail.setImage(this.items[i].thumb); thumbnail.setTitle(this.items[i].title); thumbnail.setId(thumbnail.getId(this.items[i].uri)); - thumbnail.setClickEvent(this.items[i].link, this); + thumbnail.setClickEvent(this.items[i].link, this.uris, this.path.path); thumbIndex++; } diff --git a/web/js/components/path.js b/web/js/components/path.js index 9eebef6..54e75d7 100644 --- a/web/js/components/path.js +++ b/web/js/components/path.js @@ -7,13 +7,14 @@ function Path(path, parentId, query) { this.elements = []; // elements of the path this.node = null; this.parentId = parentId; // id of the parent element (probably cluster) - this.query = query; // the query which is the start of the path + this.query = null; // the query which is the start of the path - this.init(); + this.init(query); } -Path.prototype.init = function() { +Path.prototype.init = function(query) { this.node = this.html(); + if (query) ? this.query = query : this.query = "query"; if (typeof this.path === 'string' || this.path instanceof String) { this.addTitle(); } diff --git a/web/js/components/thumbnail.js b/web/js/components/thumbnail.js index 00502dc..0ac5a9c 100644 --- a/web/js/components/thumbnail.js +++ b/web/js/components/thumbnail.js @@ -74,7 +74,7 @@ Thumbnail.prototype.thumbnailTitle = function() { } // Add thumbnail click event -Thumbnail.prototype.setClickEvent = function(link, cluster) { +Thumbnail.prototype.setClickEvent = function(link, uris, path) { var _thumbnail = this; this.link = link; // update link @@ -83,7 +83,8 @@ Thumbnail.prototype.setClickEvent = function(link, cluster) { $(this.node).find(".thumbnail").on("click thumbnail", function() { // add info to local storage to be able to save context - localStorage.setItem("cluster", JSON.stringify(cluster)); + localStorage.setItem("uris", JSON.stringify(uris)); + localStorage.setItem("path", JSON.stringify(path)); document.location.href = _thumbnail.link; }); } diff --git a/web/js/item.js b/web/js/item.js index d95218c..1abb2a6 100644 --- a/web/js/item.js +++ b/web/js/item.js @@ -78,9 +78,9 @@ function itemInit() { var labelArray = initLabels(labels); // Only show path when cluster is available TODO: remove ugly check for undefined - if((localStorage.getItem("currentCluster") !== null) && - (localStorage.getItem("currentCluster") !== "undefined")) { - addPath(); + if((localStorage.getItem("uris") !== null) && + (localStorage.getItem("uris") !== "undefined")) { + addNavigation(); } addButtonEvents(user); @@ -124,7 +124,11 @@ function events(user, labels) { }); } -function addPath() { +function addNavigation() { + var uris = JSON.parse(localStorage.getItem("uris")); + var path = JSON.parse(localStorage.getItem("path")); + + console.log(uris, path); //TODO: restore path functionallity after making it an object // query = localStorage.getItem("query"); // var cluster = JSON.parse(localStorage.getItem("currentCluster")); diff --git a/web/js/results.js b/web/js/results.js index 99f9990..4298220 100644 --- a/web/js/results.js +++ b/web/js/results.js @@ -37,6 +37,8 @@ function resultsInit() { var domain = getDomain(); populateFlags(locale); + clearLocalStorage("uris"); // will be generating new clusters + clearLocalStorage("path"); userLoggedIn() .then(function(userData) { @@ -157,7 +159,6 @@ function results(target, labels) { query = "random"; random(query, labels, target, 20); } - localStorage.setItem("query", query); } // Get results based on the user query @@ -322,7 +323,7 @@ function drawCluster(cluster, clusters) { function displayClusterAsList(cluster, clusters) { // determine from where to start adding items based on the contents of the previous clusters var itemsAdded = itemsInClusters(clusters, clusters.indexOf(cluster)); - var listCluster = mergeClusters(clusters, "list"); + var allUris = mergeUrisClusters(clusters, "list"); //for every item in this cluster, add the thumbnail in the list view for (var itemIndex=0; itemIndex < cluster.uris.length; itemIndex++) { @@ -337,21 +338,21 @@ function displayClusterAsList(cluster, clusters) { display.numberDisplayedItems ); - thumbnail.setClickEvent(cluster.items[itemIndex].link, listCluster); + thumbnail.setClickEvent(cluster.items[itemIndex].link, uris, "path"); $("#" + rowId).append(thumbnail.node); itemsAdded++; } } // Function merging multiple clusters into one adding a new title -function mergeClusters(clusters, title) { +function mergeUrisClusters(clusters) { var uris = []; // retrieve all uris for (var i=0; i<clusters.length; i++) uris = uris.concat(clusters[i].uris); - return new Cluster("cluster", uris, title); + return uris; } // Add a title for the page and print a status message within the page that