From 5ad3f7a4c4445f7cd1363dd0b43c6619d9e0532c Mon Sep 17 00:00:00 2001 From: arzynik Date: Sun, 1 Dec 2013 13:03:44 -0800 Subject: [PATCH] fixes #2165. fixes #1839. partial #2106. --- .../default/crunchbutton/api/user/orders.php | 4 +- include/library/Crunchbutton/User.php | 1 + .../default/seven/frontend/location.phtml | 2 +- .../default/seven/layout/html.body.phtml | 10 ++- www/assets/js/app.js | 15 +++- www/assets/js/controllers.js | 19 ++--- www/assets/js/services.order.js | 4 - www/assets/js/services.position.js | 76 ++++++++++--------- www/assets/js/services.restaurant.js | 1 + 9 files changed, 74 insertions(+), 58 deletions(-) diff --git a/include/controllers/default/crunchbutton/api/user/orders.php b/include/controllers/default/crunchbutton/api/user/orders.php index a0f79ebcd..c0b21df3f 100644 --- a/include/controllers/default/crunchbutton/api/user/orders.php +++ b/include/controllers/default/crunchbutton/api/user/orders.php @@ -5,10 +5,10 @@ class Controller_api_user_orders extends Crunchbutton_Controller_Rest { switch ($this->method()) { case 'get': $orders = c::user()->orders('compact'); - if( $orders->count() > 0 ){ + if ($orders->count() > 0) { echo $orders->json(); } else { - json_encode([]); + //echo json_encode([]); } break; diff --git a/include/library/Crunchbutton/User.php b/include/library/Crunchbutton/User.php index 49f07f776..8e6741d81 100644 --- a/include/library/Crunchbutton/User.php +++ b/include/library/Crunchbutton/User.php @@ -61,6 +61,7 @@ class Crunchbutton_User extends Cana_Table { if (!$this->id_user) { return new Order; } + if (!isset($this->_orders)) { if ($type == 'compact') { $q = ' diff --git a/include/views/default/seven/frontend/location.phtml b/include/views/default/seven/frontend/location.phtml index 927ed7160..23db8b594 100644 --- a/include/views/default/seven/frontend/location.phtml +++ b/include/views/default/seven/frontend/location.phtml @@ -45,7 +45,7 @@ We listen to our users Let us know
and we will add it!
- What's your favorite? + What's your
favorite?
We check this
stuff daily!
diff --git a/include/views/default/seven/layout/html.body.phtml b/include/views/default/seven/layout/html.body.phtml index 34722b7e5..e9d5273cf 100644 --- a/include/views/default/seven/layout/html.body.phtml +++ b/include/views/default/seven/layout/html.body.phtml @@ -12,7 +12,7 @@ -
  • +
  • @@ -20,7 +20,7 @@
  • -
  • +
  • @@ -127,9 +127,11 @@
  • About
  • Log In
  • Log Out
  • - -
  • Download for iPhone
  • + +
  • Download for iPhone
  • + +
  • TEST: card
  • TEST: clear location
  • TEST: go home
  • diff --git a/www/assets/js/app.js b/www/assets/js/app.js index edc87d056..e77736187 100644 --- a/www/assets/js/app.js +++ b/www/assets/js/app.js @@ -242,7 +242,7 @@ NGApp.config(['$routeProvider', '$locationProvider', function($routeProvider, $l }]); // global route change items -NGApp.controller('AppController', function ($scope, $route, $routeParams, $rootScope, $location, $window, AccountService, MainNavigationService, AccountSignOut, CartService, ReferralService) { +NGApp.controller('AppController', function ($scope, $route, $routeParams, $rootScope, $location, $window, AccountService, MainNavigationService, AccountSignOut, CartService, ReferralService, LocationService) { // define external pointers App.rootScope = $rootScope; @@ -295,8 +295,17 @@ NGApp.controller('AppController', function ($scope, $route, $routeParams, $rootS if( !App.config.user.id_user ){ CartService.clean(); } - // reload the actual controller + + LocationService.init(true); + if (App.config.user.id_user) { + $location.path('/food-delivery'); + } + + App.snap.close(); + console.log('userAuth!'); + + // reload the actual controller if( !AccountService.forceDontReloadAfterAuth ){ $rootScope.reload(); } @@ -414,6 +423,8 @@ NGApp.controller('AppController', function ($scope, $route, $routeParams, $rootS }); AccountService.checkUser(); + + LocationService.init(); ReferralService.check(); diff --git a/www/assets/js/controllers.js b/www/assets/js/controllers.js index 3e059f249..1733d88aa 100644 --- a/www/assets/js/controllers.js +++ b/www/assets/js/controllers.js @@ -75,16 +75,17 @@ NGApp.controller('HelpCtrl', function ($scope) { */ NGApp.controller('HomeCtrl', function ($scope, $http, $location, RestaurantsService, LocationService) { if (!App.isPhoneGap) { - LocationService.init(); + // If it have a valid restaurant position just reditect to restaurants page + if (LocationService.position.pos().valid('restaurants')) { + $location.path('/' + RestaurantsService.permalink); + } else { + $location.path('/location'); + } } else { // @hack // just force the location to the food-delivery page. if we dont have a loc it sends us back to location anyway - $location.path( '/' + RestaurantsService.permalink ); + $location.path('/' + RestaurantsService.permalink); } - // If it have a valid restaurant position just reditect to restaurants page - if( LocationService.position.pos().valid( 'restaurants' ) ){ - $location.path( '/' + RestaurantsService.permalink ); - } }); @@ -123,13 +124,13 @@ NGApp.controller('DefaultCtrl', function ($scope, $http, $location, CommunityAli NGApp.controller( 'RestaurantsCtrl', function ( $scope, $rootScope, $http, $location, $timeout, RestaurantsService, LocationService) { $scope.restaurants = false; - $scope.showMoreRestaurants = function(){ + $scope.showMoreRestaurants = function() { var step = 3; $scope.restaurantsToShow += step; - } + }; var location = LocationService; - if( !location.initied ){ + if (!location.initied) { location.init(); $location.path( '/' ); return; diff --git a/www/assets/js/services.order.js b/www/assets/js/services.order.js index d6039d4dd..4f2b9d3b8 100644 --- a/www/assets/js/services.order.js +++ b/www/assets/js/services.order.js @@ -57,10 +57,6 @@ NGApp.factory('OrderService', function ($http, $location, $rootScope, $filter, A service.init = function () { - // If this variable is true the restaurant's page will be loaded after the location get started - service.location.loadRestaurantsPage = false; - service.location.init(); - if (App.config.ab && App.config.ab.dollarSign == 'show') { service.info.dollarSign = '$'; } diff --git a/www/assets/js/services.position.js b/www/assets/js/services.position.js index bd8c1cf03..08814408b 100644 --- a/www/assets/js/services.position.js +++ b/www/assets/js/services.position.js @@ -156,11 +156,17 @@ NGApp.factory('LocationService', function ($location, $rootScope, RestaurantsSer * initilize location functions */ service.init = function () { + // force refresh + + var force = false; + if (arguments[0]) { + force = true; + } + // this method could not be called twice - if (service.initied){ + if (service.initied && !force) { return; } - service.initied = true; // 1) set bounding to maxmind results if we have them if (App.config.loc.lat && App.config.loc.lon) { @@ -176,13 +182,6 @@ NGApp.factory('LocationService', function ($location, $rootScope, RestaurantsSer for (var x in cookieLocs) { service.position.addLocation(new Location(cookieLocs[x]._properties)); } - // If we have a valid coockie position redirect the user to restaurants page - if ( ( $location.path() == '/' || $location.path() == '/location' ) && service.position.pos().valid( 'restaurants' ) ) { - setTimeout( function(){ $location.path( '/' + RestaurantsService.permalink ); }, 1 ); - service.loadRestaurantsPage = false; - } - } else { - $location.path( '/location' ); } if (cookieBounding) { @@ -197,7 +196,21 @@ NGApp.factory('LocationService', function ($location, $rootScope, RestaurantsSer lon: service.account.user.location_lon, type: 'user' }; + + service.position.addLocation(new Location({ + lat: service.account.user.location_lat, + lon: service.account.user.location_lon, + type: 'user' + })); + + service.loadRestaurantsPage = true; } + + if (service.initied) { + return; + } + + service.initied = true; // 4) get a more specific bounding location result from google if (App.isPhoneGap) { @@ -235,9 +248,6 @@ NGApp.factory('LocationService', function ($location, $rootScope, RestaurantsSer service.restaurantsService.list( // Success function () { - if (service.loadRestaurantsPage) { - $location.path('/' +RestaurantsService.permalink); - } service.loadRestaurantsPage = true; }, // Error @@ -267,30 +277,27 @@ NGApp.factory('LocationService', function ($location, $rootScope, RestaurantsSer // 5) if there are location if( service.position.locs.length ){ - var loc = service.position.pos(); - service.reverseGeocode(loc.lat(), loc.lon(), + var loc = service.position.pos(); + service.reverseGeocode(loc.lat(), loc.lon(), + // Success + function (loc) { + service.bounding = { + lat: loc.lat(), + lon: loc.lon(), + city: loc.city() + }; + service.restaurantsService.list( // Success - function (loc) { - service.bounding = { - lat: loc.lat(), - lon: loc.lon(), - city: loc.city() - }; - service.restaurantsService.list( - // Success - function () { - if (service.loadRestaurantsPage) { - $location.path('/' +RestaurantsService.permalink); - } - service.loadRestaurantsPage = true; - }, - // Error - function () { - $rootScope.$broadcast( 'locationNotServed', true ); - }); + function () { + service.loadRestaurantsPage = true; }, // Error - function () {}); + function () { + $rootScope.$broadcast( 'locationNotServed', true ); + }); + }, + // Error + function () {}); } else // 6) if there is no previously used locations of any kind if (!service.position.locs.length) { @@ -304,9 +311,6 @@ NGApp.factory('LocationService', function ($location, $rootScope, RestaurantsSer service.position.addLocation(loc); service.restaurantsService.list( function () { - if (service.loadRestaurantsPage) { - $location.path('/' +RestaurantsService.permalink); - } service.loadRestaurantsPage = true; }, function () { diff --git a/www/assets/js/services.restaurant.js b/www/assets/js/services.restaurant.js index f12c9e1b4..33b25429a 100644 --- a/www/assets/js/services.restaurant.js +++ b/www/assets/js/services.restaurant.js @@ -79,6 +79,7 @@ NGApp.factory('RestaurantsService', function ($http, $rootScope, PositionsServic } service.list = function (success, error) { + if (!service.position.pos().valid('restaurants')) { if (error) { error();