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 #96 from omu/develop
Browse files Browse the repository at this point in the history
Merge develop into master
  • Loading branch information
msdundar authored Jul 10, 2018
2 parents d792119 + 1b50025 commit e345dc9
Show file tree
Hide file tree
Showing 22 changed files with 129 additions and 612 deletions.
1 change: 0 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,3 @@ AllCops:
- config/routes.rb
- app/services/kps/omu/adres.rb # WIP
- app/services/kps/omu/kimlik.rb # WIP
- app/jobs/yoksis_publications_create_job.rb # WIP
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ GEM
dotenv-rails (2.5.0)
dotenv (= 2.5.0)
railties (>= 3.2, < 6.0)
email_address (0.1.9)
email_address (0.1.10)
netaddr (~> 2.0)
simpleidn
equalizer (0.0.11)
Expand Down Expand Up @@ -169,7 +169,7 @@ GEM
mini_portile2 (~> 2.3.0)
nori (2.6.0)
orm_adapter (0.5.0)
pagy (0.11.2)
pagy (0.12.0)
parallel (1.12.1)
parser (2.5.1.0)
ast (~> 2.4.0)
Expand Down Expand Up @@ -231,7 +231,7 @@ GEM
railties (>= 4.2.0, < 5.3)
rollbar (2.16.2)
multi_json
rubocop (0.57.2)
rubocop (0.58.0)
jaro_winkler (~> 1.5.1)
parallel (~> 1.10)
parser (>= 2.5)
Expand Down
57 changes: 57 additions & 0 deletions app/controllers/concerns/reference_resource.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# frozen_string_literal: true

module ReferenceResource
extend ActiveSupport::Concern
include Pagy::Backend

# rubocop:disable Metrics/BlockLength
# rubocop:disable Rails/LexicallyScopedActionFilter
included do
before_action :set_variables
before_action :set_resource, only: %i[edit update destroy]

def index
@pagy, value = pagy(@model_name.all)
instance_variable_set("@#{controller_name}", value)
end

def new
instance_variable_set(@singular_variable.to_sym, @model_name.new)
end

def create
instance_variable_set(@singular_variable.to_sym, @model_name.new(secure_params))
instance_variable_get(@singular_variable).save ? redirect_with('success') : render(:new)
end

def update
if instance_variable_get(@singular_variable).update(secure_params)
flash[:notice] = t('.success')
redirect_to action: :index
else
render(:edit)
end
end

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

private

def set_variables
@singular_variable = "@#{controller_name.singularize}"
@model_name = controller_name.classify.constantize
end

def set_resource
instance_variable_set(@singular_variable.to_sym, @model_name.find(params[:id]))
end

def redirect_with(message)
redirect_to(send("#{controller_name}_path"), notice: t(".#{message}"))
end
end
# rubocop:enable Metrics/BlockLength
# rubocop:enable Rails/LexicallyScopedActionFilter
end
41 changes: 2 additions & 39 deletions app/controllers/references/student_disability_types_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,11 @@

module References
class StudentDisabilityTypesController < ApplicationController
include Pagy::Backend

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

def index
@pagy, @student_disability_types = pagy(StudentDisabilityType.all)
end

def new
@student_disability_type = StudentDisabilityType.new
end

def edit; end

def create
@student_disability_type = StudentDisabilityType.new(student_disability_type_params)
@student_disability_type.save ? redirect_with('success') : render(:new)
end

def update
if @student_disability_type.update(student_disability_type_params)
redirect_to(@student_disability_type, notice: t('.success'))
else
render(:edit)
end
end

def destroy
@student_disability_type.destroy ? redirect_with('success') : redirect_with('warning')
end
include ReferenceResource

private

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

def set_student_disability_type
@student_disability_type = StudentDisabilityType.find(params[:id])
end

def student_disability_type_params
def secure_params
params.require(:student_disability_type).permit(:name, :code)
end
end
Expand Down
41 changes: 2 additions & 39 deletions app/controllers/references/student_drop_out_types_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,11 @@

module References
class StudentDropOutTypesController < ApplicationController
include Pagy::Backend

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

def index
@pagy, @student_drop_out_types = pagy(StudentDropOutType.all)
end

def new
@student_drop_out_type = StudentDropOutType.new
end

def edit; end

def create
@student_drop_out_type = StudentDropOutType.new(student_drop_out_type_params)
@student_drop_out_type.save ? redirect_with('success') : render(:new)
end

