Return-Path: X-Original-To: apmail-cordova-commits-archive@www.apache.org Delivered-To: apmail-cordova-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 45271186CE for ; Mon, 22 Jun 2015 21:27:32 +0000 (UTC) Received: (qmail 83120 invoked by uid 500); 22 Jun 2015 21:27:32 -0000 Delivered-To: apmail-cordova-commits-archive@cordova.apache.org Received: (qmail 83092 invoked by uid 500); 22 Jun 2015 21:27:32 -0000 Mailing-List: contact commits-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list commits@cordova.apache.org Received: (qmail 83083 invoked by uid 99); 22 Jun 2015 21:27:32 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 22 Jun 2015 21:27:32 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 0BF18E362D; Mon, 22 Jun 2015 21:27:32 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: nikhilkh@apache.org To: commits@cordova.apache.org Message-Id: <224e74ec81b744c9b7c7e8c22bc8424a@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: cordova-registry-web git commit: Refactor code Date: Mon, 22 Jun 2015 21:27:32 +0000 (UTC) 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 Authored: Fri Jun 19 18:51:01 2015 -0700 Committer: Raghav Katyal 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() + } }); - 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 =
  • ...
  • + } return (
      {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 =

      {downloadCount} downloads last month

      ; } @@ -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 -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(); + 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(); + } }.bind(this)); return (
      @@ -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