This repository has been archived by the owner on Jun 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #570 from omu/develop
Merge develop into master
- Loading branch information
Showing
64 changed files
with
917 additions
and
380 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
app/controllers/course_management/course_types_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.