Skip to content
10 changes: 8 additions & 2 deletions app/components/shared/index_table_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,14 @@ def sort_value_for(record, column)
return nil unless record.respond_to?(column.attribute)

value = record.send(column.attribute)
return value.to_i.to_s if value.is_a?(Time) || value.is_a?(DateTime) || value.is_a?(Date)
return value.to_f.to_s if value.is_a?(Numeric)
case value
when Time, DateTime
return value.to_i.to_s
when Date
return value.to_time.to_i.to_s
when Numeric
return value.to_f.to_s
end

nil
end
Expand Down
11 changes: 11 additions & 0 deletions app/models/log_entry.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
class LogEntry < ApplicationRecord
belongs_to :subproject
belongs_to :user

validate :not_empty

private

def not_empty
return if metadata.is_a?(Hash) && metadata.values.any? { |v| v.present? || v == false }

# i18n-tasks-use t('activerecord.errors.models.log_entry.attributes.base.not_empty')
errors.add(:base, :not_empty)
end
end
2 changes: 1 addition & 1 deletion app/views/shared/_flash.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="fixed bottom-4 right-4 space-y-1 z-50 w-100 animate-fade-in-out">
<div class="fixed bottom-4 right-4 space-y-1 z-[9999] w-100 animate-fade-in-out">
<% flash.each do |key, message| %>
<% case key.to_sym %>
<% when :info %>
Expand Down
6 changes: 6 additions & 0 deletions config/locales/en/projects/subprojects/log_entries.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ en:
subproject: Subproject
updated_at: Updated At
user: User
errors:
models:
log_entry:
attributes:
base:
not_empty: At least one field must be filled in before saving.
projects:
subprojects:
log_entries:
Expand Down
6 changes: 6 additions & 0 deletions config/locales/es/projects/subprojects/log_entries.es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ es:
subproject: Subproyecto
updated_at: Actualizado en
user: Usuario
errors:
models:
log_entry:
attributes:
base:
not_empty: Al menos un campo debe estar completado antes de guardar.
projects:
subprojects:
log_entries:
Expand Down
24 changes: 24 additions & 0 deletions test/models/log_entry_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,28 @@
require "test_helper"

class LogEntryTest < ActiveSupport::TestCase
setup do
@project = create(:project, log_schema: { "content" => "text", "verified" => "boolean", "notes" => "text" })
@subproject = create(:subproject, project: @project)
end

test "log entry is not valid if metadata is empty" do
log_entry = build(:log_entry, subproject: @subproject, metadata: {})

assert_not log_entry.valid?
assert_includes log_entry.errors.full_messages,
I18n.t("activerecord.errors.models.log_entry.attributes.base.not_empty")
end

test "log entry is not valid if metadata contains only nil values" do
log_entry = build(:log_entry, subproject: @subproject, metadata: { "content" => nil, "verified" => nil })
assert_not log_entry.valid?
assert_includes log_entry.errors.full_messages,
I18n.t("activerecord.errors.models.log_entry.attributes.base.not_empty")
end

test "log entry is valid if metadata contains a boolean false" do
log_entry = build(:log_entry, subproject: @subproject, metadata: { "verified" => false })
assert log_entry.valid?
end
end
Loading