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 #265 from omu/language
Browse files Browse the repository at this point in the history
Diller için gerekli geliştirmeleri yap
  • Loading branch information
msdundar authored Sep 7, 2018
2 parents c70acab + 1f9752e commit 3e5c37a
Show file tree
Hide file tree
Showing 23 changed files with 1,046 additions and 4 deletions.
4 changes: 2 additions & 2 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ApplicationController < ActionController::Base
rescue_from ActiveRecord::RecordNotFound, with: :not_found

def set_locale
language = language_params
language = locale_params

if user_signed_in?
current_user.update(preferred_language: language) if language
Expand All @@ -26,7 +26,7 @@ def default_url_options

protected

def language_params
def locale_params
params[:locale] && I18n.available_locales.include?(params[:locale].to_sym) ? params[:locale] : nil
end

Expand Down
48 changes: 48 additions & 0 deletions app/controllers/languages_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# frozen_string_literal: true

class LanguagesController < ApplicationController
include Pagy::Backend

before_action :set_language, only: %i[show edit update destroy]

def index
languages = Language.all

@pagy, @languages = if params[:term].present?
pagy(languages.search(params[:term]))
else
pagy(languages)
end
end

def show; end

def new
@language = Language.new
end

def create
@language = Language.new(language_params)
@language.save ? redirect_to(@language, notice: t('.success')) : render(:new)
end

def edit; end

def update
@language.update(language_params) ? redirect_to(@language, notice: t('.success')) : render(:edit)
end

def destroy
@language.destroy ? redirect_to(languages_path, notice: t('.success')) : redirect_with('warning')
end

private

def set_language
@language = Language.find(params[:id])
end

def language_params
params.require(:language).permit(:name, :iso, :yoksis_code)
end
end
22 changes: 22 additions & 0 deletions app/models/language.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

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

# validations
validates :name, presence: true, uniqueness: true
validates :iso, presence: true, uniqueness: true
validates :yoksis_code, uniqueness: true, allow_nil: true

# callbacks
before_save do
self.name = name.capitalize_all
self.iso = iso.upcase_tr
end
end
32 changes: 32 additions & 0 deletions app/views/languages/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<div class='row'>
<div class='col-sm-12'>
<div class='card'>
<div class='card-header'>
<%= fa_icon 'calendar' %>
<strong><%= form_title %></strong>
</div>
<div class='card-body'>
<%= simple_form_for(language) do |f| %>
<div class='row'>
<div class='form-group col-sm-12'>
<%= f.error_notification %>
</div>
<div class='form-group col-sm-4'>
<%= f.input :name, required: true %>
</div>
<div class='form-group col-sm-4'>
<%= f.input :iso, required: true %>
</div>
<div class='form-group col-sm-4'>
<%= f.input :yoksis_code, required: true %>
</div>
<div class='form-group col-sm-12'>
<%= f.button :submit, class: 'btn btn-outline-success btn-sm' %>
<%= link_to_back(:back) %>
</div>
</div>
<% end %>
</div>
</div>
</div>
</div>
1 change: 1 addition & 0 deletions app/views/languages/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= render 'form', language: @language, form_title: t('.form_title') %>
51 changes: 51 additions & 0 deletions app/views/languages/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<div class='alert alert-light'>
<%= link_to_new new_language_path, t('.new_language_link') %>
</div>

<div class='row'>
<div class='col-lg-12'>
<div class='card'>
<div class='card-header'>
<%= fa_icon 'language', text: t('.card_header') %>
</div>
<div class='card-body'>
<%= form_tag languages_path, method: :get do %>
<div class="form-group">
<%= text_field_tag 'term', params[:term], placeholder: t('.name'), class: 'form-control' %>
</div>
<%= submit_tag t('search'), class: 'btn btn-primary' %>
<% end %>
<hr \>
<table class='table table-responsive-sm table-striped'>
<thead>
<tr>
<th><%= t('.name') %></th>
<th><%= t('.iso') %></th>
<th><%= t('.yoksis_code') %></th>
<th><%= t('actions') %></th>
</tr>
</thead>
<tbody>
<% @languages.each do |language| %>
<tr>
<td><%= language.name %></td>
<td><%= language.iso %></td>
<td><%= language.yoksis_code %></td>
<td>
<%= link_to_show(language_path(language)) %>
<%= link_to_edit(edit_language_path(language)) %>
<%= link_to_destroy(language) %>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>
</div>
<nav aria-label='pagination'>
<ul class='pagination justify-content-center'>
<%== pagy_nav_bootstrap(@pagy) %>
</ul>
</nav>
</div>
</div>
1 change: 1 addition & 0 deletions app/views/languages/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= render 'form', language: @language, form_title: t('.form_title') %>
36 changes: 36 additions & 0 deletions app/views/languages/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<div class="row">
<div class="col-sm-12">
<div class="card">
<div class="card-header">
<%= fa_icon 'language' %><strong><%= @language.name %></strong>
<div class="card-header-actions">
<%= link_to_edit(edit_language_path(@language)) %>
<%= link_to_destroy(@language) %>
</div>
</div>

