Skip to content

Commit

Permalink
Merge pull request #1304 from openjournals/buddys_for_editors
Browse files Browse the repository at this point in the history
Adding buddy to editor form
  • Loading branch information
arfon committed Jan 19, 2024
2 parents c1b8934 + b6f0767 commit 0b6465c
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/controllers/editors_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def set_current_editor
end

def editor_params
params.require(:editor).permit(:max_assignments, :availability_comment, :kind, :title, :first_name, :last_name, :login, :email, :avatar_url, :category_list, :url, :description, { track_ids: [] })
params.require(:editor).permit(:max_assignments, :availability_comment, :kind, :title, :first_name, :last_name, :buddy_id, :login, :email, :avatar_url, :category_list, :url, :description, { track_ids: [] })
end

def profile_params
Expand Down
2 changes: 2 additions & 0 deletions app/models/editor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class Editor < ApplicationRecord
has_and_belongs_to_many :tracks
has_many :track_aeics, dependent: :destroy
has_many :managed_tracks, through: :track_aeics, source: :track
belongs_to :buddy, class_name: "Editor", optional: true
has_one :buddy_editor, class_name: "Editor", foreign_key: "buddy_id"

normalizes :login, with: -> login { login.gsub(/^@/, "") }
before_save :clear_title, if: :board_removed?
Expand Down
5 changes: 5 additions & 0 deletions app/views/editors/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@
<% end %>
</div>

<div class="col">
<%= f.label :buddy %>
<%= f.select :buddy_id, Editor.active.collect { |e| ["#{e.full_name} (@#{e.login})", e.id] }, { include_blank: true }, { class: "form-control" } %>
</div>

<div class="col">
<%= f.label :email %>
<%= f.text_field :email, class: "form-control" %>
Expand Down
9 changes: 9 additions & 0 deletions app/views/editors/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@
<%= @editor.email %>
</p>

<p>
<strong>Buddy:</strong>
<% if @editor.buddy.present? %>
<%= "#{@editor.buddy.full_name} (@#{@editor.buddy.login})" %>
<% else %>
<i>None</i>
<% end %>
</p>

<p>
<strong>Avatar url:</strong>
<%= @editor.avatar_url %>
Expand Down
6 changes: 6 additions & 0 deletions db/migrate/20240109210521_add_start_date_to_editors.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddStartDateToEditors < ActiveRecord::Migration[7.1]
def change
add_column :editors, :buddy_id, :integer
add_index :editors, :buddy_id
end
end
10 changes: 6 additions & 4 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.0].define(version: 2023_06_09_104144) do
ActiveRecord::Schema[7.1].define(version: 2024_01_09_210521) do
# These are extensions that must be enabled in order to support this database
enable_extension "hstore"
enable_extension "plpgsql"
Expand All @@ -31,6 +31,8 @@
t.integer "user_id"
t.string "availability_comment"
t.integer "max_assignments", default: 4, null: false
t.integer "buddy_id"
t.index ["buddy_id"], name: "index_editors_on_buddy_id"
t.index ["user_id"], name: "index_editors_on_user_id"
end

Expand Down Expand Up @@ -78,7 +80,7 @@
t.index ["token"], name: "index_onboarding_invitations_on_token"
end

create_table "papers", force: :cascade do |t|
create_table "papers", id: :serial, force: :cascade do |t|
t.string "title"
t.string "state"
t.string "repository_url"
Expand All @@ -93,10 +95,10 @@
t.string "doi"
t.text "paper_body"
t.integer "meta_review_issue_id"
t.string "kind"
t.text "authors"
t.text "citation_string"
t.datetime "accepted_at", precision: nil
t.string "kind"
t.integer "editor_id"
t.string "reviewers", default: [], array: true
t.text "activities"
Expand Down Expand Up @@ -149,7 +151,7 @@
t.index ["name"], name: "index_tracks_on_name"
end

create_table "users", force: :cascade do |t|
create_table "users", id: :serial, force: :cascade do |t|
t.string "provider"
t.string "uid"
t.string "name"
Expand Down

0 comments on commit 0b6465c

Please sign in to comment.