mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Fixing bugs, improving dates
This commit is contained in:
2
Gemfile
2
Gemfile
@@ -50,7 +50,7 @@ group :assets do
|
||||
|
||||
gem 'turbo-sprockets-rails3'
|
||||
gem 'foundation-icons-sass-rails'
|
||||
|
||||
gem 'momentjs-rails'
|
||||
end
|
||||
gem "foundation-rails"
|
||||
gem 'foundation_rails_helper', github: 'willrjmarshall/foundation_rails_helper', branch: "rails3"
|
||||
|
||||
@@ -327,6 +327,8 @@ GEM
|
||||
method_source (0.8.1)
|
||||
mime-types (1.25.1)
|
||||
mini_portile (0.5.2)
|
||||
momentjs-rails (2.5.1)
|
||||
railties (>= 3.1)
|
||||
money (5.0.0)
|
||||
i18n (~> 0.4)
|
||||
json
|
||||
@@ -527,6 +529,7 @@ DEPENDENCIES
|
||||
json_spec
|
||||
letter_opener
|
||||
local_organics_feature!
|
||||
momentjs-rails
|
||||
newrelic_rpm
|
||||
oj
|
||||
paperclip
|
||||
|
||||
@@ -13,8 +13,8 @@
|
||||
#= require ../search/jquery.backstretch.js
|
||||
#= require angular-backstretch.js
|
||||
#= require angular-flash.min.js
|
||||
#= require moment
|
||||
#
|
||||
#= require ../shared/jquery.timeago
|
||||
#= require foundation
|
||||
#= require ./darkswarm
|
||||
#= require ./overrides
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
window.Darkswarm = angular.module("Darkswarm", ["ngResource", "filters", 'mm.foundation', 'angularLocalStorage', 'pasvaz.bindonce', 'infinite-scroll', 'angular-flash.service', 'backstretch']).config ($httpProvider, $tooltipProvider) ->
|
||||
window.Darkswarm = angular.module("Darkswarm", ["ngResource", 'mm.foundation', 'angularLocalStorage', 'pasvaz.bindonce', 'infinite-scroll', 'angular-flash.service', 'backstretch']).config ($httpProvider, $tooltipProvider) ->
|
||||
$httpProvider.defaults.headers.post['X-CSRF-Token'] = $('meta[name="csrf-token"]').attr('content')
|
||||
$httpProvider.defaults.headers.put['X-CSRF-Token'] = $('meta[name="csrf-token"]').attr('content')
|
||||
$httpProvider.defaults.headers['common']['X-Requested-With'] = 'XMLHttpRequest'
|
||||
|
||||
10
app/assets/javascripts/darkswarm/filters/dates.js.coffee
Normal file
10
app/assets/javascripts/darkswarm/filters/dates.js.coffee
Normal file
@@ -0,0 +1,10 @@
|
||||
Darkswarm.filter "date_in_words", ->
|
||||
(date) ->
|
||||
moment(date).fromNow()
|
||||
|
||||
Darkswarm.filter "sensible_timeframe", (date_in_wordsFilter)->
|
||||
(date) ->
|
||||
if moment().add('days', 2) < moment(date)
|
||||
"Orders open"
|
||||
else
|
||||
"Closing in #{date_in_wordsFilter(date)}"
|
||||
@@ -1,4 +1,4 @@
|
||||
angular.module("filters", []).filter "truncate", ->
|
||||
Darkswarm.filter "truncate", ->
|
||||
(text, length, end) ->
|
||||
text = text || ""
|
||||
length = 10 if isNaN(length)
|
||||
@@ -7,8 +7,3 @@ angular.module("filters", []).filter "truncate", ->
|
||||
text
|
||||
else
|
||||
String(text).substring(0, length - end.length) + end
|
||||
|
||||
$.timeago.settings.allowFuture = true;
|
||||
angular.module("filters").filter "date_in_words", ->
|
||||
(date) ->
|
||||
$.timeago(date)
|
||||
@@ -64,6 +64,11 @@ class OrderCycle < ActiveRecord::Base
|
||||
with_distributor(distributor).soonest_opening.first
|
||||
end
|
||||
|
||||
def self.first_closing_for(distributor)
|
||||
with_distributor(distributor).soonest_closing.first
|
||||
end
|
||||
|
||||
|
||||
def self.most_recently_closed_for(distributor)
|
||||
with_distributor(distributor).most_recently_closed.first
|
||||
end
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
.columns.small-1
|
||||
{{ hub.address.state | uppercase }}
|
||||
.columns.small-3{"bo-if" => "hub.active"}
|
||||
Orders closing when?
|
||||
{{ hub.orders_close_at | sensible_timeframe }}
|
||||
.columns.small-3{"bo-if" => "!hub.active"}
|
||||
Orders closed
|
||||
.columns.small-1.text-right
|
||||
|
||||
@@ -37,8 +37,6 @@
|
||||
.small-12.columns
|
||||
= render partial: 'darkswarm/skinny'
|
||||
= render partial: 'darkswarm/fat'
|
||||
|
||||
.small-12.columns
|
||||
.row{"ng-show" => "filteredHubs.length == 0"}
|
||||
.columns.small-12.text-center
|
||||
No results
|
||||
|
||||
@@ -25,5 +25,5 @@ node :active do |hub|
|
||||
end
|
||||
|
||||
node :orders_close_at do |hub|
|
||||
OrderCycle.with_distributor(hub).soonest_closing.first.andand.orders_close_at
|
||||
OrderCycle.first_closing_for(hub).andand.orders_close_at
|
||||
end
|
||||
|
||||
@@ -14,10 +14,9 @@ describe DarkswarmController do
|
||||
assigns[:active_distributors].should == [distributor]
|
||||
end
|
||||
|
||||
# This is done inside RABL template
|
||||
# This is done inside the json/hubs RABL template
|
||||
it "gets the next order cycle for each hub" do
|
||||
OrderCycle.stub_chain(:with_distributor, :soonest_closing, :first)
|
||||
OrderCycle.should_receive(:with_distributor).with(distributor)
|
||||
OrderCycle.should_receive(:first_closing_for).with(distributor)
|
||||
get :index
|
||||
end
|
||||
end
|
||||
|
||||
@@ -494,4 +494,13 @@ describe OrderCycle do
|
||||
OrderCycle.first_opening_for(distributor).should == nil
|
||||
end
|
||||
end
|
||||
|
||||
describe "finding open order cycles" do
|
||||
it "should give the soonest closing order cycle for a distributor" do
|
||||
distributor = create(:distributor_enterprise)
|
||||
oc = create(:simple_order_cycle, name: 'oc 1', distributors: [distributor], orders_open_at: 1.days.ago, orders_close_at: 11.days.from_now)
|
||||
oc2 = create(:simple_order_cycle, name: 'oc 2', distributors: [distributor], orders_open_at: 2.days.ago, orders_close_at: 12.days.from_now)
|
||||
OrderCycle.first_closing_for(distributor).should == oc
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user