<div class="card-body">
<table class="table table-responsive-sm">
<tbody>
<tr>
<td><%= t('.name') %></td>
<td><%= @language.name %></td>
</tr>
<tr>
<td><%= t('.iso') %></td>
<td><%= @language.iso %></td>
</tr>
<tr>
<td><%= t('.yoksis_code') %></td>
<td><%= @language.yoksis_code %></td>
</tr>
</tbody>
</table>
</div>

<div class="card-footer">
<%= link_to_back(languages_path) %>
</div>
</div>
</div>
</div>
5 changes: 5 additions & 0 deletions app/views/layouts/shared/_sidebar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@
<%= fa_icon('user', text: t('.users'), class: 'nav-icon') %>
<% end %>
</li>
<li class="nav-item">
<%= link_to languages_path, class: 'nav-link' do %>
<%= fa_icon('language', text: t('.languages'), class: 'nav-icon') %>
<% end %>
</li>
<li class="nav-item nav-dropdown">
<a class="nav-link nav-dropdown-toggle" href="#">
<%= fa_icon('university', class: 'nav-icon') %><%= t('.references') %>
Expand Down
1 change: 1 addition & 0 deletions config/locales/layouts/shared/sidebar_en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ en:
academic_terms: Academic Terms
academic_calendars: Academic Calendars
courses: Courses
languages: Languages
users: Users
references: References
student_disability_types: Disability Types
Expand Down
1 change: 1 addition & 0 deletions config/locales/layouts/shared/sidebar_tr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ tr:
academic_terms: Akademik Dönemler
academic_calendars: Akademik Takvimler
courses: Dersler
languages: Diller
users: Kullanıcılar
references: Referanslar
student_disability_types: Engel Türleri
Expand Down
32 changes: 32 additions & 0 deletions config/locales/models/languages/en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
en:
activerecord:
attributes:
language: &language_attributes
name: Name
iso: ISO Code
yoksis_code: YOKSIS Code
helpers:
submit:
language:
create: Create Language
update: Update Language
languages:
common:
languages: Languages
show:
<<: *language_attributes
index:
<<: *language_attributes
new_language_link: Create a New Language
card_header: Languages
new:
form_title: Create a Language
edit:
form_title: Update the Language
update:
success: Language successfully updated.
create:
success: Language successfully created.
destroy:
success: Language successfully deleted!
warning: Language can not be deleted.
32 changes: 32 additions & 0 deletions config/locales/models/languages/tr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
tr:
activerecord:
attributes:
language: &language_attributes
name: Ad
iso: ISO Kodu
yoksis_code: YOKSIS Kodu
helpers:
submit:
language:
create: Dil Oluştur
update: Dil Güncelle
languages:
common:
languages: Diller
show:
<<: *language_attributes
index:
<<: *language_attributes
new_language_link: Yeni Dil Oluştur
card_header: Diller
new:
form_title: Dil Oluştur
edit:
form_title: Dil Güncelle
update:
success: Dil başarıyla güncellendi.
create:
success: Dil başarıyla oluşturuldu.
destroy:
success: Dil başarıyla silindi!
warning: Dil silinemedi.
3 changes: 2 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
resources :calendar_titles, except: :show
resources :calendar_types
end


resources :languages
resources :units

scope module: :curriculum do
Expand Down
11 changes: 11 additions & 0 deletions db/migrate/20180906103618_create_languages.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class CreateLanguages < ActiveRecord::Migration[5.2]
def change
create_table :languages do |t|
t.string :name, null: false, unique: true
t.string :iso, null: false, unique: true
t.integer :yoksis_code

t.timestamps
end
end
end
10 changes: 9 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2018_08_17_060355) do
ActiveRecord::Schema.define(version: 2018_09_06_103618) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -253,6 +253,14 @@
t.index ["user_id"], name: "index_identities_on_user_id"
end

create_table "languages", force: :cascade do |t|
t.string "name"
t.string "iso"
t.integer "yoksis_code"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

create_table "positions", force: :cascade do |t|
t.bigint "duty_id"
t.bigint "administrative_function_id"
Expand Down
5 changes: 5 additions & 0 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@
end
end

# create languages
YAML.load_file(Rails.root.join('db', 'static_data', 'languages.yml')).each do |_, language|
Language.create(language)
end

# Fetch YOKSIS References
Rake::Task['yoksis:fetch_references'].invoke

Expand Down
Loading

0 comments on commit 3e5c37a

Please sign in to comment.