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 #560 from omu/develop
Browse files Browse the repository at this point in the history
Merge develop into master
  • Loading branch information
msdundar authored Nov 24, 2018
2 parents 3bea9fa + f72d685 commit 0a845ff
Show file tree
Hide file tree
Showing 89 changed files with 850 additions and 497 deletions.
47 changes: 32 additions & 15 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ jobs:
key: nokul-yarn-{{ checksum "yarn.lock" }}
paths:
- node_modules/
test_suite:
quality:
<<: *ruby_2_5_1
steps:
- restore_cache:
Expand All @@ -92,9 +92,9 @@ jobs:
<<: *restore_yarn
- run: bundle --path vendor/bundle --without development
- run: bin/yarn install
- run: bundle exec rake db:create db:schema:load
- run: bundle exec rake test
karma:
- run: bundle exec rake quality:all
- run: bin/yarn run lint
security:
<<: *ruby_2_5_1
steps:
- restore_cache:
Expand All @@ -105,9 +105,8 @@ jobs:
<<: *restore_yarn
- run: bundle --path vendor/bundle --without development
- run: bin/yarn install
- run: bundle exec rake quality:rails
- run: bin/yarn run lint
security:
- run: bundle exec rake security:all
database:
<<: *ruby_2_5_1
steps:
- restore_cache:
Expand All @@ -118,7 +117,20 @@ jobs:
<<: *restore_yarn
- run: bundle --path vendor/bundle --without development
- run: bin/yarn install
- run: bundle exec rake security:all
- run: bundle exec rake database:all
test_suite:
<<: *ruby_2_5_1
steps:
- restore_cache:
<<: *repository
- restore_cache:
<<: *restore_bundle
- restore_cache:
<<: *restore_yarn
- run: bundle --path vendor/bundle --without development
- run: bin/yarn install
- run: bundle exec rake db:create db:schema:load
- run: bundle exec rake test
deploy_develop:
machine:
enabled: true
Expand Down Expand Up @@ -152,28 +164,33 @@ workflows:
- bundle_assets:
requires:
- bundle_dependencies
- test_suite:
- quality:
requires:
- bundle_assets
- security:
requires:
- bundle_assets
- karma:
- database:
requires:
- bundle_assets
- security:
- test_suite:
requires:
- bundle_assets
- deploy_develop:
requires:
- test_suite
- karma
- quality
- security
- database
- test_suite
filters:
branches:
only: develop
- deploy_master:
requires:
- test_suite
- karma
- quality
- security
- database
- test_suite
filters:
branches:
only: master
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ group :development, :test do
gem 'bundler-audit'
gem 'byebug', platforms: %i[mri mingw x64_mingw]
gem 'dotenv-rails'
gem 'lol_dba'
gem 'rubocop'
gem 'simplecov', require: false
end
Expand Down
27 changes: 16 additions & 11 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,17 @@ GEM
arel (9.0.0)
ast (2.4.0)
aws-eventstream (1.0.1)
aws-partitions (1.113.0)
aws-sdk-core (3.38.0)
aws-partitions (1.115.0)
aws-sdk-core (3.39.0)
aws-eventstream (~> 1.0)
aws-partitions (~> 1.0)
aws-sigv4 (~> 1.0)
jmespath (~> 1.0)
aws-sdk-kms (1.11.0)
aws-sdk-core (~> 3, >= 3.26.0)
aws-sdk-kms (1.12.0)
aws-sdk-core (~> 3, >= 3.39.0)
aws-sigv4 (~> 1.0)
aws-sdk-s3 (1.23.1)
aws-sdk-core (~> 3, >= 3.26.0)
aws-sdk-s3 (1.25.0)
aws-sdk-core (~> 3, >= 3.39.0)
aws-sdk-kms (~> 1)
aws-sigv4 (~> 1.0)
aws-sigv4 (1.0.3)
Expand All @@ -78,7 +78,7 @@ GEM
bundler (~> 1.2)
thor (~> 0.18)
byebug (10.0.2)
capybara (3.11.0)
capybara (3.11.1)
addressable
mini_mime (>= 0.1.3)
nokogiri (~> 1.8)
Expand Down Expand Up @@ -149,6 +149,10 @@ GEM
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
ruby_dep (~> 1.2)
lol_dba (2.1.5)
actionpack (>= 3.0)
activerecord (>= 3.0)
railties (>= 3.0)
loofah (2.2.3)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
Expand All @@ -169,7 +173,7 @@ GEM
nokogiri (1.8.5)
mini_portile2 (~> 2.3.0)
orm_adapter (0.5.0)
pagy (0.23.1)
pagy (1.1.0)
parallel (1.12.1)
parser (2.5.3.0)
ast (~> 2.4.0)
Expand Down Expand Up @@ -287,15 +291,15 @@ GEM
tilt (2.0.8)
tzinfo (1.2.5)
thread_safe (~> 0.1)
uglifier (4.1.19)
uglifier (4.1.20)
execjs (>= 0.3.0, < 3)
unf (0.1.4)
unf_ext
unf_ext (0.0.7.5)
unicode-display_width (1.4.0)
uniform_notifier (1.12.1)
warden (1.2.7)
rack (>= 1.0)
warden (1.2.8)
rack (>= 2.0.6)
web-console (3.7.0)
actionview (>= 5.0)
activemodel (>= 5.0)
Expand Down Expand Up @@ -339,6 +343,7 @@ DEPENDENCIES
jbuilder (~> 2.5)
letter_opener
listen (>= 3.0.5, < 3.2)
lol_dba
pagy
pg
pg_search
Expand Down
10 changes: 6 additions & 4 deletions app/controllers/calendar/academic_calendars_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@ def set_academic_calendar
def calendar_params
params.require(:academic_calendar)
.permit(
:name, :year, :academic_term_id, :calendar_type_id, :senate_decision_date, :senate_decision_no,
:description, calendar_events_attributes: %i[
id academic_calendar_id calendar_title_id start_date end_date _destroy
]
:name, :year, :academic_term_id, :calendar_type_id,
:senate_decision_date, :senate_decision_no, :description,
calendar_events_attributes: %i[
id calendar_type_id academic_term_id calendar_title_id start_date end_date _destroy
],
unit_ids: []
)
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/calendar/calendar_types_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def set_calendar_type
end

