From 82c931997b459de7cace1d5e402e97cd1db0ab57 Mon Sep 17 00:00:00 2001 From: Jiatong Li Date: Sat, 25 Mar 2023 12:55:26 -0400 Subject: [PATCH 1/5] downtime update --- app/models/organization.rb | 2 +- app/models/organization_timeline_entry.rb | 1 + .../fixtures/organization_timeline_entries.yml | 18 ++++++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/organization_timeline_entries.yml diff --git a/app/models/organization.rb b/app/models/organization.rb index f3548d55..4b86a7d4 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -41,7 +41,7 @@ def short_name def downtime elapsed = 0 - organization_timeline_entries.downtime.each do |timeline_entry| + organization_timeline_entries.today.downtime.each do |timeline_entry| elapsed += timeline_entry.duration end diff --git a/app/models/organization_timeline_entry.rb b/app/models/organization_timeline_entry.rb index b84fbd24..9392ca7e 100644 --- a/app/models/organization_timeline_entry.rb +++ b/app/models/organization_timeline_entry.rb @@ -14,6 +14,7 @@ class OrganizationTimelineEntry < ApplicationRecord scope :current, -> { where(ended_at: nil) } scope :active, -> { where(active: true) } scope :inactive, -> { where(active: false) } + scope :today, -> { where("started_at >= ? AND started_at < ?", Date.current, Date.current + 1.day)} def duration return ended_at.to_i - started_at.to_i if ended_at.present? diff --git a/test/fixtures/organization_timeline_entries.yml b/test/fixtures/organization_timeline_entries.yml new file mode 100644 index 00000000..078c4c64 --- /dev/null +++ b/test/fixtures/organization_timeline_entries.yml @@ -0,0 +1,18 @@ +entry1: + started_at: 2023-03-25 9:30:00 + ended_at: 2023-03-25 11:00:00 + organization: aepi + entry_type: 2 + +entry2: + started_at: 2023-03-25 6:15:00 + ended_at: 2023-03-25 7:00:00 + organization: aepi + entry_type: 2 + +entry3: + started_at: 2023-03-22 12:00:00 + ended_at: 2023-03-22 15:00:00 + organization: aepi + entry_type: 2 + From c34ee64b78d04327cc067ab775e781ce7d6820fc Mon Sep 17 00:00:00 2001 From: Jiatong Li Date: Sat, 25 Mar 2023 13:35:45 -0400 Subject: [PATCH 2/5] date time helper --- .../organization_timeline_entries_helper.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 app/helpers/organization_timeline_entries_helper.rb diff --git a/app/helpers/organization_timeline_entries_helper.rb b/app/helpers/organization_timeline_entries_helper.rb new file mode 100644 index 00000000..8ea88ce2 --- /dev/null +++ b/app/helpers/organization_timeline_entries_helper.rb @@ -0,0 +1,19 @@ +module OrganizationTimelineEntriesHelper + def format_duration(time) + time = time.to_i + if time.negative? + neg = '−'.html_safe + time *= -1 + else + neg = '' + end + hours = time / 3600 + minutes = (time % 3600) / 60 + "#{neg}#{'%d' % hours}:#{'%02d' % minutes}" + end + + def date_and_time(display_date_and_time) + #[date(display_date_and_time), time(display_date_and_time)].compact.join(' ') + display_date_and_time + end +end From c3032cee5b81a5471e174b87762d921e99d57523 Mon Sep 17 00:00:00 2001 From: Jiatong Li Date: Sat, 1 Apr 2023 12:44:02 -0400 Subject: [PATCH 3/5] downtime date and time format --- app/helpers/organization_timeline_entries_helper.rb | 4 ++-- app/views/organization_timeline_entries/_form.html.erb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/helpers/organization_timeline_entries_helper.rb b/app/helpers/organization_timeline_entries_helper.rb index 8ea88ce2..e57b8df7 100644 --- a/app/helpers/organization_timeline_entries_helper.rb +++ b/app/helpers/organization_timeline_entries_helper.rb @@ -13,7 +13,7 @@ def format_duration(time) end def date_and_time(display_date_and_time) - #[date(display_date_and_time), time(display_date_and_time)].compact.join(' ') - display_date_and_time + [display_date_and_time.to_date.strftime('%m/%d/%Y'), display_date_and_time.strftime("%H:%M %p")].compact.join(' ') + end end diff --git a/app/views/organization_timeline_entries/_form.html.erb b/app/views/organization_timeline_entries/_form.html.erb index 9d1f3b5b..9854c53f 100644 --- a/app/views/organization_timeline_entries/_form.html.erb +++ b/app/views/organization_timeline_entries/_form.html.erb @@ -1,9 +1,9 @@ <%= simple_form_for @organization_timeline_entry do |f| %>
<%= f.input :description %> - <%= f.input :ended_at, placeholder: @organization_timeline_entry.ended_at %> <%= f.input :started_at, placeholder: @organization_timeline_entry.started_at %> -
+ <%= f.input :ended_at, placeholder: @organization_timeline_entry.ended_at %> +
<%= f.button :submit, class: 'btn-primary' %> <%= link_to t('.cancel', default: t('helpers.links.cancel')), From c3c408948221f17edce1de160acda0088589131c Mon Sep 17 00:00:00 2001 From: Jiatong Li Date: Sat, 1 Apr 2023 12:58:47 -0400 Subject: [PATCH 4/5] format date and time --- app/helpers/organization_timeline_entries_helper.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/helpers/organization_timeline_entries_helper.rb b/app/helpers/organization_timeline_entries_helper.rb index e57b8df7..de0ab99e 100644 --- a/app/helpers/organization_timeline_entries_helper.rb +++ b/app/helpers/organization_timeline_entries_helper.rb @@ -14,6 +14,5 @@ def format_duration(time) def date_and_time(display_date_and_time) [display_date_and_time.to_date.strftime('%m/%d/%Y'), display_date_and_time.strftime("%H:%M %p")].compact.join(' ') - end end From 1d252001aa41ed469b231c052ebbe9f083d4118e Mon Sep 17 00:00:00 2001 From: Jiatong Li Date: Sat, 1 Apr 2023 12:59:43 -0400 Subject: [PATCH 5/5] gem simple_form --- Gemfile | 3 +++ Gemfile.lock | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/Gemfile b/Gemfile index 8e803b33..bb7830c9 100644 --- a/Gemfile +++ b/Gemfile @@ -26,6 +26,9 @@ gem 'stimulus-rails' # Build JSON APIs with ease [https://github.com/rails/jbuilder] gem 'jbuilder' +#Rails forms +gem 'simple_form' + # Use Redis adapter to run Action Cable in production # gem "redis", "~> 4.0" diff --git a/Gemfile.lock b/Gemfile.lock index 01b8d173..e784426a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -169,6 +169,8 @@ GEM net-smtp (0.3.3) net-protocol nio4r (2.5.8) + nokogiri (1.14.2-arm64-darwin) + racc (~> 1.4) nokogiri (1.14.2-x86_64-darwin) racc (~> 1.4) nokogiri (1.14.2-x86_64-linux) @@ -265,8 +267,12 @@ GEM rexml (~> 3.2, >= 3.2.5) rubyzip (>= 1.2.2, < 3.0) websocket (~> 1.0) + simple_form (5.2.0) + actionpack (>= 5.2) + activemodel (>= 5.2) singleton (0.1.1) smart_properties (1.17.0) + sqlite3 (1.6.1-arm64-darwin) sqlite3 (1.6.1-x86_64-darwin) sqlite3 (1.6.1-x86_64-linux) stimulus-rails (1.2.1) @@ -303,6 +309,7 @@ GEM zeitwerk (2.6.7) PLATFORMS + arm64-darwin-21 x86_64-darwin-22 x86_64-linux @@ -327,6 +334,7 @@ DEPENDENCIES rubocop-rails savon selenium-webdriver + simple_form sqlite3 (~> 1.4) stimulus-rails turbo-rails