diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index a870b1ef..704c97ac 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -50,4 +50,22 @@ $(document).on("turbolinks:load", function () { .classList.add("active-topic__hidden"); }); } + + var changeNotificationDateLink = document.querySelector("#change-notification-date-link"); + if (changeNotificationDateLink) { + changeNotificationDateLink.addEventListener("click", function (e) { + e.preventDefault(); + $("#change-notification-date").removeClass("sdn-appear-link-hide"); + $("#deadline-notifications-info").addClass("sdn-appear-link-hide"); + }); + } + + var changeNotificationDateClose = document.querySelector("#change-notification-date-close"); + if (changeNotificationDateClose) { + changeNotificationDateClose.addEventListener("click", function (e) { + e.preventDefault(); + $("#change-notification-date").addClass("sdn-appear-link-hide"); + $("#deadline-notifications-info").removeClass("sdn-appear-link-hide"); + }); + } }); diff --git a/app/controllers/deadline_notifications_controller.rb b/app/controllers/deadline_notifications_controller.rb new file mode 100644 index 00000000..57354ea1 --- /dev/null +++ b/app/controllers/deadline_notifications_controller.rb @@ -0,0 +1,54 @@ +class DeadlineNotificationsController < ApplicationController + before_action :set_journey_and_step + def subscribe_to_deadline_notification + 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 'deadline_notifications_updated' + end + end + + rescue Date::Error => e + respond_to do |format| + format.html do + redirect_to [@journey, @current_step] + end + format.js do + render 'deadline_notifications_update_error' + end + end + end + + def unsubscribe_deadline_notification + @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 'deadline_notifications_updated' + end + end + + end + + private + + def set_journey_and_step + @journey = Journey.published.find_by!(slug: params[:journey_id]) + @current_step = @journey.steps.find_by!(slug: params[:id]) + end +end diff --git a/app/controllers/steps_controller.rb b/app/controllers/steps_controller.rb index af0e179c..ba40fb96 100644 --- a/app/controllers/steps_controller.rb +++ b/app/controllers/steps_controller.rb @@ -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(new_status: params['status']) + @user_step.update(status: params['status'], submitted_at: params['status'] == 'waiting' ? Date.today : nil) respond_to do |format| format.html do @@ -41,58 +41,6 @@ def start redirect_to step.app_url end - def subscribe_to_deadline_notification - @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" diff --git a/app/models/step.rb b/app/models/step.rb index e141049a..27bccfe0 100644 --- a/app/models/step.rb +++ b/app/models/step.rb @@ -18,7 +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 } + validates :waiting_time, :numericality => { greater_than_or_equal_to: 0 } # FIXME: fill in position from id! diff --git a/app/models/user_step.rb b/app/models/user_step.rb index f8098ae5..d617d84e 100644 --- a/app/models/user_step.rb +++ b/app/models/user_step.rb @@ -18,10 +18,6 @@ def refresh_status end end - def update_status(new_status:) - update(status: new_status, submitted_at: new_status == 'waiting' ? Date.today : nil) - end - def remaining_time step.waiting_time - (Date.today - submitted_at).to_i end diff --git a/app/views/steps/_step_subscription.html.erb b/app/views/deadline_notifications/_subscription_info.erb similarity index 50% rename from app/views/steps/_step_subscription.html.erb rename to app/views/deadline_notifications/_subscription_info.erb index 231e0ecf..217ee3f4 100644 --- a/app/views/steps/_step_subscription.html.erb +++ b/app/views/deadline_notifications/_subscription_info.erb @@ -1,29 +1,24 @@ -
- <% if current_user_step.submitted_at %> -

- 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) %>. -

- <% end %> +
<% if current_user_step.to_be_notified_at %>

- Budeme vás o tom notifikovať e-mailom <%= current_user_step.to_be_notified_at.strftime('%d.%m.%Y') %>. + O vypršaní lehoty vám zašleme notifikáciu e-mailom dňa <%= current_user_step.to_be_notified_at.strftime('%d.%m.%Y') %>. + Zmeniť dátum

<%= 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' %> + <%= submit_tag 'Zrušiť notifikáciu', class: 'govuk-button govuk-button--warning' %> <% end %> <% else current_user_step.submitted_at %>

- 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') %> + Ak si želáte môžeme vám poslať notifikáciu dňa <%= current_user_step.expected_resolution_date.strftime('%d.%m.%Y') %>. + Zmeniť dátum

