From 5ea22a8ddace7d4b3ca9eb93f2669949dba1845f Mon Sep 17 00:00:00 2001 From: Daniel Camargo Date: Tue, 24 Sep 2013 18:41:07 -0300 Subject: [PATCH] partial #1801 --- .../crunchbutton/frontend/restaurants.phtml | 2 +- www/assets/js/controllers.js | 17 +++++++++- www/assets/js/restaurant.js | 6 ++++ www/assets/js/services.restaurant.js | 33 ++++++++++++------- 4 files changed, 44 insertions(+), 14 deletions(-) diff --git a/include/views/default/crunchbutton/frontend/restaurants.phtml b/include/views/default/crunchbutton/frontend/restaurants.phtml index 92c2ad8e4..f4919434a 100644 --- a/include/views/default/crunchbutton/frontend/restaurants.phtml +++ b/include/views/default/crunchbutton/frontend/restaurants.phtml @@ -29,7 +29,7 @@

{{restaurant._short_description}}

Take out only
-
Hurry, closes in {{restaurant.isAboutToClose()}} min!
+
Hurry, closes in {{restaurant._minToClose}} min!
Opens in a few hours
diff --git a/www/assets/js/controllers.js b/www/assets/js/controllers.js index b96c62deb..6eaf17075 100644 --- a/www/assets/js/controllers.js +++ b/www/assets/js/controllers.js @@ -90,7 +90,7 @@ NGApp.controller('DefaultCtrl', function ($scope, $http, $location, CommunityAli /** * Show the restaurants */ -NGApp.controller( 'RestaurantsCtrl', function ( $scope, $rootScope, $http, $location, RestaurantsService, LocationService) { +NGApp.controller( 'RestaurantsCtrl', function ( $scope, $rootScope, $http, $location, $timeout, RestaurantsService, LocationService) { $scope.restaurants = false; @@ -108,6 +108,20 @@ NGApp.controller( 'RestaurantsCtrl', function ( $scope, $rootScope, $http, $loca $scope.mealItemClass = App.isAndroid() ? 'meal-food-android' : ''; + // Update the close/open/about_to_close status from the restaurants + var updateStatus = function(){ + updateRestaurantStatus = $timeout( function(){ + // Update status of the restaurant's list + $scope.restaurants = restaurants.sort(); + updateStatus(); + } , 1000 * 15 ); + } + + $scope.$on( '$destroy', function(){ + // Kills the timer when the controller is changed + $timeout.cancel( updateRestaurantStatus ); + }); + $scope.display = function($event) { var restaurant = this.restaurant; if (!restaurant.open()) { @@ -153,6 +167,7 @@ NGApp.controller( 'RestaurantsCtrl', function ( $scope, $rootScope, $http, $loca document.title = city + ' Food Delivery | Order Food from ' + (city || 'Local') + ' Restaurants | Crunchbutton'; $scope.restaurants = restaurants.sort(); + updateStatus(); $scope.slogan = slogan; $scope.tagline = tagline; diff --git a/www/assets/js/restaurant.js b/www/assets/js/restaurant.js index 38a2620ed..93032b693 100644 --- a/www/assets/js/restaurant.js +++ b/www/assets/js/restaurant.js @@ -298,6 +298,12 @@ var Restaurant = function(id) { } } + if( isOpen ){ + var minToClose = self.isAboutToClose(); + if( !isNaN( parseFloat( minToClose ) ) && minToClose == 0 ){ + isOpen = false; + } + } this._open = isOpen; return isOpen; } diff --git a/www/assets/js/services.restaurant.js b/www/assets/js/services.restaurant.js index f515791a1..818fd3186 100644 --- a/www/assets/js/services.restaurant.js +++ b/www/assets/js/services.restaurant.js @@ -15,8 +15,27 @@ NGApp.factory('RestaurantsService', function ($http, $rootScope, PositionsServic service.position = PositionsService; service.sort = function () { - // dont not sort. if a restaurant closes we want to make sure it apears so + var list = service.getStatus(); + + list.sort(sort_by({ + name: '_open', + reverse: true + }, { + name: 'delivery', + reverse: true + }, { + name: '_weight', + primer: parseInt, + reverse: true + })); + + restaurants = list; + return restaurants; + } + + service.getStatus = function () { + var list = restaurants; for (var x in list) { @@ -31,23 +50,13 @@ NGApp.factory('RestaurantsService', function ($http, $rootScope, PositionsServic if (list[x].delivery != '1') { list[x]._tag = 'takeout'; } else if (list[x].isAboutToClose()) { + list[x]._minToClose = list[x].isAboutToClose(); list[x]._tag = 'closing'; } } // show short description list[x]._short_description = (list[x].short_description || ('Top Order: ' + (list[x].top_name ? (list[x].top_name || list[x].top_name) : ''))); }; - list.sort(sort_by({ - name: '_open', - reverse: true - }, { - name: 'delivery', - reverse: true - }, { - name: '_weight', - primer: parseInt, - reverse: true - })); restaurants = list; return restaurants;