diff --git a/app/components/login/button_component.rb b/app/components/login/button_component.rb index b6e88cf..52adb2c 100644 --- a/app/components/login/button_component.rb +++ b/app/components/login/button_component.rb @@ -3,7 +3,7 @@ module Login class ButtonComponent < ActionButtonComponent def initialize(form:) - super(form:, type: :submit, color: :primary, size: :lg, class: "w-full !py-3 mt-5 bg-midnight-600") + super(form:, type: :submit, color: :primary, size: :lg, class: "w-full !py-3 mt-5 bg-midnight-600 text-midnight-800") end end end diff --git a/app/controllers/api/v1/saved_scenarios_controller.rb b/app/controllers/api/v1/saved_scenarios_controller.rb index 580ef48..16710f6 100644 --- a/app/controllers/api/v1/saved_scenarios_controller.rb +++ b/app/controllers/api/v1/saved_scenarios_controller.rb @@ -38,7 +38,7 @@ def update result = SavedScenario::Update.call( engine_client, @saved_scenario, - saved_scenario_params + saved_scenario_params.except(:version) ) if result.successful? @@ -62,7 +62,7 @@ def destroy # Only allow a list of trusted parameters through. def saved_scenario_params params.require(:saved_scenario).permit( - :scenario_id, :title, + :scenario_id, :title, :version, :description, :area_code, :end_year, :private, :discarded ) end diff --git a/app/controllers/api/v1/versions_controller.rb b/app/controllers/api/v1/versions_controller.rb new file mode 100644 index 0000000..dad499c --- /dev/null +++ b/app/controllers/api/v1/versions_controller.rb @@ -0,0 +1,11 @@ +module Api + module V1 + class VersionsController < BaseController + skip_before_action :authenticate_request! + + def index + render json: { versions: Version.as_json }, status: :ok + end + end + end +end diff --git a/app/models/saved_scenario.rb b/app/models/saved_scenario.rb index a775be5..75a11b2 100644 --- a/app/models/saved_scenario.rb +++ b/app/models/saved_scenario.rb @@ -27,7 +27,7 @@ class SavedScenario < ApplicationRecord validates :end_year, presence: true validates :area_code, presence: true validates :version, presence: true, inclusion: { - in: Version.all, message: "Version should be one of #{Version.all}" + in: Version.tags, message: "Version should be one of #{Version.tags}" } serialize :scenario_id_history, coder: YAML, type: Array diff --git a/app/models/version.rb b/app/models/version.rb index 80ae200..9ddafda 100644 --- a/app/models/version.rb +++ b/app/models/version.rb @@ -2,13 +2,25 @@ # A valid version of the ETM class Version - LIST = %w[ - latest - ].freeze + URL = "energytransitionmodel.com".freeze + + LIST = { + "latest" => "https://#{Version::URL}", + "stable.01" => "https://stable.#{Version::URL}", + "stable.02" => "https://stable2.#{Version::URL}" + }.freeze # All available versions. Uses ActiveRecord syntax 'all' to # make future porting to db easier def self.all LIST end + + def self.tags + LIST.keys + end + + def self.as_json(*) + LIST.map { |tag, url| { tag: tag, url: url } } + end end diff --git a/app/views/layouts/_buttons.html.haml b/app/views/layouts/_buttons.html.haml index 700952f..c1df0c8 100644 --- a/app/views/layouts/_buttons.html.haml +++ b/app/views/layouts/_buttons.html.haml @@ -1,3 +1,5 @@ .flex.py-5 - .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' + .flex.basis-full{class: 'lg:basis-3/4'} + - if cookies[:last_visited_page].present? + .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/routes.rb b/config/routes.rb index 83baffe..50cf62d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -84,6 +84,7 @@ resources :collections, only: [:index, :show, :create, :destroy] resources :saved_scenarios, only: %i[index show create update destroy] resources :featured_scenarios, only: %i[index show] + resources :versions, only: [:index] end end diff --git a/spec/controllers/api/v1/versions_controller_spec.rb b/spec/controllers/api/v1/versions_controller_spec.rb new file mode 100644 index 0000000..2080768 --- /dev/null +++ b/spec/controllers/api/v1/versions_controller_spec.rb @@ -0,0 +1,25 @@ +require 'rails_helper' + +RSpec.describe 'API::V1::Versions', type: :request do + let(:user) { create(:user) } + + describe 'GET /api/v1/versions' do + before do + get '/api/v1/versions', + as: :json, + headers: access_token_header(user, :read) + end + + it 'returns a successful response' do + expect(response).to have_http_status(:ok) + end + + it 'returns all versions with their URLs' do + parsed_response = JSON.parse(response.body) + + expect(parsed_response['versions']).to be_present + expect(parsed_response['versions'].map { |v| v['tag'] }).to match_array(Version.tags) + expect(parsed_response['versions'].first).to have_key('url') + end + end +end