Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added waiting time to waiting step (#460) #590

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
54 changes: 53 additions & 1 deletion app/controllers/steps_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def update

@current_step = @journey.steps.find_by(slug: params[:id])
@user_step = @user_journey.user_steps.find_or_initialize_by(step: @current_step)
@user_step.update(status: params['status'])
@user_step.update_status(new_status: params['status'])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

preco tato zmena?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Asi tam bola este nejaka logika @crutch? Vratil som tam update.


respond_to do |format|
format.html do
Expand All @@ -41,6 +41,58 @@ def start
redirect_to step.app_url
end

def subscribe_to_deadline_notification
xpavle00 marked this conversation as resolved.
Show resolved Hide resolved
@journey = Journey.published.find_by!(slug: params[:journey_id])
@current_step = @journey.steps.find_by!(slug: params[:id])

notification_date = params[:notification_date] ? Date.parse(params[:notification_date]) : nil
notification_date ||= Date.new(params[:year].to_i, params[:month].to_i, params[:day].to_i)

@user_journey = UserJourney.order(id: :desc).find_by(user: current_user, journey: @journey)
@user_step = @user_journey.user_steps.find_by(step: @current_step)

@user_step.update(to_be_notified_at: notification_date)

respond_to do |format|
format.html do
redirect_to [@journey, @current_step]
end
format.js do
render 'step_subscription_updated'
end
end

rescue Date::Error => e
respond_to do |format|
format.html do
redirect_to [@journey, @current_step]
end
format.js do
render 'step_subscription_update_error'
end
end
end

def unsubscribe_deadline_notification
@journey = Journey.published.find_by!(slug: params[:journey_id])
@current_step = @journey.steps.find_by!(slug: params[:id])

@user_journey = UserJourney.order(id: :desc).find_by(user: current_user, journey: @journey)
@user_step = @user_journey.user_steps.find_by(step: @current_step)

@user_step.update(to_be_notified_at: nil)

respond_to do |format|
format.html do
redirect_to [@journey, @current_step]
end
format.js do
render 'step_subscription_updated'
end
end

end

private def redirect_inactive_eu_application
return if Apps::EpVoteApp::ApplicationForm.active?
redirect_to apps_ep_vote_app_application_forms_path if params[:journey_id] == "volby-do-eu-parlamentu"
Expand Down
8 changes: 8 additions & 0 deletions app/helpers/format_days_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,12 @@ def format_remaining_days_count(remaining_days)
"posledný deň"
end
end

def format_past_days_count(past_days)
if past_days == 1
"1 dňom"
else
"#{past_days} dňami"
end
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 }
xpavle00 marked this conversation as resolved.
Show resolved Hide resolved

# FIXME: fill in position from id!

Expand Down
14 changes: 13 additions & 1 deletion app/models/user_step.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class UserStep < ApplicationRecord
validates :status, inclusion: { in: %w(not_started started waiting done) }

def refresh_status
if all_tasks_completed? && !step.has_app?
if all_tasks_completed? && !step.has_app? && !step.is_waiting_step?
update(status: 'done')
elsif user_tasks.completed.none?
update(status: 'not_started')
Expand All @@ -18,6 +18,18 @@ def refresh_status
end
end

def update_status(new_status:)
xpavle00 marked this conversation as resolved.
Show resolved Hide resolved
update(status: new_status, submitted_at: new_status == 'waiting' ? Date.today : nil)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mozno lepsie tu dat waiting_until ako nejaky datum kedy to vyprsi (nebude potom treba tolko pocitat).

lebo pri nejakom podani ti mozu lehotu aj posunut - cize je to od pripadu k pripadu.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Zatial som to nechal tak, aby tam ostala informacia kedy to bolo podane, mozno sa na nieco hodi.

end

def remaining_time
step.waiting_time - (Date.today - submitted_at).to_i
end

def expected_resolution_date
Date.today + remaining_time.days
end

