Add CommunitySolution
* Also slightly refactor some JS files
This commit is contained in:
13
app/models/community_solution.rb
Normal file
13
app/models/community_solution.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class CommunitySolution < ApplicationRecord
|
||||
belongs_to :exercise
|
||||
has_many :community_solution_locks
|
||||
has_many :community_solution_contributions
|
||||
has_and_belongs_to_many :users, polymorphic: true, through: :community_solution_contributions
|
||||
has_many :files, class_name: 'CodeOcean::File', through: :community_solution_contributions
|
||||
|
||||
def to_s
|
||||
"Gemeinschaftslösung für #{exercise}"
|
||||
end
|
||||
end
|
14
app/models/community_solution_contribution.rb
Normal file
14
app/models/community_solution_contribution.rb
Normal file
@@ -0,0 +1,14 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class CommunitySolutionContribution < ApplicationRecord
|
||||
include Creation
|
||||
include Context
|
||||
|
||||
belongs_to :community_solution
|
||||
belongs_to :community_solution_lock
|
||||
|
||||
validates :proposed_changes, boolean_presence: true
|
||||
validates :timely_contribution, boolean_presence: true
|
||||
validates :autosave, boolean_presence: true
|
||||
validates :working_time, presence: true
|
||||
end
|
18
app/models/community_solution_lock.rb
Normal file
18
app/models/community_solution_lock.rb
Normal file
@@ -0,0 +1,18 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class CommunitySolutionLock < ApplicationRecord
|
||||
include Creation
|
||||
|
||||
belongs_to :community_solution
|
||||
has_many :community_solution_contributions
|
||||
|
||||
validates :locked_until, presence: true
|
||||
|
||||
def active?
|
||||
Time.zone.now <= locked_until
|
||||
end
|
||||
|
||||
def working_time
|
||||
ActiveSupport::Duration.build(locked_until - created_at)
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user