Skip to content

Commit

Permalink
Merge pull request #235 from racker/meta_index/filters
Browse files Browse the repository at this point in the history
Updated filtering to be server side.
  • Loading branch information
kans committed Aug 31, 2012
2 parents 2ff6cfc + f019b52 commit 61488d0
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 30 deletions.
1 change: 0 additions & 1 deletion lib/web/plugins/ruok.js
Expand Up @@ -68,7 +68,6 @@ module.exports = {
});
results["details"][environment] = regions;
});
console.log(JSON.stringify(results));
payload.set_data(null, results);
});
}
Expand Down
1 change: 1 addition & 0 deletions lib/web/projects/project.js
Expand Up @@ -152,6 +152,7 @@ var Project = utils.make_class({
if (devops_json.related_apis.version_one !== undefined) {
devops_json.related_apis.version_one.project = [].concat(devops_json.related_apis.version_one.project);
}
devops_json.tags = _.map(devops_json.tags, function(tag) { return tag.toLowerCase();});
self.devops = devops_json;
cb();
},
Expand Down
33 changes: 31 additions & 2 deletions lib/web/routes/web.js
Expand Up @@ -386,11 +386,40 @@ module.exports.install = function(web_app, installed_projects){
add_route('get',
urls.META_INDEX,
function(req, res) {
var query_parse = url.parse(req.url).query;
var query;
var meta_index_projects = req.projects;
var tags = [];
var query_tags = [];
var intersection;
var tag_count = {};
_.each(req.projects, function(project){
if (!project.devops) {return;}
tags = tags.concat(project.devops.tags);
});
_.each(tags, function(value, i) {
if (tag_count[value]) {tag_count[value]++;}
else {tag_count[value] = 1;}
});
if (query_parse) {
meta_index_projects = [];
query = query_parse.split('=')[1];
query = decodeURIComponent(query).split(',');
_.each(req.projects, function(project){
if (!project.devops) {return;}
project_tags = project.devops.tags;
intersection = _.intersection(query, project_tags);
if (intersection.length === query.length) {
meta_index_projects.push(project);
}
});
}
var context = {
name: 'Dashboards',
projects: req.projects,
projects: meta_index_projects,
external_projects: settings.external_projects,
links: settings.metadashboard_uris
links: settings.metadashboard_uris,
tags: tag_count
};
res.render('meta_index.jade', context);
});
Expand Down
33 changes: 6 additions & 27 deletions lib/web/views/meta_index.jade
Expand Up @@ -4,33 +4,7 @@ block append scripts
script
$(document).ready(function(){
$('.project').tsort();
//- Setting up tag filtering
var tag_count = {};
var tags = $('.tags').map(function() {
return this.textContent.split(', ');
});
tags.sort();
$.each(tags, function(i, value) {
if (tag_count[value]) {tag_count[value]++}
else {tag_count[value] = 1}
});
tags = _.uniq(tags);
$.each(tags, function(i, value) {
nospace = value.replace(/\ /g,'\-'); // This sucks, fix me.
if (value !== "") {$('.filters > ul').append(
'<li id="' + nospace + '-filter"><a>' + value + '</a> <span class="muted">(' +tag_count[value] + ')</span> </li>'
)};
$('#'+nospace+'-filter').toggle(
function () {
$(this).find('a').css({"color": "red"});
$('.tags').not(':contains('+value+')').parent().hide();
},
function () {
$(this).find('a').css({"color": "#08C"});
$('.tags').not(':contains('+value+')').parent().show();
}
);
});
$('.filters > ul > li').tsort();
});

block append css
Expand Down Expand Up @@ -71,6 +45,11 @@ block content
div.filters
h4 Tag Filters
ul.unstyled
each count, tag in tags
li
a(href="/?tags="+encodeURI(tag))
#{tag}
span.muted (#{count})
// Projects
div.span10
each project in projects
Expand Down

0 comments on commit 61488d0

Please sign in to comment.