Skip to content

Commit

Permalink
Add metrics & map icons to the search results list
Browse files Browse the repository at this point in the history
Add the logic to create and update a metricsModel in the new SearchResultsView.

Issue #1720
  • Loading branch information
robyngit committed Jun 5, 2023
1 parent 4df5a58 commit ed827d4
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 20 deletions.
4 changes: 4 additions & 0 deletions src/css/metacatui-common.css
Original file line number Diff line number Diff line change
Expand Up @@ -2105,10 +2105,14 @@ i.icon.metric-icon.icon-spinner.icon-spin {
color: #666;
min-width: 47px;
text-align: center;
display: block;
}
i.catalog-metric-icon {
margin-right: 3px;
}
.catalog-stat{
display: inline-block;
}

/**********************************************************
* Metric Modal / Profile Chart (Views, Downloads, Citations) *
Expand Down
9 changes: 9 additions & 0 deletions src/js/collections/SolrResults.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,15 @@ define(['jquery', 'underscore', 'backbone', 'models/SolrHeader', 'models/SolrRes
getLastUrl: function(){
return this.lastUrl || "";
},

/**
* Get the list of PIDs for the search results
* @returns {string[]} - The list of PID strings for the search results
* @since x.x.x
*/
getPIDs: function () {
return this.pluck("id");
},

/**
* Determines whether the search parameters have changed since the last fetch. Returns true the next URL
Expand Down
18 changes: 3 additions & 15 deletions src/js/models/AppModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,20 +109,6 @@ define(['jquery', 'underscore', 'backbone'],
*/
catalogSearchMapOptions: {
showLayerList: false,
layers: [
{
"label": "Satellite imagery",
"icon": "urn:uuid:4177c2e1-3037-4964-bf00-5f13182308d9",
"type": "IonImageryProvider",
"description": "Global satellite imagery down to 15 cm resolution in urban areas",
"attribution": "Data provided by Bing Maps © 2021 Microsoft Corporation",
"moreInfoLink": "https://www.microsoft.com/maps",
"opacity": 1,
"cesiumOptions": {
"ionAssetId": "2"
}
}
],
clickFeatureAction: "zoom"
},

Expand Down Expand Up @@ -1737,7 +1723,9 @@ define(['jquery', 'underscore', 'backbone'],
label: "Taxon",
placeholder: "Class, family, etc.",
icon: "sitemap",
description: "Find data about any taxonomic rank"
description: "Find data about any taxonomic rank",
matchSubstring: true,
fieldsOperator: "OR"
},
{
fields: ["siteText"],
Expand Down
2 changes: 0 additions & 2 deletions src/js/templates/resultsItem.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
} %>
</div>

<% if(typeof MetacatUI.mapKey == "string" && MetacatUI.mapKey.length){ %>
<div class="on-map icons ">
<% if (typeof geohash_9 !== "undefined" && geohash_9 !== null){
print('<i class="icon icon-map-marker on-map open-marker " data-id="'+id+'" data-geohash="' + geohash_9 + '" title="This data set has ' + geohash_9.length + ' geographic regions on the map"></i>');
Expand All @@ -45,7 +44,6 @@
}
%>
</div>
<% } %>

<% if(hasProv){
print('<div class="icons provenance active ">');
Expand Down
2 changes: 1 addition & 1 deletion src/js/views/search/CatalogSearchView.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ define([
* The template to use in case there is a major error in rendering the
* view.
* @type {string}
* @since 2.x.x
* @since x.x.x
*/
errorTemplate: `<div class="error" role="alert">
<h2>There was an error loading the search results.</h2>
Expand Down
49 changes: 47 additions & 2 deletions src/js/views/search/SearchResultsView.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ define([
"backbone",
"collections/SolrResults",
"views/search/SearchResultView",
], function (Backbone, SearchResults, SearchResultView) {
"models/MetricsModel",
], function (Backbone, SearchResults, SearchResultView, MetricsModel) {
"use strict";

/**
Expand Down Expand Up @@ -58,13 +59,22 @@ define([
*/
noResultsTemplate: `<div class="no-search-results">No results found.</div>`,

/**
* The metrics model that will be passed to the search result view
* @type {MetricsModel}
* @since x.x.x
*/
metricsModel: null,

/**
* Render the view.
*/
render: function () {
try {
if (!this.searchResults) this.setSearchResults();

if (!this.metricsModel) this.setUpMetrics();

this.loading();

if (typeof this.searchResults.getNumFound() == "number") {
Expand Down Expand Up @@ -102,6 +112,7 @@ define([
this.listenTo(this.searchResults, "reset", this.addResultCollection);
this.listenTo(this.searchResults, "changing request", this.loading);
this.listenTo(this.searchResults, "error", this.showError);
this.listenTo(this.searchResults, "add reset", this.updateMetrics);
},

/**
Expand Down Expand Up @@ -188,7 +199,41 @@ define([
* Creates a Search Result View
*/
createSearchResultView: function () {
return new SearchResultView();
const options = {
metricsModel: this.metricsModel,
};
return new SearchResultView(options);
},

/**
* Creates a new MetricsModel if the app is configured to display metrics.
* Sets the metrics model on this view. The metrics model is used to
* display views, citations, and downloads for each search result.
* @since x.x.x
* @returns {MetricsModel}
*/
setUpMetrics: function () {
if (!MetacatUI.appModel.get("displayDatasetMetrics")) {
this.metricsModel = null;
return;
}
this.metricsModel = new MetricsModel({
type: "catalog",
});
return this.metricsModel;
},

/**
* Updates the metrics model with the PIDs of the search results and
* fetches the metrics.
* @since x.x.x
* @returns {MetricsModel}
*/
updateMetrics: function () {
if (!this.metricsModel) return;
this.metricsModel.set("pid_list", this.searchResults.getPIDs());
this.metricsModel.fetch();
return this.metricsModel;
},

/**
Expand Down

0 comments on commit ed827d4

Please sign in to comment.