]> khamidou — GitHub mirrors - kite.git/commitdiff
fixed frontend email ordering bug
authorkarim hamidou <khamidou@gmail.com>
Wed, 4 Jun 2014 14:58:39 +0000 (16:58 +0200)
committerkarim hamidou <khamidou@gmail.com>
Wed, 4 Jun 2014 14:58:39 +0000 (16:58 +0200)
src/front/app/js/app.js
src/front/app/js/controllers.js
src/front/app/js/services.js
src/front/app/partials/baselayout.html

index 2320d08907e1270d2ef2a638e0e40d00e3ccab18..b3964f8e47757f2a274c9da8643bf297d9fa8ea2 100644 (file)
@@ -3,47 +3,25 @@
 
 // Declare app level module which depends on filters, and services
 angular.module('KiteMail', ['ngRoute', 'ngCookies', 'KiteMail.filters', 'KiteMail.services', 'KiteMail.directives', 'KiteMail.controllers']).
-  config(['$routeProvider', '$httpProvider', function($routeProvider, $httpProvider) {
+  factory('errorInterceptor', ['$rootScope', '$q', '$location', function (scope, $q, $location) {
+        return {
+            response: function (response) {
+                if (response && response.status === 401) {
+                    $location.path("/login");
+                    return $q.reject(response);
+                }
+
+                return response || $q.when(response);
+            },
+    }; 
+  }]).config(['$routeProvider','$httpProvider', function($routeProvider, $httpProvider) {
+
     $routeProvider.when('/mail', {templateUrl: 'partials/mailbox.html', controller: 'InboxesListController'});
     $routeProvider.when('/login', {templateUrl: 'partials/login.html', controller: 'LoginController'});
     $routeProvider.when('/thread/:id', {templateUrl: 'partials/thread.html', controller: 'ThreadController'});
     $routeProvider.otherwise({redirectTo: '/login'});
 
-    var interceptor = ['$rootScope', '$q', '$location', function (scope, $q, $location) {
-        function success(response) {
-            var status = response.status;
-            // user is unauthorized.
-            if (status == 401) {
-                //window.location = "/account/login?redirectUrl=" + Base64.encode(document.URL);
-                $location.path("/login");
-                return;
-            }
-
-            return response;
-        }
-        function error(response) {
-                        // otherwise
-            return $q.reject(response);
-        }
-        return function (promise) {
-            return promise.then(success, error);
-        }
-    }];
-    $httpProvider.responseInterceptors.push(interceptor);
+    $httpProvider.interceptors.push('errorInterceptor');
 
   }]).run(['$rootScope', '$location', 'Auth', function($rootScope, $location, Auth) { 
-/*   $rootScope.$on( "$routeChangeStart", function(event, next, current) {
-        console.log(Auth.loggedIn());
-        if (!Auth.loggedIn()) {
-            // no logged user, redirect to /login
-            if (next.templateUrl != "partials/login.html") {
-                $location.path("/login");
-            }
-        } else { // already loggedin
-            if (next.templateUrl == "partials/login.html") {
-                $location.path("/mail");
-            }
-        }
-    }); 
-*/
   }]);
index 60f6a351f21e9443cabd77eb4f8c51a4c1f4f5ea..4088503b1f98a763597fa8f409e2796fef77eb4a 100644 (file)
@@ -2,16 +2,14 @@
 
 /* Controllers */
 
-angular.module('KiteMail.controllers', ['KiteMail.services']).
-  controller('InboxesListController', function($scope) {
-        $scope.inboxes = [
-            {"name": "Inbox", },
-            {"name": "Trash", },
-            {"name": "Spam",  },];
-            
-}).controller('MailsListController', ['$scope', 'Emails', 'Auth', function($scope, Emails, Auth) {
-        console.log(Auth.username());
+angular.module('KiteMail.controllers', ['KiteMail.services'])
+.controller('InboxesListController', ['$scope', function($scope) {
+        $scope.inboxes = ["Inbox"]; 
+
+}]).controller('MailsListController', ['$scope', 'Emails', 'Auth', function($scope, Emails, Auth) {
+
         $scope.threads = Emails.threads({username: Auth.username()});
+
 }]).controller('ThreadController', ['$scope', '$routeParams', '$sce', 'Emails', 'Auth', function($scope, $routeParams, $sce, Emails, Auth) {
     $scope.thread = Emails.thread({username: Auth.username(), "id": $routeParams.id});
     $scope.trustHTML = function(html_code) {
index 7fa39836444a0b8c0f60c2b7aa690937e70f9f17..8a84a1fcce1606d2b443b7fee2c54b03c4b3a867 100644 (file)
@@ -3,25 +3,27 @@
 /* Services */
 
 angular.module('KiteMail.services', ['ngResource', 'ngCookies']).
-factory('Emails', ['$resource',
-    function($resource) {
+factory('Emails', ['$resource', 'Utils',
+    function($resource, Utils) {
+        /* FIXME: maybe move this code to a response interceptor? */
+        var processThreads = function(data) {
+            var data = angular.fromJson(data);
+            return Utils.cleanDates(data);
+            };
+        
         var processThread = function(data) {
             var data = angular.fromJson(data);
-
-            // convert date string to js date objects
-            for(var i = 0; i < data.length; i++) {
-                data[i]["date"] = new Date(data[i]["date"]);
-            }
-
+            data.messages = Utils.cleanDates(data.messages);
+            debugger;
             return data;
-        }
+        };
 
         var res = $resource('/kite/:username/mail/:id', {}, {
             threads: {
                 method:'GET',
                 params:{username: "@username"},
                 isArray:true,
-                transformResponse: processThread,
+                transformResponse: processThreads,
             },
 
             thread: {
@@ -38,7 +40,15 @@ factory('Emails', ['$resource',
     return {
          date2array: function(date) {
             return (date+'').split(' ');
-        }
+        },
+        
+         /* cleandates: transform every field named "date" to a js Date object */
+         cleanDates: function(data) {
+            for(var i = 0; i < data.length; i++) {
+                data[i]["date"] = new Date(data[i]["date"]);
+            }
+            return data;
+        },
     };   
 }).factory('Auth', ['$cookies', '$http', 
     function($cookies, $http) {
index 70103981ed2c71246210b5dba9549f80f798bfd6..e8717dd94c61a83d973763ceeec7867345943ede 100644 (file)
@@ -27,7 +27,7 @@
                         <li>
                             <button class="btn btn-primary btn-compose">Compose</button>
                         </li>
-                        <li class="currentInbox">Inbox <span class=unreadMailCount">(4)</span></li>
+                        <li class="currentInbox">Inbox <span class=unreadMailCount"></span></li>
                         <li ng-repeat="inbox in inboxes">{{inbox.name}}</li>
                     </ul>
                 </div>