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 #694 from omu/improvements
Browse files Browse the repository at this point in the history
Genel iyileştirmeler
  • Loading branch information
msdundar authored Jan 21, 2019
2 parents 40fcdd7 + f800d6e commit 083ca49
Show file tree
Hide file tree
Showing 48 changed files with 235 additions and 116 deletions.
8 changes: 4 additions & 4 deletions app/controllers/course_management/curriculums_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module CourseManagement
class CurriculumsController < ApplicationController
include PagyBackendWithHelpers
before_action :set_curriculum, only: %i[show edit update destroy courses]
before_action :set_curriculum, only: %i[show edit update destroy openable_courses]

def index
curriculums = Curriculum.includes(:unit)
Expand Down Expand Up @@ -44,9 +44,9 @@ def destroy
redirect_with(message)
end

def courses
@courses = @curriculum.courses
render json: @courses
def openable_courses
@curriculum = CurriculumDecorator.new(@curriculum)
render json: @curriculum.openable_courses_for_active_term
end

private
Expand Down
16 changes: 16 additions & 0 deletions app/decorators/curriculum_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

class CurriculumDecorator < SimpleDelegator
def openable_courses_for_active_term(appends: nil)
term = AcademicTerm.active.last.try(:term)

return [] unless term

courses = semesters.where(term: term)
.includes(:courses)
.where.not(courses: { id: available_courses.pluck(:course_id) })
.order('courses.name')
.map(&:courses)
[*appends, courses].flatten
end
end
113 changes: 65 additions & 48 deletions app/helpers/link_helper.rb
Original file line number Diff line number Diff line change
@@ -1,62 +1,79 @@
# frozen_string_literal: true

module LinkHelper
def link_to_back(path = nil, text = t('action_group.back'))
link_to(
fa_icon('arrow-left', text: text),
path,
class: 'btn btn-secondary btn-sm'
)
end

def link_to_destroy(path = nil, text = t('action_group.destroy'))
link_to(
fa_icon('trash', text: text),
path,
method: :delete,
data: { confirm: t('are_you_sure') },
class: 'btn btn-outline-danger btn-sm'
)
end

def link_to_edit(path = nil, text = t('action_group.edit'))
link_to(
fa_icon('pencil', text: text),
path,
class: 'btn btn-outline-success btn-sm'
)
end
LINKS = {
back: {
icon: 'arrow-left',
text: I18n.t('action_group.back'),
options: {
class: 'btn btn-secondary btn-sm'
}
},
destroy: {
icon: 'trash',
text: I18n.t('action_group.destroy'),
options: {
class: 'btn btn-outline-danger btn-sm',
method: :delete,
data: { confirm: I18n.t('are_you_sure') }
}
},
edit: {
icon: 'pencil',
text: I18n.t('action_group.edit'),
options: {
class: 'btn btn-outline-success btn-sm'
}
},
new: {
icon: 'plus',
text: I18n.t('action_group.add'),
options: {
class: 'btn btn-outline-primary btn-sm',
id: 'add-button'
}
},
show: {
icon: 'eye',
text: I18n.t('action_group.show'),
options: {
class: 'btn btn-outline-info btn-sm'
}
},
update: {
icon: 'pencil-square-o',
text: I18n.t('action_group.update'),
options: {
class: 'btn btn-outline-info btn-sm'
}
},
file: {
icon: 'file-word-o',
text: I18n.t('action_group.file'),
options: {
class: 'btn btn-secondary btn-sm'
}
}
}.freeze

def link_to_new(path = nil, text = t('action_group.add'))
link_to(
fa_icon('plus', text: text),
path,
class: 'btn btn-outline-primary btn-sm',
id: 'add-button'
)
LINKS.each do |action, configuration|
define_method("link_to_#{action}") do |*args|
link_builder(args, configuration)
end
end

def link_to_show(path = nil, text = t('action_group.show'))
link_to(
fa_icon('eye', text: text),
path,
class: 'btn btn-outline-info btn-sm'
)
end
private

def link_to_update(path = nil, text = t('action_group.update'))
def link_builder(args, configuration)
text, path = split_args_for_link_to(args)
link_to(
fa_icon('pencil-square-o', text: text),
fa_icon(configuration[:icon], text: text || configuration[:text]),
path,
class: 'btn btn-outline-info btn-sm'
configuration.fetch(:options, {})
)
end

def link_to_file(path = nil, text = t('action_group.file'))
link_to(
fa_icon('file-word-o', text: text),
path,
class: 'btn btn-secondary btn-sm'
)
def split_args_for_link_to(args)
args.length == 1 ? [nil, *args] : args
end
end
4 changes: 4 additions & 0 deletions app/models/academic_term.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
class AcademicTerm < ApplicationRecord
include EnumForTerm

# callbacks
after_save -> { AcademicTerm.where.not(id: id).update(active: false) }, if: :active?

# relations
has_many :calendars, dependent: :nullify
has_many :registration_documents, dependent: :nullify
Expand All @@ -12,6 +15,7 @@ class AcademicTerm < ApplicationRecord
validates :start_of_term, presence: true
validates :end_of_term, presence: true
validates :active, inclusion: { in: [true, false] }
validates_with AcademicTermValidator

