diff --git a/app/assets/stylesheets/bootstrap_and_overrides.css.less b/app/assets/stylesheets/bootstrap_and_overrides.css.less index 8394971..da3827b 100644 --- a/app/assets/stylesheets/bootstrap_and_overrides.css.less +++ b/app/assets/stylesheets/bootstrap_and_overrides.css.less @@ -704,11 +704,11 @@ float:left; } -#s2id_user_organisation_id{ +#s2id_user_organisation_id, #s2id_user_language_id { min-width:84% !important; clear:both; float:left; - margin: 0 0 10px 0; + margin: 0 0 5px 0; } #other-org-link { diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 7160fd7..182ee9a 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -18,17 +18,18 @@ def set_locale # parameter from url takes precedence - if params[:locale] + # check if locale is defined + if params[:locale] # and I18n.available_locales.include? params[:locale] # throw an error if not available # if locales data is present in the parameter from url use it - # TODO we need to error to the user that locale is missing, it can be THE CASE because there can be a missmatch between locales files and db I18n.locale = params[:locale] - elsif false # TODO + elsif user_signed_in? and !current_user[:language_id].nil? + I18n.locale = Language.find_by_id(current_user[:language_id]).name # if user has set preferred language use it elsif false # TODO # use user's organization language, keep in mine the "OTHER ORG" edge case which should use english else # just use the default language, line can be commented out, included just for clarity - # I18n.locale = config.I18n.default_locale + I18n.locale = I18n.default_locale end end diff --git a/app/controllers/contacts_controller.rb b/app/controllers/contacts_controller.rb index 08843f2..ae9e85a 100644 --- a/app/controllers/contacts_controller.rb +++ b/app/controllers/contacts_controller.rb @@ -1,4 +1,7 @@ -class ContactsController < ContactUs::ContactsController +class ContactsController < ContactUs::ContactsController + + # in order to i18 this file recaptcha gem has to be updated + def create @contact = ContactUs::Contact.new(params[:contact_us_contact]) if (!user_signed_in?) diff --git a/app/models/user.rb b/app/models/user.rb index 9edea25..fc7a9eb 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -16,6 +16,7 @@ has_many :project_groups, :dependent => :destroy has_many :organisations , through: :user_org_roles has_many :user_role_types, through: :user_org_roles + has_one :language @@ -49,7 +50,8 @@ attr_accessible :password_confirmation, :encrypted_password, :remember_me, :id, :email, :firstname, :last_login,:login_count, :orcid_id, :password, :shibboleth_id, :user_status_id, :surname, :user_type_id, :organisation_id, :skip_invitation, - :other_organisation, :accept_terms, :role_ids, :dmponline3, :api_token + :other_organisation, :accept_terms, :role_ids, :dmponline3, :api_token, + :language_id # FIXME: The duplication in the block is to set defaults. It might be better if # they could be set in Settings::PlanList itself, if possible. diff --git a/app/views/devise/registrations/edit.html.erb b/app/views/devise/registrations/edit.html.erb index b9b67e1..fb4b07c 100644 --- a/app/views/devise/registrations/edit.html.erb +++ b/app/views/devise/registrations/edit.html.erb @@ -1,14 +1,14 @@

<%= t("helpers.edit_profile") %>

- <%= raw t("helpers.user_details_text_html")%> +<%= raw t("helpers.user_details_text_html") %>
- <%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put }) do |f| %> - <%= hidden_field_tag :unlink_flag, "false" ,:id => "unlink_flag" %> - -
+ <%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => {:method => :put}) do |f| %> + <%= hidden_field_tag :unlink_flag, "false", :id => "unlink_flag" %> + +
-

<%= raw t("helpers.user_details_paragraph_html")%>

+

<%= raw t("helpers.user_details_paragraph_html") %>