def calendar_type_params
params.require(:calendar_type).permit(:name)
params.require(:calendar_type).permit(:name, unit_type_ids: [])
end
end
end
13 changes: 9 additions & 4 deletions app/controllers/course_management/curriculums_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ def index
end

def show
@semesters = @curriculum.semesters.includes(
curriculum_semester_courses: :course
)
@semesters = @curriculum.semesters
.includes(curriculum_semester_courses: :course)
.order(:year, :sequence)
.group_by(&:year)
end

def new
Expand All @@ -27,6 +28,10 @@ def edit; end

def create
@curriculum = Curriculum.new(curriculum_params)
@curriculum.build_semesters(
number_of_semesters: params.dig(:curriculum, :number_of_semesters),
type: params.dig(:curriculum, :type)
)
@curriculum.save ? redirect_with('success') : render(:new)
end

Expand All @@ -52,7 +57,7 @@ def set_curriculum
def curriculum_params
params.require(:curriculum).permit(
:name, :unit_id, :status, program_ids: [],
semesters_attributes: %i[id name sequence _destroy]
semesters_attributes: %i[id sequence year _destroy]
)
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/full_name_helper.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module FullNameHelper
include EnumI18nHelper
include I18nHelper

def full_name(object)
case object.class.to_s
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

module EnumI18nHelper
module I18nHelper
# enum_options_for_select(Course, :status)
def enum_options_for_select(klass, enum)
klass.send(enum.to_s.pluralize).map do |key, _|
Expand All @@ -13,6 +13,13 @@ def enum_t(object, enum)
translate(object.class, enum, object.send(enum))
end

# options_for_select_for_collection([:add, :new])
def collection_options_for_select(collection)
collection.each_with_object([]) do |key, result|
result << [I18n.t(key, scope: :collection), key.to_s]
end
end

private

def translate(klass, enum, value)
Expand Down
12 changes: 4 additions & 8 deletions app/helpers/toastr_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@

module ToastrHelper
def toastr_flash_class(type)
case type
when 'alert'
'toastr.error'
when 'notice'
'toastr.success'
else
'toastr.info'
end
{
'alert' => 'toastr.error',
'notice' => 'toastr.success'
}.fetch(type, 'toastr.info')
end
end
5 changes: 4 additions & 1 deletion app/models/academic_calendar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,20 @@ class AcademicCalendar < ApplicationRecord
belongs_to :academic_term
belongs_to :calendar_type
has_many :calendar_events, dependent: :destroy
has_many :unit_calendar_events, dependent: :destroy
has_many :calendar_units, dependent: :destroy
has_many :units, through: :calendar_units
accepts_nested_attributes_for :calendar_events, allow_destroy: true

# validations
validates :name, presence: true
validates :senate_decision_date, presence: true
validates :senate_decision_no, presence: true
validates :academic_term, uniqueness: { scope: :calendar_type }
validates :units, presence: true, on: :update

# delegates
delegate :name, to: :calendar_type, prefix: :type
delegate :active?, to: :academic_term

# scopes
scope :active, -> { joins(:academic_term).merge(AcademicTerm.where(active: true)) }
Expand Down
3 changes: 3 additions & 0 deletions app/models/academic_term.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ class AcademicTerm < ApplicationRecord

# enums
enum term: { fall: 0, spring: 1, summer: 2 }

# scopes
scope :active, -> { where(active: true) }
end
14 changes: 13 additions & 1 deletion app/models/calendar_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,24 @@ class CalendarEvent < ApplicationRecord
# relations
belongs_to :academic_calendar
belongs_to :calendar_title
has_one :term, through: :academic_calendar, source: :academic_term
belongs_to :calendar_type, optional: true
belongs_to :academic_term, optional: true

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

# callbacks
after_create :set_calendar_type_and_term

# delegates
delegate :name, to: :calendar_title, prefix: :calendar_title

# scopes
scope :active, -> { where(academic_term: AcademicTerm.active) }

def set_calendar_type_and_term
update(calendar_type_id: academic_calendar.calendar_type.id,
academic_term_id: academic_calendar.academic_term.id)
end
end
3 changes: 3 additions & 0 deletions app/models/calendar_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ class CalendarType < ApplicationRecord
has_many :calendar_title_types, foreign_key: :type_id, inverse_of: :type, dependent: :destroy
has_many :titles, through: :calendar_title_types
has_many :academic_calendars, dependent: :destroy
has_many :calendar_unit_types, dependent: :destroy
has_many :unit_types, through: :calendar_unit_types
has_many :calendar_events, through: :academic_calendars

# validations
validates :name, presence: true, uniqueness: true
Expand Down
10 changes: 10 additions & 0 deletions app/models/calendar_unit.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

class CalendarUnit < ApplicationRecord
# relations
belongs_to :academic_calendar
belongs_to :unit

# validations
validates :unit, uniqueness: { scope: :academic_calendar }
end
10 changes: 10 additions & 0 deletions app/models/calendar_unit_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

class CalendarUnitType < ApplicationRecord
# relations
belongs_to :calendar_type
belongs_to :unit_type

# validations
validates :unit_type, uniqueness: { scope: :calendar_type }
end
Loading

0 comments on commit 0a845ff

Please sign in to comment.