Skip to content
This repository has been archived by the owner on Jun 16, 2021. It is now read-only.

Commit

Permalink
Merge pull request #570 from omu/develop
Browse files Browse the repository at this point in the history
Merge develop into master
  • Loading branch information
msdundar authored Dec 2, 2018
2 parents 0a845ff + bb5b32c commit 04171ca
Show file tree
Hide file tree
Showing 64 changed files with 917 additions and 380 deletions.
88 changes: 44 additions & 44 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
GEM
remote: https://rubygems.org/
specs:
actioncable (5.2.1)
actionpack (= 5.2.1)
actioncable (5.2.1.1)
actionpack (= 5.2.1.1)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
actionmailer (5.2.1)
actionpack (= 5.2.1)
actionview (= 5.2.1)
activejob (= 5.2.1)
actionmailer (5.2.1.1)
actionpack (= 5.2.1.1)
actionview (= 5.2.1.1)
activejob (= 5.2.1.1)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 2.0)
actionpack (5.2.1)
actionview (= 5.2.1)
activesupport (= 5.2.1)
actionpack (5.2.1.1)
actionview (= 5.2.1.1)
activesupport (= 5.2.1.1)
rack (~> 2.0)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
actionview (5.2.1)
activesupport (= 5.2.1)
actionview (5.2.1.1)
activesupport (= 5.2.1.1)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.3)
activejob (5.2.1)
activesupport (= 5.2.1)
activejob (5.2.1.1)
activesupport (= 5.2.1.1)
globalid (>= 0.3.6)
activemodel (5.2.1)
activesupport (= 5.2.1)
activerecord (5.2.1)
activemodel (= 5.2.1)
activesupport (= 5.2.1)
activemodel (5.2.1.1)
activesupport (= 5.2.1.1)
activerecord (5.2.1.1)
activemodel (= 5.2.1.1)
activesupport (= 5.2.1.1)
arel (>= 9.0)
activestorage (5.2.1)
actionpack (= 5.2.1)
activerecord (= 5.2.1)
activestorage (5.2.1.1)
actionpack (= 5.2.1.1)
activerecord (= 5.2.1.1)
marcel (~> 0.3.1)
activesupport (5.2.1)
activesupport (5.2.1.1)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2)
minitest (~> 5.1)
Expand All @@ -51,16 +51,16 @@ GEM
arel (9.0.0)
ast (2.4.0)
aws-eventstream (1.0.1)
aws-partitions (1.115.0)
aws-sdk-core (3.39.0)
aws-partitions (1.121.0)
aws-sdk-core (3.42.0)
aws-eventstream (~> 1.0)
aws-partitions (~> 1.0)
aws-sigv4 (~> 1.0)
jmespath (~> 1.0)
aws-sdk-kms (1.12.0)
aws-sdk-kms (1.13.0)
aws-sdk-core (~> 3, >= 3.39.0)
aws-sigv4 (~> 1.0)
aws-sdk-s3 (1.25.0)
aws-sdk-s3 (1.29.0)
aws-sdk-core (~> 3, >= 3.39.0)
aws-sdk-kms (~> 1)
aws-sigv4 (~> 1.0)
Expand All @@ -78,7 +78,7 @@ GEM
bundler (~> 1.2)
thor (~> 0.18)
byebug (10.0.2)
capybara (3.11.1)
capybara (3.12.0)
addressable
mini_mime (>= 0.1.3)
nokogiri (~> 1.8)
Expand Down Expand Up @@ -186,7 +186,7 @@ GEM
pry (0.12.2)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
pry-rails (0.3.7)
pry-rails (0.3.8)
pry (>= 0.10.4)
public_suffix (3.0.3)
puma (3.12.0)
Expand All @@ -197,27 +197,27 @@ GEM
rack
rack-test (1.1.0)
rack (>= 1.0, < 3)
rails (5.2.1)
actioncable (= 5.2.1)
actionmailer (= 5.2.1)
actionpack (= 5.2.1)
actionview (= 5.2.1)
activejob (= 5.2.1)
activemodel (= 5.2.1)
activerecord (= 5.2.1)
activestorage (= 5.2.1)
activesupport (= 5.2.1)
rails (5.2.1.1)
actioncable (= 5.2.1.1)
actionmailer (= 5.2.1.1)
actionpack (= 5.2.1.1)
actionview (= 5.2.1.1)
activejob (= 5.2.1.1)
activemodel (= 5.2.1.1)
activerecord (= 5.2.1.1)
activestorage (= 5.2.1.1)
activesupport (= 5.2.1.1)
bundler (>= 1.3.0)
railties (= 5.2.1)
railties (= 5.2.1.1)
sprockets-rails (>= 2.0.0)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
rails-html-sanitizer (1.0.4)
loofah (~> 2.2, >= 2.2.2)
railties (5.2.1)
actionpack (= 5.2.1)
activesupport (= 5.2.1)
railties (5.2.1.1)
actionpack (= 5.2.1.1)
activesupport (= 5.2.1.1)
method_source
rake (>= 0.8.7)
thor (>= 0.19.0, < 2.0)
Expand Down Expand Up @@ -263,7 +263,7 @@ GEM
connection_pool (~> 2.2, >= 2.2.2)
rack-protection (>= 1.5.0)
redis (>= 3.3.5, < 5)
simple_form (4.0.1)
simple_form (4.1.0)
actionpack (>= 5.0)
activemodel (>= 5.0)
simplecov (0.16.1)
Expand All @@ -288,7 +288,7 @@ GEM
swearjar (1.3.0)
thor (0.20.3)
thread_safe (0.3.6)
tilt (2.0.8)
tilt (2.0.9)
tzinfo (1.2.5)
thread_safe (~> 0.1)
uglifier (4.1.20)
Expand Down
19 changes: 3 additions & 16 deletions app/controllers/calendar/calendar_titles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,18 @@ module Calendar
class CalendarTitlesController < ApplicationController
include PagyBackendWithHelpers