# scopes
scope :active, -> { where(active: true) }
Expand Down
10 changes: 10 additions & 0 deletions app/validators/academic_term_validator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

class AcademicTermValidator < ActiveModel::Validator
def validate(record)
return if record.active?
return if AcademicTerm.where.not(id: record.id).exists?(active: true)

record.errors[:active] << I18n.t('active_check', scope: %i[validators academic_term])
end
end
2 changes: 1 addition & 1 deletion app/views/account/addresses/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="alert alert-light">
<%= link_to_back user_path(@user) %>
<%= link_to_new(new_user_address_path(@user), t('.new_address')) unless @user.addresses.informal.present? %>
<%= link_to_new(t('.new_address'), new_user_address_path(@user)) unless @user.addresses.informal.present? %>
<%= link_to (@addresses.formal.present? ? t('.update_from_mernis') : t('.create_from_mernis') ), save_from_mernis_user_addresses_path, class: "btn btn-outline-primary btn-sm" %>
</div>

Expand Down
2 changes: 1 addition & 1 deletion app/views/account/identities/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="alert alert-light">
<%= link_to_back user_path(@user) %>
<%= link_to_new(new_user_identity_path(@user), t('.new_identity')) unless @user.identities.informal.present? %>
<%= link_to_new(t('.new_identity'), new_user_identity_path(@user)) unless @user.identities.informal.present? %>
<%= link_to (@identities.formal.present? ? t('.update_from_mernis') : t('.create_from_mernis') ), save_from_mernis_user_identities_path, class: "btn btn-outline-primary btn-sm" %>
</div>

Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/cities/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<div class='card-header'>
<%= fa_icon 'street-view', text: t('.card_header') %>
<div class="card-header-actions">
<%= link_to_new [:new, :admin, @country, @city, :district], t('.new_district_link') %>
<%= link_to_new t('.new_district_link'), [:new, :admin, @country, @city, :district] %>
</div>
</div>
<div class='card-body'>
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/countries/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<div class='card-header'>
<%= fa_icon 'street-view', text: t('.card_header') %>
<div class="card-header-actions">
<%= link_to_new [:new, :admin, @country, 'city'], t('.new_city_link') %>
<%= link_to_new t('.new_city_link'), [:new, :admin, @country, 'city'] %>
</div>
</div>
<div class='card-body'>
Expand Down
2 changes: 1 addition & 1 deletion app/views/calendar_management/calendars/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<div class='card-header'>
<%= fa_icon 'street-view', text: t('.card_header') %>
<div class='card-header-actions'>
<%= link_to_new [:new, :calendar_management, :calendar], t('.new_calendar_link') %>
<%= link_to_new t('.new_calendar_link'), [:new, :calendar_management, :calendar] %>
</div>
</div>
<div class='card-body'>
Expand Down
2 changes: 1 addition & 1 deletion app/views/committee/agenda_types/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class='alert alert-light'>
<%= link_to_new new_agenda_type_path, t('.new_agenda_type_link') %>
<%= link_to_new t('.new_agenda_type_link'), new_agenda_type_path %>
</div>

