You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ni...@apache.org on 2015/06/22 23:27:32 UTC
cordova-registry-web git commit: Refactor code
Repository: cordova-registry-web
Updated Branches:
refs/heads/master 14fe2277e -> 786d638cc
Refactor code
Project: http://git-wip-us.apache.org/repos/asf/cordova-registry-web/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-registry-web/commit/786d638c
Tree: http://git-wip-us.apache.org/repos/asf/cordova-registry-web/tree/786d638c
Diff: http://git-wip-us.apache.org/repos/asf/cordova-registry-web/diff/786d638c
Branch: refs/heads/master
Commit: 786d638cce37188865aa0f226ff9d0020d13a17a
Parents: 14fe227
Author: Raghav Katyal <ra...@microsoft.com>
Authored: Fri Jun 19 18:51:01 2015 -0700
Committer: Raghav Katyal <ra...@microsoft.com>
Committed: Fri Jun 19 18:51:01 2015 -0700
----------------------------------------------------------------------
npm-search/assets/js/app.js | 123 +++++++++++++++++++++------------------
1 file changed, 67 insertions(+), 56 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-registry-web/blob/786d638c/npm-search/assets/js/app.js
----------------------------------------------------------------------
diff --git a/npm-search/assets/js/app.js b/npm-search/assets/js/app.js
index c0726d3..4013a25 100644
--- a/npm-search/assets/js/app.js
+++ b/npm-search/assets/js/app.js
@@ -76,15 +76,18 @@ var SupportedPlatforms = React.createClass({
});
sortedMajorPlatforms.forEach(function(platform) {
- if(platform.present)
+ if(platform.present) {
majorPlatformsSupported.push(<PlatformButton platform={platform.text} />)
+ }
});
- while(majorPlatformsSupported.length < 4 && otherPlatformsSupported.length > 0)
+ while(majorPlatformsSupported.length < 4 && otherPlatformsSupported.length > 0) {
majorPlatformsSupported.push(otherPlatformsSupported.shift());
+ }
var moreButton;
- if(otherPlatformsSupported.length > 0 && !this.state.moreClicked)
+ if(otherPlatformsSupported.length > 0 && !this.state.moreClicked) {
moreButton = <li className="clickable" onClick={this.onClick}>...</li>
+ }
return (
<ul className="supportedPlatforms">
{majorPlatformsSupported}
@@ -134,8 +137,7 @@ var Plugin = React.createClass({
'row': true
});
- if(this.props.plugin.downloadCount)
- {
+ if(this.props.plugin.downloadCount) {
var downloadCount = this.props.plugin.downloadCount.toLocaleString();
downloadField = <p><small> {downloadCount} downloads last month</small></p>;
}
@@ -169,67 +171,80 @@ var Plugin = React.createClass({
})
var PluginList = React.createClass({
- render: function() {
- var plugins = [],
- filterText = this.props.filterText.toLowerCase();
-
- var filters = filterText.split(" ");
- var platforms = [];
- var authors = [];
- var licenses = [];
- var searchWords = [];
-
- var ifPresent = function(values, pluginInfo) {
- var allValuesPresent = true;
- if(values.length == 0)
- return allValuesPresent;
- if(!pluginInfo)
- return false;
- values.forEach(function(value) {
- var valuePresent = false;
- for(var index=0;index<pluginInfo.length;index++)
- {
- if(pluginInfo[index] && pluginInfo[index].toLowerCase().indexOf(value) > -1)
- valuePresent = true;
- }
- if(!valuePresent)
- allValuesPresent = false;
- });
+ contains: function(values, pluginInfo) {
+ var allValuesPresent = true;
+ if(values.length == 0) {
return allValuesPresent;
- };
+ }
+ if(!pluginInfo) {
+ return false;
+ }
+ values.forEach(function(value) {
+ var valuePresent = false;
+ for(var index=0; index < pluginInfo.length; index++) {
+ if(pluginInfo[index] && pluginInfo[index].toLowerCase().indexOf(value) > -1) {
+ valuePresent = true;
+ }
+ }
+ if(!valuePresent) {
+ allValuesPresent = false;
+ }
+ });
+ return allValuesPresent;
+ },
+ populateFilters: function(filterText)
+ {
+ var searchStrings = filterText.split(" ");
+ var filters = [];
+ filters['platforms'] = [];
+ filters['authors'] = [];
+ filters['licenses'] = [];
+ filters['searchWords'] = [];
- filters.forEach(function(filter) {
- var keywords = filter.split(":");
- if(keywords.length == 1)
- {
+ searchStrings.forEach(function(searchString) {
+ var keywords = searchString.split(":");
+ if(keywords.length == 1) {
var param = keywords[0].trim();
- if(param)
- searchWords.push(param);
+ if(param) {
+ filters['searchWords'].push(param);
+ }
}
- else if(keywords[1].trim())
- {
+ else if(keywords[1].trim()) {
var param = keywords[1].trim();
switch(keywords[0]) {
case 'platform':
- platforms.push(param);
+ filters['platforms'].push(param);
break;
case 'author':
- authors.push(param);
+ filters['authors'].push(param);
break;
case 'license':
- licenses.push(param);
+ filters['licenses'].push(param);
break;
default:
- searchWords.push(filter);
+ filters['searchWords'].push(searchString);
}
}
- else
- searchWords.push(filter);
+ else {
+ filters['searchWords'].push(searchString);
+ }
});
+ return filters;
+ },
+ render: function() {
+ var plugins = [],
+ filterText = this.props.filterText.toLowerCase();
+
+ var filters = this.populateFilters(filterText);
+
this.props.plugins.forEach(function(plugin) {
var fullPluginText = plugin.name.concat(plugin.author, plugin.keywords, plugin.license, plugin.description);
- if(ifPresent(platforms, plugin.keywords) && ifPresent(authors, plugin.author) && ifPresent(licenses, plugin.license) && ifPresent(searchWords, fullPluginText))
- plugins.push(<Plugin plugin={plugin} key={plugin.author + plugin.name}/>);
+ if(this.contains(filters['platforms'], plugin.keywords)
+ && this.contains(filters['authors'], plugin.author)
+ && this.contains(filters['licenses'], plugin.license)
+ && this.contains(filters['searchWords'], fullPluginText)) {
+ plugins.push(<Plugin plugin={plugin} key={plugin.author + plugin.name}/>);
+ }
}.bind(this));
return (
<div className="col-xs-offset-2 col-xs-8">
@@ -257,15 +272,13 @@ var App = React.createClass({
},
addCondition: function(condition) {
this.setState(function(previousState, currentProps) {
- if(previousState.filterText.indexOf(condition) > -1)
- {
+ if(previousState.filterText.indexOf(condition) > -1) {
return {
filterText: previousState.filterText,
plugins: previousState.plugins
};
}
- else
- {
+ else {
return {
filterText: previousState.filterText + condition + ' ',
plugins: previousState.plugins
@@ -299,11 +312,9 @@ var App = React.createClass({
var getDownloadCount = function(plugins,that) {
var packageNames = "";
- for(var index=0; index < plugins.length; index++)
- {
+ for(var index=0; index < plugins.length; index++) {
packageNames += plugins[index].name + ",";
- if(index%50 === 0 || index === plugins.length -1)
- {
+ if(index%50 === 0 || index === plugins.length -1) {
xhrRequest("https://api.npmjs.org/downloads/point/last-month/" + packageNames, function(xhrResult) {
plugins.forEach(function(plugin) {
if(xhrResult[plugin.name])
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org