Implement conflicts table generation
This commit is contained in:
parent
31c7a43a18
commit
a39af296ba
|
@ -0,0 +1,11 @@
|
|||
class ConflictsController < ApplicationController
|
||||
def show
|
||||
@conflicts_table = ConflictsTable.new conflicts_table_params
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def conflicts_table_params
|
||||
params.require(:conflicts_table).permit(:talk_id, other_talks_ids: [])
|
||||
end
|
||||
end
|
|
@ -0,0 +1,12 @@
|
|||
class Conflicts
|
||||
include ActiveModel::Model
|
||||
|
||||
attr_accessor :left, :right
|
||||
|
||||
def conflicts
|
||||
TalkPreference.joins('INNER JOIN "selected_talks" AS left
|
||||
ON "left"."talk_preference_id" = "talk_preferences"."unique_id"
|
||||
INNER JOIN "selected_talks" AS right
|
||||
ON "right"."talk_preference_id" = "talk_preferences"."unique_id"').where(left: {talk_id: @left}, right: {talk_id: @right}).count
|
||||
end
|
||||
end
|
|
@ -0,0 +1,18 @@
|
|||
class ConflictsTable
|
||||
include ActiveModel::Model
|
||||
|
||||
attr_accessor :talk_id, :other_talks_ids
|
||||
|
||||
def other_talks_ids
|
||||
@other_talks_ids ||= []
|
||||
end
|
||||
|
||||
def conflicts
|
||||
other_talks_ids.map do |right|
|
||||
{
|
||||
talk_id: right,
|
||||
number_of_conflicts: Conflicts.new(left: talk_id, right: right).conflicts
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1 @@
|
|||
json.extract! @conflicts_table, :talk_id, :conflicts
|
|
@ -2,5 +2,6 @@ Rails.application.routes.draw do
|
|||
resources :talk_preferences, only: [:index, :show, :create, :update]
|
||||
root to: 'home#index'
|
||||
resource :summary, only: :show
|
||||
resource :conflicts, only: :show
|
||||
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue