diff --git a/.gitignore b/.gitignore index ee170d8..520d92b 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,9 @@ # Ignore db schema.rb # db/schema.rb +# Ignore the test DB +db/test.sqlite3 + # Ignore database configuration and token secrets config/database.yml config/secrets.yml diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 005e288..d116bf0 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -77,6 +77,8 @@ def get_plan_list_columns if user_signed_in? @selected_columns = current_user.settings(:plan_list).columns + @selected_columns = Settings::PlanList::DEFAULT_COLUMNS if @selected_columns.empty? + @all_columns = Settings::PlanList::ALL_COLUMNS end end diff --git a/app/helpers/plans_helper.rb b/app/helpers/plans_helper.rb deleted file mode 100644 index 37a6355..0000000 --- a/app/helpers/plans_helper.rb +++ /dev/null @@ -1,62 +0,0 @@ -module PlansHelper - - def project_list_head(column) - klass = case column - when 'name' then :dmp_th_big - when 'description' then :dmp_th_big - else :dmp_th_small - end - - content_tag(:th, t("helpers.project.columns.#{column}"), class: klass) - end - - def project_list_body(column, project) - klass, content = case column[0] - when 'name' - [ "dmp_td_big", link_to(project.title, project_path(project), class: "dmp_table_link") ] - - when 'owner' - user = project.owner - - text = if user.nil? - "Unknown" - elsif user == current_user - t("helpers.me") - else - user.name - end - - [ "tmp_td_small", text ] - when 'shared' - shared_num = project.project_groups.count - 1 - text = shared_num > 0 ? (t("helpers.yes_label") + " (with #{shared_num} people) ") : t("helpers.no_label") - [ "dmp_td_small", text ] - when 'last_edited' - [ "dmp_td_small", l(project.latest_update.to_date, formats: :short) ] - when 'description' - [ "dmp_td_medium", (project.try(column[0]) || "Unknown") ] - else - [ "dmp_td_small", (project.try(column[0]) || "Unknown") ] - end - - content_tag(:td, content, class: klass) - end - - # Shows whether the user has default, template-default or custom settings - # for the given plan. - def plan_settings_indicator(plan) - plan_settings = plan.super_settings(:export) - template_settings = plan.project.dmptemplate.try(:settings, :export) - - key = if plan_settings.try(:value?) - plan_settings.formatting == template_settings.formatting ? "template_formatting" : "custom_formatting" - elsif template_settings.try(:value?) - "template_formatting" - else - "default_formatting" - end - - content_tag(:small, t("helpers.settings.plans.#{key}")) - end - -end diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb new file mode 100644 index 0000000..b9ad94c --- /dev/null +++ b/app/helpers/projects_helper.rb @@ -0,0 +1,73 @@ +module ProjectsHelper + + # Build variable column headings for the project list + # -------------------------------------------------------- + def project_list_column_heading(column) + if column.kind_of?(Array) + heading = (column.first.kind_of?(String) ? column.first : t("helpers.project.columns.unknown")) + + elsif column.kind_of?(String) + heading = column + + else + heading = t("helpers.project.columns.unknown") + end + + klass = (['name', 'description'].include?(heading) ? :dmp_th_big : :dmp_th_small) + + content_tag(:th, t("helpers.project.columns.#{heading}"), class: klass) + end + + # Populate a variable column for the project list + # -------------------------------------------------------- + def project_list_column_body(column, project) + klass, content = case column[0] + when 'name' + [ "dmp_td_big", link_to(project.title, project_path(project), class: "dmp_table_link") ] + + when 'owner' + user = project.owner + + text = if user.nil? + "Unknown" + elsif user == current_user + t("helpers.me") + else + user.name + end + + [ "tmp_td_small", text ] + when 'shared' + shared_num = project.project_groups.count - 1 + text = shared_num > 0 ? (t("helpers.yes_label") + " (with #{shared_num} people) ") : t("helpers.no_label") + [ "dmp_td_small", text ] + when 'last_edited' + [ "dmp_td_small", l(project.latest_update.to_date, formats: :short) ] + when 'description' + [ "dmp_td_medium", (project.try(column[0]) || "Unknown") ] + else + [ "dmp_td_small", (project.try(column[0]) || "Unknown") ] + end + + content_tag(:td, content, class: klass) + end + + # Shows whether the user has default, template-default or custom settings + # for the given plan. + # -------------------------------------------------------- + def plan_settings_indicator(plan) + plan_settings = plan.super_settings(:export) + template_settings = plan.project.dmptemplate.try(:settings, :export) + + key = if plan_settings.try(:value?) + plan_settings.formatting == template_settings.formatting ? "template_formatting" : "custom_formatting" + elsif template_settings.try(:value?) + "template_formatting" + else + "default_formatting" + end + + content_tag(:small, t("helpers.settings.plans.#{key}")) + end + +end diff --git a/app/views/projects/_project_list_head.html.erb b/app/views/projects/_project_list_head.html.erb index a19e5d4..efb2503 100644 --- a/app/views/projects/_project_list_head.html.erb +++ b/app/views/projects/_project_list_head.html.erb @@ -1,6 +1,6 @@ <% @selected_columns.each do |column| %> - <%= project_list_head(column) %> + <%= project_list_column_heading(column) %> <% end %> <%= t("helpers.select_action")%> diff --git a/app/views/projects/_project_list_item.html.erb b/app/views/projects/_project_list_item.html.erb index 90623ca..6698fa8 100644 --- a/app/views/projects/_project_list_item.html.erb +++ b/app/views/projects/_project_list_item.html.erb @@ -1,6 +1,6 @@ <% @selected_columns.each do |column| %> - <%= project_list_body(column, project) %> + <%= project_list_column_body(column, project) %> <% end %> <% if project.editable_by(current_user.id) then %> diff --git a/config/locales/de.yml b/config/locales/de.yml index f853366..ca52757 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -564,6 +564,7 @@ principal_investigator: "Principal Investigator / Researcher" data_contact: "Plandatenkontakt" description: "Beschreibung" + unknown: " - " filter: placeholder: "Filter Pläne" submit: "Filter" diff --git a/config/locales/en-UK.yml b/config/locales/en-UK.yml index 6d809eb..57e2902 100644 --- a/config/locales/en-UK.yml +++ b/config/locales/en-UK.yml @@ -613,6 +613,7 @@ principal_investigator: "Principal Investigator / Researcher" data_contact: "Plan data contact" description: "Description" + unknown: " - " filter: placeholder: "Filter plans" submit: "Filter" diff --git a/config/locales/en-US.yml b/config/locales/en-US.yml index 2a1fdd7..12d8af8 100644 --- a/config/locales/en-US.yml +++ b/config/locales/en-US.yml @@ -602,6 +602,7 @@ principal_investigator: "Principal Investigator / Researcher" data_contact: "Plan data contact" description: "Description" + unknown: " - " filter: placeholder: "Filter plans" submit: "Filter" diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 42749c7..51094c9 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -575,6 +575,7 @@ principal_investigator: "Chercheur principal/chercheur" data_contact: "Personne-ressource pour les données du plan" description: "Description" + unknown: " - " filter: placeholder: "Filtrer les plans" submit: "Filtrer"