mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-10 17:21:38 -05:00
Add a button to create/update stats
This commit is contained in:
parent
d7670aeeb0
commit
96a9900661
6 changed files with 19 additions and 8 deletions
1
Gemfile
1
Gemfile
|
|
@ -16,7 +16,6 @@ gem 'tailwindcss-rails'
|
|||
gem 'turbo-rails'
|
||||
gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby]
|
||||
gem "importmap-rails"
|
||||
gem "mapkick-rb"
|
||||
gem "chartkick"
|
||||
gem 'geocoder'
|
||||
gem 'sidekiq'
|
||||
|
|
|
|||
|
|
@ -136,7 +136,6 @@ GEM
|
|||
net-imap
|
||||
net-pop
|
||||
net-smtp
|
||||
mapkick-rb (0.1.5)
|
||||
marcel (1.0.4)
|
||||
method_source (1.0.0)
|
||||
mini_mime (1.1.5)
|
||||
|
|
@ -333,7 +332,6 @@ DEPENDENCIES
|
|||
foreman
|
||||
geocoder
|
||||
importmap-rails
|
||||
mapkick-rb
|
||||
pg
|
||||
pry-byebug
|
||||
pry-rails
|
||||
|
|
|
|||
|
|
@ -4,4 +4,10 @@ class StatsController < ApplicationController
|
|||
def index
|
||||
@stats = current_user.stats.group_by(&:year).sort_by { _1 }.reverse
|
||||
end
|
||||
|
||||
def update
|
||||
StatCreatingJob.perform_later(current_user.id)
|
||||
|
||||
redirect_to stats_path, notice: 'Stats are being updated', status: :see_other
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -18,9 +18,11 @@ class CreateStats
|
|||
points = points(beginning_of_month_timestamp, end_of_month_timestamp)
|
||||
next if points.empty?
|
||||
|
||||
stat = Stat.create(year:, month:, user:, distance: distance(points), toponyms: toponyms(points))
|
||||
|
||||
stat.update(daily_distance: stat.distance_by_day) if stat.persisted?
|
||||
stat = Stat.find_or_initialize_by(year: year, month: month, user: user)
|
||||
stat.distance = distance(points)
|
||||
stat.toponyms = toponyms(points)
|
||||
stat.daily_distance = stat.distance_by_day
|
||||
stat.save
|
||||
|
||||
stat
|
||||
end
|
||||
|
|
|
|||
|
|
@ -38,13 +38,15 @@
|
|||
<% end %>
|
||||
</div>
|
||||
|
||||
<%= link_to 'Update stats', stats_path, method: :post, class: 'btn btn-primary mt-5' %>
|
||||
|
||||
<% @stats.each do |year, stats| %>
|
||||
<h2 class='text-3xl font-bold mt-10'>
|
||||
<%= link_to points_url(year_timespan(year)), class: 'underline hover:no-underline' do %>
|
||||
<%= year %>
|
||||
<% end %>
|
||||
</h2>
|
||||
<div class="mt-5 grid grid-cols-1 sm:grid-cols-2 md:grid-cols-2 lg:grid-cols-3 gap-6 p-4">
|
||||
<div class="mt-5 grid grid-cols-1 sm:grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6 p-4">
|
||||
<% stats.each do |stat| %>
|
||||
<%= render stat %>
|
||||
<% end %>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,11 @@
|
|||
Rails.application.routes.draw do
|
||||
get 'export', to: 'export#index'
|
||||
resources :imports
|
||||
resources :stats, only: :index
|
||||
resources :stats, only: :index do
|
||||
collection do
|
||||
post :update
|
||||
end
|
||||
end
|
||||
|
||||
root to: 'home#index'
|
||||
devise_for :users
|
||||
|
|
|
|||
Loading…
Reference in a new issue