cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject git commit: CB-5130: added prettyDate function as a service
Date Fri, 28 Feb 2014 00:22:40 GMT
Repository: cordova-registry-web
Updated Branches:
  refs/heads/refactor 51ac037ac -> abd53c536


CB-5130: added prettyDate function as a service


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

Branch: refs/heads/refactor
Commit: abd53c53695e9acb202c4c7e78722f8ec05d9476
Parents: 51ac037
Author: Steven Gill <stevengill97@gmail.com>
Authored: Thu Feb 27 16:22:37 2014 -0800
Committer: Steven Gill <stevengill97@gmail.com>
Committed: Thu Feb 27 16:22:37 2014 -0800

----------------------------------------------------------------------
 attachments/js/controllers/home.js   | 22 ++++++++------------
 attachments/js/services.js           | 34 ++++++++++++++++++++++++++++++-
 attachments/partials/views/home.html | 15 +++++++-------
 3 files changed, 49 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-registry-web/blob/abd53c53/attachments/js/controllers/home.js
----------------------------------------------------------------------
diff --git a/attachments/js/controllers/home.js b/attachments/js/controllers/home.js
index 03c4a43..7b6516e 100644
--- a/attachments/js/controllers/home.js
+++ b/attachments/js/controllers/home.js
@@ -1,10 +1,12 @@
-angular.module('registry.controllers').controller('HomeController', ['$rootScope', '$scope',
'$location', '$http','Downloads', function($rootScope, $scope, $location, $http, Downloads)
{
+angular.module('registry.controllers').controller('HomeController', ['$rootScope', '$scope',
'$location', '$http','Downloads', 'prettyDate',  function($rootScope, $scope, $location, $http,
Downloads, prettyDate) {
     
     $scope.totalPlugins = 0;
 
     $scope.mostDownloaded = [];
     $scope.lastUpdated = [];
     
+    
+
     $scope.getTotalPlugins = function(){
         //console.log($scope.packageID);
         var apiCallUrl = '/api/_all_docs?limit=0';
@@ -30,18 +32,12 @@ angular.module('registry.controllers').controller('HomeController', ['$rootScope
     };
 
     $scope.getLastUpdated = function() {
-        $scope.lastUpdated = [
-            { updated: 21865, bundle_id: 'org.apache.cordova.device' }, 
-            { updated: 15250, bundle_id: 'org.apache.cordova.inappbrowser' }, 
-            { updated: 14761, bundle_id: 'org.apache.cordova.file' }, 
-            { updated: 12974, bundle_id: 'org.apache.cordova.console' }, 
-            { updated: 11459, bundle_id: 'org.apache.cordova.camera' }, 
-            { updated: 10755, bundle_id: 'org.apache.cordova.splashscreen' }, 
-            { updated: 10441, bundle_id: 'org.apache.cordova.network-information' }, 
-            { updated: 10307, bundle_id: 'org.apache.cordova.dialogs' }, 
-            { updated: 9016, bundle_id: 'org.apache.cordova.geolocation' }, 
-            { updated: 6139, bundle_id: 'org.apache.cordova.file-transfer' }
-        ];
+        $http.get('/_view/updated?descending=true&limit=10&include_docs=false').then(function(promise){
+            promise.data.rows.forEach(function(obj){
+                obj.key = prettyDate(obj.key);
+            });
+            $scope.lastUpdated = promise.data.rows;
+        })
     };
 
     $scope.getTotalPlugins();

http://git-wip-us.apache.org/repos/asf/cordova-registry-web/blob/abd53c53/attachments/js/services.js
----------------------------------------------------------------------
diff --git a/attachments/js/services.js b/attachments/js/services.js
index 6e41626..2ad33f7 100644
--- a/attachments/js/services.js
+++ b/attachments/js/services.js
@@ -1,4 +1,6 @@
-angular.module('registry.services', []).factory('Downloads', function($http, $window, $q)
{
+service = angular.module('registry.services', []);
+
+service.factory('Downloads', function($http, $window, $q) {
     
     var promise;
     var Downloads = {
@@ -37,3 +39,33 @@ angular.module('registry.services', []).factory('Downloads', function($http,
$wi
 
     return Downloads;
 });
+
+service.factory('prettyDate', function() {
+    /*
+     * JavaScript Pretty Date
+     * Copyright (c) 2011 John Resig (ejohn.org)
+     * Licensed under the MIT and GPL licenses.
+     */
+    // Takes an ISO time and returns a string representing how
+    // long ago the date represents.
+    var prettyDate = function(time){
+    	var date = new Date((time || "").replace(/-/g,"/").replace(/[TZ]/g," ")),
+    		diff = (((new Date()).getTime() - date.getTime()) / 1000),
+    		day_diff = Math.floor(diff / 86400);
+
+    	if ( isNaN(day_diff) || day_diff < 0 || day_diff >= 31 )
+    		return;
+
+    	return day_diff == 0 && (
+    			diff < 60 && "just now" ||
+    			diff < 120 && "1 minute ago" ||
+    			diff < 3600 && Math.floor( diff / 60 ) + " minutes ago" ||
+    			diff < 7200 && "1 hour ago" ||
+    			diff < 86400 && Math.floor( diff / 3600 ) + " hours ago") ||
+    		day_diff == 1 && "Yesterday" ||
+    		day_diff < 7 && day_diff + " days ago" ||
+    		day_diff < 31 && Math.ceil( day_diff / 7 ) + " weeks ago";
+    }
+    return prettyDate;
+});
+

http://git-wip-us.apache.org/repos/asf/cordova-registry-web/blob/abd53c53/attachments/partials/views/home.html
----------------------------------------------------------------------
diff --git a/attachments/partials/views/home.html b/attachments/partials/views/home.html
index fb3bef1..34fd477 100644
--- a/attachments/partials/views/home.html
+++ b/attachments/partials/views/home.html
@@ -84,10 +84,10 @@
 			<div class="column-12--hand column-6--lap center">
 				<div ng-repeat="plugin in mostDownloaded">
 					<div class="row">
-						<div class="column-3--hand">
+						<div class="column-4--hand">
 							{{plugin.value}}
 						</div>
-						<div class="column-9--hand left">
+						<div class="column-8--hand left">
 							<a href="/#/package/{{plugin.key}}">
 								{{plugin.key}}
 							</a>
@@ -106,12 +106,12 @@
 			<div class="column-12--hand column-6--lap center">
 				<div ng-repeat="plugin in lastUpdated">
 					<div class="row">
-						<div class="column-3--hand">
-							{{plugin.updated}}
+						<div class="column-4--hand">
+							{{plugin.key}}
 						</div>
-						<div class="column-9--hand left">
-							<a href="/#/package/{{plugin.bundle_id}}">
-								{{plugin.bundle_id}}
+						<div class="column-8--hand left">
+							<a href="/#/package/{{plugin.id}}">
+								{{plugin.id}}
 							</a>
 						</div>
 					</div>
@@ -119,5 +119,4 @@
 			</div>
 		</div>
     </div>
-    {{mostDownloaded}}
 </div>


Mime
View raw message