diff --git a/app/controllers/admin/research/application_controller.rb b/app/controllers/admin/research/application_controller.rb new file mode 100644 index 0000000000000000000000000000000000000000..3d6ceb0fb6556897b3c2814843c3690623e2eaf0 --- /dev/null +++ b/app/controllers/admin/research/application_controller.rb @@ -0,0 +1,9 @@ +class Admin::Research::ApplicationController < Admin::ApplicationController + + protected + + def breadcrumb + super + add_breadcrumb 'Recherche' + end +end diff --git a/app/controllers/admin/research/journals_controller.rb b/app/controllers/admin/research/journals_controller.rb new file mode 100644 index 0000000000000000000000000000000000000000..593493749096dd66d60954d405360ccdb2358606 --- /dev/null +++ b/app/controllers/admin/research/journals_controller.rb @@ -0,0 +1,55 @@ +class Admin::Research::JournalsController < Admin::Research::ApplicationController + load_and_authorize_resource class: Research::Journal + + def index + breadcrumb + end + + def show + breadcrumb + end + + def new + breadcrumb + end + + def edit + breadcrumb + end + + def create + @journal.university = current_university + if @journal.save + redirect_to [:admin, @journal], notice: "Journal was successfully created." + else + breadcrumb + render :new, status: :unprocessable_entity + end + end + + def update + if @journal.update(journal_params) + redirect_to [:admin, @journal], notice: "Journal was successfully updated." + else + breadcrumb + render :edit, status: :unprocessable_entity + end + end + + def destroy + @journal.destroy + redirect_to admin_research_journals_url, notice: "Journal was successfully destroyed." + end + + protected + + def breadcrumb + super + add_breadcrumb Research::Journal.model_name.human(count: 2), admin_research_journals_path + breadcrumb_for @journal + end + + def journal_params + params.require(:research_journal).permit(:title, :description) + end +end diff --git a/app/controllers/research/journals_controller.rb b/app/controllers/research/journals_controller.rb new file mode 100644 index 0000000000000000000000000000000000000000..2063cefc0d3a45486de53c7978ba0be5bfb293f1 --- /dev/null +++ b/app/controllers/research/journals_controller.rb @@ -0,0 +1,9 @@ +class Research::JournalsController < ApplicationController + def index + @journals = current_university.research_journals + end + + def show + @journal = current_university.research_journals.find params[:id] + end +end diff --git a/app/models/research.rb b/app/models/research.rb new file mode 100644 index 0000000000000000000000000000000000000000..24ccdcbe3d481d5915819aa3855051ca2a7c7320 --- /dev/null +++ b/app/models/research.rb @@ -0,0 +1,5 @@ +module Research + def self.table_name_prefix + 'research_' + end +end diff --git a/app/models/research/journal.rb b/app/models/research/journal.rb new file mode 100644 index 0000000000000000000000000000000000000000..fcdf35c018f8a3635b870fccf32a6cab7f929fc3 --- /dev/null +++ b/app/models/research/journal.rb @@ -0,0 +1,26 @@ +# == Schema Information +# +# Table name: research_journals +# +# id :uuid not null, primary key +# description :text +# title :string +# created_at :datetime not null +# updated_at :datetime not null +# university_id :uuid not null +# +# Indexes +# +# index_research_journals_on_university_id (university_id) +# +# Foreign Keys +# +# fk_rails_... (university_id => universities.id) +# +class Research::Journal < ApplicationRecord + belongs_to :university + + def to_s + "#{title}" + end +end diff --git a/app/models/university.rb b/app/models/university.rb index 9354058d408771050add1e0ef1e5eb2f92faee42..97da77b18388d504942c10c1867281afbf0c5aea 100644 --- a/app/models/university.rb +++ b/app/models/university.rb @@ -20,6 +20,7 @@ class University < ApplicationRecord include WithIdentifier include WithUsers include WithFeatures + include WithResearch def to_s "#{name}" diff --git a/app/models/university/with_research.rb b/app/models/university/with_research.rb new file mode 100644 index 0000000000000000000000000000000000000000..67cef2638cba7d3f4f6efc4cc09e1b27040faeef --- /dev/null +++ b/app/models/university/with_research.rb @@ -0,0 +1,7 @@ +module University::WithResearch + extend ActiveSupport::Concern + + included do + has_many :research_journals, class_name: 'Research::Journal', dependent: :destroy + end +end diff --git a/app/views/admin/research/journals/_form.html.erb b/app/views/admin/research/journals/_form.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..0350626e53c6c76d1873dd09f028b50b5755e9ea --- /dev/null +++ b/app/views/admin/research/journals/_form.html.erb @@ -0,0 +1,13 @@ +<%= simple_form_for [:admin, journal] do |f| %> + <div class="row"> + <div class="col-md-6"> + <%= f.input :title %> + </div> + <div class="col-md-6"> + <%= f.input :description %> + </div> + </div> + <% content_for :buttons do %> + <%= submit f %> + <% end %> +<% end %> diff --git a/app/views/admin/research/journals/edit.html.erb b/app/views/admin/research/journals/edit.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..2ff5b9eb8c94108f08520f09f3bc772f538ecd66 --- /dev/null +++ b/app/views/admin/research/journals/edit.html.erb @@ -0,0 +1,3 @@ +<% content_for :title, @journal %> + +<%= render 'form', journal: @journal %> diff --git a/app/views/admin/research/journals/index.html.erb b/app/views/admin/research/journals/index.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..851be78e01f801d44d8b9effcee14d9c4930aa0f --- /dev/null +++ b/app/views/admin/research/journals/index.html.erb @@ -0,0 +1,26 @@ +<% content_for :title, Research::Journal.model_name.human(count: 2) %> + +<table class="table"> + <thead> + <tr> + <th>Title</th> + <th></th> + </tr> + </thead> + + <tbody> + <% @journals.each do |journal| %> + <tr> + <td><%= link_to journal, [:admin, journal] %></td> + <td class="text-end"> + <%= edit_link journal %> + <%= destroy_link journal %> + </td> + </tr> + <% end %> + </tbody> +</table> + +<% content_for :buttons do %> + <%= create_link Research::Journal %> +<% end %> diff --git a/app/views/admin/research/journals/new.html.erb b/app/views/admin/research/journals/new.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..926018c99b484abf2fdfa492a025869f0100b4aa --- /dev/null +++ b/app/views/admin/research/journals/new.html.erb @@ -0,0 +1,3 @@ +<% content_for :title, Research::Journal.model_name.human %> + +<%= render 'form', journal: @journal %> diff --git a/app/views/admin/research/journals/show.html.erb b/app/views/admin/research/journals/show.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..a43f749a7aea95ee73e8b20fcd72d94c47fd265b --- /dev/null +++ b/app/views/admin/research/journals/show.html.erb @@ -0,0 +1,9 @@ +<% content_for :title, @journal %> + +<p> + <%= @journal.description %> +</p> + +<% content_for :buttons do %> + <%= edit_link @journal %> +<% end %> diff --git a/app/views/research/journals/_journal.json.jbuilder b/app/views/research/journals/_journal.json.jbuilder new file mode 100644 index 0000000000000000000000000000000000000000..74b1dbbe69547725562aa3601c125388d330ddab --- /dev/null +++ b/app/views/research/journals/_journal.json.jbuilder @@ -0,0 +1,2 @@ +json.extract! journal, :id, :title, :description, :created_at, :updated_at +json.url research_journal_url(journal, format: :json) diff --git a/app/views/research/journals/index.html.erb b/app/views/research/journals/index.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..c5e1cad2e622db7ba7e10888c3c8db8da999ada0 --- /dev/null +++ b/app/views/research/journals/index.html.erb @@ -0,0 +1,13 @@ +<% content_for :title, Research::Journal.model_name.human(count: 2) %> + +<h1><%= Research::Journal.model_name.human(count: 2) %></h1> + +<div class="row"> + <% @journals.each do |journal| %> + <div class="col-md-6"> + <h2 class="mt-5"><%= journal %></h2> + <p><%= journal.description %></p> + <%= link_to 'Lire', journal, class: 'btn btn-primary stretched-link' %> + </div> + <% end %> +</div> diff --git a/app/views/research/journals/index.json.jbuilder b/app/views/research/journals/index.json.jbuilder new file mode 100644 index 0000000000000000000000000000000000000000..5e48c2f4ba9ede0e0558afb32d8c9c0d19251ab3 --- /dev/null +++ b/app/views/research/journals/index.json.jbuilder @@ -0,0 +1 @@ +json.array! @journals, partial: "research/journals/journal", as: :journal diff --git a/app/views/research/journals/show.html.erb b/app/views/research/journals/show.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..e9aa77443b641c704717392b4c491b0e0c16e06f --- /dev/null +++ b/app/views/research/journals/show.html.erb @@ -0,0 +1,8 @@ +<% content_for :title, @journal %> + +<div class="row"> + <div class="col-md-8"> + <h1><%= @journal %></h1> + <p><%= @journal.description %></p> + </div> +</div> diff --git a/app/views/research/journals/show.json.jbuilder b/app/views/research/journals/show.json.jbuilder new file mode 100644 index 0000000000000000000000000000000000000000..fd0abfd124835c78f1b9e1f0b51b07a5fe609c41 --- /dev/null +++ b/app/views/research/journals/show.json.jbuilder @@ -0,0 +1 @@ +json.partial! "research/journals/journal", journal: @journal diff --git a/config/admin_navigation.rb b/config/admin_navigation.rb index dcf622602bc81cea1204cb5c170f84ea17c89b25..8750b49a92d7ec561c363fc387cb0154a6879050 100644 --- a/config/admin_navigation.rb +++ b/config/admin_navigation.rb @@ -7,17 +7,17 @@ SimpleNavigation::Configuration.run do |navigation| primary.item :dashboard, t('dashboard'), admin_root_path, { icon: 'tachometer-alt', highlights_on: /admin$/ } primary.item :teaching, 'Enseignement', nil, { kind: :header } - primary.item :education, 'Formations', admin_features_education_programs_path, { icon: 'graduation-cap' } - primary.item :teaching, 'Ecoles', nil, { icon: 'university' } primary.item :teaching, 'Enseignants', nil, { icon: 'user-graduate' } - primary.item :teaching, 'Feedbacks', nil, { icon: 'comments' } + primary.item :teaching, 'Ecoles', nil, { icon: 'university' } + primary.item :education, 'Formations', admin_features_education_programs_path, { icon: 'graduation-cap' } primary.item :teaching, 'Ressources éducatives', nil, { icon: 'laptop' } + primary.item :teaching, 'Feedbacks', nil, { icon: 'comments' } primary.item :teaching, 'Recherche', nil, { kind: :header } - primary.item :teaching, 'Laboratoires', nil, { icon: 'flask' } primary.item :teaching, 'Chercheurs', nil, { icon: 'microscope' } - primary.item :teaching, 'Journaux', nil, { icon: 'newspaper' } + primary.item :teaching, 'Laboratoires', nil, { icon: 'flask' } primary.item :teaching, 'Veille', nil, { icon: 'eye' } + primary.item :journals, Research::Journal.model_name.human(count: 2), admin_research_journals_path, { icon: 'newspaper' } primary.item :teaching, 'Communication', nil, { kind: :header } primary.item :websites, 'Sites Web', admin_features_websites_sites_path, { icon: 'sitemap' } diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 9e129820fb573493ce05fb60321908b3afc73997..adb539dc5fa4f55f4b28f2771c40e0addc2ca2eb 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -14,6 +14,9 @@ fr: user: one: Utilisateur other: Utilisateurs + research/journal: + one: Revue scientifique + other: Revues scientifiques attributes: university: name: Nom diff --git a/config/routes.rb b/config/routes.rb index 5a01e809153319b4e0cb0fd64de15a21a16ee53d..1de595c48f675a34b8536c8c9d275562248c7afc 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -13,5 +13,9 @@ Rails.application.routes.draw do end end + namespace :research do + resources :journals, only: [:index, :show] + end + root to: 'home#index' end diff --git a/config/routes/admin.rb b/config/routes/admin.rb index ae3c23f7f05824a05c7f49eabb74dedfc7bfd090..7949fef203035b5bb65d4486ba0563f7760a0402 100644 --- a/config/routes/admin.rb +++ b/config/routes/admin.rb @@ -7,5 +7,9 @@ namespace :admin do end end + namespace :research do + resources :journals + end + root to: 'dashboard#index' end diff --git a/db/migrate/20210812085608_create_research_journals.rb b/db/migrate/20210812085608_create_research_journals.rb new file mode 100644 index 0000000000000000000000000000000000000000..f780c359a4c9d9d8f96607f098f9876db897be8a --- /dev/null +++ b/db/migrate/20210812085608_create_research_journals.rb @@ -0,0 +1,11 @@ +class CreateResearchJournals < ActiveRecord::Migration[6.1] + def change + create_table :research_journals, id: :uuid do |t| + t.references :university, null: false, foreign_key: true, type: :uuid + t.string :title + t.text :description + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 153042639f3ab3468190d2af0e8226c42c6b431f..db8f63cce0b167f5f615e5d87f203fc47a3168fa 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: 2021_08_11_171021) do +ActiveRecord::Schema.define(version: 2021_08_12_085608) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" @@ -68,6 +68,15 @@ ActiveRecord::Schema.define(version: 2021_08_11_171021) do t.index ["university_id"], name: "index_features_websites_sites_on_university_id" end + create_table "research_journals", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + t.uuid "university_id", null: false + t.string "title" + t.text "description" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["university_id"], name: "index_research_journals_on_university_id" + end + create_table "universities", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "name" t.string "identifier" @@ -114,5 +123,6 @@ ActiveRecord::Schema.define(version: 2021_08_11_171021) do add_foreign_key "features_education_programs", "universities" add_foreign_key "features_education_qualiopi_indicators", "features_education_qualiopi_criterions", column: "criterion_id" add_foreign_key "features_websites_sites", "universities" + add_foreign_key "research_journals", "universities" add_foreign_key "users", "universities" end diff --git a/test/controllers/research/journals_controller_test.rb b/test/controllers/research/journals_controller_test.rb new file mode 100644 index 0000000000000000000000000000000000000000..565356dcc553608670901d5a4c709a796e113281 --- /dev/null +++ b/test/controllers/research/journals_controller_test.rb @@ -0,0 +1,48 @@ +require "test_helper" + +class Research::JournalsControllerTest < ActionDispatch::IntegrationTest + setup do + @research_journal = research_journals(:one) + end + + test "should get index" do + get research_journals_url + assert_response :success + end + + test "should get new" do + get new_research_journal_url + assert_response :success + end + + test "should create research_journal" do + assert_difference('Research::Journal.count') do + post research_journals_url, params: { research_journal: { description: @research_journal.description, title: @research_journal.title } } + end + + assert_redirected_to research_journal_url(Research::Journal.last) + end + + test "should show research_journal" do + get research_journal_url(@research_journal) + assert_response :success + end + + test "should get edit" do + get edit_research_journal_url(@research_journal) + assert_response :success + end + + test "should update research_journal" do + patch research_journal_url(@research_journal), params: { research_journal: { description: @research_journal.description, title: @research_journal.title } } + assert_redirected_to research_journal_url(@research_journal) + end + + test "should destroy research_journal" do + assert_difference('Research::Journal.count', -1) do + delete research_journal_url(@research_journal) + end + + assert_redirected_to research_journals_url + end +end diff --git a/test/fixtures/research/journals.yml b/test/fixtures/research/journals.yml new file mode 100644 index 0000000000000000000000000000000000000000..2799b8f969a60cf903a709589ebd0c1032fdbd59 --- /dev/null +++ b/test/fixtures/research/journals.yml @@ -0,0 +1,28 @@ +# == Schema Information +# +# Table name: research_journals +# +# id :uuid not null, primary key +# description :text +# title :string +# created_at :datetime not null +# updated_at :datetime not null +# university_id :uuid not null +# +# Indexes +# +# index_research_journals_on_university_id (university_id) +# +# Foreign Keys +# +# fk_rails_... (university_id => universities.id) +# +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + title: MyString + description: MyText + +two: + title: MyString + description: MyText diff --git a/test/models/research/journal_test.rb b/test/models/research/journal_test.rb new file mode 100644 index 0000000000000000000000000000000000000000..91a25b8a41efd5c4e4cd9e20d9d52a49b3462ed7 --- /dev/null +++ b/test/models/research/journal_test.rb @@ -0,0 +1,26 @@ +# == Schema Information +# +# Table name: research_journals +# +# id :uuid not null, primary key +# description :text +# title :string +# created_at :datetime not null +# updated_at :datetime not null +# university_id :uuid not null +# +# Indexes +# +# index_research_journals_on_university_id (university_id) +# +# Foreign Keys +# +# fk_rails_... (university_id => universities.id) +# +require "test_helper" + +class Research::JournalTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/system/research/journals_test.rb b/test/system/research/journals_test.rb new file mode 100644 index 0000000000000000000000000000000000000000..3c83334e62fc4c8dd7216d7c634a5b1e8a584457 --- /dev/null +++ b/test/system/research/journals_test.rb @@ -0,0 +1,45 @@ +require "application_system_test_case" + +class Research::JournalsTest < ApplicationSystemTestCase + setup do + @research_journal = research_journals(:one) + end + + test "visiting the index" do + visit research_journals_url + assert_selector "h1", text: "Research/Journals" + end + + test "creating a Journal" do + visit research_journals_url + click_on "New Research/Journal" + + fill_in "Description", with: @research_journal.description + fill_in "Title", with: @research_journal.title + click_on "Create Journal" + + assert_text "Journal was successfully created" + click_on "Back" + end + + test "updating a Journal" do + visit research_journals_url + click_on "Edit", match: :first + + fill_in "Description", with: @research_journal.description + fill_in "Title", with: @research_journal.title + click_on "Update Journal" + + assert_text "Journal was successfully updated" + click_on "Back" + end + + test "destroying a Journal" do + visit research_journals_url + page.accept_confirm do + click_on "Destroy", match: :first + end + + assert_text "Journal was successfully destroyed" + end +end