def done?
status == 'done'
end
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
8 changes: 8 additions & 0 deletions app/views/components/_timeline.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@
<strong>
<%= link_to step.title, [@journey, step], class: 'sdn-timeline__link' %>
</strong>
<% if step.waiting_time > 0 && user_step&.status == "waiting" && user_step&.submitted_at %>
<% remaining_time = user_step.remaining_time %>
<% if remaining_time < 0 %>
Lehota vypršala pred: <strong class="govuk-tag govuk-tag--red"><%= format_past_days_count(-1 * remaining_time) %></strong>
<% else %>
Čakacia lehota: <strong class="govuk-tag govuk-tag--blue"><%= format_remaining_days_count(remaining_time) %></strong>
Comment on lines +29 to +31
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Toto by mal vidiet este nejaky dizajner.

<% end %>
<% end %>
<% else %>
<%= link_to step.title, [@journey, step], class: 'sdn-timeline__link' %>
<% end %>
Expand Down
80 changes: 80 additions & 0 deletions app/views/steps/_step_footer_logged_in.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<div class="sdn-todo-list-main-action">
<% if current_user_step.done? %>
<div class="govuk-body-s sdn-todo-list-main-action__info">
<h2 class="govuk-heading-s">Vybavené!</h2>
Ak sa chcete vrátiť späť, môžete tento krok
návodu <%= link_to 'označiť ako nevybavený', journey_step_path(@journey, @current_step, status: 'not_started'), method: :patch, remote: true %>
.
</div>
<% elsif current_user_step.waiting? %>
<div class="govuk-body-s sdn-todo-list-main-action__info">
<h2 class="govuk-heading-s">Podanie bolo zaslané
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Myslim, si ze tu treba lepsie "copy" lebo toto nemusi vzdy znamenat, ze to bolo podanie (aj ked vacsinou ano).

Zaroven sa mi zda ten navrh prilis vela textu a vela buttonov (velkych primarnych zelenych). Toto bude treba lepsie upratat. @xpavle00 ty si trufas aj na navrh toho ako by to malo vyzerat? (Staci sa pohrat s textami a govuk elementami)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Skusil som to zjednodusit. Prilozim screeny.

<% if current_user_step.submitted_at %>dňa <%= current_user_step.submitted_at.strftime('%d.%m.%Y') %>
<% end %></h2>
<div id="next-steps-info">
<%= render 'step_subscription', current_user_step: current_user_step %>
<a href="#" onclick="$('#change-notification-date').removeClass('sdn-appear-link-hide');$('#next-steps-info').addClass('sdn-appear-link-hide');return false;">Zmeniť dátum?</a>
xpavle00 marked this conversation as resolved.
Show resolved Hide resolved
</div>
<div id="change-notification-date" class="sdn-appear-link-hide">
<div class="govuk-grid-column-two-thirds">
Zmeniť dátum notifikácie
</div>
<div class="govuk-grid-column-one-third" style="text-align:right">
<a href="#" onclick="$('#change-notification-date').addClass('sdn-appear-link-hide');$('#next-steps-info').removeClass('sdn-appear-link-hide');return false;">Zatvoriť</a>
</div>
<%= form_tag subscribe_to_deadline_notification_journey_step_path(@current_step.journey, @current_step) , remote: true, authenticity_token: true do %>
<div class="govuk-form-group">
<span id="dob-error" class="govuk-error-message sdn-appear-link-hide">
<span class="govuk-visually-hidden">Chyba:</span> Zadali ste neplatný dátum
</span>
<div class="govuk-date-input" id="dob">
<div class="govuk-date-input__item">
<div class="govuk-form-group">
<%= label_tag 'dob-day', 'Deň', class: "govuk-label govuk-date-input__label" %>
<%= number_field_tag 'day', current_user_step.expected_resolution_date.day, required: true, min: 1, max: 31, class: 'govuk-input govuk-date-input__input govuk-input--width-2', id: 'dob-day' %></div>
</div>
<div class="govuk-date-input__item">
<div class="govuk-form-group">
<%= label_tag 'dob-month', 'Mesiac', class: "govuk-label govuk-date-input__label" %>
<%= number_field_tag 'month', current_user_step.expected_resolution_date.month, required: true, min: 1, max: 12, class: 'govuk-input govuk-date-input__input govuk-input--width-2', id: 'dob-month' %></div>
</div>
<div class="govuk-date-input__item">
<div class="govuk-form-group">
<%= label_tag 'dob-year', 'Rok', class: "govuk-label govuk-date-input__label" %>
<%= number_field_tag 'year', current_user_step.expected_resolution_date.year, required: true, min: 2023, class: 'govuk-input govuk-date-input__input govuk-input--width-2', id: 'dob-year' %></div>
</div>
</div>
</div>
<%= submit_tag 'Zmeniť dátum a potvrdiť notifikáciu.', class: 'govuk-button' %>
<% end %>
</div>
</div>

