cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject git commit: CB-5837: updated download service to use promises
Date Thu, 27 Feb 2014 22:47:40 GMT
Repository: cordova-registry-web
Updated Branches:
  refs/heads/refactor 9e0b80f37 -> 51ac037ac


CB-5837: updated download service to use promises


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/51ac037a
Tree: http://git-wip-us.apache.org/repos/asf/cordova-registry-web/tree/51ac037a
Diff: http://git-wip-us.apache.org/repos/asf/cordova-registry-web/diff/51ac037a

Branch: refs/heads/refactor
Commit: 51ac037ac454767224708d1ca72616edddaecccf
Parents: 9e0b80f
Author: Steven Gill <stevengill97@gmail.com>
Authored: Thu Feb 27 14:47:36 2014 -0800
Committer: Steven Gill <stevengill97@gmail.com>
Committed: Thu Feb 27 14:47:36 2014 -0800

----------------------------------------------------------------------
 attachments/css/pages/home.less      |  2 -
 attachments/css/styles.css           |  2 -
 attachments/js/controllers/home.js   | 16 ++------
 attachments/js/services.js           | 62 +++++++++++++++++--------------
 attachments/partials/views/home.html | 49 ++++++++++++------------
 5 files changed, 63 insertions(+), 68 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-registry-web/blob/51ac037a/attachments/css/pages/home.less
