gaku_core 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/gaku/core_controller.rb +3 -8
- data/app/decorators/gaku/course_decorator.rb +1 -2
- data/app/decorators/gaku/guardian_decorator.rb +1 -1
- data/app/decorators/gaku/person_decorator.rb +8 -12
- data/app/decorators/gaku/student_decorator.rb +0 -2
- data/app/decorators/gaku/teacher_decorator.rb +1 -1
- data/app/models/concerns/addresses.rb +6 -6
- data/app/models/concerns/contacts.rb +6 -6
- data/app/models/concerns/enrollmentable.rb +9 -0
- data/app/models/concerns/gradable.rb +14 -0
- data/app/models/concerns/notes.rb +1 -2
- data/app/models/concerns/pagination.rb +1 -2
- data/app/models/concerns/person.rb +0 -2
- data/app/models/concerns/picture.rb +1 -3
- data/app/models/concerns/semesterable.rb +12 -0
- data/app/models/concerns/student_reviewable.rb +7 -0
- data/app/models/gaku/ability.rb +2 -4
- data/app/models/gaku/address.rb +11 -10
- data/app/models/gaku/admin_ability.rb +0 -1
- data/app/models/gaku/assignment.rb +0 -2
- data/app/models/gaku/assignment_score.rb +0 -1
- data/app/models/gaku/attachment.rb +1 -4
- data/app/models/gaku/attendance.rb +0 -2
- data/app/models/gaku/attendance_type.rb +0 -2
- data/app/models/gaku/badge.rb +0 -2
- data/app/models/gaku/badge_type.rb +0 -1
- data/app/models/gaku/class_group.rb +13 -13
- data/app/models/gaku/commute_method_type.rb +0 -2
- data/app/models/gaku/contact.rb +6 -36
- data/app/models/gaku/contact_type.rb +0 -2
- data/app/models/gaku/country.rb +0 -3
- data/app/models/gaku/course.rb +11 -25
- data/app/models/gaku/course_group.rb +0 -2
- data/app/models/gaku/course_group_enrollment.rb +3 -4
- data/app/models/gaku/department.rb +0 -2
- data/app/models/gaku/enrollment.rb +85 -0
- data/app/models/gaku/enrollment_status.rb +0 -2
- data/app/models/gaku/exam.rb +17 -22
- data/app/models/gaku/exam_portion.rb +2 -6
- data/app/models/gaku/exam_portion_score.rb +0 -2
- data/app/models/gaku/exam_schedule.rb +0 -1
- data/app/models/gaku/exam_session.rb +14 -0
- data/app/models/gaku/exam_syllabus.rb +2 -6
- data/app/models/gaku/external_school_record.rb +1 -9
- data/app/models/gaku/extracurricular_activity.rb +1 -2
- data/app/models/gaku/faculty.rb +0 -2
- data/app/models/gaku/grading_method.rb +14 -2
- data/app/models/gaku/grading_method_connector.rb +35 -0
- data/app/models/gaku/grading_method_set.rb +6 -4
- data/app/models/gaku/grading_method_set_item.rb +4 -5
- data/app/models/gaku/guardian.rb +1 -3
- data/app/models/gaku/install.rb +0 -2
- data/app/models/gaku/lesson.rb +0 -1
- data/app/models/gaku/lesson_plan.rb +0 -2
- data/app/models/gaku/level.rb +0 -2
- data/app/models/gaku/preset.rb +18 -18
- data/app/models/gaku/program.rb +0 -2
- data/app/models/gaku/program_level.rb +0 -2
- data/app/models/gaku/program_specialty.rb +0 -2
- data/app/models/gaku/program_syllabus.rb +0 -2
- data/app/models/gaku/role.rb +0 -2
- data/app/models/gaku/schedule.rb +0 -1
- data/app/models/gaku/scholarship_status.rb +0 -2
- data/app/models/gaku/school.rb +0 -2
- data/app/models/gaku/school_role.rb +0 -2
- data/app/models/gaku/school_year.rb +4 -2
- data/app/models/gaku/semester.rb +21 -6
- data/app/models/gaku/semester_attendance.rb +14 -0
- data/app/models/gaku/semester_connector.rb +27 -0
- data/app/models/gaku/simple_grade.rb +0 -2
- data/app/models/gaku/simple_grade_type.rb +0 -1
- data/app/models/gaku/specialty.rb +0 -2
- data/app/models/gaku/state.rb +0 -3
- data/app/models/gaku/student.rb +47 -45
- data/app/models/gaku/student_exam_session.rb +11 -0
- data/app/models/gaku/student_guardian.rb +0 -2
- data/app/models/gaku/student_review.rb +11 -0
- data/app/models/gaku/student_review_category.rb +13 -0
- data/app/models/gaku/student_specialty.rb +2 -5
- data/app/models/gaku/syllabus.rb +0 -4
- data/app/models/gaku/teacher.rb +0 -2
- data/app/models/gaku/template.rb +7 -9
- data/app/models/gaku/user.rb +10 -22
- data/app/models/gaku/user_role.rb +0 -2
- data/app/services/gaku/contact_creation.rb +49 -0
- data/app/services/gaku/contact_updation.rb +41 -0
- data/app/services/gaku/student_selection.rb +57 -0
- data/app/services/gaku/user_creator.rb +31 -0
- data/config/initializers/devise.rb +1 -1
- data/config/initializers/redis.rb +5 -0
- data/config/locales/en.yml +79 -15
- data/config/routes.rb +5 -10
- data/db/default/gaku/attendance_types.rb +14 -16
- data/db/default/gaku/commute_method_types.rb +2 -4
- data/db/default/gaku/enrollment_status.rb +3 -3
- data/db/default/gaku/master_school.rb +7 -6
- data/db/default/gaku/presets.rb +6 -9
- data/db/default/gaku/scholarship_statuses.rb +1 -1
- data/db/migrate/20140128141752_change_grading_methods_arguments_field.rb +5 -0
- data/db/migrate/20140213113405_create_grading_method_connectors_table.rb +9 -0
- data/db/migrate/20140304094422_create_gaku_exam_sessions_table.rb +10 -0
- data/db/migrate/20140304101025_create_gaku_student_exam_session_table.rb +8 -0
- data/db/migrate/20140325073941_add_time_format_24_to_presets_table.rb +5 -0
- data/db/migrate/20140408111314_remove_semester_join_tables.rb +6 -0
- data/db/migrate/20140408111358_create_semester_connectors_table.rb +8 -0
- data/db/migrate/20140423093155_create_enrollments_table.rb +11 -0
- data/db/migrate/20140423100114_clean_enrollments_join_models.rb +8 -0
- data/db/migrate/20140429112725_add_counters_to_enrollmentable.rb +11 -0
- data/db/migrate/20140604104210_rename_method_to_grading_method.rb +5 -0
- data/db/migrate/20140604113045_add_default_value_to_curved.rb +5 -0
- data/db/migrate/20140610091053_add_seat_number_to_enrollments.rb +5 -0
- data/db/migrate/20140701104700_change_hstore_to_string_criteria.rb +5 -0
- data/db/migrate/20140715135152_create_semester_attendance_table.rb +16 -0
- data/db/migrate/20140718105226_create_student_review_categories_table.rb +13 -0
- data/db/migrate/20140728121353_create_student_review_table.rb +12 -0
- data/db/seeds.rb +1 -1
- data/lib/gaku/core.rb +2 -1
- data/lib/gaku/core/engine.rb +7 -5
- data/lib/gaku/core/url_helpers.rb +1 -1
- data/lib/gaku/grading/collection/base_method.rb +30 -0
- data/lib/gaku/grading/collection/calculations.rb +36 -0
- data/lib/gaku/grading/collection/interval.rb +55 -0
- data/lib/gaku/grading/collection/ordinal.rb +10 -0
- data/lib/gaku/grading/collection/percentage.rb +10 -0
- data/lib/gaku/grading/collection/result.rb +18 -0
- data/lib/gaku/grading/collection/score.rb +10 -0
- data/lib/gaku/grading/single/base_method.rb +30 -0
- data/lib/gaku/grading/single/calculations.rb +42 -0
- data/lib/gaku/grading/single/interval.rb +7 -0
- data/lib/gaku/grading/single/ordinal.rb +30 -0
- data/lib/gaku/grading/single/pass_fail.rb +2 -0
- data/lib/gaku/grading/single/percentage.rb +26 -0
- data/lib/gaku/grading/single/ratio.rb +2 -0
- data/lib/gaku/grading/single/result.rb +18 -0
- data/lib/gaku/grading/single/score.rb +15 -0
- data/lib/gaku/migrations.rb +1 -1
- data/lib/gaku/streamer/sse.rb +5 -5
- data/lib/gaku/testing/auth_helpers.rb +6 -2
- data/lib/gaku/testing/common_rake.rb +9 -3
- data/lib/gaku/testing/controller_helpers.rb +17 -12
- data/lib/gaku/testing/coverage.rb +1 -1
- data/lib/gaku/testing/deferred_garbage_collection.rb +3 -3
- data/lib/gaku/testing/factories/attachment_factory.rb +0 -1
- data/lib/gaku/testing/factories/attendance_type_factory.rb +1 -1
- data/lib/gaku/testing/factories/class_group_factory.rb +12 -1
- data/lib/gaku/testing/factories/contact_creation_factory.rb +18 -0
- data/lib/gaku/testing/factories/course_enrollment_factory.rb +9 -9
- data/lib/gaku/testing/factories/course_factory.rb +2 -4
- data/lib/gaku/testing/factories/course_group_factory.rb +2 -4
- data/lib/gaku/testing/factories/enrollment_factory.rb +10 -0
- data/lib/gaku/testing/factories/exam_factory.rb +1 -1
- data/lib/gaku/testing/factories/exam_portion_factory.rb +2 -4
- data/lib/gaku/testing/factories/exam_score_factory.rb +1 -1
- data/lib/gaku/testing/factories/exam_session_factory.rb +14 -0
- data/lib/gaku/testing/factories/extracurricular_activity_factory.rb +1 -1
- data/lib/gaku/testing/factories/grading_method_connector_factory.rb +11 -0
- data/lib/gaku/testing/factories/grading_method_factory.rb +3 -2
- data/lib/gaku/testing/factories/guardian_factory.rb +2 -4
- data/lib/gaku/testing/factories/lesson_plan_factory.rb +2 -2
- data/lib/gaku/testing/factories/preset_factory.rb +7 -7
- data/lib/gaku/testing/factories/program_factory.rb +0 -1
- data/lib/gaku/testing/factories/school_factory.rb +3 -3
- data/lib/gaku/testing/factories/semester_attendance_factory.rb +8 -0
- data/lib/gaku/testing/factories/semester_connectors_factory.rb +11 -0
- data/lib/gaku/testing/factories/semester_factory.rb +16 -0
- data/lib/gaku/testing/factories/simple_grade_type_factory.rb +1 -1
- data/lib/gaku/testing/factories/state_factory.rb +2 -1
- data/lib/gaku/testing/factories/student_exam_session_factory.rb +8 -0
- data/lib/gaku/testing/factories/student_factory.rb +15 -5
- data/lib/gaku/testing/factories/student_review_category_factory.rb +7 -0
- data/lib/gaku/testing/factories/student_review_factory.rb +13 -0
- data/lib/gaku/testing/factories/teacher_factory.rb +1 -1
- data/lib/gaku/testing/factories/template_factory.rb +5 -7
- data/lib/gaku/testing/factories/traits.rb +32 -4
- data/lib/gaku/testing/factories/user_factory.rb +0 -1
- data/lib/gaku_core.rb +1 -1
- data/lib/generators/gaku/dummy/dummy_generator.rb +5 -4
- data/lib/generators/gaku/install/install_generator.rb +16 -14
- data/lib/tasks/admin_user.rake +2 -1
- metadata +310 -264
- data/app/models/gaku/class_group_course_enrollment.rb +0 -17
- data/app/models/gaku/class_group_enrollment.rb +0 -31
- data/app/models/gaku/course_enrollment.rb +0 -23
- data/app/models/gaku/disposal.rb +0 -45
- data/app/models/gaku/extracurricular_activity_enrollment.rb +0 -15
- data/app/models/gaku/semester_class_group.rb +0 -21
- data/app/models/gaku/semester_course.rb +0 -21
- data/lib/gaku/grading/calculations.rb +0 -279
- data/lib/gaku/grading/grade.rb +0 -17
- data/lib/gaku/grading/japanese_hs_standard.rb +0 -8
- data/lib/gaku/testing/factories/class_group_course_enrollment_factory.rb +0 -8
- data/lib/gaku/testing/factories/class_group_enrollment_factory.rb +0 -9
- data/lib/gaku/testing/factories/semester_class_group_factory.rb +0 -8
- data/lib/gaku/testing/factories/semester_course.rb +0 -8
data/app/models/gaku/contact.rb
CHANGED
@@ -1,15 +1,10 @@
|
|
1
1
|
module Gaku
|
2
2
|
class Contact < ActiveRecord::Base
|
3
|
-
|
4
3
|
belongs_to :contact_type
|
5
4
|
belongs_to :contactable, polymorphic: true, counter_cache: true
|
6
5
|
|
7
6
|
validates :data, :contact_type, presence: true
|
8
7
|
|
9
|
-
before_save :ensure_first_is_primary, on: :create
|
10
|
-
before_save :remove_other_primary
|
11
|
-
after_save :update_primary_contact_field
|
12
|
-
|
13
8
|
delegate :name, to: :contact_type, allow_nil: true
|
14
9
|
|
15
10
|
def to_s
|
@@ -33,12 +28,12 @@ module Gaku
|
|
33
28
|
end
|
34
29
|
|
35
30
|
def make_primary
|
36
|
-
contacts.where.not(id: id).update_all(primary: false)
|
31
|
+
contactable.contacts.where.not(id: id).update_all(primary: false)
|
37
32
|
update_attribute(:primary, true)
|
38
33
|
|
39
|
-
if contactable.has_attribute?(:primary_contact)
|
40
|
-
|
41
|
-
end
|
34
|
+
# if contactable.has_attribute?(:primary_contact)
|
35
|
+
# contactable.update_attribute(:primary_contact, contactable.contact_widget)
|
36
|
+
# end
|
42
37
|
end
|
43
38
|
|
44
39
|
def primary?
|
@@ -56,37 +51,12 @@ module Gaku
|
|
56
51
|
private
|
57
52
|
|
58
53
|
def increment_count
|
59
|
-
contactable.class.increment_counter(:
|
54
|
+
contactable.class.increment_counter(:contacts_count, contactable.id)
|
60
55
|
end
|
61
56
|
|
62
57
|
def decrement_count
|
63
|
-
contactable.class.decrement_counter(:
|
64
|
-
end
|
65
|
-
|
66
|
-
def remove_other_primary
|
67
|
-
contacts.where.not(id: id).update_all(primary: false) if primary?
|
68
|
-
end
|
69
|
-
|
70
|
-
def ensure_first_is_primary
|
71
|
-
if contactable.respond_to? :contacts
|
72
|
-
self.primary = true if contacts.blank?
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
def contact_widget
|
77
|
-
contactable.contact_widget
|
78
|
-
end
|
79
|
-
|
80
|
-
def update_primary_contact_field
|
81
|
-
if contactable.has_attribute? :primary_contact
|
82
|
-
contactable.update_attribute(:primary_contact, contactable.contact_widget)
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
def contacts
|
87
|
-
contactable.contacts
|
58
|
+
contactable.class.decrement_counter(:contacts_count, contactable.id)
|
88
59
|
end
|
89
60
|
|
90
61
|
end
|
91
62
|
end
|
92
|
-
|
data/app/models/gaku/country.rb
CHANGED
@@ -1,11 +1,9 @@
|
|
1
1
|
module Gaku
|
2
2
|
class Country < ActiveRecord::Base
|
3
|
-
|
4
3
|
has_many :states, -> { order name: :asc },
|
5
4
|
foreign_key: :country_iso,
|
6
5
|
primary_key: :iso
|
7
6
|
|
8
|
-
|
9
7
|
default_scope -> { order('name ASC') }
|
10
8
|
|
11
9
|
validates :name, :iso_name, :iso, presence: true
|
@@ -18,6 +16,5 @@ module Gaku
|
|
18
16
|
def to_s
|
19
17
|
name
|
20
18
|
end
|
21
|
-
|
22
19
|
end
|
23
20
|
end
|
data/app/models/gaku/course.rb
CHANGED
@@ -1,23 +1,11 @@
|
|
1
1
|
module Gaku
|
2
2
|
class Course < ActiveRecord::Base
|
3
3
|
|
4
|
-
include Notes
|
5
|
-
|
6
|
-
has_many :enrollments,
|
7
|
-
class_name: 'Gaku::CourseEnrollment',
|
8
|
-
dependent: :destroy
|
9
|
-
|
10
|
-
has_many :students, through: :enrollments
|
4
|
+
include Notes, Gradable, Enrollmentable, Semesterable
|
11
5
|
|
12
6
|
has_many :course_group_enrollments
|
13
7
|
has_many :course_groups, through: :course_group_enrollments
|
14
8
|
|
15
|
-
has_many :class_groups, through: :class_group_course_enrollments
|
16
|
-
has_many :class_group_course_enrollments, dependent: :destroy
|
17
|
-
|
18
|
-
has_many :semester_courses, dependent: :destroy
|
19
|
-
has_many :semesters, through: :semester_courses
|
20
|
-
|
21
9
|
has_many :exam_schedules
|
22
10
|
|
23
11
|
belongs_to :syllabus
|
@@ -25,12 +13,10 @@ module Gaku
|
|
25
13
|
|
26
14
|
delegate :name, :code, to: :syllabus, prefix: true, allow_nil: true
|
27
15
|
|
28
|
-
accepts_nested_attributes_for :enrollments
|
16
|
+
# accepts_nested_attributes_for :enrollments
|
29
17
|
|
30
18
|
validates :code, presence: true
|
31
19
|
|
32
|
-
scope :without_semester, -> { includes(:semester_courses).where(gaku_semester_courses: { course_id: nil }) }
|
33
|
-
|
34
20
|
def to_s
|
35
21
|
if syllabus_name
|
36
22
|
"#{syllabus_name}-#{code}"
|
@@ -43,15 +29,15 @@ module Gaku
|
|
43
29
|
[to_s, id]
|
44
30
|
end
|
45
31
|
|
46
|
-
def enroll_class_group(class_group)
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
end
|
32
|
+
# def enroll_class_group(class_group)
|
33
|
+
# unless class_group.blank?
|
34
|
+
# ActiveRecord::Base.transaction do
|
35
|
+
# class_group.student_ids.each do |student_id|
|
36
|
+
# CourseEnrollment.find_or_create_by(student_id: student_id, course_id: id)
|
37
|
+
# end
|
38
|
+
# end
|
39
|
+
# end
|
40
|
+
# end
|
55
41
|
|
56
42
|
end
|
57
43
|
end
|
@@ -8,9 +8,8 @@ module Gaku
|
|
8
8
|
validates :course_id,
|
9
9
|
presence: true,
|
10
10
|
uniqueness: {
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
scope: :course_group_id,
|
12
|
+
message: I18n.t(:'course_group.already_enrolled')
|
13
|
+
}
|
15
14
|
end
|
16
15
|
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
module Gaku
|
2
|
+
class Enrollment < ActiveRecord::Base
|
3
|
+
|
4
|
+
belongs_to :student
|
5
|
+
belongs_to :enrollmentable, polymorphic: true, counter_cache: true
|
6
|
+
|
7
|
+
validates :enrollmentable_type, :enrollmentable_id, :student_id, presence: true
|
8
|
+
|
9
|
+
validates :student_id,
|
10
|
+
uniqueness: {
|
11
|
+
scope: %w( enrollmentable_type enrollmentable_id ),
|
12
|
+
message: I18n.t(:'student.already_enrolled')
|
13
|
+
}
|
14
|
+
|
15
|
+
validates :enrollmentable_type,
|
16
|
+
inclusion: {
|
17
|
+
in: %w( Gaku::Course Gaku::ClassGroup Gaku::ExtracurricularActivity ),
|
18
|
+
message: '%{value} is not a valid'
|
19
|
+
}
|
20
|
+
|
21
|
+
validate :class_group_semesters_overlap, if: ->(record) { record.class_group_type? }
|
22
|
+
|
23
|
+
before_create :increment_enrollmentable_counter
|
24
|
+
before_destroy :decrement_enrollmentable_counter
|
25
|
+
|
26
|
+
before_create :proper_position, if: ->(record) { record.class_group_type? }
|
27
|
+
after_destroy :refresh_positions, if: ->(record) { record.class_group_type? }
|
28
|
+
|
29
|
+
scope :seat_numbered, -> { order('seat_number ASC') }
|
30
|
+
|
31
|
+
def class_group_type?
|
32
|
+
enrollmentable_type == 'Gaku::ClassGroup'
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def class_group_semesters_overlap
|
38
|
+
if overlap_semester? && not_in_student_class_groups?
|
39
|
+
errors.add(:base, I18n.t('enrollment.class_group_overlapping'))
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def overlap_semester?
|
44
|
+
if student && student.semesters && enrollmentable
|
45
|
+
student.semesters.where(id: enrollmentable.semester_ids).any?
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def not_in_student_class_groups?
|
50
|
+
student.class_groups.exclude?(enrollmentable)
|
51
|
+
end
|
52
|
+
|
53
|
+
def increment_enrollmentable_counter
|
54
|
+
Student.increment_counter(resource_name_counter, student.id) if student
|
55
|
+
end
|
56
|
+
|
57
|
+
def decrement_enrollmentable_counter
|
58
|
+
Student.decrement_counter(resource_name_counter, student.id) if student
|
59
|
+
end
|
60
|
+
|
61
|
+
def resource_name_counter
|
62
|
+
enrollmentable_type.demodulize.underscore.pluralize.concat('_count') if enrollmentable_type
|
63
|
+
end
|
64
|
+
|
65
|
+
def proper_position
|
66
|
+
self.seat_number = enrollmentable.enrollments_count.next
|
67
|
+
end
|
68
|
+
|
69
|
+
def refresh_positions
|
70
|
+
enrollments = enrollmentable.enrollments
|
71
|
+
enrollments.pluck(:id).each_with_index do |id, index|
|
72
|
+
enrollments.where(id: id).update_all(seat_number: index.next)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def class_group_is_active?
|
77
|
+
Gaku::ClassGroup.active.include?(enrollmentable)
|
78
|
+
end
|
79
|
+
|
80
|
+
def not_in_student_class_groups?
|
81
|
+
student.class_groups.exclude?(enrollmentable)
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
module Gaku
|
2
2
|
class EnrollmentStatus < ActiveRecord::Base
|
3
|
-
|
4
3
|
has_many :students, foreign_key: :enrollment_status_code, primary_key: :code
|
5
4
|
|
6
5
|
translates :name
|
@@ -20,6 +19,5 @@ module Gaku
|
|
20
19
|
def set_name
|
21
20
|
self.name = code if name.nil?
|
22
21
|
end
|
23
|
-
|
24
22
|
end
|
25
23
|
end
|
data/app/models/gaku/exam.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
module Gaku
|
2
2
|
class Exam < ActiveRecord::Base
|
3
|
-
|
4
|
-
include Notes, Pagination
|
3
|
+
include Notes, Pagination, Gradable
|
5
4
|
|
6
5
|
has_many :exam_scores
|
7
6
|
has_many :exam_portions, -> { order :position }
|
@@ -12,20 +11,21 @@ module Gaku
|
|
12
11
|
|
13
12
|
has_many :attendances, as: :attendancable
|
14
13
|
|
14
|
+
has_many :exam_sessions
|
15
|
+
|
15
16
|
belongs_to :grading_method
|
16
17
|
belongs_to :department
|
17
18
|
|
18
|
-
|
19
19
|
validates :name, presence: true
|
20
20
|
|
21
|
-
validates :weight, numericality: {
|
22
|
-
allow_blank: true,
|
23
|
-
greater_than_or_equal_to: 0
|
24
|
-
}
|
25
|
-
|
21
|
+
validates :weight, numericality: { allow_blank: true, greater_than_or_equal_to: 0 }
|
26
22
|
|
27
23
|
accepts_nested_attributes_for :exam_portions
|
28
24
|
|
25
|
+
def to_s
|
26
|
+
name
|
27
|
+
end
|
28
|
+
|
29
29
|
def self.without_syllabuses
|
30
30
|
includes(:syllabuses).where(standalone: false)
|
31
31
|
.select { |p| p.syllabuses.length == 0 }
|
@@ -46,7 +46,7 @@ module Gaku
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def max_score
|
49
|
-
exam_portions.
|
49
|
+
exam_portions.inject(0) { |sum, p| sum + p.max_score }
|
50
50
|
end
|
51
51
|
|
52
52
|
def completion(students)
|
@@ -56,17 +56,17 @@ module Gaku
|
|
56
56
|
end
|
57
57
|
|
58
58
|
def ungraded(students)
|
59
|
-
|
59
|
+
ungraded = 0
|
60
60
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
61
|
+
students.each do |student|
|
62
|
+
student_exam_eps = exam_portion_scores.select do |eps|
|
63
|
+
eps.student_id == student.id
|
64
|
+
end
|
65
65
|
|
66
|
-
|
67
|
-
|
68
|
-
end
|
66
|
+
student_exam_eps.each do |eps|
|
67
|
+
ungraded += 1 if check_record_completion?(eps)
|
69
68
|
end
|
69
|
+
end
|
70
70
|
|
71
71
|
ungraded
|
72
72
|
end
|
@@ -83,7 +83,6 @@ module Gaku
|
|
83
83
|
completed
|
84
84
|
end
|
85
85
|
|
86
|
-
|
87
86
|
def completed_by_student?(student)
|
88
87
|
state = true
|
89
88
|
|
@@ -97,8 +96,6 @@ module Gaku
|
|
97
96
|
state
|
98
97
|
end
|
99
98
|
|
100
|
-
private
|
101
|
-
|
102
99
|
def check_record_completion?(student_eps)
|
103
100
|
student_eps.score.nil? && !student_eps.attendances
|
104
101
|
.last
|
@@ -107,5 +104,3 @@ module Gaku
|
|
107
104
|
end
|
108
105
|
end
|
109
106
|
end
|
110
|
-
|
111
|
-
|
@@ -15,10 +15,8 @@ module Gaku
|
|
15
15
|
validates :name, presence: true
|
16
16
|
|
17
17
|
validates :weight,
|
18
|
-
numericality: {
|
19
|
-
|
20
|
-
if: Proc.new { |ep| ep.weight.present? }
|
21
|
-
}
|
18
|
+
numericality: { greater_than_or_equal_to: 0,
|
19
|
+
if: proc { |ep| ep.weight.present? } }
|
22
20
|
|
23
21
|
validates :max_score, presence: true,
|
24
22
|
numericality: { greater_than_or_equal_to: 0 }
|
@@ -35,7 +33,6 @@ module Gaku
|
|
35
33
|
|
36
34
|
def correct_weight_with_error
|
37
35
|
self.weight = weight_was
|
38
|
-
custom_errors = I18n.t(:'exam_portion.error')
|
39
36
|
end
|
40
37
|
|
41
38
|
def weight_calculate
|
@@ -81,6 +78,5 @@ module Gaku
|
|
81
78
|
exam_portions.where(id: id).update_all(position: index)
|
82
79
|
end
|
83
80
|
end
|
84
|
-
|
85
81
|
end
|
86
82
|
end
|