def update
if @student_drop_out_type.update(student_drop_out_type_params)
redirect_to(@student_drop_out_type, notice: t('.success'))
else
render(:edit)
end
end

def destroy
@student_drop_out_type.destroy ? redirect_with('success') : redirect_with('warning')
end
include ReferenceResource

private

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

def set_student_drop_out_type
@student_drop_out_type = StudentDropOutType.find(params[:id])
end

def student_drop_out_type_params
def secure_params
params.require(:student_drop_out_type).permit(:name, :code)
end
end
Expand Down
41 changes: 2 additions & 39 deletions app/controllers/references/student_education_levels_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,11 @@

module References
class StudentEducationLevelsController < ApplicationController
include Pagy::Backend

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

def index
@pagy, @student_education_levels = pagy(StudentEducationLevel.all)
end

def new
@student_education_level = StudentEducationLevel.new
end

def edit; end

def create
@student_education_level = StudentEducationLevel.new(student_education_level_params)
@student_education_level.save ? redirect_with('success') : render(:new)
end

def update
if @student_education_level.update(student_education_level_params)
redirect_to(@student_education_level, notice: t('.success'))
else
render(:edit)
end
end

def destroy
@student_education_level.destroy ? redirect_with('success') : redirect_with('warning')
end
include ReferenceResource

private

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

def set_student_education_level
@student_education_level = StudentEducationLevel.find(params[:id])
end

def student_education_level_params
def secure_params
params.require(:student_education_level).permit(:name, :code)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,11 @@

module References
class StudentEntrancePointTypesController < ApplicationController
include Pagy::Backend

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

def index
@pagy, @student_entrance_point_types = pagy(StudentEntrancePointType.all)
end

def new
@student_entrance_point_type = StudentEntrancePointType.new
end

def edit; end

def create
@student_entrance_point_type = StudentEntrancePointType.new(student_entrance_point_type_params)
@student_entrance_point_type.save ? redirect_with('success') : render(:new)
end

def update
if @student_entrance_point_type.update(student_entrance_point_type_params)
redirect_to(@student_entrance_point_type, notice: t('.success'))
else
render(:edit)
end
end

def destroy
@student_entrance_point_type.destroy ? redirect_with('success') : redirect_with('warning')
end
include ReferenceResource

private

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

def set_student_entrance_point_type
@student_entrance_point_type = StudentEntrancePointType.find(params[:id])
end

def student_entrance_point_type_params
def secure_params
params.require(:student_entrance_point_type).permit(:name, :code)
end
end
Expand Down
41 changes: 2 additions & 39 deletions app/controllers/references/student_entrance_types_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,11 @@

module References
class StudentEntranceTypesController < ApplicationController
include Pagy::Backend

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

def index
@pagy, @student_entrance_types = pagy(StudentEntranceType.all)
end

def new
@student_entrance_type = StudentEntranceType.new
end

def edit; end

def create
@student_entrance_type = StudentEntranceType.new(student_entrance_type_params)
@student_entrance_type.save ? redirect_with('success') : render(:new)
end

def update
if @student_entrance_type.update(student_entrance_type_params)
redirect_to(@student_entrance_type, notice: t('.success'))
else
render(:edit)
end
end

def destroy
@student_entrance_type.destroy ? redirect_with('success') : redirect_with('warning')
end
include ReferenceResource

private

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

def set_student_entrance_type
@student_entrance_type = StudentEntranceType.find(params[:id])
end

def student_entrance_type_params
def secure_params
params.require(:student_entrance_type).permit(:name, :code)
end
end
Expand Down
41 changes: 2 additions & 39 deletions app/controllers/references/student_grades_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,11 @@

module References
class StudentGradesController < ApplicationController
include Pagy::Backend

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

def index
@pagy, @student_grades = pagy(StudentGrade.all)
end

def new
@student_grade = StudentGrade.new
end

def edit; end

def create
@student_grade = StudentGrade.new(student_grade_params)
@student_grade.save ? redirect_with('success') : render(:new)
end

def update
if @student_grade.update(student_grade_params)
redirect_to(@student_grade, notice: t('.success'))
else
render(:edit)
end
end

def destroy
@student_grade.destroy ? redirect_with('success') : redirect_with('warning')
end
include ReferenceResource

private

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

def set_student_grade
@student_grade = StudentGrade.find(params[:id])
end

def student_grade_params
def secure_params
params.require(:student_grade).permit(:name, :code)
end
end
Expand Down
Loading

0 comments on commit e345dc9

Please sign in to comment.