before_action :set_calendar_title, only: %i[edit update destroy]
before_action :set_calendar_title, only: %i[edit update]

def index
@calendar_titles = pagy_by_search(CalendarTitle.all)
end

def new
@calendar_title = CalendarTitle.new
@calendar_titles = pagy_by_search(CalendarTitle.includes(:types, :calendar_title_types))
end

def edit; end

def create
@calendar_title = CalendarTitle.new(calendar_title_params)
@calendar_title.save ? redirect_with('success') : render(:new)
end

def update
@calendar_title.update(calendar_title_params) ? redirect_with('success') : render(:edit)
end

def destroy
@calendar_title.destroy ? redirect_with('success') : redirect_with('warning')
end

private

def redirect_with(message)
Expand All @@ -40,7 +27,7 @@ def set_calendar_title
end

def calendar_title_params
params.require(:calendar_title).permit(:name, type_ids: [])
params.require(:calendar_title).permit(type_ids: [])
end
end
end
47 changes: 47 additions & 0 deletions app/controllers/course_management/course_types_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# frozen_string_literal: true

module CourseManagement
class CourseTypesController < ApplicationController
include PagyBackendWithHelpers

before_action :set_course_type, only: %i[edit update destroy]

def index
@course_types = pagy_by_search(CourseType.order(:name))
end

def new
@course_type = CourseType.new
end

def create
@course_type = CourseType.new(course_type_params)
@course_type.save ? redirect_with('success') : render(:new)
end

def edit; end

def update
@course_type.update(course_type_params) ? redirect_with('success') : render(:edit)
end

def destroy
message = @course_type.destroy ? 'success' : 'error'
redirect_with(message)
end

private

def redirect_with(message)
redirect_to(course_types_path, notice: t(".#{message}"))
end

def set_course_type
@course_type = CourseType.find(params[:id])
end

def course_type_params
params.require(:course_type).permit(:name, :code, :min_credit)
end
end
end
4 changes: 2 additions & 2 deletions app/controllers/course_management/courses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class CoursesController < ApplicationController
before_action :set_course, only: %i[show edit update destroy]

def index
courses = Course.includes(:unit, :language)
courses = Course.includes(:unit, :language, :course_type)
.order('units.name, courses.name')
.dynamic_search(search_params(Course))

