Compare commits
3 commits
495d29a0ae
...
0e291dc31c
| Author | SHA1 | Date | |
|---|---|---|---|
| 0e291dc31c | |||
| b1a0b21c47 | |||
| 54d721abd4 |
5 changed files with 73 additions and 12 deletions
1
Gemfile
1
Gemfile
|
|
@ -12,3 +12,4 @@ gem 'bcrypt'
|
||||||
gem 'gettext'
|
gem 'gettext'
|
||||||
gem 'mail'
|
gem 'mail'
|
||||||
gem 'redcarpet'
|
gem 'redcarpet'
|
||||||
|
gem 'whenever'
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ GEM
|
||||||
bcrypt (3.1.20)
|
bcrypt (3.1.20)
|
||||||
benchmark (0.4.0)
|
benchmark (0.4.0)
|
||||||
bigdecimal (3.1.9)
|
bigdecimal (3.1.9)
|
||||||
|
chronic (0.10.2)
|
||||||
concurrent-ruby (1.3.5)
|
concurrent-ruby (1.3.5)
|
||||||
connection_pool (2.5.0)
|
connection_pool (2.5.0)
|
||||||
date (3.4.1)
|
date (3.4.1)
|
||||||
|
|
@ -92,11 +93,16 @@ GEM
|
||||||
singleton (0.3.0)
|
singleton (0.3.0)
|
||||||
sqlite3 (2.6.0)
|
sqlite3 (2.6.0)
|
||||||
mini_portile2 (~> 2.8.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)
|
text (1.3.1)
|
||||||
tilt (2.6.0)
|
tilt (2.6.0)
|
||||||
timeout (0.4.3)
|
timeout (0.4.3)
|
||||||
tzinfo (2.0.6)
|
tzinfo (2.0.6)
|
||||||
concurrent-ruby (~> 1.0)
|
concurrent-ruby (~> 1.0)
|
||||||
|
whenever (1.1.2)
|
||||||
|
chronic (>= 0.6.3)
|
||||||
|
|
||||||
PLATFORMS
|
PLATFORMS
|
||||||
arm64-darwin
|
arm64-darwin
|
||||||
|
|
@ -117,6 +123,7 @@ DEPENDENCIES
|
||||||
sinatra
|
sinatra
|
||||||
sinatra-activerecord
|
sinatra-activerecord
|
||||||
sqlite3
|
sqlite3
|
||||||
|
whenever
|
||||||
|
|
||||||
BUNDLED WITH
|
BUNDLED WITH
|
||||||
2.3.15
|
2.3.15
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
if ENV['RACK_ENV']
|
require_relative '../vedia'
|
||||||
set :environment, ENV['RACK_ENV']
|
|
||||||
end
|
env 'MAILTO', Sinatra::Application.settings.admin
|
||||||
|
set :path, Sinatra::Application.settings.path
|
||||||
|
set :environment_variable, 'RACK_ENV'
|
||||||
|
|
||||||
every 5.minutes do
|
every 5.minutes do
|
||||||
rake "close_expired_votes"
|
rake "close_expired_votes"
|
||||||
|
|
|
||||||
29
vedia.rb
29
vedia.rb
|
|
@ -1,10 +1,4 @@
|
||||||
require 'sinatra'
|
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 'sinatra/activerecord'
|
||||||
require 'bcrypt'
|
require 'bcrypt'
|
||||||
require 'gettext'
|
require 'gettext'
|
||||||
|
|
@ -266,7 +260,22 @@ get '/admin/votes/:id' do
|
||||||
erb :admin_votes
|
erb :admin_votes
|
||||||
end
|
end
|
||||||
|
|
||||||
get '/admin/votes/:id/organizers/:user/delete' do
|
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
|
||||||
require_admin
|
require_admin
|
||||||
rating = Organizer.where(vote: params[:id]).where(user: params[:user]).each do |organizer|
|
rating = Organizer.where(vote: params[:id]).where(user: params[:user]).each do |organizer|
|
||||||
organizer.destroy
|
organizer.destroy
|
||||||
|
|
@ -650,8 +659,12 @@ helpers do
|
||||||
"#{TZInfo::Timezone.get(session[:timezone]).to_local(timestamp).strftime('%F')}"
|
"#{TZInfo::Timezone.get(session[:timezone]).to_local(timestamp).strftime('%F')}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def format_timezone
|
||||||
|
session[:timezone].gsub('_', ' ')
|
||||||
|
end
|
||||||
|
|
||||||
def format_date_and_time(timestamp)
|
def format_date_and_time(timestamp)
|
||||||
"#{TZInfo::Timezone.get(session[:timezone]).to_local(timestamp).strftime('%F %R')} (#{session[:timezone].gsub('_', ' ')})"
|
"#{TZInfo::Timezone.get(session[:timezone]).to_local(timestamp).strftime('%F %R')} (#{format_timezone})"
|
||||||
end
|
end
|
||||||
|
|
||||||
def markdown(markdown)
|
def markdown(markdown)
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,45 @@
|
||||||
|
|
||||||
<p><%= _("Description: %{description}") % { description: @vote.description } %></p>
|
<p><%= _("Description: %{description}") % { description: @vote.description } %></p>
|
||||||
|
|
||||||
<p><%= _("Closing date: %{date}") % { date: @vote.expire_on ? format_date_and_time(@vote.expire_on) : _("None") } %></p>
|
<% if @vote.state == 'closed' or @vote.state == 'open' %>
|
||||||
|
<form action="/admin/votes/<%= @vote.id %>" method="post">
|
||||||
|
<p>
|
||||||
|
<%= _("Closing date: ") %>
|
||||||
|
<% year = Time.now.strftime('%Y').to_i %>
|
||||||
|
<select name='year'>
|
||||||
|
<% (-1..1).each do |i| %>
|
||||||
|
<option value="<%= year + i %>"<% if TZInfo::Timezone.get(session[:timezone]).to_local(@vote.expire_on).strftime('%Y').to_i == year + i %> selected="selected"<% end %>><%= year + i %></option>
|
||||||
|
<% end %>
|
||||||
|
</select>
|
||||||
|
-
|
||||||
|
<select name='month'>
|
||||||
|
<% (1..11).each do |m| %>
|
||||||
|
<option value="<%= m %>"<% if TZInfo::Timezone.get(session[:timezone]).to_local(@vote.expire_on).strftime('%m').to_i == m %> selected="selected"<% end %>><%= m %></option>
|
||||||
|
<% end %>
|
||||||
|
</select>
|
||||||
|
-
|
||||||
|
<select name='day'>
|
||||||
|
<% (1..31).each do |d| %>
|
||||||
|
<option value="<%= d %>"<% if TZInfo::Timezone.get(session[:timezone]).to_local(@vote.expire_on).strftime('%d').to_i == d %> selected="selected"<% end %>><%= d %></option>
|
||||||
|
<% end %>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select name='hour'>
|
||||||
|
<% (0..23).each do |h| %>
|
||||||
|
<option value="<%= h %>"<% if TZInfo::Timezone.get(session[:timezone]).to_local(@vote.expire_on).strftime('%H').to_i == h %> selected="selected"<% end %>><%= h %></option>
|
||||||
|
<% end %>
|
||||||
|
</select>
|
||||||
|
:
|
||||||
|
<select name='minute'>
|
||||||
|
<% (0..59).each do |m| %>
|
||||||
|
<option value="<%= m %>"<% if TZInfo::Timezone.get(session[:timezone]).to_local(@vote.expire_on).strftime('%M').to_i == m %> selected="selected"<% end %>><%= m %></option>
|
||||||
|
<% end %>
|
||||||
|
</select>
|
||||||
|
(<%= format_timezone %>)
|
||||||
|
<button type="submit" class="btn btn-link"><%= _("Change") %></button>
|
||||||
|
</p>
|
||||||
|
</form>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<p class="mb-5"><%= _("State: %{state}") % { state: @vote.state } %></p>
|
<p class="mb-5"><%= _("State: %{state}") % { state: @vote.state } %></p>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue