Skip to content

Commit

Permalink
Added waiting time to waiting step (#460)
Browse files Browse the repository at this point in the history
  • Loading branch information
xpavle00 committed Jun 8, 2024
1 parent b60c671 commit 7b82819
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 3 deletions.
3 changes: 2 additions & 1 deletion app/controllers/admin/steps_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ def step_params
:position,
:app_url,
:app_link_text,
:type
:type,
:waiting_time
)
end
end
1 change: 1 addition & 0 deletions app/models/step.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Step < ApplicationRecord
validates :slug, presence: true, uniqueness: true
validates :description, presence: true
validates :is_waiting_step, inclusion: { in: [true, false] }
validates :waiting_time, :numericality => { :greater_than_or_equal_to => 0 }

# FIXME: fill in position from id!

Expand Down
1 change: 1 addition & 0 deletions app/views/admin/steps/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<%= form.text_field :custom_title %>
<%= form.text_field :keywords %>
<%= form.check_box :is_waiting_step %>
<%= form.number_field :waiting_time %>
<%= form.text_field :slug %>
<%= form.text_field :app_url %>
<%= form.text_field :app_link_text %>
Expand Down
12 changes: 12 additions & 0 deletions app/views/components/_timeline.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@
<strong>
<%= link_to step.title, [@journey, step], class: 'sdn-timeline__link' %>
</strong>
<% if step.waiting_time > 0 && user_step.status == "waiting" %>
<% time_waited = step.waiting_time - (Date.today - Date.parse(user_step.updated_at.to_s)).to_i %>
<% if time_waited < 0 %>
<strong class="govuk-tag govuk-tag--red">
<% elsif time_waited < 5 %>
<strong class="govuk-tag govuk-tag--orange">
<% else %>
<strong class="govuk-tag govuk-tag--green">
<% end %>
<%= time_waited %>
</strong>
<% end %>
<% else %>
<%= link_to step.title, [@journey, step], class: 'sdn-timeline__link' %>
<% end %>
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20230627134435_add_waiting_time_to_steps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddWaitingTimeToSteps < ActiveRecord::Migration[6.1]
def change
add_column :steps, :waiting_time, :integer, default: 0
end
end
6 changes: 4 additions & 2 deletions db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,8 @@ CREATE TABLE public.steps (
app_url character varying,
type character varying DEFAULT 'BasicStep'::character varying NOT NULL,
app_link_text character varying,
custom_title character varying
custom_title character varying,
waiting_time integer DEFAULT 0
);


Expand Down Expand Up @@ -2440,6 +2441,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20230325092744'),
('20230325095737'),
('20230325151049'),
('20240427124856');
('20240427124856'),
('20230627134435');


0 comments on commit 7b82819

Please sign in to comment.