----------------------------------------------------------------------
diff --git a/attachments/css/pages/home.less b/attachments/css/pages/home.less
index 6de67d1..d06ab06 100644
--- a/attachments/css/pages/home.less
+++ b/attachments/css/pages/home.less
@@ -38,9 +38,7 @@
 }
 
 .home-plugin-listing-headers {
-	border-bottom: dotted 2px @border-faded-color;
 	margin: 20px auto;
-	text-align: center;
 
 	h3 {
 		color: @header-bg-color;

http://git-wip-us.apache.org/repos/asf/cordova-registry-web/blob/51ac037a/attachments/css/styles.css
----------------------------------------------------------------------
diff --git a/attachments/css/styles.css b/attachments/css/styles.css
index 8489e4b..b8aff50 100644
--- a/attachments/css/styles.css
+++ b/attachments/css/styles.css
@@ -2885,9 +2885,7 @@ div.left {
   text-align: center;
 }
 .home-plugin-listing-headers {
-  border-bottom: dotted 2px #bfb7b9;
   margin: 20px auto;
-  text-align: center;
 }
 .home-plugin-listing-headers h3 {
   color: #3b4854;

http://git-wip-us.apache.org/repos/asf/cordova-registry-web/blob/51ac037a/attachments/js/controllers/home.js
----------------------------------------------------------------------
diff --git a/attachments/js/controllers/home.js b/attachments/js/controllers/home.js
index 35168a6..03c4a43 100644
--- a/attachments/js/controllers/home.js
+++ b/attachments/js/controllers/home.js
@@ -24,18 +24,9 @@ angular.module('registry.controllers').controller('HomeController', ['$rootScope
     };
 
     $scope.getMostDownloaded = function() {
-        $scope.mostDownloaded = [ 
-            { download_count: 21865, bundle_id: 'org.apache.cordova.device' }, 
-            { download_count: 15250, bundle_id: 'org.apache.cordova.inappbrowser' }, 
-            { download_count: 14761, bundle_id: 'org.apache.cordova.file' }, 
-            { download_count: 12974, bundle_id: 'org.apache.cordova.console' }, 
-            { download_count: 11459, bundle_id: 'org.apache.cordova.camera' }, 
-            { download_count: 10755, bundle_id: 'org.apache.cordova.splashscreen' }, 
-            { download_count: 10441, bundle_id: 'org.apache.cordova.network-information'
}, 
-            { download_count: 10307, bundle_id: 'org.apache.cordova.dialogs' }, 
-            { download_count: 9016, bundle_id: 'org.apache.cordova.geolocation' }, 
-            { download_count: 6139, bundle_id: 'org.apache.cordova.file-transfer' }
-        ];
+        Downloads.getDownloads().then(function(obj){
+            $scope.mostDownloaded = obj.slice(0, 9);
+        });
     };
 
     $scope.getLastUpdated = function() {
@@ -56,5 +47,4 @@ angular.module('registry.controllers').controller('HomeController', ['$rootScope
     $scope.getTotalPlugins();
     $scope.getMostDownloaded();
     $scope.getLastUpdated();
-
 }]);

http://git-wip-us.apache.org/repos/asf/cordova-registry-web/blob/51ac037a/attachments/js/services.js
----------------------------------------------------------------------
diff --git a/attachments/js/services.js b/attachments/js/services.js
index 1520400..6e41626 100644
--- a/attachments/js/services.js
+++ b/attachments/js/services.js
@@ -1,33 +1,39 @@
-console.log('hi');
-angular.module('registry.services', []).factory('Downloads', ['$http', '$window', function($http,
$window) {
-        console.log('here');
-        
-        var downloads = $window.sessionStorage.getItem("Downloads") ? JSON.parse($window.sessionStorage.getItem("Downloads"))
: {data:{}};
-        var refresh_data_from_couchdb = function() {
-            $http.get('/downloads/_design/downloads/_view/byId?group=true').
-              success(function(data) {
-
-                data.rows.forEach(function(d){
+angular.module('registry.services', []).factory('Downloads', function($http, $window, $q)
{
+    
+    var promise;
+    var Downloads = {
+    getDownloads:function(){
+        //var downloads = $window.sessionStorage.getItem("Downloads") ? JSON.parse($window.sessionStorage.getItem("Downloads"))
: {data:{}, arrData:[]};
+        //var a_week_ago = 1000*60*60*24*7;
+        //var now = new Date().valueOf();
+                    
+        //console.log("arraylength: " + downloads.arrData.length);
+        //if (downloads.arrData.length === 0 || !downloads.timestamp || (downloads.timestamp
< (now - a_week_ago)))
+        if (!promise){
+            promise = $http.get('/downloads/_design/downloads/_view/byId?group=true').then(function(data)
{
+                var downloads = {data:{}, arrData:[]};
+                data.data.rows.forEach(function(d){
                     downloads.data[d.key] = d.value;
+                    downloads.arrData.push({key:d.key, value:d.value});
                 });
                 downloads.timestamp = new Date().valueOf();
-                $window.sessionStorage.setItem("Downloads", JSON.stringify(downloads));
-            }).error(function(data) {
-                console.log('error loading downloads data!');
+                downloads.arrData.sort(function(a, b) {
+                    if (a.value < b.value){
+                        return 1;
+                    }
+                    if (a.value > b.value){
+                        return -1;
+                    }
+                    //a must be equal to b
+                    return 0;
+                });
+                //$window.sessionStorage.setItem("Downloads", JSON.stringify(downloads));
+                return downloads.arrData;
             });
         }
-        if(downloads){
-            if (!downloads.timestamp) {
-                refresh_data_from_couchdb();
-            } else {
-                var a_week_ago = 1000*60*60*24*7;
-                var now = new Date().valueOf();
-                if (downloads.timestamp < (now - a_week_ago)) {
-                    console.log('download data old, refreshing');
-                    refresh_data_from_couchdb();
-                }
-            }
-        }
-        console.log(downloads);
-        return downloads;
-    }]);
+        return promise;
+    }
+    };
+
+    return Downloads;
+});

http://git-wip-us.apache.org/repos/asf/cordova-registry-web/blob/51ac037a/attachments/partials/views/home.html
----------------------------------------------------------------------
diff --git a/attachments/partials/views/home.html b/attachments/partials/views/home.html
index 563abea..fb3bef1 100644
--- a/attachments/partials/views/home.html
+++ b/attachments/partials/views/home.html
@@ -70,44 +70,46 @@
 		</div>
 
 		<div class="row home-plugin-listing-headers">
-			<div class="column-4--hand offset-2--hand">
+			<div class="column-12--hand column-6--lap center" >
 				<h3>Most Downloaded</h3>
-			</div>
-			<div class="call-to-action-mid-spacer">
-			</div>
-			<div class="column-4--hand">
+            </div>
+			<div class="column-12--hand column-6--lap center visible--lap invisible--hand">
 				<h3>Last Updated</h3>
-			</div>
+            </div>
+            <div class="column-12--hand"  style="border-bottom:dotted 2px #bfb7b9;"></div>
+
 		</div>		
 
 		<div class="row home-plugin-listing">
-			<div class="column-4--hand offset-2--hand">
+			<div class="column-12--hand column-6--lap center">
 				<div ng-repeat="plugin in mostDownloaded">
 					<div class="row">
-						<div class="column-1--hand">
-							{{plugin.download_count}}
-						</div>
-						<div class="column-1--hand">
+						<div class="column-3--hand">
+							{{plugin.value}}
 						</div>
-						<div class="column-10--hand">
-							<a href="/#/package/{{plugin.bundle_id}}">
-								{{plugin.bundle_id}}
+						<div class="column-9--hand left">
+							<a href="/#/package/{{plugin.key}}">
+								{{plugin.key}}
 							</a>
 						</div>
 					</div>
 				</div>
-			</div>
-			<div class="call-to-action-mid-spacer">
-			</div>
-			<div class="column-4--hand">
+            </div>
+            <div class="column-12--hand visible--hand invisible--lap">
+		        <div class="row home-plugin-listing-headers">
+			        <div class="column-12--hand center">
+				        <h3>Last Updated</h3>
+                    </div>
+                    <div class="column-12--hand"  style="border-bottom:dotted 2px #bfb7b9;"></div>
+                </div>
+            </div>		
+			<div class="column-12--hand column-6--lap center">
 				<div ng-repeat="plugin in lastUpdated">
 					<div class="row">
-						<div class="column-1--hand">
+						<div class="column-3--hand">
 							{{plugin.updated}}
 						</div>
-						<div class="column-1--hand">
-						</div>
-						<div class="column-10--hand">
+						<div class="column-9--hand left">
 							<a href="/#/package/{{plugin.bundle_id}}">
 								{{plugin.bundle_id}}
 							</a>
@@ -116,5 +118,6 @@
 				</div>
 			</div>
 		</div>
-	</div>
+    </div>
+    {{mostDownloaded}}
 </div>


Mime
View raw message