accurator/commit
Random results put in a cluster object for rendering.
author | Chris Dijkshoorn |
---|---|
Wed Mar 23 17:02:34 2016 +0100 | |
committer | Chris Dijkshoorn |
Wed Mar 23 17:02:34 2016 +0100 | |
commit | 39d58a462fb2893b4460e158b6704908a8c77a42 |
tree | 493bff4b553c761a0b0689bc0254c17af5841b60 |
parent | c945d0f256b023f6205e36ced29f0460924001e3 |
Diff style: patch stat
diff --git a/web/js/components/pagination.js b/web/js/components/pagination.js index e2fcd2b..ef939d8 100644 --- a/web/js/components/pagination.js +++ b/web/js/components/pagination.js @@ -110,11 +110,11 @@ Pagination.prototype.goToPage = function(page) { // set new node to active newNode.addClass("active"); // remove events - // newNode.off("click pagination"); + newNode.off("click pagination"); this.page = page; // remove event to not add duplicates - // leftArrow.off("click pagination"); + leftArrow.off("click pagination"); if(page === 1) { // disable left arrow because switching to page one leftArrow.addClass("disabled"); @@ -125,7 +125,7 @@ Pagination.prototype.goToPage = function(page) { } // remove event to not add duplicates - // rightArrow.off("click pagination"); + rightArrow.off("click pagination"); if(page === this.numberOfPages) { // disable right arrow because switching to last page rightArrow.addClass("disabled"); diff --git a/web/js/components/path.js b/web/js/components/path.js index 2d93c84..cfaf326 100644 --- a/web/js/components/path.js +++ b/web/js/components/path.js @@ -1,8 +1,8 @@ /******************************************************************************* Path *******************************************************************************/ -function Path(uris, parentId) { - this.uris = uris; // uris of elements of the path +function Path(path, parentId) { + this.path = path; // uris or title element of the path this.labels = null; // labels of elements of the path this.elements = []; // elements of the path this.node = null; @@ -13,6 +13,9 @@ function Path(uris, parentId) { Path.prototype.init = function() { this.node = this.html(); + if (typeof this.path === 'string' || this.path instanceof String) { + this.addTitle(); + } } Path.prototype.html = function() { @@ -30,19 +33,29 @@ Path.prototype.addSubject = function() { ); } +Path.prototype.addTitle = function() { + $(this.node).find("h4").append( + $.el.span({'class':'path-label path-resource'}, + this.path) + ); +} + Path.prototype.enrich = function() { var _path = this; + // no need for enriching if we have a title + if (typeof this.path === 'string' || this.path instanceof String) return; + return $.ajax({type: "POST", url: "metadata", contentType: "application/json", - data: JSON.stringify({"uris":this.uris, "type":"label"})}) + data: JSON.stringify({"uris":this.path, "type":"label"})}) .then(function(labels) { _path.labels = labels; - for (var i=0; i<_path.uris.length; i++) { + for (var i=0; i<_path.path.length; i++) { _path.elements[i] = { - uri:_path.uris[i], + uri:_path.path[i], label:truncate(_path.labels[i], 50) }; } diff --git a/web/js/components/thumbnail.js b/web/js/components/thumbnail.js index 828d19e..542cf2c 100644 --- a/web/js/components/thumbnail.js +++ b/web/js/components/thumbnail.js @@ -79,7 +79,7 @@ Thumbnail.prototype.setClickEvent = function(link, parentId) { this.link = link; // update link // remove possible old event - // $(this.node).find(".thumbnail").off("click thumbnail"); + $(this.node).find(".thumbnail").off("click thumbnail"); $(this.node).find(".thumbnail").on("click thumbnail", function() { //TODO check what should be added to local storage diff --git a/web/js/results.js b/web/js/results.js index a6bb96c..6262617 100644 --- a/web/js/results.js +++ b/web/js/results.js @@ -139,7 +139,7 @@ Search, Recommend or Random results function results(target, labels) { var query = getParameterByName("query"); // get query from url when present var userQuery = getParameterByName("user"); // get user from url when present - var recommendBoolean = true; // don't do random stuff + var recommendBoolean = false; // don't do random stuff if(query) { // results based on the user query @@ -152,7 +152,7 @@ function results(target, labels) { } else { // random results query = "random"; - random(query, labels, target, 10); + random(query, labels, target, 30); } localStorage.setItem("query", query); } @@ -209,46 +209,52 @@ function random(query, labels, target, noResults) { $.getJSON("recommendation", {strategy:'random', number:noResults, target:target}) - .then(function(uris){ - // populate the page with random - randoms = uris; - // TODO add in local storage?! - // localStorage.setItem("randoms", JSON.stringify(randoms)); - - // enrich retrieved clusters if any - if(randoms.length == 0){ - statusMessage(labels.resultsTxtNoResults, query); - } else { - statusMessage(labels.resultsHdrRandomResults); - - if (query === "expertise"){ - // set page title - $(document).prop('title', labels.resultsTxtRecommendationsFor + labels.realName); - } - - var noRandomItems = randoms.length; - - if (query === "expertise" && display.layout === "cluster") { - addRandomPath(); - } else { - // add rows for random objects and display them as a list - addRandomRows(noRandomItems); - } - - // enrich random objects - enrichRandoms(randoms) - .then(function(){ - // TODO add pagination here for cluster items and add cluster items - if (query === "expertise" && display.layout === "cluster"){ - $("#randoms").append(pagination(getNoOfPagesOrRows(noRandomItems), - randoms, "randoms")); - displayRandomCluster(0); - } - else { - displayRandomList(); - } - }); - } + .then(function(uris) { + // create cluster array with first entry a cluster with random items + var clusters = []; + clusters[0] = new Cluster("clusterRandom", uris, "random"); + controls(clusters, labels); + drawResults(clusters); + + // // populate the page with random + // randoms = uris; + // // TODO add in local storage?! + // // localStorage.setItem("randoms", JSON.stringify(randoms)); + // + // // enrich retrieved clusters if any + // if(randoms.length == 0){ + // statusMessage(labels.resultsTxtNoResults, query); + // } else { + // statusMessage(labels.resultsHdrRandomResults); + // + // if (query === "expertise"){ + // // set page title + // $(document).prop('title', labels.resultsTxtRecommendationsFor + labels.realName); + // } + // + // var noRandomItems = randoms.length; + // + // if (query === "expertise" && display.layout === "cluster") { + // addRandomPath(); + // } else { + // // add rows for random objects and display them as a list + // addRandomRows(noRandomItems); + // } + // + // // enrich random objects + // enrichRandoms(randoms) + // .then(function(){ + // // TODO add pagination here for cluster items and add cluster items + // if (query === "expertise" && display.layout === "cluster"){ + // $("#randoms").append(pagination(getNoOfPagesOrRows(noRandomItems), + // randoms, "randoms")); + // displayRandomCluster(0); + // } + // else { + // displayRandomList(); + // } + // }); + // } }, function(data) { statusMessage(labels.resultsTxtError, data.responseText); });