Expand Down Expand Up @@ -49,7 +49,7 @@ def set_course
def course_params
params.require(:course).permit(
:unit_id, :name, :code, :theoric, :practice, :program_type,
:language_id, :laboratory, :status
:language_id, :laboratory, :status, :course_type_id
)
end
end
Expand Down
6 changes: 6 additions & 0 deletions app/models/calendar_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ class CalendarEvent < ApplicationRecord

# validations
validates :start_date, presence: true
validates :end_date, presence: true
validates :academic_calendar, uniqueness: { scope: :calendar_title }
validates_with CalendarEventValidator

# callbacks
after_create :set_calendar_type_and_term
Expand All @@ -24,4 +26,8 @@ def set_calendar_type_and_term
update(calendar_type_id: academic_calendar.calendar_type.id,
academic_term_id: academic_calendar.academic_term.id)
end

def proper_range?
Time.current.between?(start_date, end_date)
end
end
1 change: 1 addition & 0 deletions app/models/calendar_title.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ class CalendarTitle < ApplicationRecord

# validations
validates :name, presence: true, uniqueness: true
validates :identifier, presence: true, uniqueness: true
end
7 changes: 5 additions & 2 deletions app/models/course.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@ class Course < ApplicationRecord
)

# dynamic_search
search_keys :program_type, :language_id, :unit_id, :status
search_keys :course_type_id, :program_type, :language_id, :unit_id, :status

# relations
belongs_to :course_type
belongs_to :unit
belongs_to :language

# validations
validates :code, presence: true, uniqueness: true
validates :credit, presence: true, numericality: { greater_than: 0 }
validates :credit, presence: true, numericality: {
greater_than_or_equal_to: ->(course) { course.course_type.try(:min_credit).to_i }
}
validates :program_type, presence: true
validates :laboratory, presence: true, numericality: { greater_than_or_equal_to: 0 }
validates :name, presence: true, uniqueness: { scope: :unit_id }
Expand Down
19 changes: 19 additions & 0 deletions app/models/course_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

class CourseType < ApplicationRecord
# search
include PgSearch
pg_search_scope(
:search,
against: %i[name code],
using: { tsearch: { prefix: true } }
)

# relations
has_many :courses, dependent: :nullify

# validations
validates :name, presence: true, uniqueness: true
validates :code, presence: true, uniqueness: true
validates :min_credit, presence: true, numericality: { greater_than_or_equal_to: 0 }
end
8 changes: 8 additions & 0 deletions app/models/student.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class Student < ApplicationRecord
belongs_to :user
belongs_to :unit
has_one :identity, dependent: :destroy
has_many :academic_calendars, -> { AcademicCalendar.active }, through: :unit

# validations
validates :unit_id, uniqueness: { scope: %i[user] }
Expand All @@ -19,4 +20,11 @@ class Student < ApplicationRecord
def build_identity_information
Kps::IdentitySaveJob.perform_later(user, id)
end

def proper_event_range?(title)
event =
academic_calendars.last.calendar_events
.find_by(calendar_title: CalendarTitle.find_by(identifier: title))
!event.nil? && event.proper_range?
end
end
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class User < ApplicationRecord
)

# authentication
devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable
devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable, :lockable

# relations
has_one_attached :avatar
Expand Down
30 changes: 30 additions & 0 deletions app/validators/calendar_event_validator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# frozen_string_literal: true

class CalendarEventValidator < ActiveModel::Validator
def validate(record)
@event = record
@term = record.academic_calendar.academic_term

term_start_date_validation if @event.start_date?
term_end_date_validation if @event.end_date?
date_range_validation if @event.start_date? && @event.end_date?
end

def term_start_date_validation
@event.errors[:start_date] << message('invalid_start_date') if @event.start_date <= @term.start_of_term
end

def term_end_date_validation
@event.errors[:end_date] << message('invalid_end_date') if @event.end_date >= @term.end_of_term
end

def date_range_validation
@event.errors[:end_date] << message('invalid_date_range') if @event.end_date < @event.start_date
end

private

def message(key)
I18n.t(key, scope: %i[validators calendar_event])
end
end
Loading

0 comments on commit 04171ca

Please sign in to comment.