diff --git a/app/controllers/admin/research/laboratories_controller.rb b/app/controllers/admin/research/laboratories_controller.rb index 58f78a82af8488e3ee2f3fb9c07fc7455248b52d..b9cd7f1fec0bfce005218d1296d20a5873589230 100644 --- a/app/controllers/admin/research/laboratories_controller.rb +++ b/app/controllers/admin/research/laboratories_controller.rb @@ -9,6 +9,7 @@ class Admin::Research::LaboratoriesController < Admin::Research::ApplicationCont end def show + @axes = @laboratory.axes.ordered breadcrumb end diff --git a/app/controllers/admin/research/laboratory/application_controller.rb b/app/controllers/admin/research/laboratory/application_controller.rb new file mode 100644 index 0000000000000000000000000000000000000000..a43dc2d32f33bd9a68f99c258ee09b3d7830bcb0 --- /dev/null +++ b/app/controllers/admin/research/laboratory/application_controller.rb @@ -0,0 +1,15 @@ +class Admin::Research::Laboratory::ApplicationController < Admin::Research::ApplicationController + load_and_authorize_resource :laboratory, + class: Research::Laboratory, + through: :current_university, + through_association: :research_laboratories + + protected + + def default_url_options + return {} unless params.has_key? :laboratory_id + { + laboratory_id: params[:laboratory_id] + } + end +end diff --git a/app/controllers/admin/research/laboratory/axes_controller.rb b/app/controllers/admin/research/laboratory/axes_controller.rb new file mode 100644 index 0000000000000000000000000000000000000000..4405e1334becc3774ecaa91c0b18be9ad14be9e9 --- /dev/null +++ b/app/controllers/admin/research/laboratory/axes_controller.rb @@ -0,0 +1,61 @@ +class Admin::Research::Laboratory::AxesController < Admin::Research::Laboratory::ApplicationController + load_and_authorize_resource class: Research::Laboratory::Axis, through: :laboratory + + include Admin::Reorderable + + def index + breadcrumb + end + + def show + breadcrumb + end + + def new + breadcrumb + end + + def edit + breadcrumb + add_breadcrumb t('edit') + end + + def create + @axis.laboratory = @laboratory + if @axis.save + redirect_to admin_research_laboratory_axis_path(@axis), notice: t('admin.successfully_created_html', model: @axis.to_s) + else + breadcrumb + render :new, status: :unprocessable_entity + end + end + + def update + if @axis.update(axis_params) + redirect_to admin_research_laboratory_axis_path(@axis), notice: t('admin.successfully_updated_html', model: @axis.to_s) + else + breadcrumb + add_breadcrumb t('edit') + render :edit, status: :unprocessable_entity + end + end + + def destroy + @axis.destroy + redirect_to admin_research_laboratory_path(@laboratory), notice: t('admin.successfully_destroyed_html', model: @axis.to_s) + end + + private + + def breadcrumb + super + add_breadcrumb Research::Laboratory::Axis.model_name.human(count: 2), admin_research_laboratory_axes_path + breadcrumb_for @axis + end + + def axis_params + params.require(:research_laboratory_axis) + .permit(:name, :description, :text) + .merge(university_id: current_university.id) + end +end diff --git a/app/models/research/laboratory.rb b/app/models/research/laboratory.rb index f81db88aebd7b7db8827609ec0d3a3ca7a2dd22d..89574a529eb03fe1d126dd2a86ea1624290ef545 100644 --- a/app/models/research/laboratory.rb +++ b/app/models/research/laboratory.rb @@ -23,7 +23,11 @@ class Research::Laboratory < ApplicationRecord include WithGit - belongs_to :university + belongs_to :university + has_many :axes, + class_name: "Research::Laboratory::Axis", + foreign_key: :research_laboratory_id, + dependent: :destroy scope :ordered, -> { order(:name) } diff --git a/app/models/research/laboratory/axis.rb b/app/models/research/laboratory/axis.rb new file mode 100644 index 0000000000000000000000000000000000000000..6d8a63d94b6b64cd84251501e12d0980a4603e48 --- /dev/null +++ b/app/models/research/laboratory/axis.rb @@ -0,0 +1,44 @@ +# == Schema Information +# +# Table name: research_laboratory_axes +# +# id :uuid not null, primary key +# description :text +# name :string +# position :integer +# created_at :datetime not null +# updated_at :datetime not null +# research_laboratory_id :uuid not null +# university_id :uuid not null +# +# Indexes +# +# index_research_laboratory_axes_on_research_laboratory_id (research_laboratory_id) +# index_research_laboratory_axes_on_university_id (university_id) +# +# Foreign Keys +# +# fk_rails_... (research_laboratory_id => research_laboratories.id) +# fk_rails_... (university_id => universities.id) +# +class Research::Laboratory::Axis < ApplicationRecord + include WithPosition + + has_rich_text :text + + belongs_to :university + belongs_to :laboratory, foreign_key: :research_laboratory_id + + def to_s + "#{name}" + end + + protected + + def last_ordered_element + Research::Laboratory::Axis.where( + university_id: university_id, + research_laboratory_id: research_laboratory_id + ).ordered.last + end +end diff --git a/app/views/admin/research/laboratories/show.html.erb b/app/views/admin/research/laboratories/show.html.erb index b10698500adfa827a24c08c6accef3205535f929..1dc1c44b0d3e2107d47280853b82af91de13b7a2 100644 --- a/app/views/admin/research/laboratories/show.html.erb +++ b/app/views/admin/research/laboratories/show.html.erb @@ -1,5 +1,19 @@ <% content_for :title, @laboratory %> +<div class="card mt-5"> + <div class="card-header"> + <div class="float-end"> + <%= link_to t('create'), + new_admin_research_laboratory_axis_path(laboratory_id: @laboratory), + class: button_classes %> + </div> + <h2 class="card-title"> + <%= link_to Research::Laboratory::Axis.model_name.human(count: 2), + admin_research_laboratory_axes_path(laboratory_id: @laboratory) %></h2> + </div> + <%= render 'admin/research/laboratory/axes/list', axes: @axes %> +</div> + <% content_for :action_bar_right do %> <%= edit_link @laboratory %> <% end %> diff --git a/app/views/admin/research/laboratory/axes/_form.html.erb b/app/views/admin/research/laboratory/axes/_form.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..90a3730ae806d44e57b2f9ebc255d95561ba2d0c --- /dev/null +++ b/app/views/admin/research/laboratory/axes/_form.html.erb @@ -0,0 +1,19 @@ +<%= simple_form_for [:admin, axis] do |f| %> + <div class="row"> + <div class="col-md-8"> + <div class="card flex-fill w-100"> + <div class="card-header"> + <h5 class="card-title mb-0"><%= t('content') %></h5> + </div> + <div class="card-body"> + <%= f.input :name %> + <%= f.input :description, as: :text, input_html: { rows: 8 } %> + <%= f.input :text, as: :rich_text_area %> + </div> + </div> + </div> + </div> + <% content_for :action_bar_right do %> + <%= submit f %> + <% end %> +<% end %> diff --git a/app/views/admin/research/laboratory/axes/_list.html.erb b/app/views/admin/research/laboratory/axes/_list.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..659fe3fa89253a778d81e7b3244b073c6c48f48a --- /dev/null +++ b/app/views/admin/research/laboratory/axes/_list.html.erb @@ -0,0 +1,29 @@ +<table class="table table-sortable"> + <thead> + <tr> + <th><%= Research::Laboratory::Axis.model_name.human %></th> + <th></th> + </tr> + </thead> + <tbody data-reorder-url="<%= reorder_admin_research_laboratory_axes_path(laboratory_id: @laboratory.id) %>"> + <% axes.each do |axis| %> + <tr class="handle" data-id="<%= axis.id %>"> + <td> + <%= link_to axis, admin_research_laboratory_axis_path(laboratory_id: axis.laboratory, id: axis) %> + </td> + <td class="text-end"> + <div class="btn-group" role="group"> + <%= link_to t('edit'), + edit_admin_research_laboratory_axis_path(laboratory_id: axis.laboratory, id: axis), + class: button_classes %> + <%= link_to t('delete'), + admin_research_laboratory_axis_path(laboratory_id: axis.laboratory, id: axis), + method: :delete, + data: { confirm: t('please_confirm') }, + class: button_classes_danger %> + </div> + </td> + </tr> + <% end %> + </tbody> +</table> diff --git a/app/views/admin/research/laboratory/axes/edit.html.erb b/app/views/admin/research/laboratory/axes/edit.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..078bcc9a159d0f1510828a03b0073449e35cce37 --- /dev/null +++ b/app/views/admin/research/laboratory/axes/edit.html.erb @@ -0,0 +1,3 @@ +<% content_for :title, @axis %> + +<%= render 'form', axis: @axis %> diff --git a/app/views/admin/research/laboratory/axes/index.html.erb b/app/views/admin/research/laboratory/axes/index.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..dfe60dc90513a75553c2ee3b201d0eabbfe65b02 --- /dev/null +++ b/app/views/admin/research/laboratory/axes/index.html.erb @@ -0,0 +1,7 @@ +<% content_for :title, Research::Laboratory::Axis.model_name.human(count: 2) %> + +<%= render 'admin/research/laboratory/axes/list', axes: @axes %> + +<% content_for :action_bar_right do %> + <%= create_link Research::Laboratory::Axis %> +<% end %> diff --git a/app/views/admin/research/laboratory/axes/new.html.erb b/app/views/admin/research/laboratory/axes/new.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..efb0a6c26d509ca7262aa0d111f9d94b148e6cef --- /dev/null +++ b/app/views/admin/research/laboratory/axes/new.html.erb @@ -0,0 +1,3 @@ +<% content_for :title, Research::Laboratory::Axis.model_name.human %> + +<%= render 'form', axis: @axis %> diff --git a/app/views/admin/research/laboratory/axes/show.html.erb b/app/views/admin/research/laboratory/axes/show.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..fe8467edb0297e386bd7f721231dfdf0d02bc421 --- /dev/null +++ b/app/views/admin/research/laboratory/axes/show.html.erb @@ -0,0 +1,21 @@ +<% content_for :title, @axis %> + +<div class="row"> + <div class="col-md-8"> + <div class="card flex-fill w-100"> + <div class="card-header"> + <h2 class="card-title mb-0 h5"><%= t('content') %></h2> + </div> + <div class="card-body"> + <h3 class="h5"><%= Research::Laboratory::Axis.human_attribute_name('description') %></h3> + <%= simple_format @axis.description %> + <h3 class="h5 mt-4"><%= Research::Laboratory::Axis.human_attribute_name('text') %></h3> + <%= @axis.text %> + </div> + </div> + </div> +</div> + +<% content_for :action_bar_right do %> + <%= edit_link @axis %> +<% end %> diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb index ac033bf9dc846101320c96a5ce8aceb8c96ec098..2f804f76171aff60b900d7dcf71294194cfbea26 100644 --- a/config/initializers/inflections.rb +++ b/config/initializers/inflections.rb @@ -3,12 +3,12 @@ # Add new inflection rules using the following format. Inflections # are locale specific, and you may define rules for as many different # locales as you wish. All of these examples are active by default: -# ActiveSupport::Inflector.inflections(:en) do |inflect| -# inflect.plural /^(ox)$/i, '\1en' -# inflect.singular /^(ox)en/i, '\1' -# inflect.irregular 'person', 'people' -# inflect.uncountable %w( fish sheep ) -# end +ActiveSupport::Inflector.inflections(:en) do |inflect| + # inflect.plural /^(ox)$/i, '\1en' + # inflect.singular /^(ox)en/i, '\1' + # inflect.uncountable %w( fish sheep ) + inflect.irregular 'axis', 'axes' +end # These inflection rules are supported but not enabled by default: # ActiveSupport::Inflector.inflections(:en) do |inflect| diff --git a/config/locales/research/en.yml b/config/locales/research/en.yml index b5396fc33657fdf3923880b4b91070f6ba026c68..f90ca5eb09c5c6828a2881106c807014161041e4 100644 --- a/config/locales/research/en.yml +++ b/config/locales/research/en.yml @@ -16,6 +16,9 @@ en: research/laboratory: one: Laboratory other: Laboratories + research/laboratory/axis: + one: Axis + other: Axes attributes: research/journal: issn: ISSN @@ -45,6 +48,10 @@ en: city: City name: Name zipcode: Zipcode + research/laboratory/axis: + description: Description + name: Name + text: Text research: manage_researchers: Managege researchers number_of_articles: Number of articles diff --git a/config/locales/research/fr.yml b/config/locales/research/fr.yml index 7035ea43220976e2145c377484312dffb26cff87..951a1d64ad1fe60db4653965f6ca026c95f2f993 100644 --- a/config/locales/research/fr.yml +++ b/config/locales/research/fr.yml @@ -16,6 +16,9 @@ fr: research/laboratory: one: Laboratoire other: Laboratoires + research/laboratory/axis: + one: Axe + other: Axes attributes: research/journal: issn: ISSN @@ -45,6 +48,10 @@ fr: city: Ville name: Nom zipcode: Code postal + research/laboratory/axis: + description: Description + name: Nom + text: Texte research: manage_researchers: Gérer les Chercheu·rs·ses number_of_articles: Nombre d'articles diff --git a/config/routes/admin/research.rb b/config/routes/admin/research.rb index e8bdb55df2a66a57af75989b652a4bee34de84f4..e6b84cc51b2fa2a91346c600a8932399129b874c 100644 --- a/config/routes/admin/research.rb +++ b/config/routes/admin/research.rb @@ -8,5 +8,11 @@ namespace :research do end end end - resources :laboratories + resources :laboratories do + resources :axes, controller: 'laboratory/axes' do + collection do + post :reorder + end + end + end end diff --git a/db/migrate/20220119174230_create_research_laboratory_axes.rb b/db/migrate/20220119174230_create_research_laboratory_axes.rb new file mode 100644 index 0000000000000000000000000000000000000000..8be8ac682a7faeff7db11c339921160c98948112 --- /dev/null +++ b/db/migrate/20220119174230_create_research_laboratory_axes.rb @@ -0,0 +1,13 @@ +class CreateResearchLaboratoryAxes < ActiveRecord::Migration[6.1] + def change + create_table :research_laboratory_axes, id: :uuid do |t| + t.references :university, null: false, foreign_key: true, type: :uuid + t.references :research_laboratory, null: false, foreign_key: true, type: :uuid + t.string :name + t.text :description + t.integer :position + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 4c661a49e80694af57bac72d46ec6b16ed66bf2c..8a0a858a8ba41bacbe122a0a84894c9dc28bca4d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2022_01_19_164036) do +ActiveRecord::Schema.define(version: 2022_01_19_174230) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" @@ -511,6 +511,18 @@ ActiveRecord::Schema.define(version: 2022_01_19_164036) do t.index ["university_id"], name: "index_research_laboratories_on_university_id" end + create_table "research_laboratory_axes", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + t.uuid "university_id", null: false + t.uuid "research_laboratory_id", null: false + t.string "name" + t.text "description" + t.integer "position" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["research_laboratory_id"], name: "index_research_laboratory_axes_on_research_laboratory_id" + t.index ["university_id"], name: "index_research_laboratory_axes_on_university_id" + end + create_table "universities", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "name" t.string "identifier" @@ -652,6 +664,8 @@ ActiveRecord::Schema.define(version: 2022_01_19_164036) do add_foreign_key "research_journal_volumes", "universities" add_foreign_key "research_journals", "universities" add_foreign_key "research_laboratories", "universities" + add_foreign_key "research_laboratory_axes", "research_laboratories" + add_foreign_key "research_laboratory_axes", "universities" add_foreign_key "university_people", "universities" add_foreign_key "university_people", "users" add_foreign_key "users", "languages" diff --git a/test/fixtures/research/laboratories.yml b/test/fixtures/research/laboratories.yml index e39ae63490bbdf89ba4879257c1a3b623b33e595..ced250caf792e144439fafa9ff141e6cfcaeb4fd 100644 --- a/test/fixtures/research/laboratories.yml +++ b/test/fixtures/research/laboratories.yml @@ -20,7 +20,6 @@ # # fk_rails_... (university_id => universities.id) # -# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html one: university: one diff --git a/test/fixtures/research/laboratory/axes.yml b/test/fixtures/research/laboratory/axes.yml new file mode 100644 index 0000000000000000000000000000000000000000..c13513c5d92123863d1399bf30a9fca2d0993756 --- /dev/null +++ b/test/fixtures/research/laboratory/axes.yml @@ -0,0 +1,38 @@ +# == Schema Information +# +# Table name: research_laboratory_axes +# +# id :uuid not null, primary key +# description :text +# name :string +# position :integer +# created_at :datetime not null +# updated_at :datetime not null +# research_laboratory_id :uuid not null +# university_id :uuid not null +# +# Indexes +# +# index_research_laboratory_axes_on_research_laboratory_id (research_laboratory_id) +# index_research_laboratory_axes_on_university_id (university_id) +# +# Foreign Keys +# +# fk_rails_... (research_laboratory_id => research_laboratories.id) +# fk_rails_... (university_id => universities.id) +# +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + university: one + research_laboratory: one + name: MyString + description: MyText + position: 1 + +two: + university: two + research_laboratory: two + name: MyString + description: MyText + position: 1 diff --git a/test/models/research/laboratory/axis_test.rb b/test/models/research/laboratory/axis_test.rb new file mode 100644 index 0000000000000000000000000000000000000000..a4228e54f88da6ffe7c98ab7f1690e6f50061fae --- /dev/null +++ b/test/models/research/laboratory/axis_test.rb @@ -0,0 +1,30 @@ +# == Schema Information +# +# Table name: research_laboratory_axes +# +# id :uuid not null, primary key +# description :text +# name :string +# position :integer +# created_at :datetime not null +# updated_at :datetime not null +# research_laboratory_id :uuid not null +# university_id :uuid not null +# +# Indexes +# +# index_research_laboratory_axes_on_research_laboratory_id (research_laboratory_id) +# index_research_laboratory_axes_on_university_id (university_id) +# +# Foreign Keys +# +# fk_rails_... (research_laboratory_id => research_laboratories.id) +# fk_rails_... (university_id => universities.id) +# +require "test_helper" + +class Research::Laboratory::AxisTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end