mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-10 01:01:39 -05:00
Fix interface inconsistencies
This commit is contained in:
parent
082cbf159d
commit
5f18a3051d
9 changed files with 28 additions and 22 deletions
|
|
@ -53,8 +53,8 @@ module ApplicationHelper
|
|||
DateTime.new(year, month).past?
|
||||
end
|
||||
|
||||
def points_exist?(year, month)
|
||||
Point.where(
|
||||
def points_exist?(year, month, user)
|
||||
user.tracked_points.where(
|
||||
timestamp: DateTime.new(year, month).beginning_of_month..DateTime.new(year, month).end_of_month
|
||||
).exists?
|
||||
end
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ class ImportJob < ApplicationJob
|
|||
user = User.find(user_id)
|
||||
import = user.imports.find(import_id)
|
||||
|
||||
result = parser(import.source).new(import).call
|
||||
result = parser(import.source).new(import, user_id).call
|
||||
|
||||
import.update(
|
||||
raw_points: result[:raw_points], doubles: result[:doubles], processed: result[:processed]
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ class CreateStats
|
|||
beginning_of_month_timestamp = DateTime.new(year, month).beginning_of_month.to_i
|
||||
end_of_month_timestamp = DateTime.new(year, month).end_of_month.to_i
|
||||
|
||||
points = points(beginning_of_month_timestamp, end_of_month_timestamp)
|
||||
points = points(user, beginning_of_month_timestamp, end_of_month_timestamp)
|
||||
next if points.empty?
|
||||
|
||||
stat = Stat.find_or_initialize_by(year:, month:, user:)
|
||||
|
|
@ -31,8 +31,9 @@ class CreateStats
|
|||
|
||||
private
|
||||
|
||||
def points(beginning_of_month_timestamp, end_of_month_timestamp)
|
||||
Point
|
||||
def points(user, beginning_of_month_timestamp, end_of_month_timestamp)
|
||||
user
|
||||
.tracked_points
|
||||
.without_raw_data
|
||||
.where(timestamp: beginning_of_month_timestamp..end_of_month_timestamp)
|
||||
.order(:timestamp)
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class GoogleMaps::SemanticHistoryParser
|
||||
attr_reader :import
|
||||
attr_reader :import, :user_id
|
||||
|
||||
def initialize(import)
|
||||
def initialize(import, user_id)
|
||||
@import = import
|
||||
@user_id = user_id
|
||||
end
|
||||
|
||||
def call
|
||||
|
|
@ -22,7 +23,8 @@ class GoogleMaps::SemanticHistoryParser
|
|||
raw_data: point_data[:raw_data],
|
||||
topic: 'Google Maps Timeline Export',
|
||||
tracker_id: 'google-maps-timeline-export',
|
||||
import_id: import.id
|
||||
import_id: import.id,
|
||||
user_id:
|
||||
)
|
||||
|
||||
points += 1
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class OwnTracks::ExportParser
|
||||
attr_reader :import, :json
|
||||
attr_reader :import, :json, :user_id
|
||||
|
||||
def initialize(import)
|
||||
def initialize(import, user_id)
|
||||
@import = import
|
||||
@json = import.raw_data
|
||||
@user_id = user_id
|
||||
end
|
||||
|
||||
def call
|
||||
|
|
@ -23,7 +24,8 @@ class OwnTracks::ExportParser
|
|||
raw_data: point_data[:raw_data],
|
||||
topic: point_data[:topic],
|
||||
tracker_id: point_data[:tracker_id],
|
||||
import_id: import.id
|
||||
import_id: import.id,
|
||||
user_id:
|
||||
)
|
||||
|
||||
points += 1
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
<div class="dropdown">
|
||||
<div tabindex="0" role="button" class="btn m-1">Select year</div>
|
||||
<ul tabindex="0" class="dropdown-content z-[1] menu p-2 shadow bg-base-100 rounded-box w-52">
|
||||
<% Stat.years.each do |year| %>
|
||||
<% current_user.stats.years.each do |year| %>
|
||||
<li><%= link_to year, map_url(year_timespan(year).merge(year: year)) %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
|
|
@ -18,7 +18,7 @@
|
|||
<div class='grid grid-cols-3 gap-3'>
|
||||
<% (1..12).to_a.each_slice(3) do |months| %>
|
||||
<% months.each do |month_number| %>
|
||||
<% if past?(year, month_number) && points_exist?(year, month_number) %>
|
||||
<% if past?(year, month_number) && points_exist?(year, month_number, current_user) %>
|
||||
<%= link_to Date::ABBR_MONTHNAMES[month_number], map_url(timespan(month_number, year)), class: 'btn btn-default' %>
|
||||
<% else %>
|
||||
<div class='btn btn-disabled'><%= Date::ABBR_MONTHNAMES[month_number] %></div>
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe CreateStats do
|
||||
|
|
@ -9,16 +11,15 @@ RSpec.describe CreateStats do
|
|||
|
||||
context 'when there are no points' do
|
||||
it 'does not create stats' do
|
||||
expect { create_stats }.not_to change { Stat.count }
|
||||
expect { create_stats }.not_to(change { Stat.count })
|
||||
end
|
||||
end
|
||||
|
||||
context 'when there are points' do
|
||||
let!(:import) { create(:import, user: user) }
|
||||
let!(:point_1) { create(:point, import: import, latitude: 0, longitude: 0) }
|
||||
let!(:point_2) { create(:point, import: import, latitude: 1, longitude: 2) }
|
||||
let!(:point_3) { create(:point, import: import, latitude: 3, longitude: 4) }
|
||||
|
||||
let!(:import) { create(:import, user:) }
|
||||
let!(:point1) { create(:point, user:, import:, latitude: 0, longitude: 0) }
|
||||
let!(:point2) { create(:point, user:, import:, latitude: 1, longitude: 2) }
|
||||
let!(:point3) { create(:point, user:, import:, latitude: 3, longitude: 4) }
|
||||
|
||||
it 'creates stats' do
|
||||
expect { create_stats }.to change { Stat.count }.by(1)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ require 'rails_helper'
|
|||
|
||||
RSpec.describe OwnTracks::ExportParser do
|
||||
describe '#call' do
|
||||
subject(:parser) { described_class.new(import).call }
|
||||
subject(:parser) { described_class.new(import, user.id).call }
|
||||
|
||||
let(:user) { create(:user) }
|
||||
let(:import) { create(:import, user:, name: 'owntracks_export.json') }
|
||||
|
|
|
|||
|
|
@ -180,7 +180,7 @@ paths:
|
|||
lat: 52.502397
|
||||
lon: 13.356718
|
||||
tid: Swagger
|
||||
tst: 1716636414
|
||||
tst: 1716636973
|
||||
servers:
|
||||
- url: http://{defaultHost}
|
||||
variables:
|
||||
|
|
|
|||
Loading…
Reference in a new issue