-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
ismail Akbudak
committed
Jun 22, 2016
1 parent
90e4810
commit 8d81a6c
Showing
26 changed files
with
385 additions
and
2 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
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,54 @@ | ||
class Hq::CitiesController < Hq::ApplicationController | ||
|
||
before_action :set_city, only: [:show, :edit, :update, :destroy] | ||
add_breadcrumb I18n.t('activerecord.models.cities'), :hq_cities_path | ||
|
||
def index | ||
@search = City.includes(:country).order(id: :desc).search(params[:q]) | ||
@cities = @search.result(distinct: true).paginate(page: params[:page]) | ||
respond_with(@cities) | ||
end | ||
|
||
def show | ||
add_breadcrumb @city.name, hq_city_path(@city) | ||
respond_with(@city) | ||
end | ||
|
||
def new | ||
add_breadcrumb t('tooltips.new'), new_hq_city_path | ||
@city = City.new | ||
respond_with(@city) | ||
end | ||
|
||
def edit | ||
add_breadcrumb @city.name, hq_city_path(@city) | ||
add_breadcrumb t('tooltips.edit'), edit_hq_city_path | ||
end | ||
|
||
def create | ||
@city = City.new(city_params) | ||
@city.save | ||
respond_with(:hq, @city) | ||
end | ||
|
||
def update | ||
@city.update(city_params) | ||
respond_with(:hq, @city) | ||
end | ||
|
||
def destroy | ||
@city.destroy | ||
respond_with(:hq, @city, location: request.referer) | ||
end | ||
|
||
private | ||
|
||
def city_params | ||
params.require(:city).permit(:name, :country_id) | ||
end | ||
|
||
def set_city | ||
@city = City.find(params[:id]) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
class Hq::CountriesController < Hq::ApplicationController | ||
|
||
before_action :set_country, only: [:show, :edit, :update, :destroy] | ||
add_breadcrumb I18n.t('activerecord.models.countries'), :hq_countries_path | ||
|
||
def index | ||
@search = Country.order(id: :desc).search(params[:q]) | ||
@countries = @search.result(distinct: true).paginate(page: params[:page]) | ||
respond_with(@countries) | ||
end | ||
|
||
def show | ||
add_breadcrumb @country.name, hq_country_path(@country) | ||
respond_with(@country) | ||
end | ||
|
||
def new | ||
add_breadcrumb t('tooltips.new'), new_hq_country_path | ||
@country = Country.new | ||
respond_with(@country) | ||
end | ||
|
||
def edit | ||
add_breadcrumb @country.name, hq_country_path(@country) | ||
add_breadcrumb t('tooltips.edit'), edit_hq_country_path | ||
end | ||
|
||
def create | ||
@country = Country.new(country_params) | ||
@country.save | ||
respond_with(:hq, @country) | ||
end | ||
|
||
def update | ||
@country.update(country_params) | ||
respond_with(:hq, @country) | ||
end | ||
|
||
def destroy | ||
@country.destroy | ||
respond_with(:hq, @country, location: request.referer) | ||
end | ||
|
||
private | ||
|
||
def country_params | ||
params.require(:country).permit(:name) | ||
end | ||
|
||
def set_country | ||
@country = Country.find(params[:id]) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module ApplicationHelper | ||
|
||
def get_countries | ||
Country.all.map{|c| ["#{c.name}", c.id] } | ||
end | ||
|
||
def get_cities | ||
City.all.map{|c| ["#{c.name}", c.id] } | ||
end | ||
|
||
def get_active_users | ||
User.active.map{|c| ["#{c.email} - #{c.full_name}", c.id] } | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class City < ActiveRecord::Base | ||
|
||
# Relations | ||
belongs_to :country | ||
|
||
# Validations | ||
validates_presence_of :name, :country_id | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class Country < ActiveRecord::Base | ||
|
||
# Relations | ||
has_many :cities, dependent: :restrict_with_error | ||
|
||
# Validations | ||
validates_presence_of :name | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
- if params[:q].present? | ||
= render 'list' | ||
- else | ||
.alert.alert-warning | ||
%p | ||
%h3= t('view.there_is_no_data', resource: City.model_name.human.downcase) | ||
= link_to new_hq_city_path, class: 'btn btn-primary' do | ||
= t('action_button.new', resource_name: City.model_name.human) | ||
= t('btn.add') |
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,12 @@ | ||
%tr | ||
%td= city.id | ||
%td= city.name | ||
%td= city.country.name | ||
%td=l city.created_at | ||
%td.action | ||
= link_to([:hq, city], class: 'btn btn-success', toogle: 'tooltip', title: t('tooltips.zoom')) do | ||
%i.icon-eye-open | ||
= link_to(edit_hq_city_path(city) , class: 'btn btn-info') do | ||
%i.icon-edit | ||
= link_to([:hq, city], class: 'btn btn-danger', method: :delete, data: { confirm: t('tooltips.are_you_sure') }) do | ||
%i.icon-trash |
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,15 @@ | ||
.table-header.row | ||
.col-lg-3 | ||
- if params[:q].present? && (params[:q][:name_cont].present?) | ||
= link_to hq_cities_path, class: 'btn btn-info' do | ||
= t('view.all') | ||
%span.badge= City.count | ||
.col-lg-9 | ||
= search_form_for [:hq, @search], builder: SimpleForm::FormBuilder, html: {class: 'form-inline', data: { turboform: true }} do |f| | ||
.pull-right | ||
= f.input :country_id_eq, label: false, collection: get_countries, include_blank: "#{t('activerecord.attributes.city.country')} #{t('view.select').downcase}", input_html: { class: 'chosen-select form-control'} | ||
.input-group | ||
= f.input_field :name_cont, label: false, class: 'form-control', placeholder: t('view.quick_search') | ||
%span.input-group-btn | ||
= button_tag( class: 'btn btn-primary') do | ||
%i.icon-search |
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,15 @@ | ||
.panel.panel-default | ||
.panel-heading | ||
%i.icon-edit.icon-large | ||
= yield :form_title | ||
.panel-body | ||
= simple_form_for([:hq, @city]) do |f| | ||
= f.error_notification | ||
|
||
.form-inputs | ||
= f.input :name | ||
= f.input :country_id, collection: get_countries, include_blank: t('view.select'), input_html: { class: 'chosen-select' } | ||
|
||
.form-actions | ||
= f.button :submit, class: 'btn btn-primary' | ||
= link_to t('cancel'), hq_cities_path, class: 'btn' |
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,13 @@ | ||
.panel-body.filters | ||
= render 'filters' | ||
%table.table | ||
%thead | ||
%tr | ||
%th= sort_link(@search, :id, t('activerecord.attributes.city.id')) | ||
%th= sort_link(@search, :name, t('activerecord.attributes.city.name')) | ||
%th= sort_link(@search, :country_id, t('activerecord.attributes.city.country_id')) | ||
%th= sort_link(@search, :created_at, t('activerecord.attributes.city.created_at')) | ||
%th.actions | ||
= t('view.actions') | ||
%tbody | ||
= render @cities |
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,3 @@ | ||
- content_for :form_title do | ||
= t('tt.edit', resource_name: City.model_name.human) | ||
= render 'form' |
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,18 @@ | ||
- content_for :toolbar do | ||
= link_to new_hq_city_path, class: 'btn btn-default' do | ||
%i.icon-plus | ||
= t('action_button.new', resource_name: City.model_name.human) | ||
|
||
.panel.panel-default.grid | ||
.panel-heading | ||
%i.icon-table.icon-large | ||
= t('tt.index', resource_name: City.model_name.human) | ||
.panel-tools | ||
.btn-group | ||
%a.btn{href: hq_cities_path, data: {toggle: 'toolbar-tooltip'}, title: t('view.reload')} | ||
%i.icon-refresh | ||
.badge= @cities.count | ||
=blankable(@cities) | ||
.panel-footer | ||
.pagination.pagination-sm | ||
= will_paginate @cities, renderer: BootstrapPagination::Rails, bootstrap: 3 |
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,3 @@ | ||
- content_for :form_title do | ||
= t('tt.new', resource_name: City.model_name.human) | ||
= render 'form' |
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,13 @@ | ||
- content_for :toolbar do | ||
= link_to edit_hq_city_path(@city ), class: 'btn btn-default' do | ||
%i.icon-pencil | ||
= t('action_button.edit') | ||
.panel.panel-default | ||
.panel-heading | ||
%i.icon-edit.icon-large | ||
= t('tt.show', resource_name: City.model_name.human) | ||
.panel-body | ||
= show_for @city do |s| | ||
= s.attribute :id | ||
= s.attribute :name | ||
= s.attribute :name, in: :country |
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,9 @@ | ||
- if params[:q].present? | ||
= render 'list' | ||
- else | ||
.alert.alert-warning | ||
%p | ||
%h3= t('view.there_is_no_data', resource: Country.model_name.human.downcase) | ||
= link_to new_hq_country_path, class: 'btn btn-primary' do | ||
= t('action_button.new', resource_name: Country.model_name.human) | ||
= t('btn.add') |
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,11 @@ | ||
%tr | ||
%td= country.id | ||
%td= country.name | ||
%td=l country.created_at | ||
%td.action | ||
= link_to([:hq, country], class: 'btn btn-success', toogle: 'tooltip', title: t('tooltips.zoom')) do | ||
%i.icon-eye-open | ||
= link_to(edit_hq_country_path(country) , class: 'btn btn-info') do | ||
%i.icon-edit | ||
= link_to([:hq, country], class: 'btn btn-danger', method: :delete, data: { confirm: t('tooltips.are_you_sure') }) do | ||
%i.icon-trash |
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,14 @@ | ||
.table-header.row | ||
.col-lg-3 | ||
- if params[:q].present? && (params[:q][:name_cont].present?) | ||
= link_to hq_countries_path, class: 'btn btn-info' do | ||
= t('view.all') | ||
%span.badge= Country.count | ||
.col-lg-9 | ||
= search_form_for [:hq, @search], builder: SimpleForm::FormBuilder, html: {class: 'form-inline', data: { turboform: true }} do |f| | ||
.pull-right | ||
.input-group | ||
= f.input_field :name_cont, label: false, class: 'form-control', placeholder: t('view.quick_search') | ||
%span.input-group-btn | ||
= button_tag( class: 'btn btn-primary') do | ||
%i.icon-search |
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,14 @@ | ||
.panel.panel-default | ||
.panel-heading | ||
%i.icon-edit.icon-large | ||
= yield :form_title | ||
.panel-body | ||
= simple_form_for([:hq, @country]) do |f| | ||
= f.error_notification | ||
|
||
.form-inputs | ||
= f.input :name | ||
|
||
.form-actions | ||
= f.button :submit, class: 'btn btn-primary' | ||
= link_to t('cancel'), hq_countries_path, class: 'btn' |
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,12 @@ | ||
.panel-body.filters | ||
= render 'filters' | ||
%table.table | ||
%thead | ||
%tr | ||
%th= sort_link(@search, :id, t('activerecord.attributes.country.id')) | ||
%th= sort_link(@search, :name, t('activerecord.attributes.country.name')) | ||
%th= sort_link(@search, :created_at, t('activerecord.attributes.country.created_at')) | ||
%th.actions | ||
= t('view.actions') | ||
%tbody | ||
= render @countries |
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,3 @@ | ||
- content_for :form_title do | ||
= t('tt.edit', resource_name: Country.model_name.human) | ||
= render 'form' |
Oops, something went wrong.