diff --git a/app/controllers/admin/education/schools_controller.rb b/app/controllers/admin/education/schools_controller.rb new file mode 100644 index 0000000000000000000000000000000000000000..821eb116ef1f81cd475fbc4d9486036aeb704754 --- /dev/null +++ b/app/controllers/admin/education/schools_controller.rb @@ -0,0 +1,59 @@ +class Admin::Education::SchoolsController < Admin::Education::ApplicationController + load_and_authorize_resource class: Education::School + + def index + @schools = current_university.education_schools + breadcrumb + end + + def show + breadcrumb + end + + def new + breadcrumb + end + + def edit + breadcrumb + add_breadcrumb t('edit') + end + + def create + @school.university = current_university + if @school.save + redirect_to [:admin, @school], notice: t('admin.successfully_created_html', model: @school.to_s) + else + breadcrumb + render :new, status: :unprocessable_entity + end + end + + def update + if @school.update(school_params) + redirect_to [:admin, @school], notice: t('admin.successfully_updated_html', model: @school.to_s) + else + breadcrumb + add_breadcrumb t('edit') + render :edit, status: :unprocessable_entity + end + end + + def destroy + @school.destroy + redirect_to admin_university_schools_url, notice: t('admin.successfully_destroyed_html', model: @school.to_s) + end + + private + + def breadcrumb + super + add_breadcrumb Education::School.model_name.human(count: 2), admin_education_schools_path + breadcrumb_for @school + end + + def school_params + params.require(:education_school) + .permit(:university_id, :name, :address, :zipcode, :city, :country, :latitude, :longitude) + end +end diff --git a/app/models/ability.rb b/app/models/ability.rb index ec5b779113b2189822207f4f60e2fc32f018e7c1..488d9fb67168192e6ba9ce02ce0ab7bc6714b453 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -20,6 +20,7 @@ class Ability can :read, Communication::Website::Imported::Page, university_id: @user.university_id can :read, Communication::Website::Imported::Post, university_id: @user.university_id can :read, Education::Program, university_id: @user.university_id + can :read, Education::School, university_id: @user.university_id can :read, Research::Researcher can :read, Research::Journal, university_id: @user.university_id can :read, Research::Journal::Article, university_id: @user.university_id diff --git a/app/models/education/school.rb b/app/models/education/school.rb new file mode 100644 index 0000000000000000000000000000000000000000..f5352ef5a6e0644f899173dca02bf6777c94b60e --- /dev/null +++ b/app/models/education/school.rb @@ -0,0 +1,31 @@ +# == Schema Information +# +# Table name: education_schools +# +# id :uuid not null, primary key +# address :string +# city :string +# country :string +# latitude :float +# longitude :float +# name :string +# zipcode :string +# created_at :datetime not null +# updated_at :datetime not null +# university_id :uuid not null +# +# Indexes +# +# index_education_schools_on_university_id (university_id) +# +# Foreign Keys +# +# fk_rails_... (university_id => universities.id) +# +class Education::School < ApplicationRecord + belongs_to :university + + def to_s + "#{name}" + end +end diff --git a/app/models/research/journal/article.rb b/app/models/research/journal/article.rb index b389b460a43c48f1e2bc0828b6ac870f261ca7a1..6dbbde9097d0ed07b5064f8c99de0e3102e20efe 100644 --- a/app/models/research/journal/article.rb +++ b/app/models/research/journal/article.rb @@ -11,7 +11,7 @@ # text :text # title :string # created_at :datetime not null -# updated_at :datetime not null +# updated_at :date not null # research_journal_id :uuid not null # research_journal_volume_id :uuid # university_id :uuid not null diff --git a/app/models/university/with_education.rb b/app/models/university/with_education.rb index 35317c68f38b1f230b63a80de21ec1a6583c0775..5acddc90f4055bb204487797d97d6994c82a189e 100644 --- a/app/models/university/with_education.rb +++ b/app/models/university/with_education.rb @@ -3,5 +3,6 @@ module University::WithEducation included do has_many :education_programs, class_name: 'Education::Program', dependent: :destroy + has_many :education_schools, class_name: 'Education::School', dependent: :destroy end end diff --git a/app/views/admin/education/programs/index.html.erb b/app/views/admin/education/programs/index.html.erb index e220d4867bc49606aebee8b787486df754eb94f4..9d3783318ad8f3433eec879937d09ed1f8ba20eb 100644 --- a/app/views/admin/education/programs/index.html.erb +++ b/app/views/admin/education/programs/index.html.erb @@ -14,8 +14,10 @@ <td><%= link_to program, [:admin, program] %></td> <td><%= program.level %></td> <td class="text-end"> - <%= edit_link program %> - <%= destroy_link program %> + <div class="btn-group" role="group"> + <%= edit_link program %> + <%= destroy_link program %> + </div> </td> </tr> <% end %> diff --git a/app/views/admin/education/schools/_form.html.erb b/app/views/admin/education/schools/_form.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..a6859f685187a580f2a959d908626175ddce92ac --- /dev/null +++ b/app/views/admin/education/schools/_form.html.erb @@ -0,0 +1,22 @@ +<%= simple_form_for [:admin, school] do |f| %> + <div class="row"> + <div class="col-md-4"> + <%= f.input :name %> + </div> + <div class="col-md-8"> + <%= f.input :address %> + <div class="row"> + <div class="col-md-4"> + <%= f.input :zipcode %> + </div> + <div class="col-md-8"> + <%= f.input :city %> + </div> + </div> + <%= f.input :country %> + </div> + </div> + <% content_for :action_bar_right do %> + <%= submit f %> + <% end %> +<% end %> diff --git a/app/views/admin/education/schools/edit.html.erb b/app/views/admin/education/schools/edit.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..2ffe2c0eae8f57cc9cf0e87a198f1758245bf694 --- /dev/null +++ b/app/views/admin/education/schools/edit.html.erb @@ -0,0 +1,3 @@ +<% content_for :title, @school %> + +<%= render 'form', school: @school %> diff --git a/app/views/admin/education/schools/index.html.erb b/app/views/admin/education/schools/index.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..60026b10e5e4bb122924ca5ba9b74f55685e5c26 --- /dev/null +++ b/app/views/admin/education/schools/index.html.erb @@ -0,0 +1,33 @@ +<% content_for :title, Education::School.model_name.human(count: 2) %> + +<table class="table"> + <thead> + <tr> + <th><%= Education::School.human_attribute_name('name') %></th> + <th><%= Education::School.human_attribute_name('address') %></th> + <th><%= Education::School.human_attribute_name('zipcode') %></th> + <th><%= Education::School.human_attribute_name('city') %></th> + <th></th> + </tr> + </thead> + + <tbody> + <% @schools.each do |school| %> + <tr> + <td><%= link_to school.name, [:admin, school] %></td> + <td><%= school.address %></td> + <td><%= school.zipcode %></td> + <td><%= school.city %></td> + <td class="text-end"> + <div class="btn-group" role="group"> + <%= edit_link school %> + <%= destroy_link school %> + </div> + </td> + <% end %> + </tbody> +</table> + +<% content_for :action_bar_right do %> + <%= create_link Education::School %> +<% end %> diff --git a/app/views/admin/education/schools/new.html.erb b/app/views/admin/education/schools/new.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..788e600fdea80796a7f45d2ef9ed33894ce484e4 --- /dev/null +++ b/app/views/admin/education/schools/new.html.erb @@ -0,0 +1,3 @@ +<% content_for :title, Education::School.model_name.human %> + +<%= render 'form', school: @school %> diff --git a/app/views/admin/education/schools/show.html.erb b/app/views/admin/education/schools/show.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..94882003380bd2d36c2c0cea903f0c5aeefef19c --- /dev/null +++ b/app/views/admin/education/schools/show.html.erb @@ -0,0 +1,11 @@ +<% content_for :title, @school %> + +<p> + <%= @school.address %><br> + <%= @school.zipcode %> <%= @school.city %><br> + <%= @school.country %> +</p> + +<% content_for :action_bar_right do %> + <%= edit_link @school %> +<% end %> diff --git a/app/views/admin/research/journal/volumes/index.html.erb b/app/views/admin/research/journal/volumes/index.html.erb index 34a38c7259885dacd18d488585a6a091d1d70232..6cc3da67ae2a67c2e560d702432c5f056ee9051a 100644 --- a/app/views/admin/research/journal/volumes/index.html.erb +++ b/app/views/admin/research/journal/volumes/index.html.erb @@ -17,8 +17,10 @@ height: 100 if volume.cover.attached? %></td> <td><%= volume.published_at %></td> <td class="text-end"> - <%= edit_link volume, { journal_id: @journal.id } %> - <%#= destroy_link volume, journal_id: @journal.id %> + <div class="btn-group" role="group"> + <%= edit_link volume, { journal_id: @journal.id } %> + <%#= destroy_link volume, journal_id: @journal.id %> + </div> </td> </tr> <% end %> diff --git a/app/views/admin/research/journals/index.html.erb b/app/views/admin/research/journals/index.html.erb index e3a66dd73fccf3f6efa14d5eca051482a9ae85b7..3f4804c69d25a01b022b1fd595fe0b613c767085 100644 --- a/app/views/admin/research/journals/index.html.erb +++ b/app/views/admin/research/journals/index.html.erb @@ -17,8 +17,10 @@ <td><%= link_to "#{journal.volumes.count}", admin_research_journal_volumes_path(journal_id: journal) %></td> <td><%= link_to "#{journal.articles.count}", admin_research_journal_articles_path(journal_id: journal) %></td> <td class="text-end"> - <%= edit_link journal %> - <%= destroy_link journal %> + <div class="btn-group" role="group"> + <%= edit_link journal %> + <%= destroy_link journal %> + </div> </td> </tr> <% end %> diff --git a/app/views/admin/research/researchers/index.html.erb b/app/views/admin/research/researchers/index.html.erb index f7307ecaba379dfd569cdf8aa1df0d34e972880e..c975d12203568d10a7df768e0ea306e29885d53f 100644 --- a/app/views/admin/research/researchers/index.html.erb +++ b/app/views/admin/research/researchers/index.html.erb @@ -17,8 +17,10 @@ <td><%= link_to researcher.last_name, [:admin, researcher] %></td> <td><%= link_to researcher.user, [:admin, researcher.user] if researcher.user %></td> <td class="text-end"> - <%= edit_link researcher %> - <%= destroy_link researcher %> + <div class="btn-group" role="group"> + <%= edit_link researcher %> + <%= destroy_link researcher %> + </div> </td> </tr> <% end %> diff --git a/config/admin_navigation.rb b/config/admin_navigation.rb index eb04f04d58421c52c8412310218f73209a0b5ef1..5cee38c3a407b151643b9bb4fcb4722b33c2ecb1 100644 --- a/config/admin_navigation.rb +++ b/config/admin_navigation.rb @@ -9,7 +9,7 @@ SimpleNavigation::Configuration.run do |navigation| if can?(:read, Education::Program) primary.item :education, Education.model_name.human, nil, { kind: :header } primary.item :education, 'Enseignants', nil, { icon: 'user-graduate' } - primary.item :education, 'Ecoles', nil, { icon: 'university' } + primary.item :education, Education::School.model_name.human(count: 2), admin_education_schools_path, { icon: 'university' } if can?(:read, Education::School) primary.item :education_programs, Education::Program.model_name.human(count: 2), admin_education_programs_path, { icon: 'graduation-cap' } if can?(:read, Education::Program) primary.item :education, 'Ressources éducatives', nil, { icon: 'laptop' } primary.item :education, 'Feedbacks', nil, { icon: 'comments' } diff --git a/config/locales/education/en.yml b/config/locales/education/en.yml index de3454cea74f4e79e334c451a2e3871f50fda1b1..6fe56f66bc7f578accbb56deba4ec2133eb74063 100644 --- a/config/locales/education/en.yml +++ b/config/locales/education/en.yml @@ -7,6 +7,9 @@ en: education/program: one: Program other: Programs + education/school: + one: School + other: Schools attributes: education/program: name: Name diff --git a/config/locales/education/fr.yml b/config/locales/education/fr.yml index ce89d9fb20eb74968cdf491c66c6ba0534e0a27f..983bb8e43e123ab3da8773a00286770977e090e7 100644 --- a/config/locales/education/fr.yml +++ b/config/locales/education/fr.yml @@ -7,6 +7,9 @@ fr: education/program: one: Formation other: Formations + education/school: + one: École + other: Écoles attributes: education/program: name: Nom diff --git a/config/routes.rb b/config/routes.rb index 7741968a9db05e355dce1c3aaf9bb4c6582ac0ac..47406f626d9ccb002e8f6b0dfda383fcd4b24754 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,7 +1,6 @@ Rails.application.routes.draw do - match "/delayed_job" => DelayedJobWeb, :anchor => false, :via => [:get, :post] - + devise_for :users, controllers: { confirmations: 'users/confirmations', passwords: 'users/passwords', diff --git a/config/routes/admin/education.rb b/config/routes/admin/education.rb index c6f58926f146a580495fc6c75d818000dd9ba9dd..9f158d5913f21e726c3547314429eaeabb3901e3 100644 --- a/config/routes/admin/education.rb +++ b/config/routes/admin/education.rb @@ -1,3 +1,3 @@ namespace :education do - resources :programs + resources :programs, :schools end diff --git a/db/migrate/20211026035253_create_university_schools.rb b/db/migrate/20211026035253_create_university_schools.rb new file mode 100644 index 0000000000000000000000000000000000000000..020a3a4b76f49fc05bfe8611cd3b0787da91bb33 --- /dev/null +++ b/db/migrate/20211026035253_create_university_schools.rb @@ -0,0 +1,16 @@ +class CreateUniversitySchools < ActiveRecord::Migration[6.1] + def change + create_table :education_schools, id: :uuid do |t| + t.references :university, null: false, foreign_key: true, type: :uuid + t.string :name + t.string :address + t.string :zipcode + t.string :city + t.string :country + t.float :latitude + t.float :longitude + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 0d683a41552ae7acc7389d3d1e4fc1a958adbded..8f3bd4863cddcb2750418eab2f6a88bc8c9f9410 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_10_25_124617) do +ActiveRecord::Schema.define(version: 2021_10_26_035253) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" @@ -238,6 +238,20 @@ ActiveRecord::Schema.define(version: 2021_10_25_124617) do t.index ["university_id"], name: "index_education_programs_on_university_id" end + create_table "education_schools", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + t.uuid "university_id", null: false + t.string "name" + t.string "address" + t.string "zipcode" + t.string "city" + t.string "country" + t.float "latitude" + t.float "longitude" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["university_id"], name: "index_education_schools_on_university_id" + end + create_table "languages", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "name" t.string "iso_code" @@ -390,6 +404,7 @@ ActiveRecord::Schema.define(version: 2021_10_25_124617) do add_foreign_key "communication_website_posts", "universities" add_foreign_key "communication_websites", "universities" add_foreign_key "education_programs", "universities" + add_foreign_key "education_schools", "universities" add_foreign_key "research_journal_articles", "research_journal_volumes" add_foreign_key "research_journal_articles", "research_journals" add_foreign_key "research_journal_articles", "universities" diff --git a/docs/models.md b/docs/models.md index 9df28aff1c56747536c59644b03e5e7695cfab50..b34f9b807007166e172a03de55d7bbbd9d6468ce 100644 --- a/docs/models.md +++ b/docs/models.md @@ -17,6 +17,8 @@ - zipcode:string - city:string - country:string +- latitude:float +- longitude:float ## university/Campus diff --git a/test/controllers/university/schools_controller_test.rb b/test/controllers/university/schools_controller_test.rb new file mode 100644 index 0000000000000000000000000000000000000000..cebe7f55a5bdc06fcd9c08ed034b1dc15fa303fc --- /dev/null +++ b/test/controllers/university/schools_controller_test.rb @@ -0,0 +1,48 @@ +require "test_helper" + +class University::SchoolsControllerTest < ActionDispatch::IntegrationTest + setup do + @university_school = university_schools(:one) + end + + test "should get index" do + get university_schools_url + assert_response :success + end + + test "should get new" do + get new_university_school_url + assert_response :success + end + + test "should create university_school" do + assert_difference('University::School.count') do + post university_schools_url, params: { university_school: { address: @university_school.address, city: @university_school.city, country: @university_school.country, latitude: @university_school.latitude, longitude: @university_school.longitude, name: @university_school.name, university_id: @university_school.university_id, zipcode: @university_school.zipcode } } + end + + assert_redirected_to university_school_url(University::School.last) + end + + test "should show university_school" do + get university_school_url(@university_school) + assert_response :success + end + + test "should get edit" do + get edit_university_school_url(@university_school) + assert_response :success + end + + test "should update university_school" do + patch university_school_url(@university_school), params: { university_school: { address: @university_school.address, city: @university_school.city, country: @university_school.country, latitude: @university_school.latitude, longitude: @university_school.longitude, name: @university_school.name, university_id: @university_school.university_id, zipcode: @university_school.zipcode } } + assert_redirected_to university_school_url(@university_school) + end + + test "should destroy university_school" do + assert_difference('University::School.count', -1) do + delete university_school_url(@university_school) + end + + assert_redirected_to university_schools_url + end +end diff --git a/test/fixtures/university/schools.yml b/test/fixtures/university/schools.yml new file mode 100644 index 0000000000000000000000000000000000000000..b6652d0a125c108e1971eb272513858472a21172 --- /dev/null +++ b/test/fixtures/university/schools.yml @@ -0,0 +1,21 @@ +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + university: one + name: MyString + address: MyString + zipcode: MyString + city: MyString + country: MyString + latitude: 1.5 + longitude: 1.5 + +two: + university: two + name: MyString + address: MyString + zipcode: MyString + city: MyString + country: MyString + latitude: 1.5 + longitude: 1.5 diff --git a/test/models/university/school_test.rb b/test/models/university/school_test.rb new file mode 100644 index 0000000000000000000000000000000000000000..f27e5f1bc3f59599f98bd9da8a352812f7af9c03 --- /dev/null +++ b/test/models/university/school_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class University::SchoolTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/system/university/schools_test.rb b/test/system/university/schools_test.rb new file mode 100644 index 0000000000000000000000000000000000000000..3055e119d1ed67d5ef2008ac5d96f69da11d84a9 --- /dev/null +++ b/test/system/university/schools_test.rb @@ -0,0 +1,57 @@ +require "application_system_test_case" + +class University::SchoolsTest < ApplicationSystemTestCase + setup do + @university_school = university_schools(:one) + end + + test "visiting the index" do + visit university_schools_url + assert_selector "h1", text: "University/Schools" + end + + test "creating a School" do + visit university_schools_url + click_on "New University/School" + + fill_in "Address", with: @university_school.address + fill_in "City", with: @university_school.city + fill_in "Country", with: @university_school.country + fill_in "Latitude", with: @university_school.latitude + fill_in "Longitude", with: @university_school.longitude + fill_in "Name", with: @university_school.name + fill_in "University", with: @university_school.university_id + fill_in "Zipcode", with: @university_school.zipcode + click_on "Create School" + + assert_text "School was successfully created" + click_on "Back" + end + + test "updating a School" do + visit university_schools_url + click_on "Edit", match: :first + + fill_in "Address", with: @university_school.address + fill_in "City", with: @university_school.city + fill_in "Country", with: @university_school.country + fill_in "Latitude", with: @university_school.latitude + fill_in "Longitude", with: @university_school.longitude + fill_in "Name", with: @university_school.name + fill_in "University", with: @university_school.university_id + fill_in "Zipcode", with: @university_school.zipcode + click_on "Update School" + + assert_text "School was successfully updated" + click_on "Back" + end + + test "destroying a School" do + visit university_schools_url + page.accept_confirm do + click_on "Destroy", match: :first + end + + assert_text "School was successfully destroyed" + end +end