@@ -119,20 +119,20 @@ <%# = button_to "Cancel my account", registration_path(resource_name), :data => { :confirm => "Are you sure?" }, :method => :delete %> - + diff --git a/app/views/layouts/_dmponline_footer.html.erb b/app/views/layouts/_dmponline_footer.html.erb index 9a21582..0e017bc 100644 --- a/app/views/layouts/_dmponline_footer.html.erb +++ b/app/views/layouts/_dmponline_footer.html.erb @@ -6,7 +6,6 @@
  • <%= t("contact_page.title") %>
  • |
  • <%= t("terms_page.title") %>
  • -
    diff --git a/config/initializers/formatter_override.rb b/config/initializers/formatter_override.rb new file mode 100644 index 0000000..32c8430 --- /dev/null +++ b/config/initializers/formatter_override.rb @@ -0,0 +1,26 @@ +ActionDispatch::Journey::Formatter.module_eval do + + # this overrides formatter in order to solve bug + # might not be needed, bug is present anyway + # see https://github.com/rails/rails/issues/12178 + def extract_parameterized_parts(route, options, recall, parameterize = nil) + parameterized_parts = recall.merge(options) + keys_to_keep = route.parts.reverse.drop_while { |part| + !options.key?(part) || (options[part] || recall[part]).nil? + } | route.required_parts + + # symbolize keys to make sure the right parameters are removed + (parameterized_parts.symbolize_keys.keys - keys_to_keep.map(&:to_sym)).each do |bad_key| + parameterized_parts.delete(bad_key) + end + + if parameterize + parameterized_parts.each do |k, v| + parameterized_parts[k] = parameterize.call(k, v) + end + end + + parameterized_parts.keep_if { |_, v| v } + parameterized_parts + end +end diff --git a/config/locales/en-UK.yml b/config/locales/en-UK.yml index 75b5a0d..a093835 100644 --- a/config/locales/en-UK.yml +++ b/config/locales/en-UK.yml @@ -339,6 +339,7 @@ valid_email: "You must enter a valid email address." user_details_text_html: "

    Please note that your email address is used as your username. If you change this, remember to use your new email address on sign in.

    " user_details_paragraph_html: "You can edit any of the details below." + user_details_language: "Language" remember_me: "Remember me" org_not_listed: "My organisation isn't listed." diff --git a/db/migrate/20160729091510_add_language_to_user.rb b/db/migrate/20160729091510_add_language_to_user.rb new file mode 100644 index 0000000..e130972 --- /dev/null +++ b/db/migrate/20160729091510_add_language_to_user.rb @@ -0,0 +1,5 @@ +class AddLanguageToUser < ActiveRecord::Migration + def change + add_reference :users, :language + end +end diff --git a/db/schema.rb b/db/schema.rb index a7e5f15..3841184 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20160719140055) do +ActiveRecord::Schema.define(version: 20160729091510) do create_table "answers", force: :cascade do |t| t.text "text", limit: 65535 @@ -401,6 +401,7 @@ t.string "api_token", limit: 255 t.integer "invited_by_id", limit: 4 t.string "invited_by_type", limit: 255 + t.integer "language_id", limit: 4 end add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true, using: :btree diff --git a/db/seeds.rb b/db/seeds.rb index 5d4aedd..69b3ed6 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -6,6 +6,32 @@ d1 = DateTime.new(2015, 6, 22) +languages = { + 'EN-UK' => { + abbreviation: "en-UK", + description: "", + name: "en-UK" + }, + 'FR' => { + abbreviation: "fr", + description: "", + name: "fr" + }, + 'DE' => { + abbreviation: "de", + description: "", + name: "de" + } +} + +languages.each do |l, details| + language = Language.new + language.abbreviation = details[:abbreviation] + language.description = details[:description] + language.name = details[:name] + language.save! +end + organisation_types = { 'Organisation' => { name: "Organisation" @@ -129,6 +155,7 @@ surname: "Admin", password_confirmation: "password123", organisation: "RCC", + language: "en-UK", roles: ['admin','org_admin'], accept_terms: true, confirmed_at: Time.zone.now @@ -140,6 +167,7 @@ firstname: "Funder", surname: "Admin", organisation: "RegSciFed", + language: "en-UK", roles: ['org_admin'], accept_terms: true, confirmed_at: Time.zone.now @@ -151,6 +179,7 @@ firstname: "Organization", surname: "Admin", organisation: "CapColl", + language: "en-UK", roles: ['org_admin'], accept_terms: true, confirmed_at: Time.zone.now @@ -162,6 +191,7 @@ firstname: "Jane", surname: "Researcher", organisation: "CapColl", + language: "en-UK", roles: ['user'], accept_terms: true, confirmed_at: Time.zone.now @@ -178,6 +208,7 @@ usr.organisation_id = Organisation.find_by_abbreviation(details[:organisation]).id # usr.user_org_roles << UserOrgRole.create(organisation: Organisation.find_by_abbreviation(details[:organisation]), # user_role_type: UserRoleType.find_by_name('admin')) + usr.language_id = Language.find_by_name(details[:language]).id details[:roles].each do |role| usr.roles << Role.find_by_name(role) end @@ -613,9 +644,9 @@ } formatting.each do |org, settings| - template = Dmptemplate.find_by_title("#{org} Template") - template.settings(:export).formatting = settings - template.save! + #template = Dmptemplate.find_by_title("#{org} Template") # this is bugged, there is no Funder Template nor DCC template + #template.settings(:export).formatting = settings + #template.save! end token_permission_types = { @@ -640,30 +671,5 @@ token_permission_type.save! end -languages = { - 'EN-UK' => { - abbreviation: "en-UK", - description: "", - name: "en-UK" - }, - 'FR' => { - abbreviation: "fr", - description: "", - name: "fr" - }, - 'DE' => { - abbreviation: "de", - description: "", - name: "de" - } -} - -languages.each do |l, details| - language = Language.new - language.abbreviation = details[:abbreviation] - language.description = details[:description] - language.name = details[:name] - language.save! -end