<%= 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' %> + <%= submit_tag 'Zapnúť notifikáciu', class: 'govuk-button' %> <% end %> <% end %>
diff --git a/app/views/deadline_notifications/_subscription_settings.erb b/app/views/deadline_notifications/_subscription_settings.erb new file mode 100644 index 00000000..4101515c --- /dev/null +++ b/app/views/deadline_notifications/_subscription_settings.erb @@ -0,0 +1,36 @@ +
+ <%= render 'deadline_notifications/subscription_info', current_user_step: current_user_step %> +
+ diff --git a/app/views/steps/step_subscription_update_error.js.erb b/app/views/deadline_notifications/deadline_notifications_update_error.js.erb similarity index 100% rename from app/views/steps/step_subscription_update_error.js.erb rename to app/views/deadline_notifications/deadline_notifications_update_error.js.erb diff --git a/app/views/steps/step_subscription_updated.js.erb b/app/views/deadline_notifications/deadline_notifications_updated.js.erb similarity index 54% rename from app/views/steps/step_subscription_updated.js.erb rename to app/views/deadline_notifications/deadline_notifications_updated.js.erb index c66180d7..4fa03861 100644 --- a/app/views/steps/step_subscription_updated.js.erb +++ b/app/views/deadline_notifications/deadline_notifications_updated.js.erb @@ -1,5 +1,5 @@ -$('#step_subscription').replaceWith('<%= j render "step_subscription", current_user_step: @user_step %>'); -$('#next-steps-info').removeClass('sdn-appear-link-hide') +$('#subsciption_info').replaceWith('<%= j render "deadline_notifications/subscription_info", current_user_step: @user_step %>'); +$('#deadline-notifications-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') diff --git a/app/views/steps/_step_footer_logged_in.html.erb b/app/views/steps/_step_footer_logged_in.html.erb deleted file mode 100644 index 62ccaa9e..00000000 --- a/app/views/steps/_step_footer_logged_in.html.erb +++ /dev/null @@ -1,80 +0,0 @@ -
- <% if current_user_step.done? %> -
-

Vybavené!

- 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 %> - . -
- <% elsif current_user_step.waiting? %> -
-

Podanie bolo zaslané - <% if current_user_step.submitted_at %>dňa <%= current_user_step.submitted_at.strftime('%d.%m.%Y') %> - <% end %>

-
- <%= render 'step_subscription', current_user_step: current_user_step %> - Zmeniť dátum? -
- -
- -

- Po úspešnom vybavení podania, keď dostanete pozitívnu odpoveď, označte úlohu za vybavenú. -

-
-
- <%= link_to 'Označiť ako vybavené', journey_step_path(@journey, @current_step, status: 'done'), class: 'govuk-button', method: :patch, remote: true %> -
-
- <% else %> - <% if @current_step.tasks.any? && @current_step.has_app? %> -
- Po splnení všetkých povinností môžete podať elektronickú žiadosť a potom označiť tento krok ako podaný. -
- <% end %> -
-
- <% 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 %> -
-
- <% end %> -
diff --git a/app/views/steps/_todo_list_logged_in.html.erb b/app/views/steps/_todo_list_logged_in.html.erb index 0be89766..075ef75c 100644 --- a/app/views/steps/_todo_list_logged_in.html.erb +++ b/app/views/steps/_todo_list_logged_in.html.erb @@ -22,7 +22,62 @@ <% end %> <% if @current_step %> - <%= render 'step_footer_logged_in', current_user_step: current_user_step %> - <% end %> +
+ <% if current_user_step.done? %> +
+

Vybavené!

+ 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 %>. +
+ <% elsif current_user_step.waiting? %> +
+

Podané

+ <% if current_user_step.submitted_at %> +

+ Čakacia lehota na vybavenie je <%= t('components.deadline.remaining_days', count: @current_step.waiting_time) %>. + Ostáva <%= t('components.deadline.remaining_days', count: current_user_step.remaining_time) %>. +

+ <% end %> + + Po úspešnom vybavení, keď dostanete pozitívnu odpoveď, označte + úlohu za vybavenú. +
+ +
+
+ <%= link_to 'Označiť ako vybavené', journey_step_path(@journey, @current_step, status: 'done'), class: 'govuk-button', method: :patch, remote: true %> +
+
+
+
+ + + Notifikácia e-mailom + + +
+ <%= render 'deadline_notifications/subscription_settings', current_user_step: current_user_step %> +
+
+ <% else %> + <% if @current_step.tasks.any? && @current_step.has_app? %> +
+ Po splnení všetkých povinností môžete podať elektronickú žiadosť a potom označiť tento krok ako podaný. +
+ <% end %> +
+
+ <% 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 %> +
+
+ <% end %> +
+ <% end %>
<% end %> diff --git a/config/routes.rb b/config/routes.rb index 9e9a4d0d..98d6ab32 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -54,8 +54,10 @@ 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' + member do + post 'vytvorit-notifikaciu', to: 'deadline_notifications#subscribe_to_deadline_notification', as: :subscribe_to_deadline_notification + delete 'zrusit-notifikaciu', to: 'deadline_notifications#unsubscribe_deadline_notification', as: :unsubscribe_deadline_notification + end resources :tasks do member do post :complete