<div class='row'>
Expand Down
2 changes: 1 addition & 1 deletion app/views/committee/agendas/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class='alert alert-light'>
<%= link_to_new new_committee_agenda_path(@committee), t('.new_agenda_link') %>
<%= link_to_new t('.new_agenda_link'), new_committee_agenda_path(@committee) %>
<span class="pull-right">
<%= link_to(fa_icon('archive', text: t('.meetings')),
committee_meetings_path(@committee),
Expand Down
2 changes: 1 addition & 1 deletion app/views/committee/decisions/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
</table>
</div>
<div class="card-footer">
<%= link_to_edit(edit_committee_meeting_agenda_decision_path(@committee, @agenda), t('.update_decision')) %>
<%= link_to_edit(t('.update_decision'), edit_committee_meeting_agenda_decision_path(@committee, @agenda)) %>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/committee/meetings/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class='alert alert-light'>
<%= link_to_new new_committee_meeting_path(@committee), t('.new_committee_meeting_link') %>
<%= link_to_new t('.new_committee_meeting_link'), new_committee_meeting_path(@committee) %>
<span class="pull-right">
<%= link_to(fa_icon('tasks', text: t('.agendas')), committee_agendas_path(@committee),
class: 'btn btn-dark btn-sm') %>
Expand Down
6 changes: 3 additions & 3 deletions app/views/committee/meetings/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@
<td><%= agenda.decision.try(:decision_no) %></td>
<td>
<% if agenda.decision.present? %>
<%= link_to_show(committee_meeting_agenda_decision_path(@committee, agenda, agenda.decision), t('.show_decision')) %>
<%= link_to_edit(edit_committee_meeting_agenda_decision_path(@committee, agenda), t('.update_decision')) %>
<%= link_to_show(t('.show_decision'), committee_meeting_agenda_decision_path(@committee, agenda, agenda.decision)) %>
<%= link_to_edit(t('.update_decision'), edit_committee_meeting_agenda_decision_path(@committee, agenda)) %>
<% else %>
<%= link_to_new(new_committee_meeting_agenda_decision_path(@committee, agenda), t('.create_decision')) %>
<%= link_to_new(t('.create_decision'), new_committee_meeting_agenda_decision_path(@committee, agenda)) %>
<% end %>
</td>
</tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div class='card-header'>
<%= fa_icon 'list-alt' %><strong><%= t('.card_header') %></strong>
<span class='pull-right'>
<%= link_to_new(new_available_course_evaluation_type_path(@available_course), t('.create_evaluation_type')) %>
<%= link_to_new(t('.create_evaluation_type'), new_available_course_evaluation_type_path(@available_course)) %>
</span>
</div>
<div class='card-body'>
Expand Down
18 changes: 14 additions & 4 deletions app/views/course_management/available_courses/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,26 @@
<% end %>
<div class='row mt-3'>
<div class='form-group col-sm-6'>
<%= f.association :unit, collection: Unit.active.coursable.order(:name), label_method: :names_depth_cache %>
<%= f.association :unit,
collection: Unit.active.coursable.order(:name),
label_method: :names_depth_cache %>
</div>
<div class='form-group col-sm-6'>
<%= f.association :curriculum, collection: f.object.unit.present? ? f.object.unit.managed_curriculums : [] %>
<%= f.association :curriculum,
collection: [*f.object.unit.try(:managed_curriculums)] %>
</div>
<div class='form-group col-sm-6'>
<%= f.association :coordinator, collection: f.object.unit.present? ? f.object.unit.subtree_employees : [], label_method: lambda { |c| full_name(c) } %>
<%= f.association :coordinator,
collection: [*f.object.unit.try(:subtree_employees)],
label_method: lambda { |c| full_name(c) } %>
</div>
<div class='form-group col-sm-6'>
<%= f.association :course, collection: f.object.curriculum.present? ? f.object.curriculum.courses : [] %>
<% if f.object.curriculum %>
<% courses = CurriculumDecorator.new(f.object.curriculum)
.openable_courses_for_active_term(appends: f.object.course) %>
<% end %>
<%= f.association :course,
collection: [*courses] %>
</div>
<div class='form-group col-sm-12'>
<%= f.button :submit, class: 'btn btn-outline-success btn-sm' %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div class='card-header'>
<%= fa_icon 'cubes' %><b><%= t('.available_course_groups') %></b>
<span class='pull-right'>
<%= link_to_new(new_available_course_available_course_group_path(@available_course), t('.create_available_course_group')) %>
<%= link_to_new(t('.create_available_course_group'), new_available_course_available_course_group_path(@available_course)) %>
</span>
</div>
<div class='card-body'>
Expand Down
14 changes: 9 additions & 5 deletions app/views/course_management/available_courses/_js.html.erb
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
<script type='text/javascript'>
$(document).ready(function() {
$('#available_course_unit_id, #available_course_course_id').select2();
$('#available_course_coordinator_id').select2();
elements = [
'#available_course_coordinator_id',
'#available_course_course_id',
'#available_course_curriculum_id',
'#available_course_unit_id',
]

$(elements.join(',')).select2();

var parameters = [
{
el: '#available_course_unit_id',
target: '#available_course_curriculum_id',
params: { 'unit_id': '#available_course_unit_id' },
source: '/units/:unit_id/curriculums/',
label_attribute: 'name',
reset_selectors: '#available_course_curriculum_id, #available_course_course_id',
placeholder: 'Müfredat Seçiniz'
},
{
el: '#available_course_curriculum_id',
target: '#available_course_course_id',
params: { 'curriculum_id': '#available_course_curriculum_id' },
source: '/curriculums/:curriculum_id/courses/',
label_attribute: 'name',
source: '/curriculums/:curriculum_id/openable_courses',
reset_selectors: '#available_course_course_id',
placeholder: 'Ders Seçiniz'
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<div class="card-header">
<%= fa_icon 'align-justify', text: t('.available_courses') %>
<span class='pull-right'>
<%= link_to_new new_available_course_path, t('.add_new_available_course') %>
<%= link_to_new t('.add_new_available_course'), new_available_course_path %>
</span>
</div>
<div class="card-body">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class='alert alert-light'>
<%= link_to_new new_course_group_type_path, t('.new_course_group_type_link') %>
<%= link_to_new t('.new_course_group_type_link'), new_course_group_type_path %>
</div>

<div class='row'>
Expand Down
2 changes: 1 addition & 1 deletion app/views/course_management/course_groups/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class='alert alert-light'>
<%= link_to_new new_course_group_path, t('.new_course_group_link') %>
<%= link_to_new t('.new_course_group_link'), new_course_group_path %>
</div>

<%= render 'search' %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/course_management/course_types/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class='alert alert-light'>
<%= link_to_new new_course_type_path, t('.new_course_type_link') %>
<%= link_to_new t('.new_course_type_link'), new_course_type_path %>
</div>

<div class='row'>
Expand Down
Loading

0 comments on commit 083ca49

Please sign in to comment.