Skip to content

Rstudio #77

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions api/controllers/RstudioController.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module.exports = {
var topic = req.param("topic");
//if topicNames and packageNames where found by the local help function, search for it in the specified packages (might be none)
if(packageNames != null && topicNames != null){
return RStudioService.helpFindByTopicsAndPackages(topicNames,packageNames).then(function(json){
return RStudioService.helpFindByTopicsAndPackages(topic,topicNames,packageNames).then(function(json){
if(json.length == 0){
//with no results : fuzzy search
return ElasticSearchService.helpSearchQuery(topic,['aliases'],true,2).then(function(json){
Expand Down Expand Up @@ -86,7 +86,7 @@ module.exports = {
findPackage:function(req,res){
var package = req.param("packageName");
return RStudioService.findLatestVersion(package).then(function(version){
if(version === null) return res.rstudio_redirect(301, '/packages/' + encodeURIComponent(packageName));
if(version === null) return res.ok([],'rStudio/package_not_found.ejs');
else {
return res.rstudio_redirect(301,'/packages/'+package+'/versions/'+version.version);
}
Expand Down
31 changes: 15 additions & 16 deletions api/models/Alias.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ module.exports = {
include:[{
model:PackageVersion,
as:'package_version',
attributes:['package_name'],
attributes:['id','package_name'],
include:[{
model:Package,
as:'package',
as:'package_latest',
required:true,
attributes:[],
attributes:['latest_version_id'],
include:[{
model:DownloadStatistic,
as:'last_month_stats',
Expand All @@ -78,14 +78,13 @@ module.exports = {
where:{date :{
$gte: new Date(new Date() - 30*24 * 60 * 60 * 1000)
}}
}],
where:{latest_version_id:Sequelize.col('topic.package_version.id')}
}]
}]
}]
}],
where:{name:alias},
group:['topic.name','topic.package_version.id','topic.id','Alias.name','Alias.id'],
order:[sequelize.fn('SUM', sequelize.col('topic.package_version.package.last_month_stats.direct_downloads'))]
group:['topic.name','topic.package_version.id','topic.id','Alias.id','topic.package_version.package_latest.name'],
order:[sequelize.fn('SUM', sequelize.col('topic.package_version.package_latest.last_month_stats.direct_downloads'))]
}).then(function(data){
allResults = _.map(data,function(record){
return {
Expand All @@ -101,22 +100,24 @@ module.exports = {
console.log(err.message);
});
},
orderedFindByTopicsAndPackages:function(topics,packageNames){
orderedFindByTopicsAndPackages:function(alias,topics,packageNames){
return Alias.findAll({
attributes: ['id',['name','alias']],
include:[{
model:Topic,
as:'topic',
required:true,
attributes:['id','name','description'],
include:[{
model:PackageVersion,
as:'package_version',
attributes:['package_name'],
required:true,
attributes:['package_name','id'],
include:[{
model:Package,
as:'package',
as:'package_latest',
required:true,
attributes:[],
attributes:['latest_version_id'],
include:[{
model:DownloadStatistic,
as:'last_month_stats',
Expand All @@ -126,9 +127,6 @@ module.exports = {
$gte: new Date(new Date() - 30*24 * 60 * 60 * 1000)
}}
}],
where:{
latest_version_id:Sequelize.col('topic.package_version.id'),
}
}],
where:{
package_name:{
Expand All @@ -142,8 +140,9 @@ module.exports = {
}
}
}],
group:['topic.name','topic.package_version.id','topic.id','Alias.name','Alias.id'],
order:[sequelize.fn('SUM', sequelize.col('topic.package_version.package.last_month_stats.direct_downloads'))]
where:{name:alias},
group:['topic.name','topic.package_version.id','topic.id','Alias.id','topic.package_version.package_latest.name'],
order:[sequelize.fn('SUM', sequelize.col('topic.package_version.package_latest.last_month_stats.direct_downloads'))]
}).then(function(data){
allResults = _.map(data,function(record){
return {
Expand Down
4 changes: 2 additions & 2 deletions api/services/RStudioService.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ var _ = require('lodash');
cheerio = require('cheerio');

module.exports = {
helpFindByTopicsAndPackages :function(topicNames,packageNames){
return Alias.orderedFindByTopicsAndPackages(topicNames,packageNames).then(_processResults);
helpFindByTopicsAndPackages :function(alias,topicNames,packageNames){
return Alias.orderedFindByTopicsAndPackages(alias,topicNames,packageNames).then(_processResults);
},
helpFindByAlias:function(alias){
return Alias.orderedFindByAlias(alias).then(_processResults);
Expand Down
34 changes: 34 additions & 0 deletions views/rStudio/package_not_found.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<%- partial ('../shared/_navbar.ejs') %>
<% var packages = data; %>
<section class="package">
<div class="container">
<header>
<h4>There where no packages found matching your search term</h4>
<%if(packages.length>0){ %>
Perhaps you meant one of these:
<section class="table-list">
<input id="packagefilter" type="text" placeholder="Filter packages">
<table>
<thead>
<tr>
<td>Package</td>
<td>Description</td>
</tr>
</thead>
<tbody id="filterableItems">
<% for(var i = 0; i < packages.length; ++i) { %>
<%var package = package[i];%>
<tr>
<td><a href="<%= '/packages/' + package.name +'/versions/'+package.version %>"><%= package.name %></td>
<td><%-package.description%></td>
</tr>
<% } %>
<tr class="no-results"><td colspan="3">No Results!</td></tr>
</tbody>
</table>
</section>
<%}%>
</header>
</div>
</section>
<%- partial ('../shared/_footer.ejs') %>