<p>
Po úspešnom vybavení podania, keď dostanete pozitívnu odpoveď, označte úlohu za vybavenú.
</p>
<div class="sdn-todo-list-main-action-buttons-wrapper">
<div class="sdn-todo-list-main-action-buttons">
<%= link_to 'Označiť ako vybavené', journey_step_path(@journey, @current_step, status: 'done'), class: 'govuk-button', method: :patch, remote: true %>
</div>
</div>
<% else %>
<% if @current_step.tasks.any? && @current_step.has_app? %>
<div class="govuk-body-s sdn-todo-list-main-action__info">
Po splnení všetkých povinností môžete podať elektronickú žiadosť a potom označiť tento krok ako podaný.
</div>
<% end %>
<div class="sdn-todo-list-main-action-buttons-wrapper">
<div class="sdn-todo-list-main-action-buttons">
<% if @current_step.has_app? %>
<%= link_to @current_step.app_link_text.presence || 'Požiadať elektronicky', start_journey_step_path(@journey, @current_step), target: '_blank', class: 'govuk-button govuk-button--start', draggable: false %>
<% end %>
<% if @current_step.is_waiting_step? %>
<%= link_to 'Označiť ako podané', journey_step_path(@journey, @current_step, status: 'waiting'), class: 'govuk-button', method: :patch, remote: true %>
<% else %>
<%= link_to 'Označiť ako vybavené', journey_step_path(@journey, @current_step, status: 'done'), class: 'govuk-button', method: :patch, remote: true %>
<% end %>
</div>
</div>
<% end %>
</div>
29 changes: 29 additions & 0 deletions app/views/steps/_step_subscription.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<div id="step_subscription">
<% if current_user_step.submitted_at %>
<p>
Teraz treba počkať na rozhodnutie. Ostáva <%= current_user_step.remaining_time %> z
pôvodných <%= t('components.deadline.remaining_days', count: @current_step.waiting_time) %>.
</p>
<% end %>
<% if current_user_step.to_be_notified_at %>
<p>
Budeme vás o tom notifikovať e-mailom <%= current_user_step.to_be_notified_at.strftime('%d.%m.%Y') %>.
</p>
<%= form_tag unsubscribe_deadline_notification_journey_step_path(@current_step.journey, @current_step), remote: true, authenticity_token: true, method: :delete do %>
<%= hidden_field_tag :current_user_step_id, current_user_step.id %>
<%= submit_tag 'Zrušiť naplánovanú notifikáciu.', class: 'govuk-button' %>
<% end %>
<% else
current_user_step.submitted_at %>
<p>
Pošleme Vám na e-mail notifikáciu keď sa bude lehota blížiť?
Vychádza to na <%= current_user_step.expected_resolution_date.strftime('%d.%m.%Y') %>
</p>

<%= form_tag subscribe_to_deadline_notification_journey_step_path(@current_step.journey, @current_step), remote: true, authenticity_token: true do %>
<%= hidden_field_tag :current_user_step_id, current_user_step.id %>
<%= hidden_field_tag :notification_date, current_user_step.expected_resolution_date %>
<%= submit_tag 'Áno, toto chcem.', class: 'govuk-button' %>
<% end %>
<% end %>
</div>
42 changes: 2 additions & 40 deletions app/views/steps/_todo_list_logged_in.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,45 +22,7 @@
<% end %>

