diff --git a/Gemfile b/Gemfile index 4bb57e8..2b75e8a 100644 --- a/Gemfile +++ b/Gemfile @@ -12,4 +12,3 @@ gem 'bcrypt' gem 'gettext' gem 'mail' gem 'redcarpet' -gem 'whenever' diff --git a/Gemfile.lock b/Gemfile.lock index 955384c..249f759 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -23,7 +23,6 @@ GEM bcrypt (3.1.20) benchmark (0.4.0) bigdecimal (3.1.9) - chronic (0.10.2) concurrent-ruby (1.3.5) connection_pool (2.5.0) date (3.4.1) @@ -93,16 +92,11 @@ GEM singleton (0.3.0) sqlite3 (2.6.0) mini_portile2 (~> 2.8.0) - sqlite3 (2.6.0-arm64-darwin) - sqlite3 (2.6.0-x86_64-darwin) - sqlite3 (2.6.0-x86_64-linux-gnu) text (1.3.1) tilt (2.6.0) timeout (0.4.3) tzinfo (2.0.6) concurrent-ruby (~> 1.0) - whenever (1.1.2) - chronic (>= 0.6.3) PLATFORMS arm64-darwin @@ -123,7 +117,6 @@ DEPENDENCIES sinatra sinatra-activerecord sqlite3 - whenever BUNDLED WITH 2.3.15 diff --git a/config/schedule.rb b/config/schedule.rb index c72feae..6247285 100644 --- a/config/schedule.rb +++ b/config/schedule.rb @@ -1,8 +1,6 @@ -require_relative '../vedia' - -env 'MAILTO', Sinatra::Application.settings.admin -set :path, Sinatra::Application.settings.path -set :environment_variable, 'RACK_ENV' +if ENV['RACK_ENV'] + set :environment, ENV['RACK_ENV'] +end every 5.minutes do rake "close_expired_votes" diff --git a/vedia.rb b/vedia.rb index 4403543..36a524f 100644 --- a/vedia.rb +++ b/vedia.rb @@ -1,4 +1,10 @@ require 'sinatra' + +# Set environment before requiring 'sinatra/activerecord' to make `whenever` uses the database. +if ENV['RAILS_ENV'] + set :environment, ENV['RAILS_ENV'] +end + require 'sinatra/activerecord' require 'bcrypt' require 'gettext' @@ -260,22 +266,7 @@ get '/admin/votes/:id' do erb :admin_votes end -post '/admin/votes/:id' do - require_admin - @vote = Vote.find(params[:id]) - if params.has_key?('year') - new_expiry = TZInfo::Timezone.get(session[:timezone]).local_time(params['year'].to_i, params['month'].to_i, params['day'].to_i, params['hour'].to_i, params['minute'].to_i) - if (@vote.state == 'open' or @vote.state == 'closed') and new_expiry > Time.now - puts "change" - @vote.expire_on = new_expiry - @vote.state = 'open' - @vote.save - end - end - erb :admin_votes -end - -get 'admin/votes/:id/organizers/:user/delete' do +get '/admin/votes/:id/organizers/:user/delete' do require_admin rating = Organizer.where(vote: params[:id]).where(user: params[:user]).each do |organizer| organizer.destroy @@ -659,12 +650,8 @@ helpers do "#{TZInfo::Timezone.get(session[:timezone]).to_local(timestamp).strftime('%F')}" end - def format_timezone - session[:timezone].gsub('_', ' ') - end - def format_date_and_time(timestamp) - "#{TZInfo::Timezone.get(session[:timezone]).to_local(timestamp).strftime('%F %R')} (#{format_timezone})" + "#{TZInfo::Timezone.get(session[:timezone]).to_local(timestamp).strftime('%F %R')} (#{session[:timezone].gsub('_', ' ')})" end def markdown(markdown) diff --git a/views/admin_votes.erb b/views/admin_votes.erb index 6275f24..b580872 100644 --- a/views/admin_votes.erb +++ b/views/admin_votes.erb @@ -12,45 +12,7 @@

<%= _("Description: %{description}") % { description: @vote.description } %>

-<% if @vote.state == 'closed' or @vote.state == 'open' %> -
-

- <%= _("Closing date: ") %> - <% year = Time.now.strftime('%Y').to_i %> - - - - - - - -   - - : - - (<%= format_timezone %>) - -

-
-<% end %> +

<%= _("Closing date: %{date}") % { date: @vote.expire_on ? format_date_and_time(@vote.expire_on) : _("None") } %>

<%= _("State: %{state}") % { state: @vote.state } %>