diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 45a7ae5..f140b25 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -36,6 +36,10 @@ def set_locale session[:locale] || http_accept_language.preferred_language_from(I18n.available_locales) end + def last_visited_page + redirect_to cookies[:last_visited_page] || root_path + end + private def require_user diff --git a/app/models/featured_scenario.rb b/app/models/featured_scenario.rb index 83c7372..7765815 100644 --- a/app/models/featured_scenario.rb +++ b/app/models/featured_scenario.rb @@ -87,6 +87,10 @@ def localized_description(locale) end def as_json(options = {}) - super.merge(version: version, end_year: end_year) + super.merge( + version: version, + end_year: end_year, + author: owner&.user&.name || "No author" + ) end end diff --git a/app/models/featured_scenario_user.rb b/app/models/featured_scenario_user.rb index c51bb54..9a11b07 100644 --- a/app/models/featured_scenario_user.rb +++ b/app/models/featured_scenario_user.rb @@ -1,2 +1,9 @@ class FeaturedScenarioUser < ApplicationRecord + # TODO user should be optional. Either User or Name. + # TODO form to create Featured scenario users from admin console! + belongs_to :user + has_many :featured_scenarios, foreign_key: :owner_id, dependent: :destroy + + validates :name, presence: true + validates :user, presence: true end diff --git a/app/views/layouts/_buttons.html.haml b/app/views/layouts/_buttons.html.haml index 729c630..700952f 100644 --- a/app/views/layouts/_buttons.html.haml +++ b/app/views/layouts/_buttons.html.haml @@ -1,2 +1,3 @@ .flex.py-5 - .bg-gray-100.p-2.px-5.mr-0.ml-auto.rounded-md Continue working (in Classic/in Collections) + .bg-gray-100.p-2.px-5.mr-0.ml-auto.rounded-md + = link_to t('continue_working'), last_visited_page_path, class: 'continue-button' diff --git a/config/initializers/session_store.rb b/config/initializers/session_store.rb index e089e6f..6e14606 100644 --- a/config/initializers/session_store.rb +++ b/config/initializers/session_store.rb @@ -1 +1 @@ -MyEtm::Application.config.session_store :active_record_store, key: "_idp_session" +MyEtm::Application.config.session_store :active_record_store, key: "_idp_session", domain: :all, tld_length: 2 diff --git a/config/locales/en.yml b/config/locales/en.yml index 464f773..e6b0edf 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -31,6 +31,7 @@ en: undo: Undo more: More... language: English + continue_working: "Back to work" errors: sorry: Oops! We're sorry diff --git a/config/locales/nl.yml b/config/locales/nl.yml index 1f5837d..e5f5512 100644 --- a/config/locales/nl.yml +++ b/config/locales/nl.yml @@ -1,5 +1,6 @@ nl: language: Nederlands + continue_working: Terug aan het werk time: formats: short: "%-d %b %H:%M" diff --git a/config/routes.rb b/config/routes.rb index a30cd64..83baffe 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -13,6 +13,8 @@ mount Sidekiq::Web => '/sidekiq' end + get '/last_visited_page', to: 'application#last_visited_page', as: :last_visited_page + namespace :identity do get '/', to: redirect('/identity/profile') get 'profile', to: 'settings#index', as: :profile diff --git a/spec/factories/featured_scenario.rb b/spec/factories/featured_scenario.rb index 15888dd..f35fba8 100644 --- a/spec/factories/featured_scenario.rb +++ b/spec/factories/featured_scenario.rb @@ -7,6 +7,10 @@ title_en { 'English title' } title_nl { 'Dutch title' } - owner { association :featured_scenario_user } + transient do + with_owner { false } + end + + owner { with_owner ? association(:featured_scenario_user) : nil } end end diff --git a/spec/requests/api/featured_scenarios_spec.rb b/spec/requests/api/featured_scenarios_spec.rb index 2b09ba9..4c4c4e5 100644 --- a/spec/requests/api/featured_scenarios_spec.rb +++ b/spec/requests/api/featured_scenarios_spec.rb @@ -19,7 +19,7 @@ parsed_response['featured_scenarios'].each do |scenario| expect(scenario.keys).to contain_exactly( - 'id', 'saved_scenario_id', 'owner_id', 'group', 'title_en', 'title_nl', 'version', 'end_year' + 'id', 'saved_scenario_id', 'owner_id', 'group', 'title_en', 'title_nl', 'version', 'end_year', 'author' ) expect(scenario['version']).to eq('latest') end @@ -42,7 +42,7 @@ parsed_response['featured_scenarios'].each do |scenario| expect(scenario.keys).to contain_exactly( - 'id', 'saved_scenario_id', 'owner_id', 'group', 'title_en', 'title_nl', 'version', 'end_year' + 'id', 'saved_scenario_id', 'owner_id', 'group', 'title_en', 'title_nl', 'version', 'end_year', 'author' ) expect(scenario['version']).to eq('old') end @@ -58,7 +58,7 @@ expect(response).to have_http_status(:ok) parsed_response = JSON.parse(response.body) expect(parsed_response.keys).to contain_exactly( - 'id', 'saved_scenario_id', 'owner_id', 'group', 'title_en', 'title_nl', 'version', 'end_year' + 'id', 'saved_scenario_id', 'owner_id', 'group', 'title_en', 'title_nl', 'version', 'end_year', 'author' ) expect(parsed_response['id']).to eq(featured_scenario_id) expect(parsed_response['version']).to eq('latest')