<% if @current_step %>
<div class="sdn-todo-list-main-action">
<% if current_user_step.done? %>
<div class="govuk-body-s sdn-todo-list-main-action__info">
<h2 class="govuk-heading-s">Vybavené!</h2>
Ak sa chcete vrátiť späť, môžete tento krok návodu <%= link_to 'označiť ako nevybavený', journey_step_path(@journey, @current_step, status: 'not_started'), method: :patch, remote: true %>.
</div>
<% elsif current_user_step.waiting? %>
<div class="govuk-body-s sdn-todo-list-main-action__info">
<h2 class="govuk-heading-s">Podanie bolo zaslané</h2>
Po úspešnom vybavení podania, keď dostanete pozitívnu odpoveď, označte
úlohu za vybavenú.
</div>

<div class="sdn-todo-list-main-action-buttons-wrapper">
<div class="sdn-todo-list-main-action-buttons">
<%= link_to 'Označiť ako vybavené', journey_step_path(@journey, @current_step, status: 'done'), class: 'govuk-button', method: :patch, remote: true %>
</div>
</div>
<% else %>
<% if @current_step.tasks.any? && @current_step.has_app? %>
<div class="govuk-body-s sdn-todo-list-main-action__info">
Po splnení všetkých povinností môžete podať elektronickú žiadosť a potom označiť tento krok ako podaný.
</div>
<% end %>
<div class="sdn-todo-list-main-action-buttons-wrapper">
<div class="sdn-todo-list-main-action-buttons">
<% if @current_step.has_app? %>
<%= link_to @current_step.app_link_text.presence || 'Požiadať elektronicky', start_journey_step_path(@journey, @current_step), target: '_blank', class: 'govuk-button govuk-button--start', draggable: false %>
<% end %>
<% if @current_step.is_waiting_step? %>
<%= link_to 'Označiť ako podané', journey_step_path(@journey, @current_step, status: 'waiting'), class: 'govuk-button', method: :patch, remote: true %>
<% else %>
<%= link_to 'Označiť ako vybavené', journey_step_path(@journey, @current_step, status: 'done'), class: 'govuk-button', method: :patch, remote: true %>
<% end %>
</div>
</div>
<% end %>

<% end %>
</div>
<%= render 'step_footer_logged_in', current_user_step: current_user_step %>
<% end %>
</div>
<% end %>
2 changes: 2 additions & 0 deletions app/views/steps/step_subscription_update_error.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
$('#change-notification-date').find('.govuk-form-group').addClass('govuk-form-group--error')
$('#change-notification-date').find('#dob-error').removeClass('sdn-appear-link-hide')
5 changes: 5 additions & 0 deletions app/views/steps/step_subscription_updated.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
$('#step_subscription').replaceWith('<%= j render "step_subscription", current_user_step: @user_step %>');
$('#next-steps-info').removeClass('sdn-appear-link-hide')
$('#change-notification-date').addClass('sdn-appear-link-hide')
$('#change-notification-date').find('.govuk-form-group').removeClass('govuk-form-group--error')
$('#change-notification-date').find('#dob-error').addClass('sdn-appear-link-hide')
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
resources :journeys, path: 'zivotne-situacie', only: [:show] do
resources :steps, path: 'krok' do
get :start, on: :member, path: 'spustit'
post :subscribe_to_deadline_notification, on: :member, path: 'vytvorit-notifikaciu'
delete :unsubscribe_deadline_notification, on: :member, path: 'zrusit-notifikaciu'
resources :tasks do
member do
post :complete
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddSubmittedAtAndToBeNotifiedAtToUserStep < ActiveRecord::Migration[6.1]
def change
add_column :user_steps, :submitted_at, :date, default: nil
add_column :user_steps, :to_be_notified_at, :date, default: nil
end
end
11 changes: 8 additions & 3 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 @@ -1168,7 +1169,9 @@ CREATE TABLE public.user_steps (
step_id bigint NOT NULL,
status character varying NOT NULL,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
updated_at timestamp without time zone NOT NULL,
submitted_at date,
to_be_notified_at date
);


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


Loading