Skip to content

Commit

Permalink
refactor(module): ajax load dpd-module list from http://npmsearch.com/
Browse files Browse the repository at this point in the history
…to query
  • Loading branch information
ericfong committed Sep 5, 2015
1 parent 4707d0b commit 469daae
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 29 deletions.
18 changes: 6 additions & 12 deletions bin/gen-gh-pages.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
#!/usr/bin/env node

var Path = require('path');
var getDpdModules = require('./getDpdModules.js');
var ghpages = require('gh-pages');

var outputFile = __dirname + '/../_site/javascripts/module-control.data.js';
getDpdModules(outputFile, function(){
console.log('Done getDpdModules');


// publish _site to 'origin gh-pages' (So make sure your 'origin' remote point to "https://github.com/[Your_Username]/deployd-docs")
var options = {
message: 'Auto-generated deployd docs',
}
ghpages.publish(Path.join(__dirname, '../_site'), options, function(err) {
console.error(err || 'Pushed');
});
// publish _site to 'origin gh-pages' (So make sure your 'origin' remote point to "https://github.com/[Your_Username]/deployd-docs")
var options = {
message: 'Auto-generated deployd docs',
}
ghpages.publish(Path.join(__dirname, '../_site'), options, function(err) {
console.error(err || 'Pushed');
});
49 changes: 37 additions & 12 deletions public/javascripts/module-control.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,57 @@
angular.module('docs', [])

.controller('ModulesCtrl', function($scope, $http) {
.config(['$httpProvider', function($httpProvider) {
delete $httpProvider.defaults.headers.common["X-Requested-With"]
}])

.controller('ModulesCtrl', function($scope, $http) {
$scope.input = {};

var allModules = $.map(window.Modules, function(value, index) {
return value;
});

$scope.modules = allModules;
var allMoudles = [];

var fields = ['name','keywords','rating','description','author','modified','homepage','version', 'maintainers']
$http.get('http://npmsearch.com/query', {
params: {
"default_field": "name",
"analyze_wildcard": true,
"q": "name:dpd-*",
"fields": fields.join(','),
start: 0,
size: 1000,
sort: 'rating:desc'
},
})
.then(function(response){
// console.log(response.data)
var results = response.data.results
$scope.modules = allMoudles = _(results)
.map(function(data){
fields.forEach(function(k){
if (k === 'keywords' || k === 'maintainers') return;
if (!Array.isArray(data[k])) return;
data[k] = data[k][0];
});
return data;
})
.filter(function(result){
return result.modified >= '2013-01-01';
}).value()
$scope.$apply()
})


$scope.search = function(){
var searchFor = $scope.input.searchFor;
var regex = new RegExp(searchFor);
$scope.modules = [];
for (var i = 0, ii = allModules.length; i < ii; i++) {
var mod = allModules[i];
for (var i = 0, ii = allMoudles.length; i < ii; i++) {
var mod = allMoudles[i];
if (regex.test(mod.name) || regex.test(mod.description)) {
$scope.modules.push(mod);
}
}
}

$scope.moduleMaintainers = function(module){
return _.pluck(module.maintainers, 'name').join();
}

// auto focus
$('#searchFor').focus();

Expand Down
9 changes: 4 additions & 5 deletions views/modules.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
<ul id="modules" class="unstyled">
<li ng-repeat="module in modules | orderBy:'time.modified':true">
<h4>
<a href="https://www.npmjs.org/package/{{module._id}}" target="_blank">
<a href="https://www.npmjs.org/package/{{module.name}}" target="_blank">
<i class="icon-certificate"></i>
{{module.name}}
</a>
- {{module.description}}
<div class="pull-right">
<span>{{moduleMaintainers(module)}}</span>
<img ng-src="https://img.shields.io/npm/v/{{module._id}}.svg?style=flat"/>
<span class="badge badge-success">{{module.time.modified | date:'yyyy-MM-dd'}}</span>
<span>{{module.maintainers.join()}}</span>
<img ng-src="https://img.shields.io/npm/v/{{module.name}}.svg?style=flat"/>
<span class="badge badge-success">{{module.modified | date:'yyyy-MM-dd'}}</span>
</div>
</h4>
</li>
Expand All @@ -35,5 +35,4 @@
</div>

<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.js"></script>
<%- script('module-control.data') %>
<%- script('module-control') %>

0 comments on commit 469daae

Please sign in to comment.