-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #199 from GSA/ajax-recent-view
Ajax recent view
- Loading branch information
Showing
12 changed files
with
160 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// This js file loads with datagov-popular.html snippet | ||
|
||
jQuery(function ($) { | ||
|
||
// This api takes a list of package ids from querystring and returns the view count for each package | ||
var pupolar_api = "/datagovtheme/get-popular-count"; | ||
|
||
// all ids in a string, comma separated | ||
var pkgs = {'pkgs': collect_all_packages().join(',')}; | ||
|
||
$.getJSON(pupolar_api, pkgs, function(data) { | ||
$.each( data, function( key, val ) { | ||
$("ul.dataset-list li.dataset-item h3.dataset-heading").each(function() { | ||
if ($(this).attr('pkg_id') == key) { | ||
$(this).find('span.recent-views-datagov').attr('title', val['recent']).html('<i class="fa fa-line-chart"></i> ' + val['recent'] + ' recent views'); | ||
// If the view count is greater than 10, make it visible | ||
if (val['recent'] >= 10) { | ||
$(this).find('span.recent-views').css('visibility', 'visible'); | ||
}else{ | ||
$(this).find('span.recent-views').css('display', 'hidden'); | ||
} | ||
} | ||
}); | ||
}); | ||
}); | ||
|
||
// We have pkg_id in each dataset-item, added in the template. | ||
function collect_all_packages() { | ||
var pkgs = []; | ||
$("ul.dataset-list li.dataset-item h3.dataset-heading").each(function() { | ||
pkgs.push($(this).attr('pkg_id')); | ||
}); | ||
|
||
return pkgs; | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<span class="recent-views recent-views-datagov" title="" xmlns="http://www.w3.org/1999/xhtml"> | ||
<i class="fa fa-line-chart"></i> recent views | ||
</span> | ||
{% asset 'datagovtheme/popular-js' %} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters